openMSX
ImGuiMedia.hh
Go to the documentation of this file.
1#ifndef IMGUI_MEDIA_HH
2#define IMGUI_MEDIA_HH
3
4#include "ImGuiPart.hh"
5
7#include "HD.hh"
8#include "IDECDROM.hh"
9#include "RealDrive.hh"
10#include "RomTypes.hh"
11#include "TclObject.hh"
12
13#include "circular_buffer.hh"
14#include "function_ref.hh"
15#include "stl.hh"
16#include "zstring_view.hh"
17
18#include <array>
19#include <functional>
20#include <string>
21#include <vector>
22
23namespace openmsx {
24
25class HardwareConfig;
26class RomInfo;
27
28class ImGuiMedia final : public ImGuiPart
29{
30public:
32 std::string configName;
33 std::string displayName;
34 std::vector<std::pair<std::string, std::string>> configInfo;
35 std::optional<std::string> testResult; // lazily initialized
36 };
37
38public:
40
41 [[nodiscard]] zstring_view iniName() const override { return "media"; }
42 void save(ImGuiTextBuffer& buf) override;
43 void loadLine(std::string_view name, zstring_view value) override;
44 void showMenu(MSXMotherBoard* motherBoard) override;
45 void paint(MSXMotherBoard* motherBoard) override;
46
47 [[nodiscard]] std::string displayNameForExtension(std::string_view config);
48 [[nodiscard]] std::string displayNameForRom(const std::string& filename, bool compact = false);
49 [[nodiscard]] std::string displayNameForHardwareConfig(const HardwareConfig& config, bool compact = false);
50 [[nodiscard]] std::string displayNameForSlotContent(const CartridgeSlotManager& slotManager, unsigned slotNr, bool compact = false);
51 [[nodiscard]] std::string slotAndNameForHardwareConfig(const CartridgeSlotManager& slotManager, const HardwareConfig& config);
52 [[nodiscard]] std::string displayNameForDriveContent(unsigned drive, bool compact = false);
53
54 std::vector<ExtensionInfo>& getAllExtensions();
55 void resetExtensionInfo();
56 ExtensionInfo* findExtensionInfo(std::string_view config);
57 [[nodiscard]] const std::string& getTestResult(ExtensionInfo& info);
58
59public:
60 enum class SelectDiskType : int {
62 NUM
63 };
64 enum class SelectCartridgeType : int {
66 NUM
67 };
68
69 struct MediaItem {
70 std::string name;
71 std::vector<std::string> ipsPatches; // only used for disk and rom images
72 RomType romType = RomType::UNKNOWN; // only used for rom images
73
74 [[nodiscard]] bool isEject() const { return romType == RomType::NUM; } // hack
75 [[nodiscard]] bool operator==(const MediaItem&) const = default;
76 };
77
78 struct ItemGroup { // MediaItem + history
79 static constexpr size_t HISTORY_SIZE = 8;
80
82 int patchIndex = -1; // only used for IPSItem
84 };
85
105 bool show = false;
106 };
107
108public:
109 bool resetOnInsertRom = true;
110
111 static void printDatabase(const RomInfo& romInfo, const char* buf);
112 static bool selectMapperType(const char* label, RomType& item);
113
114 static std::string diskFilter();
115
116private:
117 bool selectRecent(ItemGroup& group, function_ref<std::string(const std::string&)> displayFunc, float width) const;
118 bool selectImage(ItemGroup& group, const std::string& title,
119 function_ref<std::string()> createFilter, zstring_view current,
120 function_ref<std::string(const std::string&)> displayFunc = std::identity{},
121 const std::function<void()>& createNewCallback = {});
122 bool selectDirectory(ItemGroup& info, const std::string& title, zstring_view current,
123 const std::function<void()>& createNewCallback);
124 bool selectPatches(MediaItem& item, int& patchIndex);
125 bool insertMediaButton(std::string_view mediaName, ItemGroup& group, bool* showWindow);
126 TclObject showDiskInfo(std::string_view mediaName, DiskMediaInfo& info);
127 TclObject showCartridgeInfo(std::string_view mediaName, CartridgeMediaInfo& info, int slot);
128 void diskMenu(int i);
129 void cartridgeMenu(int i);
130 void cassetteMenu(const TclObject& cmdResult);
131 void insertMedia(std::string_view mediaName, ItemGroup& group);
132
133 void printExtensionInfo(ExtensionInfo& info);
134 void extensionTooltip(ExtensionInfo& info);
135 bool drawExtensionFilter();
136
137private:
138 std::array<DiskMediaInfo, RealDrive::MAX_DRIVES> diskMediaInfo;
139 std::array<CartridgeMediaInfo, CartridgeSlotManager::MAX_SLOTS> cartridgeMediaInfo;
140 ItemGroup extensionMediaInfo;
141 CassetteMediaInfo cassetteMediaInfo;
142 std::array<ItemGroup, HD::MAX_HD> hdMediaInfo;
143 std::array<ItemGroup, IDECDROM::MAX_CD> cdMediaInfo;
144 ItemGroup laserdiscMediaInfo;
145
146 std::string filterType;
147 std::string filterString;
148 bool filterOpen = false;
149
150 std::vector<ExtensionInfo> extensionInfo;
151
152 static constexpr auto persistentElements = std::tuple{
153 PersistentElement{"resetOnInsertRom", &ImGuiMedia::resetOnInsertRom},
154 // most media stuff is handled elsewhere
155 };
156};
157
158} // namespace openmsx
159
160#endif
Circular buffer class, based on boost::circular_buffer/.
ExtensionInfo * findExtensionInfo(std::string_view config)
static void printDatabase(const RomInfo &romInfo, const char *buf)
std::string displayNameForHardwareConfig(const HardwareConfig &config, bool compact=false)
static std::string diskFilter()
std::string displayNameForRom(const std::string &filename, bool compact=false)
std::string slotAndNameForHardwareConfig(const CartridgeSlotManager &slotManager, const HardwareConfig &config)
void showMenu(MSXMotherBoard *motherBoard) override
std::string displayNameForDriveContent(unsigned drive, bool compact=false)
std::string displayNameForExtension(std::string_view config)
void save(ImGuiTextBuffer &buf) override
Definition ImGuiMedia.cc:45
zstring_view iniName() const override
Definition ImGuiMedia.hh:41
static bool selectMapperType(const char *label, RomType &item)
void paint(MSXMotherBoard *motherBoard) override
std::string displayNameForSlotContent(const CartridgeSlotManager &slotManager, unsigned slotNr, bool compact=false)
void loadLine(std::string_view name, zstring_view value) override
std::vector< ExtensionInfo > & getAllExtensions()
const std::string & getTestResult(ExtensionInfo &info)
ImGuiPart(ImGuiManager &manager_)
Definition ImGuiPart.hh:12
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
Definition Autofire.cc:11
array_with_enum_index< SelectCartridgeType, ItemGroup > groups
Definition ImGuiMedia.hh:90
array_with_enum_index< SelectDiskType, ItemGroup > groups
Definition ImGuiMedia.hh:99
std::vector< std::pair< std::string, std::string > > configInfo
Definition ImGuiMedia.hh:34
std::optional< std::string > testResult
Definition ImGuiMedia.hh:35
static constexpr size_t HISTORY_SIZE
Definition ImGuiMedia.hh:79
circular_buffer< MediaItem > recent
Definition ImGuiMedia.hh:83
std::vector< std::string > ipsPatches
Definition ImGuiMedia.hh:71
bool operator==(const MediaItem &) const =default