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 CassettePlayer;
26class HardwareConfig;
27class RomInfo;
28
29class ImGuiMedia final : public ImGuiPart
30{
31public:
33 std::string configName;
34 std::string displayName;
35 std::vector<std::pair<std::string, std::string>> configInfo;
36 std::optional<std::string> testResult; // lazily initialized
37 };
38
39public:
41
42 [[nodiscard]] zstring_view iniName() const override { return "media"; }
43 void save(ImGuiTextBuffer& buf) override;
44 void loadLine(std::string_view name, zstring_view value) override;
45 void showMenu(MSXMotherBoard* motherBoard) override;
46 void paint(MSXMotherBoard* motherBoard) override;
47
48 [[nodiscard]] std::string displayNameForExtension(std::string_view config);
49 [[nodiscard]] std::string displayNameForRom(const std::string& filename, bool compact = false);
50 [[nodiscard]] std::string displayNameForHardwareConfig(const HardwareConfig& config, bool compact = false);
51 [[nodiscard]] std::string displayNameForSlotContent(const CartridgeSlotManager& slotManager, unsigned slotNr, bool compact = false);
52 [[nodiscard]] std::string slotAndNameForHardwareConfig(const CartridgeSlotManager& slotManager, const HardwareConfig& config);
53 [[nodiscard]] std::string displayNameForDriveContent(unsigned drive, bool compact = false);
54
55 std::vector<ExtensionInfo>& getAllExtensions();
56 void resetExtensionInfo();
57 ExtensionInfo* findExtensionInfo(std::string_view config);
58 [[nodiscard]] const std::string& getTestResult(ExtensionInfo& info);
59
60 void addRecent(const TclObject& cmd);
61
62public:
63 enum class SelectDiskType : int {
65 NUM
66 };
67 enum class SelectCartridgeType : int {
69 NUM
70 };
71
72 struct MediaItem {
73 std::string name;
74 std::vector<std::string> ipsPatches; // only used for disk and rom images
75 RomType romType = RomType::UNKNOWN; // only used for rom images
76
77 [[nodiscard]] bool isEject() const { return romType == RomType::NUM; } // hack
78 [[nodiscard]] bool operator==(const MediaItem&) const = default;
79 };
80
81 struct ItemGroup { // MediaItem + history
82 static constexpr size_t HISTORY_SIZE = 8;
83
85 int patchIndex = -1; // only used for IPSItem
87 };
88
108 bool show = false;
109 };
110
111public:
113
114 static void printDatabase(const RomInfo& romInfo, const char* buf);
115 static bool selectMapperType(const char* label, RomType& item);
116
117 static std::string diskFilter();
118
119private:
120 bool selectRecent(ItemGroup& group, function_ref<std::string(const std::string&)> displayFunc, float width) const;
121 bool selectImage(ItemGroup& group, const std::string& title,
122 function_ref<std::string()> createFilter, zstring_view current,
123 function_ref<std::string(const std::string&)> displayFunc = std::identity{},
124 const std::function<void()>& createNewCallback = {});
125 bool selectDirectory(ItemGroup& info, const std::string& title, zstring_view current,
126 const std::function<void()>& createNewCallback);
127 bool selectPatches(MediaItem& item, int& patchIndex);
128 bool insertMediaButton(std::string_view mediaName, const ItemGroup& group, bool* showWindow);
129 TclObject showDiskInfo(std::string_view mediaName, DiskMediaInfo& info);
130 TclObject showCartridgeInfo(std::string_view mediaName, CartridgeMediaInfo& info, int slot);
131 void diskMenu(int i);
132 void cartridgeMenu(int i);
133 void cassetteMenu(CassettePlayer& cassettePlayer);
134 void insertMedia(std::string_view mediaName, const MediaItem& item);
135
136 void printExtensionInfo(ExtensionInfo& info);
137 void extensionTooltip(ExtensionInfo& info);
138 bool drawExtensionFilter();
139
140private:
141 std::array<DiskMediaInfo, RealDrive::MAX_DRIVES> diskMediaInfo;
142 std::array<CartridgeMediaInfo, CartridgeSlotManager::MAX_SLOTS> cartridgeMediaInfo;
143 ItemGroup extensionMediaInfo;
144 CassetteMediaInfo cassetteMediaInfo;
145 std::array<ItemGroup, HD::MAX_HD> hdMediaInfo;
146 std::array<ItemGroup, IDECDROM::MAX_CD> cdMediaInfo;
147 ItemGroup laserdiscMediaInfo;
148
149 std::string filterType;
150 std::string filterString;
151 bool filterOpen = false;
152
153 std::vector<ExtensionInfo> extensionInfo;
154
155 static constexpr auto persistentElements = std::tuple{
156 PersistentElement{"resetOnCartChanges", &ImGuiMedia::resetOnCartChanges},
157 // most media stuff is handled elsewhere
158 };
159};
160
161} // namespace openmsx
162
163#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:47
zstring_view iniName() const override
Definition ImGuiMedia.hh:42
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 addRecent(const TclObject &cmd)
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:93
array_with_enum_index< SelectDiskType, ItemGroup > groups
std::vector< std::pair< std::string, std::string > > configInfo
Definition ImGuiMedia.hh:35
std::optional< std::string > testResult
Definition ImGuiMedia.hh:36
static constexpr size_t HISTORY_SIZE
Definition ImGuiMedia.hh:82
circular_buffer< MediaItem > recent
Definition ImGuiMedia.hh:86
std::vector< std::string > ipsPatches
Definition ImGuiMedia.hh:74
bool operator==(const MediaItem &) const =default