mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-15 17:25:06 +00:00
GUI: finish the modified thing
This commit is contained in:
parent
9a1853249b
commit
0f7ea7c269
2 changed files with 75 additions and 9 deletions
|
@ -2499,6 +2499,12 @@ int FurnaceGUI::load(String path) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void FurnaceGUI::showWarning(String what, FurnaceGUIWarnings type) {
|
||||
warnString=what;
|
||||
warnAction=type;
|
||||
warnQuit=true;
|
||||
}
|
||||
|
||||
void FurnaceGUI::showError(String what) {
|
||||
errorString=what;
|
||||
ImGui::OpenPopup("Error");
|
||||
|
@ -2598,8 +2604,12 @@ bool FurnaceGUI::loop() {
|
|||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
if (modified) {
|
||||
showWarning("Unsaved changes! Are you sure you want to quit?",GUI_WARN_QUIT);
|
||||
} else {
|
||||
quit=true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2613,13 +2623,23 @@ bool FurnaceGUI::loop() {
|
|||
ImGui::BeginMainMenuBar();
|
||||
if (ImGui::BeginMenu("file")) {
|
||||
if (ImGui::MenuItem("new")) {
|
||||
if (modified) {
|
||||
showWarning("Unsaved changes! Are you sure?",GUI_WARN_NEW);
|
||||
} else {
|
||||
e->createNew();
|
||||
undoHist.clear();
|
||||
redoHist.clear();
|
||||
curFileName="";
|
||||
modified=false;
|
||||
}
|
||||
}
|
||||
if (ImGui::MenuItem("open...")) {
|
||||
if (modified) {
|
||||
showWarning("Unsaved changes! Are you sure?",GUI_WARN_OPEN);
|
||||
} else {
|
||||
openFileDialog(GUI_FILE_OPEN);
|
||||
}
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("save")) {
|
||||
if (curFileName=="") {
|
||||
|
@ -2650,8 +2670,12 @@ bool FurnaceGUI::loop() {
|
|||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("exit")) {
|
||||
if (modified) {
|
||||
showWarning("Unsaved changes! Are you sure you want to quit?",GUI_WARN_QUIT);
|
||||
} else {
|
||||
quit=true;
|
||||
}
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("edit")) {
|
||||
|
@ -2773,6 +2797,11 @@ bool FurnaceGUI::loop() {
|
|||
ImGuiFileDialog::Instance()->Close();
|
||||
}
|
||||
|
||||
if (warnQuit) {
|
||||
warnQuit=false;
|
||||
ImGui::OpenPopup("Warning");
|
||||
}
|
||||
|
||||
if (aboutOpen) drawAbout();
|
||||
|
||||
if (ImGui::BeginPopupModal("Error",NULL,ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
|
@ -2783,6 +2812,33 @@ bool FurnaceGUI::loop() {
|
|||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupModal("Warning",NULL,ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::Text("%s",warnString.c_str());
|
||||
if (ImGui::Button("Yes")) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
switch (warnAction) {
|
||||
case GUI_WARN_QUIT:
|
||||
quit=true;
|
||||
break;
|
||||
case GUI_WARN_NEW:
|
||||
e->createNew();
|
||||
undoHist.clear();
|
||||
redoHist.clear();
|
||||
curFileName="";
|
||||
modified=false;
|
||||
break;
|
||||
case GUI_WARN_OPEN:
|
||||
openFileDialog(GUI_FILE_OPEN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("No")) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(sdlRend,uiColors[GUI_COLOR_BACKGROUND].x*255,
|
||||
uiColors[GUI_COLOR_BACKGROUND].y*255,
|
||||
uiColors[GUI_COLOR_BACKGROUND].z*255,
|
||||
|
@ -2904,10 +2960,12 @@ bool FurnaceGUI::finish() {
|
|||
FurnaceGUI::FurnaceGUI():
|
||||
e(NULL),
|
||||
quit(false),
|
||||
warnQuit(false),
|
||||
willCommit(false),
|
||||
edit(false),
|
||||
modified(false),
|
||||
curFileDialog(GUI_FILE_OPEN),
|
||||
warnAction(GUI_WARN_OPEN),
|
||||
scrW(1280),
|
||||
scrH(800),
|
||||
dpiScale(1),
|
||||
|
|
|
@ -73,6 +73,12 @@ enum FurnaceGUIFileDialogs {
|
|||
GUI_FILE_SAMPLE_SAVE
|
||||
};
|
||||
|
||||
enum FurnaceGUIWarnings {
|
||||
GUI_WARN_QUIT,
|
||||
GUI_WARN_NEW,
|
||||
GUI_WARN_OPEN
|
||||
};
|
||||
|
||||
struct SelectionPoint {
|
||||
int xCoarse, xFine;
|
||||
int y;
|
||||
|
@ -131,11 +137,12 @@ class FurnaceGUI {
|
|||
SDL_Window* sdlWin;
|
||||
SDL_Renderer* sdlRend;
|
||||
|
||||
String workingDir, fileName, clipboard, errorString, lastError, curFileName;
|
||||
String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName;
|
||||
|
||||
bool quit, willCommit, edit, modified;
|
||||
bool quit, warnQuit, willCommit, edit, modified;
|
||||
|
||||
FurnaceGUIFileDialogs curFileDialog;
|
||||
FurnaceGUIWarnings warnAction;
|
||||
|
||||
int scrW, scrH;
|
||||
|
||||
|
@ -246,6 +253,7 @@ class FurnaceGUI {
|
|||
int save(String path);
|
||||
int load(String path);
|
||||
|
||||
void showWarning(String what, FurnaceGUIWarnings type);
|
||||
void showError(String what);
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue