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
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 parts.push_back(this);
165
166 // In order that they appear in the menubar
167 machine = std::make_unique<ImGuiMachine>(*this);
168 media = std::make_unique<ImGuiMedia>(*this);
169 connector = std::make_unique<ImGuiConnector>(*this);
170 reverseBar = std::make_unique<ImGuiReverseBar>(*this);
171 tools = std::make_unique<ImGuiTools>(*this);
172 settings = std::make_unique<ImGuiSettings>(*this);
173 debugger = std::make_unique<ImGuiDebugger>(*this);
174 help = std::make_unique<ImGuiHelp>(*this);
175
176 breakPoints = std::make_unique<ImGuiBreakPoints>(*this);
177 symbols = std::make_unique<ImGuiSymbols>(*this);
178 watchExpr = std::make_unique<ImGuiWatchExpr>(*this);
179 bitmap = std::make_unique<ImGuiBitmapViewer>(*this);
180 character = std::make_unique<ImGuiCharacter>(*this);
181 sprite = std::make_unique<ImGuiSpriteViewer>(*this);
182 vdpRegs = std::make_unique<ImGuiVdpRegs>(*this);
183 palette = std::make_unique<ImGuiPalette>(*this);
184 osdIcons = std::make_unique<ImGuiOsdIcons>(*this);
185 openFile = std::make_unique<ImGuiOpenFile>(*this);
186 trainer = std::make_unique<ImGuiTrainer>(*this);
187 cheatFinder = std::make_unique<ImGuiCheatFinder>(*this);
188 diskManipulator = std::make_unique<ImGuiDiskManipulator>(*this);
189 soundChip = std::make_unique<ImGuiSoundChip>(*this);
190 keyboard = std::make_unique<ImGuiKeyboard>(*this);
191 console = std::make_unique<ImGuiConsole>(*this);
192 messages = std::make_unique<ImGuiMessages>(*this);
193 initializeImGui();
194
195 ImGuiSettingsHandler ini_handler;
196 ini_handler.TypeName = "openmsx";
197 ini_handler.TypeHash = ImHashStr("openmsx");
198 ini_handler.UserData = this;
199 //ini_handler.ClearAllFn = [](ImGuiContext*, ImGuiSettingsHandler* handler) { // optional
200 // // Clear all settings data
201 // static_cast<ImGuiManager*>(handler->UserData)->iniClearAll();
202 //};
203 ini_handler.ReadInitFn = [](ImGuiContext*, ImGuiSettingsHandler* handler) { // optional
204 // Read: Called before reading (in registration order)
205 static_cast<ImGuiManager*>(handler->UserData)->iniReadInit();
206 };
207 ini_handler.ReadOpenFn = [](ImGuiContext*, ImGuiSettingsHandler* handler, const char* name) -> void* { // required
208 // Read: Called when entering into a new ini entry e.g. "[Window][Name]"
209 return static_cast<ImGuiManager*>(handler->UserData)->iniReadOpen(name);
210 };
211 ini_handler.ReadLineFn = [](ImGuiContext*, ImGuiSettingsHandler* handler, void* entry, const char* line) { // required
212 // Read: Called for every line of text within an ini entry
213 static_cast<ImGuiManager*>(handler->UserData)->loadLine(entry, line);
214 };
215 ini_handler.ApplyAllFn = [](ImGuiContext*, ImGuiSettingsHandler* handler) { // optional
216 // Read: Called after reading (in registration order)
217 static_cast<ImGuiManager*>(handler->UserData)->iniApplyAll();
218 };
219 ini_handler.WriteAllFn = [](ImGuiContext*, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf) { // required
220 // Write: Output every entries into 'out_buf'
221 static_cast<ImGuiManager*>(handler->UserData)->iniWriteAll(*out_buf);
222 };
223 ImGui::AddSettingsHandler(&ini_handler);
224
225 auto& eventDistributor = reactor.getEventDistributor();
226 using enum EventType;
230 eventDistributor.registerEventListener(type, *this, EventDistributor::Priority::IMGUI);
231 }
232
235 fontPropSize.attach(*this);
236 fontMonoSize.attach(*this);
237}
238
240{
241 fontMonoSize.detach(*this);
242 fontPropSize.detach(*this);
245
246 auto& eventDistributor = reactor.getEventDistributor();
247 using enum EventType;
248 for (auto type : {BREAK, IMGUI_DELAYED_ACTION, FILE_DROP, WINDOW, TEXT,
251 eventDistributor.unregisterEventListener(type, *this);
252 }
253
254 cleanupImGui();
255}
256
258{
259 assert(!contains(parts, part));
260 assert(!contains(toBeAddedParts, part));
261 toBeAddedParts.push_back(part);
262}
263
265{
266 if (auto it1 = ranges::find(parts, part); it1 != parts.end()) {
267 *it1 = nullptr;
268 removeParts = true; // filter nullptr later
269 } else if (auto it2 = ranges::find(toBeAddedParts, part); it2 != toBeAddedParts.end()) {
270 toBeAddedParts.erase(it2); // fine to remove now
271 }
272}
273
274void ImGuiManager::updateParts()
275{
276 if (removeParts) {
277 removeParts = false;
278 parts.erase(ranges::remove(parts, nullptr), parts.end());
279 }
280
281 append(parts, toBeAddedParts);
282 toBeAddedParts.clear();
283}
284
285void ImGuiManager::save(ImGuiTextBuffer& buf)
286{
287 // We cannot query "reactor.getDisplay().getWindowPosition()" here
288 // because display may already be destroyed. Instead Display pushes
289 // window position to here
290 savePersistent(buf, *this, persistentElements);
291}
292
293void ImGuiManager::loadLine(std::string_view name, zstring_view value)
294{
295 loadOnePersistent(name, value, *this, persistentElements);
296}
297
298void ImGuiManager::loadEnd()
299{
300 reactor.getDisplay().setWindowPosition(windowPos);
301}
302
304{
305 return reactor.getInterpreter();
306}
307
309{
310 return reactor.getCliComm();
311}
312
313std::optional<TclObject> ImGuiManager::execute(TclObject command)
314{
315 try {
316 return command.executeCommand(getInterpreter());
317 } catch (CommandException&) {
318 // ignore
319 return {};
320 }
321}
322
323void ImGuiManager::executeDelayed(std::function<void()> action)
324{
325 delayedActionQueue.push_back(std::move(action));
327}
328
330 const std::function<void(const TclObject&)>& ok,
331 const std::function<void(const std::string&)>& error)
332{
333 executeDelayed([this, command, ok, error]() mutable {
334 try {
335 auto result = command.executeCommand(getInterpreter());
336 if (ok) ok(result);
337 } catch (CommandException& e) {
338 if (error) error(e.getMessage());
339 }
340 });
341}
342
344 const std::function<void(const TclObject&)>& ok)
345{
346 executeDelayed(std::move(command), ok,
347 [this](const std::string& message) { this->printError(message); });
348}
349
350void ImGuiManager::printError(std::string_view message)
351{
352 getCliComm().printError(message);
353}
354
355bool ImGuiManager::signalEvent(const Event& event)
356{
357 if (auto* evt = get_event_if<SdlEvent>(event)) {
358 const SDL_Event& sdlEvent = evt->getSdlEvent();
360 const ImGuiIO& io = ImGui::GetIO();
361 if ((io.WantCaptureMouse &&
362 sdlEvent.type == one_of(SDL_MOUSEMOTION, SDL_MOUSEWHEEL,
363 SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP)) ||
364 (io.WantCaptureKeyboard &&
365 sdlEvent.type == one_of(SDL_KEYDOWN, SDL_KEYUP, SDL_TEXTINPUT))) {
366 return true; // block event for lower priority listeners
367 }
368 } else {
369 switch (getType(event)) {
371 for (auto& action : delayedActionQueue) {
372 std::invoke(action);
373 }
374 delayedActionQueue.clear();
375 break;
376 }
378 const auto& fde = get_event<FileDropEvent>(event);
379 droppedFile = fde.getFileName();
380 handleDropped = true;
381 break;
382 }
383 case EventType::BREAK:
384 debugger->signalBreak();
385 break;
386 default:
388 }
389 }
390 return false;
391}
392
393void ImGuiManager::update(const Setting& /*setting*/) noexcept
394{
395 needReloadFont = true;
396}
397
398// TODO share code with ImGuiMedia
399static std::vector<std::string> getDrives(MSXMotherBoard* motherBoard)
400{
401 std::vector<std::string> result;
402 if (!motherBoard) return result;
403
404 std::string driveName = "diskX";
405 auto drivesInUse = RealDrive::getDrivesInUse(*motherBoard);
406 for (auto i : xrange(RealDrive::MAX_DRIVES)) {
407 if (!(*drivesInUse)[i]) continue;
408 driveName[4] = char('a' + i);
409 result.push_back(driveName);
410 }
411 return result;
412}
413
414static std::vector<std::string> getSlots(MSXMotherBoard* motherBoard)
415{
416 std::vector<std::string> result;
417 if (!motherBoard) return result;
418
419 const auto& slotManager = motherBoard->getSlotManager();
420 std::string cartName = "cartX";
421 for (auto slot : xrange(CartridgeSlotManager::MAX_SLOTS)) {
422 if (!slotManager.slotExists(slot)) continue;
423 cartName[4] = char('a' + slot);
424 result.push_back(cartName);
425 }
426 return result;
427}
428
430{
431 if (!loadIniFile.empty()) {
432 ImGui::LoadIniSettingsFromDisk(loadIniFile.c_str());
433 loadIniFile.clear();
434 }
435 if (needReloadFont) {
436 needReloadFont = false;
437 reloadFont();
438 }
439}
440
442{
443 // Apply added/removed parts. Avoids iterating over a changing vector.
444 updateParts();
445
446 auto* motherBoard = reactor.getMotherBoard();
447 for (auto* part : parts) {
448 part->paint(motherBoard);
449 }
451 openFile->doPaint();
452 }
453
454 auto drawMenu = [&]{
455 for (auto* part : parts) {
456 part->showMenu(motherBoard);
457 }
458 };
459 if (mainMenuBarUndocked) {
460 im::Window("openMSX main menu", &mainMenuBarUndocked, ImGuiWindowFlags_MenuBar, [&]{
461 im::MenuBar([&]{
462 if (ImGui::ArrowButton("re-dock-button", ImGuiDir_Down)) {
463 mainMenuBarUndocked = false;
464 }
465 simpleToolTip("Dock the menu bar in the main openMSX window.");
466 drawMenu();
467 });
468 });
469 } else {
470 bool active = ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow) ||
471 ImGui::IsWindowFocused(ImGuiHoveredFlags_AnyWindow);
472 if (active != guiActive) {
473 guiActive = active;
474 auto& eventDistributor = reactor.getEventDistributor();
475 eventDistributor.distributeEvent(ImGuiActiveEvent(active));
476 }
477 menuAlpha = [&] {
478 if (!menuFade) return 1.0f;
479 auto target = active ? 1.0f : 0.0001f;
480 auto period = active ? 0.5f : 5.0f;
481 return calculateFade(menuAlpha, target, period);
482 }();
483 im::StyleVar(ImGuiStyleVar_Alpha, menuAlpha, [&]{
484 im::MainMenuBar([&]{
485 if (ImGui::ArrowButton("undock-button", ImGuiDir_Up)) {
486 mainMenuBarUndocked = true;
487 }
488 simpleToolTip("Undock the menu bar from the main openMSX window.");
489 drawMenu();
490 });
491 });
492 }
493
494 // drag and drop (move this to ImGuiMedia ?)
495 auto insert2 = [&](std::string_view displayName, TclObject cmd) {
496 auto message = strCat("Inserted ", droppedFile, " in ", displayName);
497 executeDelayed(cmd, [this, message](const TclObject&){
498 insertedInfo = message;
499 openInsertedInfo = true;
500 });
501 };
502 auto insert = [&](std::string_view displayName, std::string_view cmd) {
503 insert2(displayName, makeTclList(cmd, "insert", droppedFile));
504 };
505 if (handleDropped) {
506 handleDropped = false;
507 insertedInfo.clear();
508
509 auto category = execute(makeTclList("openmsx_info", "file_type_category", droppedFile))->getString();
510 if (category == "unknown" && FileOperations::isDirectory(droppedFile)) {
511 category = "disk";
512 }
513
514 auto error = [&](auto&& ...message) {
515 executeDelayed(makeTclList("error", strCat(message...)));
516 };
517 auto cantHandle = [&](auto&& ...message) {
518 error("Can't handle dropped file ", droppedFile, ": ", message...);
519 };
520 auto notPresent = [&](const auto& mediaType) {
521 cantHandle("no ", mediaType, " present.");
522 };
523
524 auto testMedia = [&](std::string_view displayName, std::string_view cmd) {
525 if (auto cmdResult = execute(TclObject(cmd))) {
526 insert(displayName, cmd);
527 } else {
528 notPresent(displayName);
529 }
530 };
531
532 if (category == "disk") {
533 auto list = getDrives(motherBoard);
534 if (list.empty()) {
535 notPresent("disk drive");
536 } else if (list.size() == 1) {
537 const auto& drive = list.front();
538 insert(strCat("disk drive ", char(drive.back() - 'a' + 'A')), drive);
539 } else {
540 selectList = std::move(list);
541 ImGui::OpenPopup("select-drive");
542 }
543 } else if (category == "rom") {
544 auto list = getSlots(motherBoard);
545 if (list.empty()) {
546 notPresent("cartridge slot");
547 return;
548 }
549 selectedMedia = list.front();
550 selectList = std::move(list);
551 if (auto sha1 = reactor.getFilePool().getSha1Sum(droppedFile)) {
552 romInfo = reactor.getSoftwareDatabase().fetchRomInfo(*sha1);
553 } else {
554 romInfo = nullptr;
555 }
556 selectedRomType = romInfo ? romInfo->getRomType()
557 : RomType::UNKNOWN; // auto-detect
558 ImGui::OpenPopup("select-cart");
559 } else if (category == "cassette") {
560 testMedia("casette port", "cassetteplayer");
561 } else if (category == "laserdisc") {
562 testMedia("laser disc player", "laserdiscplayer");
563 } else if (category == "savestate") {
564 executeDelayed(makeTclList("loadstate", droppedFile));
565 } else if (category == "replay") {
566 executeDelayed(makeTclList("reverse", "loadreplay", droppedFile));
567 } else if (category == "script") {
568 executeDelayed(makeTclList("source", droppedFile));
569 } else if (FileOperations::getExtension(droppedFile) == ".txt") {
570 executeDelayed(makeTclList("type_from_file", droppedFile));
571 } else {
572 cantHandle("unknown file type");
573 }
574 }
575 im::Popup("select-drive", [&]{
576 ImGui::TextUnformatted(tmpStrCat("Select disk drive for ", droppedFile));
577 auto n = std::min(3.5f, narrow<float>(selectList.size()));
578 auto height = n * ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().FramePadding.y;
579 im::ListBox("##select-media", {-FLT_MIN, height}, [&]{
580 for (const auto& item : selectList) {
581 auto drive = item.back() - 'a';
582 auto display = strCat(char('A' + drive), ": ", media->displayNameForDriveContent(drive, true));
583 if (ImGui::Selectable(display.c_str())) {
584 insert(strCat("disk drive ", char(drive + 'A')), item);
585 ImGui::CloseCurrentPopup();
586 }
587 }
588 });
589 });
590 im::Popup("select-cart", [&]{
591 ImGui::TextUnformatted(strCat("Filename: ", droppedFile));
592 ImGui::Separator();
593
594 if (!romInfo) {
595 ImGui::TextUnformatted("ROM not present in software database"sv);
596 }
597 im::Table("##extension-info", 2, [&]{
598 const char* buf = reactor.getSoftwareDatabase().getBufferStart();
599 ImGui::TableSetupColumn("description", ImGuiTableColumnFlags_WidthFixed);
600 ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);
601
602 if (romInfo) {
603 ImGuiMedia::printDatabase(*romInfo, buf);
604 }
605 if (ImGui::TableNextColumn()) {
606 ImGui::AlignTextToFramePadding();
607 ImGui::TextUnformatted("Mapper"sv);
608 }
609 if (ImGui::TableNextColumn()) {
610 ImGuiMedia::selectMapperType("##mapper-type", selectedRomType);
611 }
612 });
613 ImGui::Separator();
614
615 if (selectList.size() > 1) {
616 const auto& slotManager = motherBoard->getSlotManager();
617 ImGui::TextUnformatted("Select cartridge slot"sv);
618 auto n = std::min(3.5f, narrow<float>(selectList.size()));
619 auto height = n * ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().FramePadding.y;
620 im::ListBox("##select-media", {-FLT_MIN, height}, [&]{
621 for (const auto& item : selectList) {
622 auto slot = item.back() - 'a';
623 auto display = strCat(
624 char('A' + slot),
625 " (", slotManager.getPsSsString(slot), "): ",
626 media->displayNameForSlotContent(slotManager, slot, true));
627
628 if (ImGui::Selectable(display.c_str(), item == selectedMedia)) {
629 selectedMedia = item;
630 }
631 }
632 });
633 }
634
635 ImGui::Checkbox("Reset MSX on inserting ROM", &media->resetOnInsertRom);
636
637 if (ImGui::Button("Insert ROM")) {
638 auto cmd = makeTclList(selectedMedia, "insert", droppedFile);
639 if (selectedRomType != RomType::UNKNOWN) {
640 cmd.addListElement("-romtype", RomInfo::romTypeToName(selectedRomType));
641 }
642 insert2(strCat("cartridge slot ", char(selectedMedia.back() - 'a' + 'A')), cmd);
643 if (media->resetOnInsertRom) {
644 executeDelayed(TclObject("reset"));
645 }
646 ImGui::CloseCurrentPopup();
647 }
648 ImGui::SameLine();
649 if (ImGui::Button("Cancel")) {
650 ImGui::CloseCurrentPopup();
651 }
652 });
653 if (openInsertedInfo) {
654 openInsertedInfo = false;
655 insertedInfoTimeout = 3.0f;
656 ImGui::OpenPopup("inserted-info");
657 }
658 im::Popup("inserted-info", [&]{
659 insertedInfoTimeout -= ImGui::GetIO().DeltaTime;
660 if (insertedInfoTimeout <= 0.0f || insertedInfo.empty()) {
661 ImGui::CloseCurrentPopup();
662 }
663 im::TextWrapPos(ImGui::GetFontSize() * 35.0f, [&]{
664 ImGui::TextUnformatted(insertedInfo);
665 });
666 });
667}
668
669void ImGuiManager::iniReadInit()
670{
671 updateParts();
672 for (auto* part : parts) {
673 if (part) { // loadStart() could call unregisterPart()
674 part->loadStart();
675 }
676 }
677}
678
679void* ImGuiManager::iniReadOpen(std::string_view name)
680{
681 updateParts();
682 for (auto* part : parts) {
683 if (part->iniName() == name) return part;
684 }
685 return nullptr;
686}
687
688void ImGuiManager::loadLine(void* entry, const char* line_) const
689{
690 zstring_view line = line_;
691 auto pos = line.find('=');
692 if (pos == zstring_view::npos) return;
693 std::string_view name = line.substr(0, pos);
694 zstring_view value = line.substr(pos + 1);
695
696 assert(entry);
697 static_cast<ImGuiPartInterface*>(entry)->loadLine(name, value);
698}
699
700void ImGuiManager::iniApplyAll()
701{
702 updateParts();
703 for (auto* part : parts) {
704 part->loadEnd();
705 }
706}
707
708void ImGuiManager::iniWriteAll(ImGuiTextBuffer& buf)
709{
710 updateParts();
711 for (auto* part : parts) {
712 if (auto name = part->iniName(); !name.empty()) {
713 buf.appendf("[openmsx][%s]\n", name.c_str());
714 part->save(buf);
715 buf.append("\n");
716 }
717 }
718}
719
720} // namespace openmsx
void printError(std::string_view message)
Definition CliComm.cc:17
void printWarning(std::string_view message)
Definition CliComm.cc:12
void setWindowPosition(gl::ivec2 pos)
Definition Display.cc:230
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=Priority::OTHER)
Registers a given object to receive certain events.
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()
std::unique_ptr< ImGuiConsole > console
std::unique_ptr< ImGuiSoundChip > soundChip
ImGuiManager(Reactor &reactor_)
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:75
MSXMotherBoard * getMotherBoard() const
Definition Reactor.cc:409
Display & getDisplay()
Definition Reactor.hh:94
CliComm & getCliComm()
Definition Reactor.cc:323
Interpreter & getInterpreter()
Definition Reactor.cc:328
EventDistributor & getEventDistributor()
Definition Reactor.hh:90
RomDatabase & getSoftwareDatabase()
Definition Reactor.cc:315
FilePool & getFilePool()
Definition Reactor.hh:99
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:191
RomType getRomType() const
Definition RomInfo.hh:64
void detach(Observer< T > &observer)
Definition Subject.hh:60
void attach(Observer< T > &observer)
Definition Subject.hh:54
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:2099
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:459
void MainMenuBar(std::invocable<> auto next)
Definition ImGuiCpp.hh:354
void MenuBar(std::invocable<> auto next)
Definition ImGuiCpp.hh:345
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:190
void ListBox(const char *label, const ImVec2 &size, std::invocable<> auto next)
Definition ImGuiCpp.hh:332
void TextWrapPos(float wrap_local_pos_x, std::invocable<> auto next)
Definition ImGuiCpp.hh:212
void Popup(const char *str_id, ImGuiWindowFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:395
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()
EventType
Definition Event.hh:454
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:517
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:445
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:283
auto find(InputRange &&range, const T &value)
Definition ranges.hh:162
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