Exemple #1
0
void Client::typeChatMessage(const std::wstring &message)
{
	// Discard empty line
	if (message.empty())
		return;

	// If message was ate by script API, don't send it to server
	if (m_script->on_sending_message(wide_to_utf8(message))) {
		return;
	}

	// Send to others
	sendChatMessage(message);

	// Show locally
	if (message[0] != L'/') {
		// compatibility code
		if (m_proto_ver < 29) {
			LocalPlayer *player = m_env.getLocalPlayer();
			assert(player);
			std::wstring name = narrow_to_wide(player->getName());
			pushToChatQueue(new ChatMessage(CHATMESSAGE_TYPE_NORMAL, message, name));
		}
	}
}
Exemple #2
0
const char* MSVC_LocaleLookup(const char* raw_shortname) {

	/* NULL is used to read locale only so we need to return it too */
	if (raw_shortname == NULL) return NULL;

	std::string shortname(raw_shortname);
	if (shortname == "C") return "C";
	if (shortname == "") return "";

	static std::string last_raw_value = "";
	static std::string last_full_name = "";
	static bool first_use = true;

	if (last_raw_value == shortname) {
		return last_full_name.c_str();
	}

	if (first_use) {
		EnumSystemLocalesA(UpdateLocaleCallback, LCID_SUPPORTED | LCID_ALTERNATE_SORTS);
		first_use = false;
	}

	last_raw_value = shortname;

	if (glb_supported_locales.find(utf8_to_wide(shortname)) != glb_supported_locales.end()) {
		last_full_name = wide_to_utf8(
			glb_supported_locales[utf8_to_wide(shortname)]);
		return last_full_name.c_str();
	}

	/* empty string is system default */
	errorstream << "MSVC_LocaleLookup: unsupported locale: \"" << shortname
				<< "\" switching to system default!" << std::endl;
	return "";
}
Exemple #3
0
char *
_shttpd_getcwd(char *buffer, int maxlen)
{
	char *result = NULL;
	wchar_t *wbuffer, *wresult;

	if (buffer) {
		/* User-supplied buffer */
		wbuffer = malloc(maxlen * sizeof(wchar_t));
		if (wbuffer == NULL)
			return NULL;
	} else
		/* Dynamically allocated buffer */
		wbuffer = NULL;
	wresult = _wgetcwd(wbuffer, maxlen);
	if (wresult) {
		int err = errno;
		if (buffer) {
			/* User-supplied buffer */
			int n = WideCharToMultiByte(CP_UTF8, 0, wresult, -1, buffer, maxlen, NULL, NULL);
			if (n == 0)
				err = ERANGE;
			free(wbuffer);
			result = buffer;
		} else {
			/* Buffer allocated by _wgetcwd() */
			result = wide_to_utf8(wresult);
			err = errno;
			free(wresult);
		}
		errno = err;
	}
	return result;
}
int ModApiMainMenu::l_gettext(lua_State *L)
{
	std::wstring wtext = wstrgettext((std::string) luaL_checkstring(L, 1));
	lua_pushstring(L, wide_to_utf8(wtext).c_str());

	return 1;
}
Exemple #5
0
	// async_wait 调用到这里
	void operator()(boost::system::error_code ec)
	{
		DWORD r =0;
		INPUT_RECORD ir;
		ReadConsoleInputW(console_handle.native_handle(), &ir, 1, &r);
		if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown && ir.Event.KeyEvent.uChar.UnicodeChar)
		{
			WCHAR c = ir.Event.KeyEvent.uChar.UnicodeChar;
			if (c == L'\b')
			{
				// 退格键啊,应该删了
//				WriteConsoleOutputW();
				if (!readbuf.empty())
				{
					WCHAR lc = readbuf.back();
					
					readbuf.pop_back();
					
					if (lc >= 256)
					{
						WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\b \b \b", 5, &r, 0);
					}
					else
					{
						WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\b \b", 3, &r, 0);
					}
				}
			}
			else
			{
				readbuf.push_back(c);
			}

			if (iswprint(c))
			{
				WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), &c, 1, &r, 0);
			}
			// 判定 是不是读取到了 "\n"
			// 是的话就可以调用 handler 了
			if (c == L'\r')
			{
				// 读取到行尾啦!回调吧
				std::string thisline = wide_to_utf8(std::wstring(readbuf.data(), readbuf.size()));
				readbuf.clear();
				WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, &r, 0);
				SetConsoleMode(console_handle.native_handle(), m_savedmode);
				m_handler(thisline);
				return;
			}
		}

		// 重复读取
		console_handle.async_wait(*this);
	}
