GUI: add/remove options

This commit is contained in:
tildearrow 2022-01-09 16:36:47 -05:00
parent 925a29249b
commit 4bbfc22c2a
3 changed files with 70 additions and 20 deletions

View file

@ -946,6 +946,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
ds.arpLen=reader.readC(); ds.arpLen=reader.readC();
ds.hz=reader.readF(); ds.hz=reader.readF();
ds.pal=(ds.hz>=53); ds.pal=(ds.hz>=53);
if (ds.hz!=50 && ds.hz!=60) ds.customTempo=true;
ds.patLen=reader.readS(); ds.patLen=reader.readS();
ds.ordersLen=reader.readS(); ds.ordersLen=reader.readS();
@ -2168,7 +2169,7 @@ void DivEngine::changeSystem(int index, DivSystem which) {
bool DivEngine::addSystem(DivSystem which) { bool DivEngine::addSystem(DivSystem which) {
if (song.systemLen>32) { if (song.systemLen>32) {
lastError="cannot add more than 32 systems"; lastError="cannot add more than 32";
return false; return false;
} }
if (chans+getChannelCount(which)>DIV_MAX_CHANS) { if (chans+getChannelCount(which)>DIV_MAX_CHANS) {
@ -2188,6 +2189,32 @@ bool DivEngine::addSystem(DivSystem which) {
return true; return true;
} }
bool DivEngine::removeSystem(int index) {
if (song.systemLen<=1) {
lastError="cannot remove the last one";
return false;
}
if (index<0 || index>=song.systemLen) {
lastError="invalid index";
return false;
}
quitDispatch();
isBusy.lock();
song.system[index]=DIV_SYSTEM_NULL;
song.systemLen--;
for (int i=index; i<song.systemLen; i++) {
song.system[index]=song.system[index+1];
}
recalcChans();
isBusy.unlock();
initDispatch();
isBusy.lock();
renderSamples();
reset();
isBusy.unlock();
return true;
}
String DivEngine::getLastError() { String DivEngine::getLastError() {
return lastError; return lastError;
} }

View file

@ -2343,7 +2343,7 @@ void FurnaceGUI::keyUp(SDL_Event& ev) {
void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) { void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
switch (type) { switch (type) {
case GUI_FILE_OPEN: case GUI_FILE_OPEN:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Open File","Furnace song{.fur},DefleMask module{.dmf},.*",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Open File","compatible files{.fur,.dmf},.*",workingDir);
break; break;
case GUI_FILE_SAVE: case GUI_FILE_SAVE:
ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save File","Furnace song{.fur},DefleMask module{.dmf}",workingDir); ImGuiFileDialog::Instance()->OpenModal("FileDialog","Save File","Furnace song{.fur},DefleMask module{.dmf}",workingDir);
@ -2524,7 +2524,7 @@ void FurnaceGUI::showWarning(String what, FurnaceGUIWarnings type) {
void FurnaceGUI::showError(String what) { void FurnaceGUI::showError(String what) {
errorString=what; errorString=what;
ImGui::OpenPopup("Error"); displayError=true;
} }
void FurnaceGUI::processDrags(int dragX, int dragY) { void FurnaceGUI::processDrags(int dragX, int dragY) {
@ -2563,14 +2563,14 @@ void FurnaceGUI::processDrags(int dragX, int dragY) {
#define sysAddOption(x) \ #define sysAddOption(x) \
if (ImGui::MenuItem(e->getSystemName(x))) { \ if (ImGui::MenuItem(e->getSystemName(x))) { \
if (!e->addSystem(x)) { \ if (!e->addSystem(x)) { \
showError("cannot add system! ("+e->getLastError()+")"); \ showError("cannot add platform! ("+e->getLastError()+")"); \
} \ } \
updateWindowTitle(); \ updateWindowTitle(); \
} }
#define sysChangeOption(x) \ #define sysChangeOption(x,y) \
if (ImGui::MenuItem(e->getSystemName(x),NULL,e->song.system[0]==x)) { \ if (ImGui::MenuItem(e->getSystemName(y),NULL,e->song.system[x]==y)) { \
e->changeSystem(0,x); \ e->changeSystem(x,y); \
updateWindowTitle(); \ updateWindowTitle(); \
} }
@ -2654,6 +2654,7 @@ bool FurnaceGUI::loop() {
redoHist.clear(); redoHist.clear();
curFileName=""; curFileName="";
modified=false; modified=false;
updateWindowTitle();
} }
} }
if (ImGui::MenuItem("open...")) { if (ImGui::MenuItem("open...")) {
@ -2691,18 +2692,33 @@ bool FurnaceGUI::loop() {
sysAddOption(DIV_SYSTEM_YM2610_EXT); sysAddOption(DIV_SYSTEM_YM2610_EXT);
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("change first platform...")) { if (ImGui::BeginMenu("change platform...")) {
sysChangeOption(DIV_SYSTEM_GENESIS); for (int i=0; i<e->song.systemLen; i++) {
sysChangeOption(DIV_SYSTEM_GENESIS_EXT); if (ImGui::BeginMenu(fmt::sprintf("%d. %s##_SYSC%d",i+1,e->getSystemName(e->song.system[i]),i).c_str())) {
sysChangeOption(DIV_SYSTEM_SMS); sysChangeOption(i,DIV_SYSTEM_GENESIS);
sysChangeOption(DIV_SYSTEM_GB); sysChangeOption(i,DIV_SYSTEM_GENESIS_EXT);
sysChangeOption(DIV_SYSTEM_PCE); sysChangeOption(i,DIV_SYSTEM_SMS);
sysChangeOption(DIV_SYSTEM_NES); sysChangeOption(i,DIV_SYSTEM_GB);
sysChangeOption(DIV_SYSTEM_C64_8580); sysChangeOption(i,DIV_SYSTEM_PCE);
sysChangeOption(DIV_SYSTEM_C64_6581); sysChangeOption(i,DIV_SYSTEM_NES);
sysChangeOption(DIV_SYSTEM_ARCADE); sysChangeOption(i,DIV_SYSTEM_C64_8580);
sysChangeOption(DIV_SYSTEM_YM2610); sysChangeOption(i,DIV_SYSTEM_C64_6581);
sysChangeOption(DIV_SYSTEM_YM2610_EXT); sysChangeOption(i,DIV_SYSTEM_ARCADE);
sysChangeOption(i,DIV_SYSTEM_YM2610);
sysChangeOption(i,DIV_SYSTEM_YM2610_EXT);
ImGui::EndMenu();
}
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("remove platform...")) {
for (int i=0; i<e->song.systemLen; i++) {
if (ImGui::MenuItem(fmt::sprintf("%d. %s##_SYSR%d",i+1,e->getSystemName(e->song.system[i]),i).c_str())) {
if (!e->removeSystem(i)) {
showError("cannot remove platform! ("+e->getLastError()+")");
}
}
}
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::Separator(); ImGui::Separator();
@ -2845,6 +2861,11 @@ bool FurnaceGUI::loop() {
ImGui::OpenPopup("Warning"); ImGui::OpenPopup("Warning");
} }
if (displayError) {
displayError=false;
ImGui::OpenPopup("Error");
}
if (aboutOpen) drawAbout(); if (aboutOpen) drawAbout();
if (ImGui::BeginPopupModal("Error",NULL,ImGuiWindowFlags_AlwaysAutoResize)) { if (ImGui::BeginPopupModal("Error",NULL,ImGuiWindowFlags_AlwaysAutoResize)) {
@ -2869,6 +2890,7 @@ bool FurnaceGUI::loop() {
redoHist.clear(); redoHist.clear();
curFileName=""; curFileName="";
modified=false; modified=false;
updateWindowTitle();
break; break;
case GUI_WARN_OPEN: case GUI_WARN_OPEN:
openFileDialog(GUI_FILE_OPEN); openFileDialog(GUI_FILE_OPEN);
@ -3059,6 +3081,7 @@ FurnaceGUI::FurnaceGUI():
willCommit(false), willCommit(false),
edit(false), edit(false),
modified(false), modified(false),
displayError(false),
curFileDialog(GUI_FILE_OPEN), curFileDialog(GUI_FILE_OPEN),
warnAction(GUI_WARN_OPEN), warnAction(GUI_WARN_OPEN),
scrW(1280), scrW(1280),

View file

@ -137,7 +137,7 @@ class FurnaceGUI {
String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName; String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName;
bool quit, warnQuit, willCommit, edit, modified; bool quit, warnQuit, willCommit, edit, modified, displayError;
FurnaceGUIFileDialogs curFileDialog; FurnaceGUIFileDialogs curFileDialog;
FurnaceGUIWarnings warnAction; FurnaceGUIWarnings warnAction;