furnace/src/gui/sysPicker.cpp

102 lines
3.7 KiB
C++
Raw Normal View History

2022-08-26 20:30:13 -04:00
/**
* Furnace Tracker - multi-system chiptune tracker
2025-01-28 18:49:19 -05:00
* Copyright (C) 2021-2025 tildearrow and contributors
2022-08-26 20:30:13 -04:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "gui.h"
#include "misc/cpp/imgui_stdlib.h"
#include "IconsFontAwesome4.h"
#include "guiConst.h"
#include <imgui.h>
2024-08-24 07:03:28 -04:00
DivSystem FurnaceGUI::systemPicker(bool fullWidth) {
2022-08-26 20:30:13 -04:00
DivSystem ret=DIV_SYSTEM_NULL;
2022-08-27 00:35:16 -04:00
DivSystem hoveredSys=DIV_SYSTEM_NULL;
bool reissueSearch=false;
if (curSysSection==NULL) {
curSysSection=availableSystems;
}
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
2024-05-26 20:31:17 -04:00
if (ImGui::InputTextWithHint("##SysSearch",_("Search..."),&sysSearchQuery)) reissueSearch=true;
if (ImGui::BeginTabBar("SysCats")) {
for (int i=0; chipCategories[i]; i++) {
2024-05-26 20:31:17 -04:00
if (ImGui::BeginTabItem(_(chipCategoryNames[i]))) {
if (ImGui::IsItemActive()) {
reissueSearch=true;
2022-08-27 00:35:16 -04:00
}
curSysSection=chipCategories[i];
ImGui::EndTabItem();
2022-08-27 00:35:16 -04:00
}
}
ImGui::EndTabBar();
2022-08-27 00:35:16 -04:00
}
if (reissueSearch) {
2022-08-26 20:30:13 -04:00
String lowerCase=sysSearchQuery;
for (char& i: lowerCase) {
if (i>='A' && i<='Z') i+='a'-'A';
}
sysSearchResults.clear();
2022-08-27 00:35:16 -04:00
for (int j=0; curSysSection[j]; j++) {
String lowerCase1=e->getSystemName((DivSystem)curSysSection[j]);
2022-08-26 20:30:13 -04:00
for (char& i: lowerCase1) {
if (i>='A' && i<='Z') i+='a'-'A';
}
if (lowerCase1.find(lowerCase)!=String::npos) {
2022-08-27 00:35:16 -04:00
sysSearchResults.push_back((DivSystem)curSysSection[j]);
2022-08-26 20:30:13 -04:00
}
}
}
if (ImGui::BeginTable("SysList",1,ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuterH,ImVec2(fullWidth ? ImGui::GetContentRegionAvail().x : 500.0f*dpiScale,200.0f*dpiScale))) {
2022-08-27 00:35:16 -04:00
if (sysSearchQuery.empty()) {
// display chip list
for (int j=0; curSysSection[j]; j++) {
if (!settings.hiddenSystems && CHECK_HIDDEN_SYSTEM(curSysSection[j])) continue;
2022-08-27 00:35:16 -04:00
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::Selectable(e->getSystemName((DivSystem)curSysSection[j]),false,0,ImVec2(500.0f*dpiScale,0.0f))) ret=(DivSystem)curSysSection[j];
2024-11-11 13:57:33 -05:00
if (ImGui::IsItemHovered() && hoveredSys==DIV_SYSTEM_NULL) {
2022-08-27 00:35:16 -04:00
hoveredSys=(DivSystem)curSysSection[j];
}
}
} else {
// display search results
for (DivSystem i: sysSearchResults) {
if (!settings.hiddenSystems && CHECK_HIDDEN_SYSTEM(i)) continue;
2022-08-27 00:35:16 -04:00
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::Selectable(e->getSystemName(i),false,0,ImVec2(500.0f*dpiScale,0.0f))) ret=i;
2024-11-11 13:57:33 -05:00
if (ImGui::IsItemHovered() && hoveredSys==DIV_SYSTEM_NULL) {
2022-08-27 00:35:16 -04:00
hoveredSys=i;
}
}
2022-08-26 20:30:13 -04:00
}
2022-08-27 00:35:16 -04:00
ImGui::EndTable();
}
if (ImGui::BeginChild("SysDesc",ImVec2(0.0f,150.0f*dpiScale),false,ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoScrollWithMouse)) {
if (hoveredSys!=DIV_SYSTEM_NULL) {
const DivSysDef* sysDef=e->getSystemDef(hoveredSys);
ImGui::TextWrapped("%s",sysDef->description);
ImGui::Separator();
2024-10-10 15:25:12 -04:00
drawSystemChannelInfoText(sysDef);
drawSystemChannelInfo(sysDef);
2022-08-26 20:30:13 -04:00
}
}
2022-08-27 00:35:16 -04:00
ImGui::EndChild();
2022-08-26 20:30:13 -04:00
return ret;
2024-05-26 20:31:17 -04:00
}