void GUIFileSelectMenu::acceptInput() {
	if ((m_text_dst != 0) && (this->m_formname != "")){
		StringMap fields;

		if (m_accepted)
			fields[m_formname + "_accepted"] = wide_to_utf8(m_fileOpenDialog->getFileName());
		else
			fields[m_formname + "_canceled"] = m_formname;

		this->m_text_dst->gotText(fields);
	}
}
void TerminalChatConsole::draw_text()
{
	ChatBuffer& buf = m_chat_backend.getConsoleBuffer();
	for (u32 row = 0; row < buf.getRows(); row++) {
		move_for_backend(row, 0);
		clrtoeol();
		const ChatFormattedLine& line = buf.getFormattedLine(row);
		if (line.fragments.empty())
			continue;
		for (const ChatFormattedFragment &fragment : line.fragments) {
			addstr(wide_to_utf8(fragment.text.getString()).c_str());
		}
	}
}
void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
{
	// The server didn't like our password. Note, this needs
	// to be processed even if the serialisation format has
	// not been agreed yet, the same as TOCLIENT_INIT.
	m_access_denied = true;
	m_access_denied_reason = "Unknown";

	if (pkt->getCommand() != TOCLIENT_ACCESS_DENIED) {
		// 13/03/15 Legacy code from 0.4.12 and lesser but is still used
		// in some places of the server code
		if (pkt->getSize() >= 2) {
			std::wstring wide_reason;
			*pkt >> wide_reason;
			m_access_denied_reason = wide_to_utf8(wide_reason);
		}
		return;
	}
void GUIFileSelectMenu::acceptInput()
{
	if ((m_text_dst != 0) && (this->m_formname != "")) {
		StringMap fields;
		if (m_accepted) {
			std::string path;
			if (!m_file_select_dialog) {
				core::string<fschar_t> string =
						m_fileOpenDialog->getDirectoryName();
				path = std::string(string.c_str());
			} else {
				path = wide_to_utf8(m_fileOpenDialog->getFileName());
			}
			fields[m_formname + "_accepted"] = path;
		} else {
			fields[m_formname + "_canceled"] = m_formname;
		}
		this->m_text_dst->gotText(fields);
	}
	quitMenu();
}
Exemple #10
0
    int LibInitialize()
    {
        start_memory_tracking();

        asr::global_logger().add_target(&g_log_target);

        std::stringstream sstr;
        sstr << "appleseed-max ";
        sstr << wide_to_utf8(PluginVersionString);
        sstr << " plug-in for ";
        sstr << asf::Appleseed::get_synthetic_version_string();
        sstr << " loaded";

        const std::string title = sstr.str();
        const std::string sep(title.size(), '=');

        RENDERER_LOG_INFO("%s", sep.c_str());
        RENDERER_LOG_INFO("%s", title.c_str());
        RENDERER_LOG_INFO("%s", sep.c_str());

        return TRUE;
    }
void TerminalChatConsole::step(int ch)
{
	bool complete_redraw_needed = false;

	// empty queues
	while (!m_chat_interface->outgoing_queue.empty()) {
		ChatEvent *evt = m_chat_interface->outgoing_queue.pop_frontNoEx();
		switch (evt->type) {
			case CET_NICK_REMOVE:
				m_nicks.remove(((ChatEventNick *)evt)->nick);
				break;
			case CET_NICK_ADD:
				m_nicks.push_back(((ChatEventNick *)evt)->nick);
				break;
			case CET_CHAT:
				complete_redraw_needed = true;
				// This is only used for direct replies from commands
				// or for lua's print() functionality
				m_chat_backend.addMessage(L"", ((ChatEventChat *)evt)->evt_msg);
				break;
			case CET_TIME_INFO:
				ChatEventTimeInfo *tevt = (ChatEventTimeInfo *)evt;
				m_game_time = tevt->game_time;
				m_time_of_day = tevt->time;
		};
		delete evt;
	}
	while (!m_log_output.queue.empty()) {
		complete_redraw_needed = true;
		std::pair<LogLevel, std::string> p = m_log_output.queue.pop_frontNoEx();
		if (p.first > m_log_level)
			continue;

		m_chat_backend.addMessage(
			utf8_to_wide(Logger::getLevelLabel(p.first)),
			utf8_to_wide(p.second));
	}

	// handle input
	if (!m_esc_mode) {
		handleInput(ch, complete_redraw_needed);
	} else {
		switch (ch) {
			case ERR: // no input
				break;
			case 27: // ESC
				// Toggle ESC mode
				m_esc_mode = !m_esc_mode;
				break;
			case 'L':
				m_log_level--;
				m_log_level = MYMAX(m_log_level, LL_NONE + 1); // LL_NONE isn't accessible
				break;
			case 'l':
				m_log_level++;
				m_log_level = MYMIN(m_log_level, LL_MAX - 1);
				break;
		}
	}

	// was there a resize?
	int xn, yn;
	getmaxyx(stdscr, yn, xn);
	if (xn != m_cols || yn != m_rows) {
		m_cols = xn;
		m_rows = yn;
		m_can_draw_text = reformat_backend(&m_chat_backend, m_rows, m_cols);
		complete_redraw_needed = true;
	}

	// draw title
	move(0, 0);
	clrtoeol();
	addstr(PROJECT_NAME_C);
	addstr(" ");
	addstr(g_version_hash);

	u32 minutes = m_time_of_day % 1000;
	u32 hours = m_time_of_day / 1000;
	minutes = (float)minutes / 1000 * 60;

	if (m_game_time)
		printw(" | Game %d Time of day %02d:%02d ",
			m_game_time, hours, minutes);

	// draw text
	if (complete_redraw_needed && m_can_draw_text)
		draw_text();

	// draw prompt
	if (!m_esc_mode) {
		// normal prompt
		ChatPrompt& prompt = m_chat_backend.getPrompt();
		std::string prompt_text = wide_to_utf8(prompt.getVisiblePortion());
		move(m_rows - 1, 0);
		clrtoeol();
		addstr(prompt_text.c_str());
		// Draw cursor
		s32 cursor_pos = prompt.getVisibleCursorPosition();
		if (cursor_pos >= 0) {
			move(m_rows - 1, cursor_pos);
		}
	} else {
		// esc prompt
		move(m_rows - 1, 0);
		clrtoeol();
		printw("[ESC] Toggle ESC mode |"
			" [CTRL+C] Shut down |"
			" (L) in-, (l) decrease loglevel %s",
			Logger::getLevelLabel((LogLevel) m_log_level).c_str());
	}

	refresh();
}
Exemple #12
0
	std::string parse(std::string templ_text, data_map &data)
	{
		return wide_to_utf8(parse(utf8_to_wide(templ_text), data));
	}
Exemple #13
0
void TextDestGuiEngine::gotText(std::wstring text)
{
	m_engine->getScriptIface()->handleMainMenuEvent(wide_to_utf8(text));
}
Exemple #14
0
void TestUtilities::testUTF8()
{
	UASSERT(wide_to_utf8(utf8_to_wide("")) == "");
	UASSERT(wide_to_utf8(utf8_to_wide("the shovel dug a crumbly node!"))
		== "the shovel dug a crumbly node!");
}
int AppleseedRenderer::Render(
    TimeValue               time,
    Bitmap*                 bitmap,
    FrameRendParams&        frame_rend_params,
    HWND                    hwnd,
    RendProgressCallback*   progress_cb,
    ViewParams*             view_params)
{
    SuspendAll suspend(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

    m_time = time;

    if (view_params)
        m_view_params = *view_params;

    if (m_view_node)
        get_view_params_from_view_node(m_view_params, m_view_node, time);

    // Retrieve and tweak renderer settings.
    RendererSettings renderer_settings = m_settings;
    if (m_rend_params.inMtlEdit)
    {
        renderer_settings.m_pixel_samples = m_rend_params.mtlEditAA ? 32 : 4;
        renderer_settings.m_passes = 1;
        renderer_settings.m_gi = true;
        renderer_settings.m_background_emits_light = false;
    }

    // Collect the entities we're interested in.
    if (progress_cb)
        progress_cb->SetTitle(_T("Collecting Entities..."));
    m_entities.clear();
    MaxSceneEntityCollector collector(m_entities);
    collector.collect(m_scene);

    // Call RenderBegin() on all object instances.
    render_begin(m_entities.m_objects, m_time);

    // Build the project.
    if (progress_cb)
        progress_cb->SetTitle(_T("Building Project..."));
    asf::auto_release_ptr<asr::Project> project(
        build_project(
            m_entities,
            m_default_lights,
            m_view_params,
            m_rend_params,
            frame_rend_params,
            renderer_settings,
            bitmap,
            time));

    if (m_rend_params.inMtlEdit)
    {
        // Write the project to disk, useful to debug material previews.
        // asr::ProjectFileWriter::write(project.ref(), "MaterialEditor.appleseed");

        // Render the project.
        if (progress_cb)
            progress_cb->SetTitle(_T("Rendering..."));
        render(project.ref(), m_settings, bitmap, progress_cb);
    }
    else
    {
        // Write the project to disk.
        if (m_settings.m_output_mode == RendererSettings::OutputMode::SaveProjectOnly ||
            m_settings.m_output_mode == RendererSettings::OutputMode::SaveProjectAndRender)
        {
            if (progress_cb)
                progress_cb->SetTitle(_T("Writing Project To Disk..."));
            asr::ProjectFileWriter::write(
                project.ref(),
                wide_to_utf8(m_settings.m_project_file_path).c_str());
        }

        // Render the project.
        if (m_settings.m_output_mode == RendererSettings::OutputMode::RenderOnly ||
            m_settings.m_output_mode == RendererSettings::OutputMode::SaveProjectAndRender)
        {
            if (progress_cb)
                progress_cb->SetTitle(_T("Rendering..."));
            if (m_settings.m_low_priority_mode)
            {
                asf::ProcessPriorityContext background_context(
                    asf::ProcessPriority::ProcessPriorityLow,
                    &asr::global_logger());
                render(project.ref(), m_settings, bitmap, progress_cb);
            }
            else
            {
                render(project.ref(), m_settings, bitmap, progress_cb);
            }
        }
    }

    if (progress_cb)
        progress_cb->SetTitle(_T("Done."));

    // Success.
    return 1;
}