aboutsummaryrefslogtreecommitdiff
path: root/src/gui/guiPathSelectMenu.cpp
blob: 489927a11d822989a6332caba3225169d82f1463 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<
core.async_jobs = {}

local function handle_job(jobid, serialized_retval)
	local retval = core.deserialize(serialized_retval)
	assert(type(core.async_jobs[jobid]) == "function")
	core.async_jobs[jobid](retval)
	core.async_jobs[jobid] = nil
end

if core.register_globalstep then
	core.register_globalstep(function(dtime)
		for i, job in ipairs(core.get_finished_jobs()) do
			handle_job(job.jobid, job.retval)
		end
	end)
else
	core.async_event_handler = handle_job
end

function core.handle_async(func, parameter, callback)
	-- Serialize function
	local serialized_func = string.dump(func)

	assert(serialized_func ~= nil)

	-- Serialize parameters
	local serialized_param = core.serialize(parameter)

	if serialized_param == nil then
		return false
	end

	local jobid = core.do_async_callback(serialized_func, serialized_param)

	core.async_jobs[jobid] = callback

	return true
end

uManager *menumgr, const std::string &title, const std::string &formname, bool is_file_select) : GUIModalMenu(env, parent, id, menumgr), m_title(utf8_to_wide(title)), m_formname(formname), m_file_select_dialog(is_file_select) { } GUIFileSelectMenu::~GUIFileSelectMenu() { removeChildren(); setlocale(LC_NUMERIC, "C"); } void GUIFileSelectMenu::regenerateGui(v2u32 screensize) { removeChildren(); m_fileOpenDialog = 0; core::dimension2du size(600 * m_gui_scale, 400 * m_gui_scale); core::rect<s32> rect(0, 0, screensize.X, screensize.Y); DesiredRect = rect; recalculateAbsolutePosition(false); m_fileOpenDialog = Environment->addFileOpenDialog(m_title.c_str(), false, this, -1); core::position2di pos = core::position2di(screensize.X / 2 - size.Width / 2, screensize.Y / 2 - size.Height / 2); m_fileOpenDialog->setRelativePosition(pos); m_fileOpenDialog->setMinSize(size); } void GUIFileSelectMenu::drawMenu() { gui::IGUISkin *skin = Environment->getSkin(); if (!skin) return; gui::IGUIElement::draw(); } void GUIFileSelectMenu::acceptInput() { if (m_text_dst && !m_formname.empty()) { 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; } m_text_dst->gotText(fields); } quitMenu(); } bool GUIFileSelectMenu::OnEvent(const SEvent &event) { if (event.EventType == irr::EET_GUI_EVENT) { switch (event.GUIEvent.EventType) { case gui::EGET_ELEMENT_CLOSED: case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED: m_accepted = false; acceptInput(); return true; case gui::EGET_DIRECTORY_SELECTED: m_accepted = !m_file_select_dialog; acceptInput(); return true; case gui::EGET_FILE_SELECTED: m_accepted = m_file_select_dialog; acceptInput(); return true; default: // ignore this event break; } } return Parent ? Parent->OnEvent(event) : false; }