32#include <CustomFont.h>
34#include <imgui_stdlib.h>
41using namespace std::literals;
50 if (item.
name.empty())
return;
51 buf.appendf(
"%s.name=%s\n", name.c_str(), item.
name.c_str());
53 buf.appendf(
"%s.patch=%s\n", name.c_str(), patch.c_str());
56 buf.appendf(
"%s.romType=%s\n", name.c_str(),
61 saveItem(group.
edit, name);
62 auto recentName =
tmpStrCat(name,
".recent");
63 for (
const auto& item : group.
recent) {
64 saveItem(item, recentName);
71 for (
const auto& info : diskMediaInfo) {
76 if (info.show) buf.appendf(
"%s.show=1\n", name.c_str());
81 for (
const auto& info : cartridgeMediaInfo) {
85 if (info.show) buf.appendf(
"%s.show=1\n", name.c_str());
90 for (
const auto& info : hdMediaInfo) {
91 saveGroup(info, name);
96 for (
const auto& info : cdMediaInfo) {
97 saveGroup(info, name);
101 if (cassetteMediaInfo.
show) buf.append(
"cassette.show=1\n");
102 saveGroup(cassetteMediaInfo.
group,
"cassette");
104 saveGroup(extensionMediaInfo,
"extension");
105 saveGroup(laserdiscMediaInfo,
"laserdisc");
110 auto get = [&](std::string_view prefix,
auto& array) -> std::remove_reference_t<
decltype(array[0])>* {
111 if ((name.size() >= (prefix.size() + 2)) && name.starts_with(prefix) && (name[prefix.size() + 1] ==
'.')) {
112 char c = name[prefix.size()];
113 if ((
'a' <= c) && (c < char(
'a' + array.size()))) {
114 return &array[c -
'a'];
119 auto loadItem = [&](
MediaItem& item, std::string_view suffix) {
120 if (suffix ==
"name") {
122 }
else if (suffix ==
"patch") {
124 }
else if (suffix ==
"romType") {
130 auto loadGroup = [&](
ItemGroup& group, std::string_view suffix) {
131 if (suffix.starts_with(
"recent.")) {
132 if (suffix ==
"recent.name" && !group.
recent.full()) {
135 if (!group.
recent.empty()) {
136 loadItem(group.
recent.back(), suffix.substr(7));
139 loadItem(group.
edit, suffix);
145 }
else if (
auto* disk = get(
"disk", diskMediaInfo)) {
147 auto suffix = name.substr(6);
148 if (suffix.starts_with(
"image.")) {
149 loadGroup(disk->groups[
IMAGE], suffix.substr(6));
150 }
else if (suffix.starts_with(
"dirAsDsk.")) {
151 loadGroup(disk->groups[
DIR_AS_DISK], suffix.substr(9));
152 }
else if (suffix ==
"select") {
153 if (
auto i = StringOp::stringTo<unsigned>(value)) {
158 }
else if (suffix ==
"show") {
161 }
else if (
auto* cart = get(
"cart", cartridgeMediaInfo)) {
163 auto suffix = name.substr(6);
164 if (suffix.starts_with(
"rom.")) {
165 loadGroup(cart->groups[
IMAGE], suffix.substr(4));
166 }
else if (suffix.starts_with(
"extension.")) {
167 loadGroup(cart->groups[
EXTENSION], suffix.substr(10));
168 }
else if (suffix ==
"select") {
169 if (
auto i = StringOp::stringTo<unsigned>(value)) {
174 }
else if (suffix ==
"show") {
177 }
else if (
auto* hd = get(
"hd", hdMediaInfo)) {
178 loadGroup(*hd, name.substr(4));
179 }
else if (
auto* cd = get(
"cd", cdMediaInfo)) {
180 loadGroup(*cd, name.substr(4));
181 }
else if (name.starts_with(
"cassette.")) {
182 auto suffix = name.substr(9);
183 if (suffix ==
"show") {
186 loadGroup(cassetteMediaInfo.
group, suffix);
188 }
else if (name.starts_with(
"extension.")) {
189 loadGroup(extensionMediaInfo, name.substr(10));
190 }
else if (name.starts_with(
"laserdisc.")) {
191 loadGroup(laserdiscMediaInfo, name.substr(10));
195static std::string buildFilter(std::string_view description, std::span<const std::string_view> extensions)
197 auto formatExtensions = [&]() -> std::string {
198 if (extensions.size() <= 3) {
200 [](
const auto& ext) {
return strCat(
"*.", ext); }),
203 return join(extensions,
',');
207 description,
" (", formatExtensions(),
"){",
209 [](
const auto& ext) {
return strCat(
'.', ext); }),
219static std::string romFilter()
224static std::string cassetteFilter()
229static std::string hdFilter()
231 return buildFilter(
"Hard disk images", std::array{
"dsk"sv});
234static std::string cdFilter()
236 return buildFilter(
"CDROM images", std::array{
"iso"sv});
239template<std::invocable<const std::
string&> DisplayFunc = std::
identity>
240static std::string display(
const ImGuiMedia::MediaItem& item, DisplayFunc displayFunc = {})
242 std::string result = displayFunc(item.name);
246 if (
auto n = item.ipsPatches.size()) {
247 strAppend(result,
" (+", n,
" patch", (n == 1 ?
"" :
"es"),
')');
254 if (extensionInfo.empty()) {
255 extensionInfo = parseAllConfigFiles<ExtensionInfo>(
manager,
"extensions", {
"Manufacturer"sv,
"Product code"sv,
"Name"sv});
257 return extensionInfo;
262 extensionInfo.clear();
279 std::optional<MSXMotherBoard> mb;
283 mb->getMSXCliComm().setSuppressMessages(
true);
285 mb->loadMachine(
"C-BIOS_MSX1");
290 if (
const auto* current = reactor.getMotherBoard()) {
292 mb->getMSXCliComm().setSuppressMessages(true);
293 mb->loadMachine(std::string(current->getMachineName()));
302 auto ext = mb->loadExtension(info.
configName,
"any");
303 mb->insertExtension(info.
configName, std::move(ext));
318 return (it != allExtensions.end()) ? std::to_address(it) :
nullptr;
324 return info ? info->displayName
325 : std::string(config);
331 if (
auto sha1 = reactor.getFilePool().getSha1Sum(filename)) {
333 if (
const auto* romInfo = database.fetchRomInfo(*sha1)) {
334 if (
auto title = romInfo->getTitle(database.getBufferStart());
336 return std::string(title);
364 std::string result = slot
374 std::string_view display;
376 display = result->getListIndexUnchecked(1).getString();
378 return display.empty() ?
"Empty"
383void ImGuiMedia::printExtensionInfo(ExtensionInfo& info)
386 bool ok =
test.empty();
389 ImGui::TableSetupColumn(
"description", ImGuiTableColumnFlags_WidthFixed);
390 ImGui::TableSetupColumn(
"value", ImGuiTableColumnFlags_WidthStretch);
392 for (
const auto& [desc, value_] : info.configInfo) {
393 const auto& value = value_;
394 if (ImGui::TableNextColumn()) {
397 if (ImGui::TableNextColumn()) {
413void ImGuiMedia::extensionTooltip(ExtensionInfo& info)
416 printExtensionInfo(info);
420bool ImGuiMedia::drawExtensionFilter()
422 std::string filterDisplay =
"filter";
423 if (!filterType.empty() || !filterString.empty())
strAppend(filterDisplay,
':');
424 if (!filterType.empty())
strAppend(filterDisplay,
' ', filterType);
425 if (!filterString.empty())
strAppend(filterDisplay,
' ', filterString);
427 bool newFilterOpen = filterOpen;
428 im::TreeNode(filterDisplay.c_str(), &newFilterOpen, [&]{
429 displayFilterCombo(filterType,
"Type", getAllExtensions());
430 ImGui::InputText(ICON_IGFD_FILTER, &filterString);
431 simpleToolTip(
"A list of substrings that must be part of the extension.\n"
433 "For example: enter 'ko' to search for 'Konami' extensions. "
434 "Then refine the search by appending '<space>sc' to find the 'Konami SCC' extension.");
436 bool changed = filterOpen != newFilterOpen;
437 filterOpen = newFilterOpen;
443 im::Menu(
"Media", motherBoard !=
nullptr, [&]{
446 enum class Status {
NONE, ITEM, SEPARATOR };
448 Status status =
NONE;
450 auto endGroup = [&] {
451 if (status == ITEM) status = SEPARATOR;
453 auto elementInGroup = [&] {
454 if (status == SEPARATOR) {
460 auto showCurrent = [&](
TclObject current, std::string_view type) {
461 if (current.
empty()) {
469 auto showRecent = [&](std::string_view mediaName,
ItemGroup& group,
470 function_ref<std::string(
const std::string&)> displayFunc = std::identity{},
471 const std::function<void(
const std::string&)>& toolTip = {}) {
472 if (!group.recent.empty()) {
476 for (
const auto& item : group.recent) {
477 auto d =
strCat(display(item, displayFunc),
"##", count++);
478 if (ImGui::MenuItem(d.c_str())) {
480 insertMedia(mediaName, group);
482 if (toolTip) toolTip(item.name);
492 bool anySlot =
false;
494 if (!slotManager.slotExists(i))
continue;
496 auto displayName =
strCat(
"Cartridge Slot ",
char(
'A' + i));
497 ImGui::MenuItem(displayName.c_str(),
nullptr, &cartridgeMediaInfo[i].show);
501 ImGui::TextDisabled(
"No cartridge slots present");
508 auto mediaName =
"ext"sv;
509 auto& group = extensionMediaInfo;
512 HelpMarker(
"Note that some extensions are I/O only and will not occupy any cartridge slot when inserted. "
513 "These can only be removed via the 'Media > Extensions > Remove' menu. "
514 "To insert (non I/O-only) extensions in a specific slot, use the 'Media > Cartridge Slot' menu.");
515 drawExtensionFilter();
522 float width = 40.0f * ImGui::GetFontSize();
523 float height = 10.25f * ImGui::GetTextLineHeightWithSpacing();
526 auto& ext = allExtensions[filteredExtensions[i]];
527 bool ok = getTestResult(ext).empty();
528 im::StyleColor(!ok, ImGuiCol_Text, getColor(imColor::ERROR), [&]{
529 if (ImGui::Selectable(ext.displayName.c_str())) {
530 group.edit.name = ext.configName;
531 insertMedia(mediaName, group);
532 ImGui::CloseCurrentPopup();
534 extensionTooltip(ext);
540 showRecent(mediaName, group,
541 [
this](
const std::string& config) {
544 [
this](
const std::string& e) {
546 extensionTooltip(*info);
554 im::Menu(
"Remove", [&]{
556 for (const auto& ext : extensions) {
557 auto name = strCat(slotAndNameForHardwareConfig(slotManager, *ext),
"##", count++);
558 if (ImGui::Selectable(name.c_str())) {
559 manager.executeDelayed(makeTclList(
"remove_extension", ext->getName()));
561 if (auto* info = findExtensionInfo(ext->getConfigName())) {
562 extensionTooltip(*info);
573 bool anyDrive =
false;
575 if (!(*drivesInUse)[i])
continue;
577 auto displayName =
strCat(
"Disk Drive ",
char(
'A' + i));
578 ImGui::MenuItem(displayName.c_str(),
nullptr, &diskMediaInfo[i].show);
579 simpleToolTip([&] {
return displayNameForDriveContent(i); });
582 ImGui::TextDisabled(
"No disk drives present");
588 if (
auto cmdResult = manager.execute(TclObject(
"cassetteplayer"))) {
589 ImGui::MenuItem(
"Tape Deck",
nullptr, &cassetteMediaInfo.show);
591 auto tip = cmdResult->getListIndexUnchecked(1).getString();
592 return !tip.empty() ? std::string(tip) :
"Empty";
595 ImGui::TextDisabled(
"No cassette port present");
601 std::string hdName =
"hdX";
603 if (!(*hdInUse)[i])
continue;
604 hdName.back() = char(
'a' + i);
605 auto displayName =
strCat(
"Hard Disk ",
char(
'A' + i));
606 if (
auto cmdResult = manager.execute(TclObject(hdName))) {
608 auto& group = hdMediaInfo[i];
610 auto currentImage = cmdResult->getListIndex(interp, 1);
611 showCurrent(currentImage,
"hard disk");
612 bool powered = motherBoard->isPowered();
613 im::Disabled(powered, [&]{
614 if (ImGui::MenuItem(
"Select hard disk image...")) {
615 manager.openFile->selectFile(
616 "Select image for " + displayName,
618 [this, &group, hdName](const auto& fn) {
619 group.edit.name = fn;
620 this->insertMedia(hdName, group);
622 currentImage.getString());
626 HelpMarker(
"Hard disk image cannot be switched while the MSX is powered on.");
629 showRecent(hdName, group);
637 auto cdInUse = IDECDROM::getDrivesInUse(*motherBoard);
638 std::string cdName =
"cdX";
640 if (!(*cdInUse)[i])
continue;
641 cdName.back() = char(
'a' + i);
642 auto displayName =
strCat(
"CDROM Drive ",
char(
'A' + i));
643 if (
auto cmdResult = manager.execute(TclObject(cdName))) {
645 auto& group = cdMediaInfo[i];
647 auto currentImage = cmdResult->getListIndex(interp, 1);
648 showCurrent(currentImage,
"CDROM");
649 if (ImGui::MenuItem(
"Eject", nullptr, false, !currentImage.empty())) {
650 manager.executeDelayed(makeTclList(cdName,
"eject"));
652 if (ImGui::MenuItem(
"Insert CDROM image...")) {
653 manager.openFile->selectFile(
654 "Select CDROM image for " + displayName,
656 [
this, &group, cdName](
const auto& fn) {
657 group.edit.name = fn;
658 this->insertMedia(cdName, group);
660 currentImage.getString());
662 showRecent(cdName, group);
669 if (
auto cmdResult = manager.execute(TclObject(
"laserdiscplayer"))) {
672 auto currentImage = cmdResult->getListIndex(interp, 1);
673 showCurrent(currentImage,
"laserdisc");
674 if (ImGui::MenuItem(
"eject",
nullptr,
false, !currentImage.empty())) {
675 manager.executeDelayed(
makeTclList(
"laserdiscplayer",
"eject"));
677 if (ImGui::MenuItem(
"Insert LaserDisc image...")) {
678 manager.openFile->selectFile(
679 "Select LaserDisc image",
680 buildFilter(
"LaserDisc images", std::array<std::string_view, 1>{
"ogv"}),
681 [
this](
const auto& fn) {
682 laserdiscMediaInfo.edit.name = fn;
683 this->insertMedia(
"laserdiscplayer", laserdiscMediaInfo);
685 currentImage.getString());
687 showRecent(
"laserdiscplayer", laserdiscMediaInfo);
696 if (!motherBoard)
return;
698 auto drivesInUse = RealDrive::getDrivesInUse(*motherBoard);
699 for (
auto i :
xrange(RealDrive::MAX_DRIVES)) {
700 if (!(*drivesInUse)[i])
continue;
701 if (diskMediaInfo[i].show) {
707 for (
auto i :
xrange(CartridgeSlotManager::MAX_SLOTS)) {
708 if (!slotManager.slotExists(i))
continue;
709 if (cartridgeMediaInfo[i].show) {
714 if (cassetteMediaInfo.show) {
715 if (
auto cmdResult = manager.execute(
TclObject(
"cassetteplayer"))) {
716 cassetteMenu(*cmdResult);
726static void printPatches(
const TclObject& patches)
728 if (!patches.empty()) {
731 for (
const auto& patch : patches) {
738static std::string leftClip(std::string_view s,
float maxWidth)
741 if (fullWidth <= maxWidth)
return std::string(s);
744 if (maxWidth <= 0.0f)
return "...";
749 return strCat(
"...", s.substr(len - num));
752bool ImGuiMedia::selectRecent(ItemGroup& group,
function_ref<std::string(
const std::string&)> displayFunc,
float width)
const
754 bool interacted =
false;
755 ImGui::SetNextItemWidth(-width);
756 const auto& style = ImGui::GetStyle();
757 auto textWidth = ImGui::GetContentRegionAvail().x - (3.0f * style.FramePadding.x + ImGui::GetFrameHeight() + width);
758 auto preview = leftClip(displayFunc(group.edit.name), textWidth);
759 im::Combo(
"##recent", preview.c_str(), [&]{
761 for (const auto& item : group.recent) {
762 auto d = strCat(display(item, displayFunc),
"##", count++);
763 if (ImGui::Selectable(d.c_str())) {
769 interacted |= ImGui::IsItemActive();
773static float calcButtonWidth(std::string_view text1,
const char* text2)
775 const auto& style = ImGui::GetStyle();
776 float width = style.ItemSpacing.x + 2.0f * style.FramePadding.x +
ImGui::CalcTextSize(text1).x;
783bool ImGuiMedia::selectImage(ItemGroup& group,
const std::string& title,
785 function_ref<std::string(
const std::string&)> displayFunc,
786 const std::function<
void()>& createNewCallback)
788 bool interacted =
false;
790 auto width = calcButtonWidth(ICON_IGFD_FOLDER_OPEN, createNewCallback ? ICON_IGFD_ADD : nullptr);
791 interacted |= selectRecent(group, displayFunc, width);
792 if (createNewCallback) {
794 if (ImGui::Button(ICON_IGFD_ADD)) {
801 if (ImGui::Button(ICON_IGFD_FOLDER_OPEN)) {
803 manager.openFile->selectFile(
806 [&](
const auto& fn) { group.edit.name = fn; },
814bool ImGuiMedia::selectDirectory(ItemGroup& group,
const std::string& title,
zstring_view current,
815 const std::function<
void()>& createNewCallback)
817 bool interacted =
false;
819 auto width = calcButtonWidth(ICON_IGFD_FOLDER_OPEN, createNewCallback ? ICON_IGFD_ADD : nullptr);
820 interacted |= selectRecent(group, std::identity{}, width);
821 if (createNewCallback) {
823 if (ImGui::Button(ICON_IGFD_ADD)) {
830 if (ImGui::Button(ICON_IGFD_FOLDER_OPEN)) {
832 manager.openFile->selectDirectory(
834 [&](
const auto& fn) { group.edit.name = fn; },
842bool ImGuiMedia::selectMapperType(
const char* label,
RomType& romType)
844 bool interacted =
false;
845 bool isAutoDetect = romType == RomType::UNKNOWN;
846 constexpr const char* autoStr =
"auto detect";
847 std::string current = isAutoDetect ? autoStr : std::string(RomInfo::romTypeToName(romType));
849 if (ImGui::Selectable(autoStr, isAutoDetect)) {
851 romType = RomType::UNKNOWN;
854 for (
const auto& romInfo : RomInfo::getRomTypeInfo()) {
855 bool selected = romType ==
static_cast<RomType>(count);
856 if (ImGui::Selectable(std::string(romInfo.name).c_str(), selected)) {
858 romType =
static_cast<RomType>(count);
864 interacted |= ImGui::IsItemActive();
868bool ImGuiMedia::selectPatches(MediaItem& item,
int& patchIndex)
870 bool interacted =
false;
871 std::string patchesTitle =
"IPS patches";
872 if (!item.ipsPatches.empty()) {
873 strAppend(patchesTitle,
" (", item.ipsPatches.size(),
')');
877 const auto& style = ImGui::GetStyle();
878 auto width = style.ItemSpacing.x + 2.0f * style.FramePadding.x + ImGui::CalcTextSize(
"Remove"sv).x;
879 ImGui::SetNextItemWidth(-width);
881 im::ListBox(
"##", [&]{
883 for (const auto& patch : item.ipsPatches) {
884 auto preview = leftClip(patch, ImGui::GetContentRegionAvail().x);
885 if (ImGui::Selectable(strCat(preview,
"##", count).c_str(), count == patchIndex)) {
895 if (ImGui::Button(
"Add")) {
897 manager.openFile->selectFile(
898 "Select disk IPS patch",
899 buildFilter(
"IPS patches", std::array<std::string_view, 1>{
"ips"}),
900 [&](
const std::string& ips) {
901 patchIndex = narrow<int>(item.ipsPatches.size());
902 item.ipsPatches.push_back(ips);
905 auto size = narrow<int>(item.ipsPatches.size());
906 im::Disabled(patchIndex < 0 || patchIndex >= size, [&] {
907 if (ImGui::Button(
"Remove")) {
909 item.ipsPatches.erase(item.ipsPatches.begin() + patchIndex);
912 if (ImGui::ArrowButton(
"up", ImGuiDir_Up)) {
913 std::swap(item.ipsPatches[patchIndex], item.ipsPatches[patchIndex - 1]);
918 if (ImGui::ArrowButton(
"down", ImGuiDir_Down)) {
919 std::swap(item.ipsPatches[patchIndex], item.ipsPatches[patchIndex + 1]);
929bool ImGuiMedia::insertMediaButton(std::string_view mediaName, ItemGroup& group,
bool* showWindow)
931 bool clicked =
false;
932 im::Disabled(group.edit.name.empty() && !group.edit.isEject(), [&]{
933 const auto& style = ImGui::GetStyle();
934 auto width = 4.0f * style.FramePadding.x + style.ItemSpacing.x +
935 ImGui::CalcTextSize(
"Apply"sv).x + ImGui::CalcTextSize(
"Ok"sv).x;
936 ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - width + style.WindowPadding.x);
937 clicked |= ImGui::Button(
"Apply");
939 if (ImGui::Button(
"Ok")) {
944 insertMedia(mediaName, group);
950TclObject ImGuiMedia::showDiskInfo(std::string_view mediaName, DiskMediaInfo& info)
952 TclObject currentTarget;
953 auto cmdResult = manager.execute(
makeTclList(
"machine_info",
"media", mediaName));
954 if (!cmdResult)
return currentTarget;
956 using enum SelectDiskType;
957 auto selectType = [&]{
960 auto s = type->getString();
963 }
else if (s ==
"ramdsk") {
965 }
else if (s ==
"dirasdisk") {
972 std::string_view typeStr = [&]{
973 switch (selectType) {
974 case IMAGE:
return "Disk image:";
975 case DIR_AS_DISK:
return "Dir as disk:";
976 case RAMDISK:
return "RAM disk";
977 case EMPTY:
return "No disk inserted";
981 bool detailedInfo = selectType ==
one_of(DIR_AS_DISK, IMAGE);
982 auto currentPatches = getPatches(*cmdResult);
984 bool copyCurrent = ImGui::SmallButton(
"Current disk");
985 HelpMarker(
"Press to copy current disk to 'Select new disk' section.");
991 currentTarget = *target;
994 ImGui::GetContentRegionAvail().x));
996 std::string statusLine;
997 auto add = [&](std::string_view s) {
998 if (statusLine.empty()) {
1005 if (ro->getOptionalBool().value_or(
false)) {
1010 add(doubleSided->getOptionalBool().value_or(
true) ?
"double-sided" :
"single-sided");
1013 add(
tmpStrCat(
size->getOptionalInt().value_or(0) / 1024,
"kB"));
1015 if (!statusLine.empty()) {
1018 printPatches(currentPatches);
1022 info.select = selectType;
1023 auto& edit = info.groups[selectType].edit;
1024 edit.name = currentTarget.getString();
1025 edit.ipsPatches = to_vector<std::string>(currentPatches);
1028 return currentTarget;
1031void ImGuiMedia::printDatabase(
const RomInfo& romInfo,
const char* buf)
1033 auto printRow = [](std::string_view description, std::string_view value) {
1034 if (value.empty())
return;
1035 if (ImGui::TableNextColumn()) {
1038 if (ImGui::TableNextColumn()) {
1043 printRow(
"Title", romInfo.
getTitle(buf));
1044 printRow(
"Year", romInfo.
getYear(buf));
1045 printRow(
"Company", romInfo.
getCompany(buf));
1046 printRow(
"Country", romInfo.
getCountry(buf));
1050 std::string result =
"Unmodified dump";
1052 strAppend(result,
" (confirmed by ", str,
')');
1056 return std::string(str);
1059 printRow(
"Status", status);
1060 printRow(
"Remark", romInfo.
getRemark(buf));
1066 ImGui::TableSetupColumn(
"description", ImGuiTableColumnFlags_WidthFixed);
1067 ImGui::TableSetupColumn(
"value", ImGuiTableColumnFlags_WidthStretch);
1069 if (ImGui::TableNextColumn()) {
1072 if (ImGui::TableNextColumn()) {
1077 const auto* romInfo = [&]() ->
const RomInfo* {
1079 if (
const auto* info = database.fetchRomInfo(Sha1Sum(actual->getString()))) {
1084 if (
const auto* info = database.fetchRomInfo(Sha1Sum(original->getString()))) {
1091 ImGuiMedia::printDatabase(*romInfo, database.getBufferStart());
1094 std::string mapperStr{RomInfo::romTypeToName(romType)};
1096 if (
auto dbType = romInfo->getRomType();
1097 dbType != RomType::UNKNOWN && dbType != romType) {
1098 strAppend(mapperStr,
" (database: ", RomInfo::romTypeToName(dbType),
')');
1101 if (ImGui::TableNextColumn()) {
1104 if (ImGui::TableNextColumn()) {
1110TclObject ImGuiMedia::showCartridgeInfo(std::string_view mediaName, CartridgeMediaInfo& info,
int slot)
1112 TclObject currentTarget;
1114 if (!cmdResult)
return currentTarget;
1116 using enum SelectCartridgeType;
1117 auto selectType = [&]{
1119 auto s = type->getString();
1120 if (s ==
"extension") {
1130 auto currentPatches = getPatches(*cmdResult);
1132 bool copyCurrent = ImGui::SmallButton(
"Current cartridge");
1137 RomType currentRomType = RomType::UNKNOWN;
1139 if (selectType == EMPTY) {
1142 currentTarget = *target;
1143 if (selectType == EXTENSION) {
1144 if (
auto* i = findExtensionInfo(target->getString())) {
1145 printExtensionInfo(*i);
1147 }
else if (selectType == IMAGE) {
1149 currentRomType = RomInfo::nameToRomType(mapper->getString());
1151 printRomInfo(manager, *cmdResult, target->getString(), currentRomType);
1152 printPatches(currentPatches);
1157 info.select = selectType;
1158 auto& edit = info.groups[selectType].edit;
1159 edit.name = currentTarget.getString();
1160 edit.ipsPatches = to_vector<std::string>(currentPatches);
1161 edit.romType = currentRomType;
1164 return currentTarget;
1167void ImGuiMedia::diskMenu(
int i)
1169 auto& info = diskMediaInfo[i];
1170 auto mediaName =
strCat(
"disk",
char(
'a' + i));
1171 auto displayName =
strCat(
"Disk Drive ",
char(
'A' + i));
1172 ImGui::SetNextWindowSize(
gl::vec2{29, 22} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
1173 im::Window(displayName.c_str(), &info.show, [&]{
1174 auto current = showDiskInfo(mediaName, info);
1175 im::Child(
"select", {0, -ImGui::GetFrameHeightWithSpacing()}, [&]{
1176 using enum SelectDiskType;
1177 ImGui::TextUnformatted(
"Select new disk"sv);
1179 ImGui::RadioButton(
"disk image", std::bit_cast<int*>(&info.select), to_underlying(IMAGE));
1180 im::VisuallyDisabled(info.select != IMAGE, [&]{
1182 auto& group = info.groups[IMAGE];
1183 auto createNew = [&]{
1184 manager.openFile->selectNewFile(
1185 "Select name for new blank disk image",
1186 "Disk images (*.dsk){.dsk}",
1187 [&](const auto& fn) {
1188 group.edit.name = fn;
1189 auto& diskManipulator = manager.getReactor().getDiskManipulator();
1191 diskManipulator.create(fn, MSXBootSectorType::DOS2, {1440});
1192 } catch (MSXException& e) {
1193 manager.printError(
"Couldn't create new disk image: ", e.getMessage());
1196 current.getString());
1198 bool interacted = selectImage(
1199 group, strCat(
"Select disk image for ", displayName), &diskFilter,
1200 current.getString(), std::identity{}, createNew);
1201 interacted |= selectPatches(group.edit, group.patchIndex);
1202 if (interacted) info.select = IMAGE;
1205 ImGui::RadioButton(
"dir as disk", std::bit_cast<int*>(&info.select),
to_underlying(DIR_AS_DISK));
1208 auto& group = info.groups[DIR_AS_DISK];
1209 auto createNew = [&]{
1210 manager.openFile->selectNewFile(
1211 "Select name for new empty directory",
1213 [&](const auto& fn) {
1214 group.edit.name = fn;
1216 FileOperations::mkdirp(fn);
1217 } catch (MSXException& e) {
1218 manager.printError(
"Couldn't create directory: ", e.getMessage());
1221 current.getString());
1223 bool interacted = selectDirectory(
1224 group, strCat(
"Select directory for ", displayName),
1225 current.getString(), createNew);
1226 if (interacted) info.select = DIR_AS_DISK;
1229 ImGui::RadioButton(
"RAM disk", std::bit_cast<int*>(&info.select),
to_underlying(RAMDISK));
1230 if (!current.
empty()) {
1231 ImGui::RadioButton(
"Eject", std::bit_cast<int*>(&info.select),
to_underlying(EMPTY));
1234 insertMediaButton(mediaName, info.groups[info.select], &info.show);
1238void ImGuiMedia::cartridgeMenu(
int cartNum)
1240 auto& info = cartridgeMediaInfo[cartNum];
1241 auto displayName =
strCat(
"Cartridge Slot ",
char(
'A' + cartNum));
1242 ImGui::SetNextWindowSize(
gl::vec2{37, 30} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
1243 im::Window(displayName.c_str(), &info.show, [&]{
1244 using enum SelectCartridgeType;
1245 auto cartName = strCat(
"cart", char(
'a' + cartNum));
1246 auto extName = strCat(
"ext", char(
'a' + cartNum));
1248 auto current = showCartridgeInfo(cartName, info, cartNum);
1250 im::Child(
"select", {0, -ImGui::GetFrameHeightWithSpacing()}, [&]{
1251 ImGui::TextUnformatted(
"Select new cartridge:"sv);
1253 ImGui::RadioButton(
"ROM image", std::bit_cast<int*>(&info.select), to_underlying(IMAGE));
1254 im::VisuallyDisabled(info.select != IMAGE, [&]{
1256 auto& group = info.groups[IMAGE];
1257 auto& item = group.edit;
1258 bool interacted = selectImage(
1259 group, strCat(
"Select ROM image for ", displayName), &romFilter, current.getString());
1261 const auto& style = ImGui::GetStyle();
1262 ImGui::SetNextItemWidth(-(ImGui::CalcTextSize(
"mapper-type").x + style.ItemInnerSpacing.x));
1263 interacted |= selectMapperType(
"mapper-type", item.romType);
1264 interacted |= selectPatches(item, group.patchIndex);
1265 interacted |= ImGui::Checkbox(
"Reset MSX on inserting ROM", &resetOnInsertRom);
1266 if (interacted) info.select = IMAGE;
1269 ImGui::RadioButton(
"extension", std::bit_cast<int*>(&info.select),
to_underlying(EXTENSION));
1272 auto& allExtensions = getAllExtensions();
1273 auto& group = info.groups[EXTENSION];
1274 auto& item = group.edit;
1276 bool interacted = drawExtensionFilter();
1278 auto drawExtensions = [&]{
1279 auto filteredExtensions = to_vector(xrange(allExtensions.size()));
1280 applyComboFilter(
"Type", filterType, allExtensions, filteredExtensions);
1281 applyDisplayNameFilter(filterString, allExtensions, filteredExtensions);
1283 im::ListClipper(filteredExtensions.size(), [&](int i) {
1284 auto& ext = allExtensions[filteredExtensions[i]];
1285 bool ok = getTestResult(ext).empty();
1286 im::StyleColor(!ok, ImGuiCol_Text, getColor(imColor::ERROR), [&]{
1287 if (ImGui::Selectable(ext.displayName.c_str(), item.name == ext.configName)) {
1289 item.name = ext.configName;
1291 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
1292 insertMedia(extName, group);
1294 extensionTooltip(ext);
1299 im::ListBox(
"##list", [&]{
1303 im::Combo(
"##extension", displayNameForExtension(item.name).c_str(), [&]{
1308 interacted |= ImGui::IsItemActive();
1309 if (interacted) info.select = EXTENSION;
1312 if (!current.
empty()) {
1313 ImGui::RadioButton(
"Eject", std::bit_cast<int*>(&info.select),
to_underlying(EMPTY));
1316 if (insertMediaButton(info.select == EXTENSION ? extName : cartName,
1317 info.groups[info.select], &info.show)) {
1318 if (resetOnInsertRom && info.select == IMAGE) {
1325static void addRecent(ImGuiMedia::ItemGroup& group)
1327 auto& recent = group.recent;
1328 if (
auto it2 =
ranges::find(recent, group.edit); it2 != recent.end()) {
1330 std::rotate(recent.begin(), it2, it2 + 1);
1333 if (recent.full()) recent.pop_back();
1334 recent.push_front(group.edit);
1338static bool ButtonWithCustomRendering(
1339 const char* label,
gl::vec2 size,
bool pressed,
1340 std::invocable<gl::vec2 /*center*/, ImDrawList*>
auto render)
1342 bool result =
false;
1343 im::StyleColor(pressed, ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_ButtonActive), [&]{
1344 gl::vec2 topLeft = ImGui::GetCursorScreenPos();
1346 result = ImGui::Button(label, size);
1347 render(center, ImGui::GetWindowDrawList());
1352static void RenderPlay(
gl::vec2 center, ImDrawList* drawList)
1354 float half = 0.4f * ImGui::GetTextLineHeight();
1355 auto p1 = center +
gl::vec2(half, 0.0f);
1356 auto p2 = center +
gl::vec2(-half, half);
1358 drawList->AddTriangleFilled(p1, p2,
p3,
getColor(imColor::TEXT));
1360static void RenderRewind(
gl::vec2 center, ImDrawList* drawList)
1362 float size = 0.8f * ImGui::GetTextLineHeight();
1363 float half =
size * 0.5f;
1364 auto color =
getColor(imColor::TEXT);
1365 auto p1 = center +
gl::vec2(-size, 0.0f);
1366 auto p2 = center +
gl::vec2(0.0f, -half);
1368 drawList->AddTriangleFilled(p1, p2,
p3, color);
1373 drawList->AddTriangleFilled(p1, p2,
p3, color);
1375static void RenderStop(
gl::vec2 center, ImDrawList* drawList)
1377 gl::vec2 half{0.4f * ImGui::GetTextLineHeight()};
1378 drawList->AddRectFilled(center - half, center + half,
getColor(imColor::TEXT));
1380static void RenderRecord(
gl::vec2 center, ImDrawList* drawList)
1382 float radius = 0.4f * ImGui::GetTextLineHeight();
1383 drawList->AddCircleFilled(center, radius,
getColor(imColor::TEXT));
1387void ImGuiMedia::cassetteMenu(
const TclObject& cmdResult)
1389 ImGui::SetNextWindowSize(
gl::vec2{29, 20} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
1390 auto& info = cassetteMediaInfo;
1391 auto& group = info.group;
1393 ImGui::TextUnformatted(
"Current tape"sv);
1394 auto current = cmdResult.getListIndexUnchecked(1).getString();
1396 if (current.empty()) {
1397 ImGui::TextUnformatted(
"No tape inserted"sv);
1399 ImGui::TextUnformatted(
"Tape image:"sv);
1401 ImGui::TextUnformatted(leftClip(current, ImGui::GetContentRegionAvail().x));
1405 if (ImGui::Button(
"Eject")) {
1406 manager.executeDelayed(makeTclList(
"cassetteplayer",
"eject"));
1413 auto status = cmdResult.getListIndexUnchecked(2).getString();
1414 auto size = ImGui::GetFrameHeightWithSpacing();
1415 if (ButtonWithCustomRendering(
"##Play", {2.0f *
size,
size}, status ==
"play", RenderPlay)) {
1419 if (ButtonWithCustomRendering(
"##Rewind", {2.0f *
size,
size},
false, RenderRewind)) {
1423 if (ButtonWithCustomRendering(
"##Stop", {2.0f *
size,
size}, status ==
"stop", RenderStop)) {
1427 if (ButtonWithCustomRendering(
"##Record", {2.0f *
size,
size}, status ==
"record", RenderRecord)) {
1429 "Select new wav file for record",
1430 "Tape images (*.wav){.wav}",
1431 [&](
const auto& fn) {
1432 group.edit.name = fn;
1434 [&group](
const TclObject&) {
1443 auto getFloat = [&](std::string_view subCmd) {
1444 auto r = manager.
execute(
makeTclList(
"cassetteplayer", subCmd)).value_or(TclObject(0.0));
1445 return r.getOptionalFloat().value_or(0.0f);
1447 auto length = getFloat(
"getlength");
1448 auto pos = getFloat(
"getpos");
1449 auto format = [](
float time) {
1450 int t = narrow_cast<int>(time);
1451 int s =
t % 60;
t /= 60;
1452 int m =
t % 60;
t /= 60;
1453 std::ostringstream os;
1454 os << std::setfill(
'0');
1455 if (
t) os << std::setw(2) <<
t <<
':';
1456 os << std::setw(2) << m <<
':';
1457 os << std::setw(2) << s;
1460 ImGui::Text(
"%s / %s",
format(pos).c_str(),
format(length).c_str());
1464 const auto& hotKey = reactor.getHotKey();
1465 if (
auto* autoRun =
dynamic_cast<BooleanSetting*
>(controller.findSetting(
"autoruncassettes"))) {
1466 Checkbox(hotKey,
"(try to) Auto Run", *autoRun);
1468 if (
auto* mute =
dynamic_cast<BooleanSetting*
>(controller.findSetting(
"cassetteplayer_ch1_mute"))) {
1469 Checkbox(hotKey,
"Mute tape audio", *mute, [](
const Setting&) {
return std::string{}; });
1474 im::Child(
"select", {0, -ImGui::GetFrameHeightWithSpacing()}, [&]{
1477 selectImage(group,
"Select tape image", &cassetteFilter, current);
1480 insertMediaButton(
"cassetteplayer", group, &info.show);
1484void ImGuiMedia::insertMedia(std::string_view mediaName, ItemGroup& group)
1486 auto& item = group.edit;
1489 if (item.isEject()) {
1490 cmd.addListElement(
"eject");
1492 if (item.name.empty())
return;
1493 cmd.addListElement(
"insert", item.name);
1494 for (
const auto& patch : item.ipsPatches) {
1495 cmd.addListElement(
"-ips", patch);
1497 if (item.romType != RomType::UNKNOWN) {
1498 cmd.addListElement(
"-romtype", RomInfo::romTypeToName(item.romType));
1502 [&group](
const TclObject&) {
1504 if (group.edit.isEject())
return;
void test(const IterableBitSet< N > &s, std::initializer_list< size_t > list)
static constexpr unsigned MAX_SLOTS
std::optional< unsigned > findSlotWith(const HardwareConfig &config) const
std::string getPsSsString(unsigned slot) const
const HardwareConfig * getConfigForSlot(unsigned slot) const
static std::span< const std::string_view > getExtensions()
static std::span< const std::string_view > getExtensions()
static std::shared_ptr< HDInUse > getDrivesInUse(MSXMotherBoard &motherBoard)
const std::string & getConfigName() const
std::string_view getRomFilename() const
std::optional< TclObject > execute(TclObject command)
Interpreter & getInterpreter()
std::unique_ptr< ImGuiOpenFile > openFile
void executeDelayed(std::function< void()> action)
CartridgeSlotManager & getSlotManager()
MSXCommandController & getMSXCommandController()
const Extensions & getExtensions() const
static std::span< const std::string_view > getExtensions()
MSXMotherBoard * getMotherBoard() const
RomDatabase & getSoftwareDatabase()
This class implements a real drive, single or double sided.
static std::shared_ptr< DrivesInUse > getDrivesInUse(MSXMotherBoard &motherBoard)
std::string_view getYear(const char *buf) const
std::string_view getTitle(const char *buf) const
std::string_view getCompany(const char *buf) const
std::string_view getRemark(const char *buf) const
static std::string_view romTypeToName(RomType type)
std::string_view getCountry(const char *buf) const
static RomType nameToRomType(std::string_view name)
std::string_view getOrigType(const char *buf) const
std::optional< TclObject > getOptionalDictValue(const TclObject &key) const
zstring_view getString() const
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr auto empty() const
mat3 p3(vec3(1, 2, 3), vec3(4, 5, 6), vec3(7, 0, 9))
detail::Joiner< Collection, Separator > join(Collection &&col, Separator &&sep)
auto CalcTextSize(std::string_view str)
void TextUnformatted(const std::string &str)
bool stringToBool(string_view str)
T length(const vecN< N, T > &x)
void Table(const char *str_id, int column, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, std::invocable<> auto next)
void Window(const char *name, bool *p_open, ImGuiWindowFlags flags, std::invocable<> auto next)
void VisuallyDisabled(bool b, std::invocable<> auto next)
void ID(const char *str_id, std::invocable<> auto next)
bool TreeNode(const char *label, ImGuiTreeNodeFlags flags, std::invocable<> auto next)
void Combo(const char *label, const char *preview_value, ImGuiComboFlags flags, std::invocable<> auto next)
void ListBox(const char *label, const ImVec2 &size, std::invocable<> auto next)
void StyleColor(bool active, Args &&...args)
void Child(const char *str_id, const ImVec2 &size, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags, std::invocable<> auto next)
void TextWrapPos(float wrap_local_pos_x, std::invocable<> auto next)
bool Menu(const char *label, bool enabled, std::invocable<> auto next)
void Disabled(bool b, std::invocable<> auto next)
void Group(std::invocable<> auto next)
void Indent(float indent_w, std::invocable<> auto next)
void ListClipper(size_t count, int forceIndex, float lineHeight, std::invocable< int > auto next)
void ItemTooltip(std::invocable<> auto next)
void format(SectorAccessibleDisk &disk, MSXBootSectorType bootType)
Format the given disk (= a single partition).
string_view getFilename(string_view path)
Returns the file portion of a path name.
This file implemented 3 utility functions:
bool Checkbox(const HotKey &hotKey, BooleanSetting &setting)
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void applyComboFilter(std::string_view key, std::string_view value, const std::vector< T > &items, std::vector< size_t > &indices)
void simpleToolTip(std::string_view desc)
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
void HelpMarker(std::string_view desc)
ImU32 getColor(imColor col)
void applyDisplayNameFilter(std::string_view filterString, const std::vector< T > &items, std::vector< size_t > &indices)
TclObject makeTclList(Args &&... args)
auto find(InputRange &&range, const T &value)
auto lower_bound(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
size_t size(std::string_view utf8)
constexpr auto transform(Range &&range, UnaryOp op)
auto to_vector(Range &&range) -> std::vector< detail::ToVectorType< T, decltype(std::begin(range))> >
constexpr auto to_underlying(E e) noexcept
TemporaryString tmpStrCat(Ts &&... ts)
void strAppend(std::string &result, Ts &&...ts)
constexpr auto xrange(T e)