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 return std::string(pluggable);
30}
31
33{
34 im::Menu("Connectors", motherBoard != nullptr, [&]{
35 im::Table("table", 2, [&]{
36 const auto& pluggingController = motherBoard->getPluggingController();
37 const auto& pluggables = pluggingController.getPluggables();
38 for (const auto* connector : pluggingController.getConnectors()) {
39 if (ImGui::TableNextColumn()) { // connector
40 ImGui::TextUnformatted(connector->getDescription());
41 }
42 if (ImGui::TableNextColumn()) { // pluggable
43 const auto& connectorName = connector->getName();
44 auto connectorClass = connector->getClass();
45 const auto& currentPluggable = connector->getPlugged();
46 ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12.0f);
47 im::Combo(tmpStrCat("##", connectorName).c_str(), pluggableToGuiString(currentPluggable.getName()).c_str(), [&]{
48 if (!currentPluggable.getName().empty()) {
49 if (ImGui::Selectable("[unplug]")) {
50 manager.executeDelayed(makeTclList("unplug", connectorName));
51 }
52 }
53 for (auto& plug : pluggables) {
54 if (plug->getClass() != connectorClass) continue;
55 auto plugName = plug->getName();
56 bool selected = plug.get() == &currentPluggable;
57 int flags = !selected && plug->getConnector() ? ImGuiSelectableFlags_Disabled : 0; // plugged in another connector
58 if (ImGui::Selectable(pluggableToGuiString(plugName).c_str(), selected, flags)) {
59 manager.executeDelayed(makeTclList("plug", connectorName, plugName));
60 }
61 simpleToolTip(plug->getDescription());
62 }
63 });
64 if (const auto& desc = currentPluggable.getDescription(); !desc.empty()) {
65 simpleToolTip(desc);
66 }
67 }
68 }
69 });
70 });
71}
72
73} // 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:459
void Combo(const char *label, const char *preview_value, ImGuiComboFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:293
bool Menu(const char *label, bool enabled, std::invocable<> auto next)
Definition ImGuiCpp.hh:363
This file implemented 3 utility functions:
Definition Autofire.cc:11
void simpleToolTip(std::string_view desc)
Definition ImGuiUtils.hh:66
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:293
TemporaryString tmpStrCat(Ts &&... ts)
Definition strCat.hh:742