-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.cc
158 lines (142 loc) · 4.66 KB
/
app.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <cstdio>
#include "app.h"
#include "imgui.h"
#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "imwidget/error_dialog.h"
#include "util/browser.h"
#include "util/os.h"
#include "version.h"
#ifdef HAVE_NFD
#include "nfd.h"
#endif
#include "ImGuiFileDialog.h"
#include "implot.h"
namespace project {
App::App(const std::string& name) : ImApp(name, 1280, 720) {
ImPlot::CreateContext();
}
App::~App() {
ImPlot::DestroyContext();
}
void App::Init() {
}
void App::ProcessEvent(SDL_Event* event) {
}
void App::ProcessMessage(const std::string& msg, const void* extra) {
}
void App::Draw() {
ImGui::SetNextWindowSize(ImVec2(500,300), ImGuiCond_FirstUseEver);
auto* igfd = ImGuiFileDialog::Instance();
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open", "Ctrl+O")) {
#ifdef HAVE_NFD
char *filename = nullptr;
auto result = NFD_OpenDialog("z2prj;nes", nullptr, &filename);
if (result == NFD_OKAY) {
// DOSTUFF
save_filename_.assign(filename);
}
free(filename);
#else
igfd->OpenDialog("FileOpen", "Open File", ".*", ".", 1, nullptr, ImGuiFileDialogFlags_Modal);
#endif
}
if (ImGui::MenuItem("Save", "Ctrl+S")) {
if (save_filename_.empty())
goto save_as;
// DOSTUFF
}
if (ImGui::MenuItem("Save As")) {
save_as:
#ifdef HAVE_NFD
char *filename = nullptr;
auto result = NFD_SaveDialog("z2prj", nullptr, &filename);
if (result == NFD_OKAY) {
std::string savefile = filename;
if (absl::EndsWith(savefile, ".z2prj")) {
save_filename_.assign(savefile);
// DOSTUFF
} else {
ErrorDialog::Spawn("Bad File Extension",
ErrorDialog::OK | ErrorDialog::CANCEL,
"Project files should have the extension .z2prj\n"
"If you want to save a .nes file, use File | Export\n\n"
"Press 'OK' to save anyway.\n")->set_result_cb(
[=](int result) {
if (result == ErrorDialog::OK) {
save_filename_.assign(savefile);
// DOSTUFF
}
});
}
}
free(filename);
#else
igfd->OpenDialog("FileSaveAs", "Save File", ".*", ".", 1, nullptr, ImGuiFileDialogFlags_Modal);
#endif
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit")) {
ImGui::MenuItem("Debug Console", nullptr,
&console_.visible());
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View")) {
ImGui::MenuItem("Implot Demo", nullptr, &plot_demo_);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help")) {
if (ImGui::MenuItem("Online Help")) {
Help("root");
}
if (ImGui::MenuItem("About")) {
ErrorDialog::Spawn("About App",
"Empty Project\n\n",
#ifdef BUILD_GIT_VERSION
"Version: ", BUILD_GIT_VERSION, "-", BUILD_SCM_STATUS
#else
"Version: Unknown"
#warning "Built without version stamp"
#endif
);
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
if (igfd->Display("FileOpen")) {
if (igfd->IsOk()) {
std::string filename = igfd->GetFilePathName();
LOG(ERROR) << "File|Open: " << filename;
save_filename_ = filename;
}
igfd->Close();
}
if (igfd->Display("FileSaveAs")) {
if (igfd->IsOk()) {
std::string filename = igfd->GetFilePathName();
LOG(ERROR) << "File|SaveAs: " << filename;
}
igfd->Close();
}
ImPlot::ShowDemoWindow(&plot_demo_);
#if 0
if (!loaded_) {
char *filename = nullptr;
auto result = NFD_OpenDialog("z2prj,nes", nullptr, &filename);
if (result == NFD_OKAY) {
project_.Load(filename, false);
if (ends_with(filename, ".z2prj")) {
save_filename_.assign(filename);
}
}
free(filename);
}
#endif
}
void App::Help(const std::string& topickey) {
}
} // namespace project