openMSX
ImGuiManager.cc
Go to the documentation of this file.
1#include "ImGuiManager.hh"
2
4#include "ImGuiBreakPoints.hh"
5#include "ImGuiCharacter.hh"
6#include "ImGuiCheatFinder.hh"
7#include "ImGuiCpp.hh"
8#include "ImGuiConnector.hh"
9#include "ImGuiConsole.hh"
10#include "ImGuiDebugger.hh"
12#include "ImGuiHelp.hh"
13#include "ImGuiKeyboard.hh"
14#include "ImGuiMachine.hh"
15#include "ImGuiMedia.hh"
16#include "ImGuiMessages.hh"
17#include "ImGuiOpenFile.hh"
18#include "ImGuiPalette.hh"
19#include "ImGuiOsdIcons.hh"
20#include "ImGuiReverseBar.hh"
21#include "ImGuiSettings.hh"
22#include "ImGuiSoundChip.hh"
23#include "ImGuiSpriteViewer.hh"
24#include "ImGuiSymbols.hh"
25#include "ImGuiTools.hh"
26#include "ImGuiTrainer.hh"
27#include "ImGuiUtils.hh"
28#include "ImGuiVdpRegs.hh"
29#include "ImGuiWatchExpr.hh"
30
31
33#include "CommandException.hh"
34#include "Display.hh"
35#include "Event.hh"
36#include "EventDistributor.hh"
37#include "FileContext.hh"
38#include "FileOperations.hh"
39#include "FilePool.hh"
40#include "Reactor.hh"
41#include "RealDrive.hh"
42#include "RomDatabase.hh"
43#include "RomInfo.hh"
44#include "SettingsConfig.hh"
45
46#include "stl.hh"
47#include "strCat.hh"
48
49#include <imgui.h>
50#include <imgui_impl_opengl3.h>
51#include <imgui_impl_sdl2.h>
52#include <imgui_internal.h>
53#include <CustomFont.ii> // icons for ImGuiFileDialog
54
55#include <SDL.h>
56
57namespace openmsx {
58
59using namespace std::literals;
60
61ImFont* ImGuiManager::addFont(zstring_view filename, int fontSize)
62{
63 auto& io = ImGui::GetIO();
64 if (!filename.empty()) {
65 try {
66 const auto& context = systemFileContext();
67
68 File file(context.resolve(FileOperations::join("skins", filename)));
69 auto fileSize = file.getSize();
70 auto ttfData = std::span(
71 static_cast<uint8_t*>(ImGui::MemAlloc(fileSize)), fileSize);
72 file.read(ttfData);
73
74 static const std::array<ImWchar, 2*6 + 1> ranges = {
75 0x0020, 0x00FF, // Basic Latin + Latin Supplement
76 0x0370, 0x03FF, // Greek and Coptic
77 0x0400, 0x052F, // Cyrillic + Cyrillic Supplement
78 //0x0E00, 0x0E7F, // Thai
79 //0x2000, 0x206F, // General Punctuation
80 //0x2DE0, 0x2DFF, // Cyrillic Extended-A
81 0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
82 0x3131, 0x3163, // Korean alphabets
83 0x31F0, 0x31FF, // Katakana Phonetic Extensions
84 //0x4e00, 0x9FAF, // CJK Ideograms
85 //0xA640, 0xA69F, // Cyrillic Extended-B
86 //0xAC00, 0xD7A3, // Korean characters
87 //0xFF00, 0xFFEF, // Half-width characters
88 0
89 };
90 return io.Fonts->AddFontFromMemoryTTF(
91 ttfData.data(), // transfer ownership of 'ttfData' buffer
92 narrow<int>(ttfData.size()), narrow<float>(fontSize),
93 nullptr, ranges.data());
94 } catch (MSXException& e) {
95 getCliComm().printWarning("Couldn't load font: ", filename, ": ", e.getMessage(),
96 ". Reverted to builtin font");
97 }
98 }
99 return io.Fonts->AddFontDefault(); // embedded "ProggyClean.ttf", size 13
100}
101
102void ImGuiManager::loadFont()
103{
104 ImGuiIO& io = ImGui::GetIO();
105
106 assert(fontProp == nullptr);
108
110 static constexpr std::array<ImWchar, 3> icons_ranges = {ICON_MIN_IGFD, ICON_MAX_IGFD, 0};
111 ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
112 io.Fonts->AddFontFromMemoryCompressedBase85TTF(FONT_ICON_BUFFER_NAME_IGFD, 15.0f, &icons_config, icons_ranges.data());
113 // load debugger icons, also only in default font
114 debugger->loadIcons();
115
116 assert(fontMono == nullptr);
118}
119
120void ImGuiManager::reloadFont()
121{
122 fontProp = fontMono = nullptr;
123
125
126 ImGuiIO& io = ImGui::GetIO();
127 io.Fonts->Clear();
128 loadFont();
129 io.Fonts->Build();
130
132}
133
134void ImGuiManager::initializeImGui()
135{
136 // Setup Dear ImGui context
137 IMGUI_CHECKVERSION();
138 ImGui::CreateContext();
139 ImGuiIO& io = ImGui::GetIO();
140 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard |
141 //ImGuiConfigFlags_NavEnableGamepad | // TODO revisit this later
142 ImGuiConfigFlags_DockingEnable |
143 ImGuiConfigFlags_ViewportsEnable;
144 static auto iniFilename = systemFileContext().resolveCreate("imgui.ini");
145 io.IniFilename = iniFilename.c_str();
146
147 loadFont();
148}
149
150static void cleanupImGui()
151{
152 ImGui::DestroyContext();
153}
154
155
157 : reactor(reactor_)
158 , fontPropFilename(reactor.getCommandController(), "gui_font_default_filename", "TTF font filename for the default GUI font", "DejaVuSans.ttf.gz")
159 , fontMonoFilename(reactor.getCommandController(), "gui_font_mono_filename", "TTF font filename for the monospaced GUI font", "DejaVuSansMono.ttf.gz")
160 , fontPropSize(reactor.getCommandController(), "gui_font_default_size", "size for the default GUI font", 13, 9, 72)
161 , fontMonoSize(reactor.getCommandController(), "gui_font_mono_size", "size for the monospaced GUI font", 13, 9, 72)
162 , windowPos{SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED}
163{
164 settingsConfig.setShortcuts(shortcuts);
165 parts.push_back(this);
166
167 // In order that they appear in the menubar
168 machine = std::make_unique<ImGuiMachine>(*this);
169 media = std::make_unique<ImGuiMedia>(*this);
170 connector = std::make_unique<ImGuiConnector>(*this);
171 reverseBar = std::make_unique<ImGuiReverseBar>(*this);
172 tools = std::make_unique<ImGuiTools>(*this);
173 settings = std::make_unique<ImGuiSettings>(*this);
174 debugger = std::make_unique<ImGuiDebugger>(*this);
175 help = std::make_unique<ImGuiHelp>(*this);
176
177 breakPoints = std::make_unique<ImGuiBreakPoints>(*this);
178 symbols = std::make_unique<ImGuiSymbols>(*this);
179 watchExpr = std::make_unique<ImGuiWatchExpr>(*this);
180 bitmap = std::make_unique<ImGuiBitmapViewer>(*this);
181 character = std::make_unique<ImGuiCharacter>(*this);
182 sprite = std::make_unique<ImGuiSpriteViewer>(*this);
183 vdpRegs = std::make_unique<ImGuiVdpRegs>(*this);
184 palette = std::make_unique<ImGuiPalette>(*this);
185 osdIcons = std::make_unique<ImGuiOsdIcons>(*this);
186 openFile = std::make_unique<ImGuiOpenFile>(*this);
187 trainer = std::make_unique<ImGuiTrainer>(*this);
188 cheatFinder = std::make_unique<ImGuiCheatFinder>(*this);
189 diskManipulator = std::make_unique<ImGuiDiskManipulator>(*this);
190 soundChip = std::make_unique<ImGuiSoundChip>(*this);
191 keyboard = std::make_unique<ImGuiKeyboard>(*this);
192 console = std::make_unique<ImGuiConsole>(*this);
193 messages = std::make_unique<ImGuiMessages>(*this);
194 initializeImGui();
195
196 ImGuiSettingsHandler ini_handler;
197 ini_handler.TypeName = "openmsx";
198 ini_handler.TypeHash = ImHashStr("openmsx");
199 ini_handler.UserData = this;
200 //ini_handler.ClearAllFn = [](ImGuiContext*, ImGuiSettingsHandler* handler) { // optional
201 // // Clear all settings data
202 // static_cast<ImGuiManager*>(handler->UserData)->iniClearAll();
203 //};
204 ini_handler.ReadInitFn = [](ImGuiContext*, ImGuiSettingsHandler* handler) { // optional
205 // Read: Called before reading (in registration order)
206 static_cast<ImGuiManager*>(handler->UserData)->iniReadInit();
207 };
208 ini_handler.ReadOpenFn = [](ImGuiContext*, ImGuiSettingsHandler* handler, const char* name) -> void* { // required
209 // Read: Called when entering into a new ini entry e.g. "[Window][Name]"
210 return static_cast<ImGuiManager*>(handler->UserData)->iniReadOpen(name);
211 };
212 ini_handler.ReadLineFn = [](ImGuiContext*, ImGuiSettingsHandler* handler, void* entry, const char* line) { // required
213 // Read: Called for every line of text within an ini entry
214 static_cast<ImGuiManager*>(handler->UserData)->loadLine(entry, line);
215 };
216 ini_handler.ApplyAllFn = [](ImGuiContext*, ImGuiSettingsHandler* handler) { // optional
217 // Read: Called after reading (in registration order)
218 static_cast<ImGuiManager*>(handler->UserData)->iniApplyAll();
219 };
220 ini_handler.WriteAllFn = [](ImGuiContext*, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf) { // required
221 // Write: Output every entries into 'out_buf'
222 static_cast<ImGuiManager*>(handler->UserData)->iniWriteAll(*out_buf);
223 };
224 ImGui::AddSettingsHandler(&ini_handler);
225
226 auto& eventDistributor = reactor.getEventDistributor();
227 for (auto type : {
239 eventDistributor.registerEventListener(type, *this, EventDistributor::IMGUI);
240 }
241
244 fontPropSize.attach(*this);
245 fontMonoSize.attach(*this);
246}
247
249{
250 fontMonoSize.detach(*this);
251 fontPropSize.detach(*this);
254
255 auto& eventDistributor = reactor.getEventDistributor();
256 for (auto type : {
268 eventDistributor.unregisterEventListener(type, *this);
269 }
270
271 cleanupImGui();
272}
273
275{
276 assert(!contains(parts, part));
277 assert(!contains(toBeAddedParts, part));
278 toBeAddedParts.push_back(part);
279}
280
282{
283 if (auto it1 = ranges::find(parts, part); it1 != parts.end()) {
284 *it1 = nullptr;
285 removeParts = true; // filter nullptr later
286 } else if (auto it2 = ranges::find(toBeAddedParts, part); it2 != toBeAddedParts.end()) {
287 toBeAddedParts.erase(it2); // fine to remove now
288 }
289}
290
291void ImGuiManager::updateParts()
292{
293 if (removeParts) {
294 removeParts = false;
295 parts.erase(ranges::remove(parts, nullptr), parts.end());
296 }
297
298 append(parts, toBeAddedParts);
299 toBeAddedParts.clear();
300}
301
302void ImGuiManager::save(ImGuiTextBuffer& buf)
303{
304 // We cannot query "reactor.getDisplay().getWindowPosition()" here
305 // because display may already be destroyed. Instead Display pushes
306 // window position to here
307 savePersistent(buf, *this, persistentElements);
308}
309
310void ImGuiManager::loadLine(std::string_view name, zstring_view value)
311{
312 loadOnePersistent(name, value, *this, persistentElements);
313}
314
315void ImGuiManager::loadEnd()
316{
317 reactor.getDisplay().setWindowPosition(windowPos);
318}
319
321{
322 return reactor.getInterpreter();
323}
324
326{
327 return reactor.getCliComm();
328}
329
330std::optional<TclObject> ImGuiManager::execute(TclObject command)
331{
332 try {
333 return command.executeCommand(getInterpreter());
334 } catch (CommandException&) {
335 // ignore
336 return {};
337 }
338}
339
340void ImGuiManager::executeDelayed(std::function<void()> action)
341{
342 delayedActionQueue.push_back(std::move(action));
344}
345
347 const std::function<void(const TclObject&)>& ok,
348 const std::function<void(const std::string&)>& error)
349{
350 executeDelayed([this, command, ok, error]() mutable {
351 try {
352 auto result = command.executeCommand(getInterpreter());
353 if (ok) ok(result);
354 } catch (CommandException& e) {
355 if (error) error(e.getMessage());
356 }
357 });
358}
359
361 const std::function<void(const TclObject&)>& ok)
362{
363 executeDelayed(std::move(command), ok,
364 [this](const std::string& message) { this->printError(message); });
365}
366
367void ImGuiManager::printError(std::string_view message)
368{
369 getCliComm().printError(message);
370}
371
372int ImGuiManager::signalEvent(const Event& event)
373{
374 if (auto* evt = get_event_if<SdlEvent>(event)) {
375 const SDL_Event& sdlEvent = evt->getSdlEvent();
377 ImGuiIO& io = ImGui::GetIO();
378 if ((io.WantCaptureMouse &&
379 sdlEvent.type == one_of(SDL_MOUSEMOTION, SDL_MOUSEWHEEL,
380 SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP)) ||
381 (io.WantCaptureKeyboard &&
382 sdlEvent.type == one_of(SDL_KEYDOWN, SDL_KEYUP, SDL_TEXTINPUT))) {
383 static constexpr auto block = EventDistributor::Priority(EventDistributor::IMGUI + 1);
384 return block; // block event for lower priority listeners
385 }
386 } else {
387 switch (getType(event)) {
389 for (auto& action : delayedActionQueue) {
390 std::invoke(action);
391 }
392 delayedActionQueue.clear();
393 break;
394 }
396 const auto& fde = get_event<FileDropEvent>(event);
397 droppedFile = fde.getFileName();
398 handleDropped = true;
399 break;
400 }
401 case EventType::BREAK:
402 debugger->signalBreak();
403 break;
404 default:
406 }
407 }
408 return 0;
409}
410
411void ImGuiManager::update(const Setting& /*setting*/) noexcept
412{
413 needReloadFont = true;
414}
415
416// TODO share code with ImGuiMedia
417static std::vector<std::string> getDrives(MSXMotherBoard* motherBoard)
418{
419 std::vector<std::string> result;
420 if (!motherBoard) return result;
421
422 std::string driveName = "diskX";
423 auto drivesInUse = RealDrive::getDrivesInUse(*motherBoard);
424 for (auto i : xrange(RealDrive::MAX_DRIVES)) {
425 if (!(*drivesInUse)[i]) continue;
426 driveName[4] = char('a' + i);
427 result.push_back(driveName);
428 }
429 return result;
430}
431
432static std::vector<std::string> getSlots(MSXMotherBoard* motherBoard)
433{
434 std::vector<std::string> result;
435 if (!motherBoard) return result;
436
437 auto& slotManager = motherBoard->getSlotManager();
438 std::string cartName = "cartX";
439 for (auto slot : xrange(CartridgeSlotManager::MAX_SLOTS)) {
440 if (!slotManager.slotExists(slot)) continue;
441 cartName[4] = char('a' + slot);
442 result.push_back(cartName);
443 }
444 return result;
445}
446
448{
449 if (!loadIniFile.empty()) {
450 ImGui::LoadIniSettingsFromDisk(loadIniFile.c_str());
451 loadIniFile.clear();
452 }
453 if (needReloadFont) {
454 needReloadFont = false;
455 reloadFont();
456 }
457}
458
460{
461 // Apply added/removed parts. Avoids iterating over a changing vector.
462 updateParts();
463
464 auto* motherBoard = reactor.getMotherBoard();
465 for (auto* part : parts) {
466 part->paint(motherBoard);
467 }
469 openFile->doPaint();
470 }
471
472 auto drawMenu = [&]{
473 for (auto* part : parts) {
474 part->showMenu(motherBoard);
475 }
476 };
477 if (mainMenuBarUndocked) {
478 im::Window("openMSX main menu", &mainMenuBarUndocked, ImGuiWindowFlags_MenuBar, [&]{
479 im::MenuBar([&]{
480 if (ImGui::ArrowButton("re-dock-button", ImGuiDir_Down)) {
481 mainMenuBarUndocked = false;
482 }
483 simpleToolTip("Dock the menu bar in the main openMSX window.");
484 drawMenu();
485 });
486 });
487 } else {
488 bool active = ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow) ||
489 ImGui::IsWindowFocused(ImGuiHoveredFlags_AnyWindow);
490 if (active != guiActive) {
491 guiActive = active;
492 auto& eventDistributor = reactor.getEventDistributor();
493 eventDistributor.distributeEvent(ImGuiActiveEvent(active));
494 }
495 menuAlpha = [&] {
496 if (!menuFade) return 1.0f;
497 auto target = active ? 1.0f : 0.0001f;
498 auto period = active ? 0.5f : 5.0f;
499 return calculateFade(menuAlpha, target, period);
500 }();
501 im::StyleVar(ImGuiStyleVar_Alpha, menuAlpha, [&]{
502 im::MainMenuBar([&]{
503 if (ImGui::ArrowButton("undock-button", ImGuiDir_Up)) {
504 mainMenuBarUndocked = true;
505 }
506 simpleToolTip("Undock the menu bar from the main openMSX window.");
507 drawMenu();
508 });
509 });
510 }
511
512 // drag and drop (move this to ImGuiMedia ?)
513 auto insert2 = [&](std::string_view displayName, TclObject cmd) {
514 auto message = strCat("Inserted ", droppedFile, " in ", displayName);
515 executeDelayed(cmd, [this, message](const TclObject&){
516 insertedInfo = message;
517 openInsertedInfo = true;
518 });
519 };
520 auto insert = [&](std::string_view displayName, std::string_view cmd) {
521 insert2(displayName, makeTclList(cmd, "insert", droppedFile));
522 };
523 if (handleDropped) {
524 handleDropped = false;
525 insertedInfo.clear();
526
527 auto category = execute(makeTclList("openmsx_info", "file_type_category", droppedFile))->getString();
528 if (category == "unknown" && FileOperations::isDirectory(droppedFile)) {
529 category = "disk";
530 }
531
532 auto error = [&](auto&& ...message) {
533 executeDelayed(makeTclList("error", strCat(message...)));
534 };
535 auto cantHandle = [&](auto&& ...message) {
536 error("Can't handle dropped file ", droppedFile, ": ", message...);
537 };
538 auto notPresent = [&](const auto& mediaType) {
539 cantHandle("no ", mediaType, " present.");
540 };
541
542 auto testMedia = [&](std::string_view displayName, std::string_view cmd) {
543 if (auto cmdResult = execute(TclObject(cmd))) {
544 insert(displayName, cmd);
545 } else {
546 notPresent(displayName);
547 }
548 };
549
550 if (category == "disk") {
551 auto list = getDrives(motherBoard);
552 if (list.empty()) {
553 notPresent("disk drive");
554 } else if (list.size() == 1) {
555 const auto& drive = list.front();
556 insert(strCat("disk drive ", char(drive.back() - 'a' + 'A')), drive);
557 } else {
558 selectList = std::move(list);
559 ImGui::OpenPopup("select-drive");
560 }
561 } else if (category == "rom") {
562 auto list = getSlots(motherBoard);
563 if (list.empty()) {
564 notPresent("cartridge slot");
565 return;
566 }
567 selectedMedia = list.front();
568 selectList = std::move(list);
569 if (auto sha1 = reactor.getFilePool().getSha1Sum(droppedFile)) {
570 romInfo = reactor.getSoftwareDatabase().fetchRomInfo(*sha1);
571 } else {
572 romInfo = nullptr;
573 }
574 selectedRomType = romInfo ? romInfo->getRomType()
575 : ROM_UNKNOWN; // auto-detect
576 ImGui::OpenPopup("select-cart");
577 } else if (category == "cassette") {
578 testMedia("casette port", "cassetteplayer");
579 } else if (category == "laserdisc") {
580 testMedia("laser disc player", "laserdiscplayer");
581 } else if (category == "savestate") {
582 executeDelayed(makeTclList("loadstate", droppedFile));
583 } else if (category == "replay") {
584 executeDelayed(makeTclList("reverse", "loadreplay", droppedFile));
585 } else if (category == "script") {
586 executeDelayed(makeTclList("source", droppedFile));
587 } else if (FileOperations::getExtension(droppedFile) == ".txt") {
588 executeDelayed(makeTclList("type_from_file", droppedFile));
589 } else {
590 cantHandle("unknown file type");
591 }
592 }
593 im::Popup("select-drive", [&]{
594 ImGui::TextUnformatted(tmpStrCat("Select disk drive for ", droppedFile));
595 auto n = std::min(3.5f, narrow<float>(selectList.size()));
596 auto height = n * ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().FramePadding.y;
597 im::ListBox("##select-media", {-FLT_MIN, height}, [&]{
598 for (const auto& item : selectList) {
599 auto drive = item.back() - 'a';
600 auto display = strCat(char('A' + drive), ": ", media->displayNameForDriveContent(drive, true));
601 if (ImGui::Selectable(display.c_str())) {
602 insert(strCat("disk drive ", char(drive + 'A')), item);
603 ImGui::CloseCurrentPopup();
604 }
605 }
606 });
607 });
608 im::Popup("select-cart", [&]{
609 ImGui::TextUnformatted(strCat("Filename: ", droppedFile));
610 ImGui::Separator();
611
612 if (!romInfo) {
613 ImGui::TextUnformatted("ROM not present in software database"sv);
614 }
615 im::Table("##extension-info", 2, [&]{
616 const char* buf = reactor.getSoftwareDatabase().getBufferStart();
617 ImGui::TableSetupColumn("description", ImGuiTableColumnFlags_WidthFixed);
618 ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);
619
620 if (romInfo) {
621 ImGuiMedia::printDatabase(*romInfo, buf);
622 }
623 if (ImGui::TableNextColumn()) {
624 ImGui::AlignTextToFramePadding();
625 ImGui::TextUnformatted("Mapper"sv);
626 }
627 if (ImGui::TableNextColumn()) {
628 ImGuiMedia::selectMapperType("##mapper-type", selectedRomType);
629 }
630 });
631 ImGui::Separator();
632
633 if (selectList.size() > 1) {
634 const auto& slotManager = motherBoard->getSlotManager();
635 ImGui::TextUnformatted("Select cartridge slot"sv);
636 auto n = std::min(3.5f, narrow<float>(selectList.size()));
637 auto height = n * ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().FramePadding.y;
638 im::ListBox("##select-media", {-FLT_MIN, height}, [&]{
639 for (const auto& item : selectList) {
640 auto slot = item.back() - 'a';
641 auto display = strCat(
642 char('A' + slot),
643 " (", slotManager.getPsSsString(slot), "): ",
644 media->displayNameForSlotContent(slotManager, slot, true));
645
646 if (ImGui::Selectable(display.c_str(), item == selectedMedia)) {
647 selectedMedia = item;
648 }
649 }
650 });
651 }
652
653 ImGui::Checkbox("Reset MSX on inserting ROM", &media->resetOnInsertRom);
654
655 if (ImGui::Button("Insert ROM")) {
656 auto cmd = makeTclList(selectedMedia, "insert", droppedFile);
657 if (selectedRomType != ROM_UNKNOWN) {
658 cmd.addListElement("-romtype", RomInfo::romTypeToName(selectedRomType));
659 }
660 insert2(strCat("cartridge slot ", char(selectedMedia.back() - 'a' + 'A')), cmd);
661 if (media->resetOnInsertRom) {
662 executeDelayed(TclObject("reset"));
663 }
664 ImGui::CloseCurrentPopup();
665 }
666 ImGui::SameLine();
667 if (ImGui::Button("Cancel")) {
668 ImGui::CloseCurrentPopup();
669 }
670 });
671 if (openInsertedInfo) {
672 openInsertedInfo = false;
673 insertedInfoTimeout = 3.0f;
674 ImGui::OpenPopup("inserted-info");
675 }
676 im::Popup("inserted-info", [&]{
677 insertedInfoTimeout -= ImGui::GetIO().DeltaTime;
678 if (insertedInfoTimeout <= 0.0f || insertedInfo.empty()) {
679 ImGui::CloseCurrentPopup();
680 }
681 im::TextWrapPos(ImGui::GetFontSize() * 35.0f, [&]{
682 ImGui::TextUnformatted(insertedInfo);
683 });
684 });
685}
686
687void ImGuiManager::iniReadInit()
688{
689 updateParts();
690 for (auto* part : parts) {
691 if (part) { // loadStart() could call unregisterPart()
692 part->loadStart();
693 }
694 }
695}
696
697void* ImGuiManager::iniReadOpen(std::string_view name)
698{
699 updateParts();
700 for (auto* part : parts) {
701 if (part->iniName() == name) return part;
702 }
703 return nullptr;
704}
705
706void ImGuiManager::loadLine(void* entry, const char* line_) const
707{
708 zstring_view line = line_;
709 auto pos = line.find('=');
710 if (pos == zstring_view::npos) return;
711 std::string_view name = line.substr(0, pos);
712 zstring_view value = line.substr(pos + 1);
713
714 assert(entry);
715 static_cast<ImGuiPartInterface*>(entry)->loadLine(name, value);
716}
717
718void ImGuiManager::iniApplyAll()
719{
720 updateParts();
721 for (auto* part : parts) {
722 part->loadEnd();
723 }
724}
725
726void ImGuiManager::iniWriteAll(ImGuiTextBuffer& buf)
727{
728 updateParts();
729 for (auto* part : parts) {
730 if (auto name = part->iniName(); !name.empty()) {
731 buf.appendf("[openmsx][%s]\n", name.c_str());
732 part->save(buf);
733 buf.append("\n");
734 }
735 }
736}
737
738} // namespace openmsx
void printError(std::string_view message)
Definition CliComm.cc:15
void printWarning(std::string_view message)
Definition CliComm.cc:10
void setWindowPosition(gl::ivec2 pos)
Definition Display.cc:234
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void distributeEvent(Event &&event)
Schedule the given event for delivery.
void registerEventListener(EventType type, EventListener &listener, Priority priority=OTHER)
Registers a given object to receive certain events.
Priority
Priorities from high to low, higher priority listeners can block events for lower priority listeners.
std::string resolveCreate(std::string_view filename) const
Sha1Sum getSha1Sum(File &file)
Calculate sha1sum for the given File object.
Definition FilePool.cc:58
zstring_view getString() const noexcept
std::unique_ptr< ImGuiMachine > machine
void registerPart(ImGuiPartInterface *part)
std::unique_ptr< ImGuiBreakPoints > breakPoints
void printError(std::string_view message)
std::unique_ptr< ImGuiVdpRegs > vdpRegs
std::unique_ptr< ImGuiCheatFinder > cheatFinder
std::unique_ptr< ImGuiTrainer > trainer
std::unique_ptr< ImGuiDiskManipulator > diskManipulator
IntegerSetting fontMonoSize
std::unique_ptr< ImGuiWatchExpr > watchExpr
std::unique_ptr< ImGuiPalette > palette
std::unique_ptr< ImGuiConnector > connector
std::optional< TclObject > execute(TclObject command)
std::unique_ptr< ImGuiKeyboard > keyboard
std::unique_ptr< ImGuiHelp > help
IntegerSetting fontPropSize
std::unique_ptr< ImGuiSpriteViewer > sprite
Interpreter & getInterpreter()
ImGuiManager(const ImGuiManager &)=delete
std::unique_ptr< ImGuiConsole > console
std::unique_ptr< ImGuiSoundChip > soundChip
std::unique_ptr< ImGuiReverseBar > reverseBar
std::unique_ptr< ImGuiMedia > media
std::unique_ptr< ImGuiMessages > messages
std::unique_ptr< ImGuiOpenFile > openFile
std::unique_ptr< ImGuiOsdIcons > osdIcons
FilenameSetting fontPropFilename
std::unique_ptr< ImGuiBitmapViewer > bitmap
std::unique_ptr< ImGuiSettings > settings
std::unique_ptr< ImGuiDebugger > debugger
std::unique_ptr< ImGuiCharacter > character
void unregisterPart(ImGuiPartInterface *part)
std::unique_ptr< ImGuiTools > tools
void executeDelayed(std::function< void()> action)
FilenameSetting fontMonoFilename
std::unique_ptr< ImGuiSymbols > symbols
static void printDatabase(const RomInfo &romInfo, const char *buf)
static bool selectMapperType(const char *label, RomType &item)
int getInt() const noexcept
Contains the main loop of openMSX.
Definition Reactor.hh:72
MSXMotherBoard * getMotherBoard() const
Definition Reactor.cc:410
Display & getDisplay()
Definition Reactor.hh:90
CliComm & getCliComm()
Definition Reactor.cc:324
Interpreter & getInterpreter()
Definition Reactor.cc:329
EventDistributor & getEventDistributor()
Definition Reactor.hh:86
RomDatabase & getSoftwareDatabase()
Definition Reactor.cc:316
FilePool & getFilePool()
Definition Reactor.hh:95
static std::shared_ptr< DrivesInUse > getDrivesInUse(MSXMotherBoard &motherBoard)
Definition RealDrive.cc:21
const RomInfo * fetchRomInfo(const Sha1Sum &sha1sum) const
Lookup an entry in the database by sha1sum.
static std::string_view romTypeToName(RomType type)
Definition RomInfo.cc:188
RomType getRomType() const
Definition RomInfo.hh:61
void setShortcuts(Shortcuts &shortcuts_)
void detach(Observer< T > &observer)
Definition Subject.hh:55
void attach(Observer< T > &observer)
Definition Subject.hh:49
TclObject executeCommand(Interpreter &interp, bool compile=false)
Interpret this TclObject as a command and execute it.
Definition TclObject.cc:248
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
static constexpr auto npos
constexpr auto find(char c, size_type pos=0) const
constexpr zstring_view substr(size_type pos) const
constexpr auto empty() const
ImGuiID ImHashStr(const char *data_p, size_t data_size, ImGuiID seed)
Definition imgui.cc:2086
bool ImGui_ImplOpenGL3_CreateFontsTexture()
void ImGui_ImplOpenGL3_DestroyFontsTexture()
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event *event)
void TextUnformatted(const std::string &str)
Definition ImGuiUtils.hh:24
constexpr double e
Definition Math.hh:21
std::optional< Context > context
Definition GLContext.cc:10
void Table(const char *str_id, int column, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, std::invocable<> auto next)
Definition ImGuiCpp.hh:479
void MainMenuBar(std::invocable<> auto next)
Definition ImGuiCpp.hh:374
void MenuBar(std::invocable<> auto next)
Definition ImGuiCpp.hh:365
void Window(const char *name, bool *p_open, ImGuiWindowFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:63
void StyleVar(ImGuiStyleVar idx, float val, std::invocable<> auto next)
Definition ImGuiCpp.hh:210
void ListBox(const char *label, const ImVec2 &size, std::invocable<> auto next)
Definition ImGuiCpp.hh:352
void TextWrapPos(float wrap_local_pos_x, std::invocable<> auto next)
Definition ImGuiCpp.hh:232
void Popup(const char *str_id, ImGuiWindowFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:415
string_view getExtension(string_view path)
Returns the extension portion of a path.
bool isDirectory(const Stat &st)
string join(string_view part1, string_view part2)
Join two paths.
This file implemented 3 utility functions:
Definition Autofire.cc:11
const FileContext & systemFileContext()
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void simpleToolTip(std::string_view desc)
Definition ImGuiUtils.hh:66
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
EventType getType(const Event &event)
Definition Event.hh:516
@ ROM_UNKNOWN
Definition RomTypes.hh:94
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:444
float calculateFade(float current, float target, float period)
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:293
auto remove(ForwardRange &&range, const T &value)
Definition ranges.hh:281
auto find(InputRange &&range, const T &value)
Definition ranges.hh:160
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.
Definition stl.hh:32
std::string strCat()
Definition strCat.hh:703
TemporaryString tmpStrCat(Ts &&... ts)
Definition strCat.hh:742
#define UNREACHABLE
constexpr auto xrange(T e)
Definition xrange.hh:132