From 64bb97532c13810af1c6d0724e6f960a0d74cc9f Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 11 Apr 2024 14:28:46 -0500 Subject: [PATCH 1/3] GUI: fix font oversample setting --- src/gui/settings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index bb2173d6f..02ad0b98b 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -4570,7 +4570,7 @@ void FurnaceGUI::readConfig(DivConfig& conf, FurnaceGUISettingGroups groups) { clampSetting(settings.fontBitmap,0,1); clampSetting(settings.fontAutoHint,0,2); clampSetting(settings.fontAntiAlias,0,1); - clampSetting(settings.fontOversample,0,2); + clampSetting(settings.fontOversample,1,3); clampSetting(settings.selectAssetOnLoad,0,1); clampSetting(settings.basicColors,0,1); clampSetting(settings.playbackTime,0,1); @@ -5724,7 +5724,7 @@ void FurnaceGUI::applyUISettings(bool updateFonts) { fontConf.OversampleV=1; fontConf.OversampleH=settings.fontOversample; fontConfP.OversampleV=1; - fontConfP.OversampleH=2; + fontConfP.OversampleH=settings.fontOversample; fontConfB.OversampleV=1; fontConfB.OversampleH=1; fontConfH.OversampleV=1; From 17aab13d9a82a52587c0593375c7f5bf13791dcc Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 11 Apr 2024 15:02:32 -0500 Subject: [PATCH 2/3] GUI: move user presets to its own file --- CMakeLists.txt | 1 + src/gui/presets.cpp | 354 ------------------------------------- src/gui/userPresets.cpp | 379 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 380 insertions(+), 354 deletions(-) create mode 100644 src/gui/userPresets.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 50a6c1a2a..a60657aeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -860,6 +860,7 @@ src/gui/sysManager.cpp src/gui/sysPartNumber.cpp src/gui/sysPicker.cpp src/gui/tutorial.cpp +src/gui/userPresets.cpp src/gui/util.cpp src/gui/waveEdit.cpp src/gui/volMeter.cpp diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index 78d5286bb..96912d0c5 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -3156,357 +3156,3 @@ FurnaceGUISysDef::FurnaceGUISysDef(const char* n, const char* def, DivEngine* e) // extract extra extra=conf.toString(); } - -// functions for loading/saving user presets -#ifdef _WIN32 -#define PRESETS_FILE "\\presets.cfg" -#else -#define PRESETS_FILE "/presets.cfg" -#endif - -#define REDUNDANCY_NUM_ATTEMPTS 5 -#define CHECK_BUF_SIZE 8192 - -std::vector* digDeep(std::vector& entries, int depth) { - if (depth==0) return &entries; - std::vector& result=entries; - - for (int i=0; igetConfigPath()+PRESETS_FILE; - String line; - logD("opening user presets: %s",path); - - FILE* f=NULL; - - if (redundancy) { - unsigned char* readBuf=new unsigned char[CHECK_BUF_SIZE]; - size_t readBufLen=0; - for (int i=0; i0) { - line=fmt::sprintf("%s.%d",path,i); - } else { - line=path; - } - logV("trying: %s",line); - - // try to open config - f=ps_fopen(line.c_str(),"rb"); - // check whether we could open it - if (f==NULL) { - logV("fopen(): %s",strerror(errno)); - continue; - } - - // check whether there's something - while (!feof(f)) { - readBufLen=fread(readBuf,1,CHECK_BUF_SIZE,f); - if (ferror(f)) { - logV("fread(): %s",strerror(errno)); - break; - } - - for (size_t j=0; jsystems.clear(); - - char nextLine[4096]; - while (!feof(f)) { - if (fgets(nextLine,4095,f)==NULL) { - break; - } - int indent=0; - bool readIndent=true; - bool keyOrValue=false; - String key=""; - String value=""; - for (char* i=nextLine; *i; i++) { - if ((*i)=='\n') break; - if (readIndent) { - if ((*i)==' ') { - indent++; - } else { - readIndent=false; - } - } - if (!readIndent) { - if (keyOrValue) { - value+=*i; - } else { - if ((*i)=='=') { - keyOrValue=true; - } else { - key+=*i; - } - } - } - } - indent>>=1; - - if (!key.empty() && !value.empty()) { - std::vector* where=digDeep(userCategory->systems,indent); - where->push_back(FurnaceGUISysDef(key.c_str(),value.c_str(),e)); - } - } - - fclose(f); - return true; -} - -void writeSubEntries(FILE* f, std::vector& entries, int depth) { - for (FurnaceGUISysDef& i: entries) { - String safeName; - safeName.reserve(i.name.size()); - bool beginning=false; - for (char j: i.name) { - if (beginning && j==' ') continue; - if (j=='=') continue; - if (j<0x20) continue; - safeName+=j; - } - - String data; - for (int i=0; igetConfigPath()+PRESETS_FILE; - FurnaceGUISysCategory* userCategory=NULL; - - for (FurnaceGUISysCategory& i: sysCategories) { - if (strcmp(i.name,"User")==0) { - userCategory=&i; - break; - } - } - - if (userCategory==NULL) { - logE("could not find user category!"); - return false; - } - - if (redundancy) { - char oldPath[4096]; - char newPath[4096]; - - if (fileExists(path.c_str())==1) { - logD("rotating preset files..."); - for (int i=4; i>=0; i--) { - if (i>0) { - snprintf(oldPath,4095,"%s.%d",path.c_str(),i); - } else { - strncpy(oldPath,path.c_str(),4095); - } - snprintf(newPath,4095,"%s.%d",path.c_str(),i+1); - - if (i>=4) { - logV("remove %s",oldPath); - deleteFile(oldPath); - } else { - logV("move %s to %s",oldPath,newPath); - moveFiles(oldPath,newPath); - } - } - } - } - logD("saving user presets: %s",path); - FILE* f=ps_fopen(path.c_str(),"wb"); - if (f==NULL) { - logW("could not write presets! %s",strerror(errno)); - return false; - } - - writeSubEntries(f,userCategory->systems,0); - - fclose(f); - logD("presets written successfully."); - return true; -} - -// user presets management -void FurnaceGUI::printPresets(std::vector& items, size_t depth, std::vector& depthStack) { - if (depth>0) ImGui::Indent(); - int index=0; - for (FurnaceGUISysDef& i: items) { - bool isSelected=(selectedUserPreset.size()==(depth+1)); - if (isSelected) { - for (size_t j=0; j<=depth; j++) { - int item=-1; - if (j>=depthStack.size()) { - item=index; - } else { - item=depthStack[j]; - } - - if (selectedUserPreset[j]!=item) { - isSelected=false; - break; - } - } - } - ImGui::PushID(index+1); - if (ImGui::Selectable(i.name.c_str(),isSelected)) { - selectedUserPreset=depthStack; - selectedUserPreset.push_back(index); - } - ImGui::PopID(); - if (!i.subDefs.empty()) { - depthStack.push_back(index); - ImGui::PushID(index); - printPresets(i.subDefs,depth+1,depthStack); - ImGui::PopID(); - depthStack.pop_back(); - } - index++; - } - if (depth>0) ImGui::Unindent(); -} - -FurnaceGUISysDef* FurnaceGUI::selectPreset(std::vector& items) { - FurnaceGUISysDef* ret=NULL; - for (size_t i=0; i(int)items.size()) return NULL; - ret=&items[selectedUserPreset[i]]; - if (isubDefs; - } - } - return ret; -} - -void FurnaceGUI::drawUserPresets() { - if (nextWindow==GUI_WINDOW_USER_PRESETS) { - userPresetsOpen=true; - ImGui::SetNextWindowFocus(); - nextWindow=GUI_WINDOW_NOTHING; - } - if (!userPresetsOpen) return; - if (ImGui::Begin("User Presets",&userPresetsOpen,globalWinFlags)) { - FurnaceGUISysCategory* userCategory=NULL; - for (FurnaceGUISysCategory& i: sysCategories) { - if (strcmp(i.name,"User")==0) { - userCategory=&i; - break; - } - } - - std::vector depthStack; - - if (userCategory==NULL) { - ImGui::Text("Error! User category does not exist!"); - } else if (ImGui::BeginTable("UserPresets",2,ImGuiTableFlags_BordersInnerV)) { - // preset list - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - if (ImGui::Button(ICON_FA_PLUS "##AddPreset")) { - userCategory->systems.push_back(FurnaceGUISysDef("New Preset",{})); - selectedUserPreset.clear(); - selectedUserPreset.push_back(userCategory->systems.size()-1); - } - printPresets(userCategory->systems,0,depthStack); - - // editor - ImGui::TableNextColumn(); - if (selectedUserPreset.empty()) { - ImGui::Text("select a preset"); - } else { - FurnaceGUISysDef* preset=selectPreset(userCategory->systems); - - if (preset!=NULL) { - ImGui::AlignTextToFramePadding(); - ImGui::Text("Name"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - ImGui::InputText("##PName",&preset->name); - ImGui::Separator(); - ImGui::Text("the rest..."); - } - } - - ImGui::EndTable(); - } - - if (ImGui::Button("Save and Close")) { - userPresetsOpen=false; - } - } - if (!userPresetsOpen) { - saveUserPresets(true); - } - if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_USER_PRESETS; - ImGui::End(); -} diff --git a/src/gui/userPresets.cpp b/src/gui/userPresets.cpp new file mode 100644 index 000000000..f78848300 --- /dev/null +++ b/src/gui/userPresets.cpp @@ -0,0 +1,379 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2024 tildearrow and contributors + * + * 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 "../baseutils.h" +#include "../fileutils.h" +#include +#include "IconsFontAwesome4.h" +#include +#include "misc/cpp/imgui_stdlib.h" + +#ifdef _WIN32 +#define PRESETS_FILE "\\presets.cfg" +#else +#define PRESETS_FILE "/presets.cfg" +#endif + +#define REDUNDANCY_NUM_ATTEMPTS 5 +#define CHECK_BUF_SIZE 8192 + +std::vector* digDeep(std::vector& entries, int depth) { + if (depth==0) return &entries; + std::vector& result=entries; + + for (int i=0; igetConfigPath()+PRESETS_FILE; + String line; + logD("opening user presets: %s",path); + + FILE* f=NULL; + + if (redundancy) { + unsigned char* readBuf=new unsigned char[CHECK_BUF_SIZE]; + size_t readBufLen=0; + for (int i=0; i0) { + line=fmt::sprintf("%s.%d",path,i); + } else { + line=path; + } + logV("trying: %s",line); + + // try to open config + f=ps_fopen(line.c_str(),"rb"); + // check whether we could open it + if (f==NULL) { + logV("fopen(): %s",strerror(errno)); + continue; + } + + // check whether there's something + while (!feof(f)) { + readBufLen=fread(readBuf,1,CHECK_BUF_SIZE,f); + if (ferror(f)) { + logV("fread(): %s",strerror(errno)); + break; + } + + for (size_t j=0; jsystems.clear(); + + char nextLine[4096]; + while (!feof(f)) { + if (fgets(nextLine,4095,f)==NULL) { + break; + } + int indent=0; + bool readIndent=true; + bool keyOrValue=false; + String key=""; + String value=""; + for (char* i=nextLine; *i; i++) { + if ((*i)=='\n') break; + if (readIndent) { + if ((*i)==' ') { + indent++; + } else { + readIndent=false; + } + } + if (!readIndent) { + if (keyOrValue) { + value+=*i; + } else { + if ((*i)=='=') { + keyOrValue=true; + } else { + key+=*i; + } + } + } + } + indent>>=1; + + if (!key.empty() && !value.empty()) { + std::vector* where=digDeep(userCategory->systems,indent); + where->push_back(FurnaceGUISysDef(key.c_str(),value.c_str(),e)); + } + } + + fclose(f); + return true; +} + +void writeSubEntries(FILE* f, std::vector& entries, int depth) { + for (FurnaceGUISysDef& i: entries) { + String safeName; + safeName.reserve(i.name.size()); + bool beginning=false; + for (char j: i.name) { + if (beginning && j==' ') continue; + if (j=='=') continue; + if (j<0x20) continue; + safeName+=j; + } + + String data; + for (int i=0; igetConfigPath()+PRESETS_FILE; + FurnaceGUISysCategory* userCategory=NULL; + + for (FurnaceGUISysCategory& i: sysCategories) { + if (strcmp(i.name,"User")==0) { + userCategory=&i; + break; + } + } + + if (userCategory==NULL) { + logE("could not find user category!"); + return false; + } + + if (redundancy) { + char oldPath[4096]; + char newPath[4096]; + + if (fileExists(path.c_str())==1) { + logD("rotating preset files..."); + for (int i=4; i>=0; i--) { + if (i>0) { + snprintf(oldPath,4095,"%s.%d",path.c_str(),i); + } else { + strncpy(oldPath,path.c_str(),4095); + } + snprintf(newPath,4095,"%s.%d",path.c_str(),i+1); + + if (i>=4) { + logV("remove %s",oldPath); + deleteFile(oldPath); + } else { + logV("move %s to %s",oldPath,newPath); + moveFiles(oldPath,newPath); + } + } + } + } + logD("saving user presets: %s",path); + FILE* f=ps_fopen(path.c_str(),"wb"); + if (f==NULL) { + logW("could not write presets! %s",strerror(errno)); + return false; + } + + writeSubEntries(f,userCategory->systems,0); + + fclose(f); + logD("presets written successfully."); + return true; +} + +// user presets management +void FurnaceGUI::printPresets(std::vector& items, size_t depth, std::vector& depthStack) { + if (depth>0) ImGui::Indent(); + int index=0; + for (FurnaceGUISysDef& i: items) { + bool isSelected=(selectedUserPreset.size()==(depth+1)); + if (isSelected) { + for (size_t j=0; j<=depth; j++) { + int item=-1; + if (j>=depthStack.size()) { + item=index; + } else { + item=depthStack[j]; + } + + if (selectedUserPreset[j]!=item) { + isSelected=false; + break; + } + } + } + ImGui::PushID(index+1); + if (ImGui::Selectable(i.name.c_str(),isSelected)) { + selectedUserPreset=depthStack; + selectedUserPreset.push_back(index); + } + ImGui::PopID(); + if (!i.subDefs.empty()) { + depthStack.push_back(index); + ImGui::PushID(index); + printPresets(i.subDefs,depth+1,depthStack); + ImGui::PopID(); + depthStack.pop_back(); + } + index++; + } + if (depth>0) ImGui::Unindent(); +} + +FurnaceGUISysDef* FurnaceGUI::selectPreset(std::vector& items) { + FurnaceGUISysDef* ret=NULL; + for (size_t i=0; i(int)items.size()) return NULL; + ret=&items[selectedUserPreset[i]]; + if (isubDefs; + } + } + return ret; +} + +void FurnaceGUI::drawUserPresets() { + if (nextWindow==GUI_WINDOW_USER_PRESETS) { + userPresetsOpen=true; + ImGui::SetNextWindowFocus(); + nextWindow=GUI_WINDOW_NOTHING; + } + if (!userPresetsOpen) return; + if (ImGui::Begin("User Presets",&userPresetsOpen,globalWinFlags)) { + FurnaceGUISysCategory* userCategory=NULL; + for (FurnaceGUISysCategory& i: sysCategories) { + if (strcmp(i.name,"User")==0) { + userCategory=&i; + break; + } + } + + std::vector depthStack; + + if (userCategory==NULL) { + ImGui::Text("Error! User category does not exist!"); + } else if (ImGui::BeginTable("UserPresets",2,ImGuiTableFlags_BordersInnerV)) { + // preset list + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::Button(ICON_FA_PLUS "##AddPreset")) { + userCategory->systems.push_back(FurnaceGUISysDef("New Preset",{})); + selectedUserPreset.clear(); + selectedUserPreset.push_back(userCategory->systems.size()-1); + } + printPresets(userCategory->systems,0,depthStack); + + // editor + ImGui::TableNextColumn(); + if (selectedUserPreset.empty()) { + ImGui::Text("select a preset"); + } else { + FurnaceGUISysDef* preset=selectPreset(userCategory->systems); + + if (preset!=NULL) { + ImGui::AlignTextToFramePadding(); + ImGui::Text("Name"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::InputText("##PName",&preset->name); + ImGui::Separator(); + ImGui::Text("the rest..."); + } + } + + ImGui::EndTable(); + } + + if (ImGui::Button("Save and Close")) { + userPresetsOpen=false; + } + } + if (!userPresetsOpen) { + saveUserPresets(true); + } + if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_USER_PRESETS; + ImGui::End(); +} From 3ad2f407d4671047b35463d85a48c0b554a1f552 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 11 Apr 2024 17:31:53 -0500 Subject: [PATCH 3/3] CI: build on Metal push it will be 100% guesswork --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ea758367..673e18ff3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build furnace on: push: - branches: master + branches: [master, metal] pull_request: branches: master