openMSX
ImGuiConnector.cc
Go to the documentation of this file.
1#include "ImGuiConnector.hh"
2
3#include "ImGuiCpp.hh"
4#include "ImGuiManager.hh"
5#include "ImGuiUtils.hh"
6
7#include "Connector.hh"
8#include "MSXMotherBoard.hh"
9#include "Pluggable.hh"
10#include "PluggingController.hh"
11
12#include <imgui.h>
13
14namespace openmsx {
15
16[[nodiscard]] static std::string pluggableToGuiString(std::string_view pluggable)
17{
18 if (pluggable == "msxjoystick1") return "MSX joystick 1";
19 if (pluggable == "msxjoystick2") return "MSX joystick 2";
20 if (pluggable == "joymega1") return "JoyMega controller 1";
21 if (pluggable == "joymega2") return "JoyMega controller 2";
22 if (pluggable == "arkanoidpad") return "Arkanoid Vaus paddle";
23 if (pluggable == "ninjatap") return "Ninja Tap";
24 if (pluggable == "cassetteplayer") return "Tape deck";
25 if (pluggable == "simpl") return "SIMPL";
26 if (pluggable == "msx-printer") return "MSX printer";
27 if (pluggable == "epson-printer") return "Epson printer";
28 if (pluggable == "tetris2-protection") return "Tetris II SE dongle";
29 if (pluggable == "circuit-designer-rd-dongle") return "Circuit Designer RD dongle";
30 return std::string(pluggable);
31}
32
34{
35 im::Menu("Connectors", motherBoard != nullptr, [&]{
36 im::Table("table", 2, [&]{
37 const auto& pluggingController = motherBoard->getPluggingController();
38 const auto& pluggables = pluggingController.getPluggables();
39 for (const auto* connector : pluggingController.getConnectors()) {
40 if (ImGui::TableNextColumn()) { // connector
41 ImGui::TextUnformatted(connector->getDescription());
42 }
43 if (ImGui::TableNextColumn()) { // pluggable
44 const auto& connectorName = connector->getName();
45 auto connectorClass = connector->getClass();
46 const auto& currentPluggable = connector->getPlugged();
47 ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12.0f);
48 im::Combo(tmpStrCat("##", connectorName).c_str(), pluggableToGuiString(currentPluggable.getName()).c_str(), [&]{
49 if (!currentPluggable.getName().empty()) {
50 if (ImGui::Selectable("[unplug]")) {
51 manager.executeDelayed(makeTclList("unplug", connectorName));
52 }
53 }
54 for (auto& plug : pluggables) {
55 if (plug->getClass() != connectorClass) continue;
56 auto plugName = plug->getName();
57 bool selected = plug.get() == &currentPluggable;
58 int flags = !selected && plug->getConnector() ? ImGuiSelectableFlags_Disabled : 0; // plugged in another connector
59 if (ImGui::Selectable(pluggableToGuiString(plugName).c_str(), selected, flags)) {
60 manager.executeDelayed(makeTclList("plug", connectorName, plugName));
61 }
62 simpleToolTip(plug->getDescription());
63 if (selected) {
64 ImGui::SetItemDefaultFocus();
65 }
66 }
67 });
68 if (const auto& desc = currentPluggable.getDescription(); !desc.empty()) {
69 simpleToolTip(desc);
70 }
71 }
72 }
73 });
74 });
75}
76
77} // namespace openmsx
void showMenu(MSXMotherBoard *motherBoard) override
void executeDelayed(std::function< void()> action)
ImGuiManager & manager
Definition ImGuiPart.hh:30
PluggingController & getPluggingController()
const auto & getPluggables() const
void TextUnformatted(const std::string &str)
Definition ImGuiUtils.hh:24
void Table(const char *str_id, int column, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, std::invocable<> auto next)
Definition ImGuiCpp.hh:455
void Combo(const char *label, const char *preview_value, ImGuiComboFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:289
bool Menu(const char *label, bool enabled, std::invocable<> auto next)
Definition ImGuiCpp.hh:359
This file implemented 3 utility functions:
Definition Autofire.cc:11
void simpleToolTip(std::string_view desc)
Definition ImGuiUtils.hh:77
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:293
TemporaryString tmpStrCat(Ts &&... ts)
Definition strCat.hh:742