gui error handler
This commit is contained in:
parent
da1dfd4c13
commit
461b92ccc3
@ -6,7 +6,7 @@ UsefulException_::UsefulException_(const std::string& _message, const std::strin
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<message<<'\n';
|
||||
ss<<file<<':'<<_line_n<<" in "<<function;
|
||||
ss<<" at "<<file<<':'<<_line_n<<" in "<<function;
|
||||
complete_text = ss.str();
|
||||
}
|
||||
|
||||
|
||||
@ -43,7 +43,11 @@ void GUI::init(const char* window_title){
|
||||
sdl_window = SDL_CreateWindow(window_title,
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
1280, 720, window_flags);
|
||||
if(sdl_window == nullptr)
|
||||
throw SDLException();
|
||||
gl_context = SDL_GL_CreateContext(sdl_window);
|
||||
if(gl_context == nullptr)
|
||||
throw SDLException();
|
||||
SDL_TRY_ZERO( SDL_GL_MakeCurrent(sdl_window, gl_context));
|
||||
SDL_TRY_ZERO( SDL_GL_SetSwapInterval(1)); // Enable vsync
|
||||
|
||||
@ -108,20 +112,58 @@ void GUI::poll_events(u16& frame_updates_requested, bool wait){
|
||||
} while (SDL_PollEvent(&event)); // if there are more events, handles them
|
||||
}
|
||||
|
||||
void ImGui_drawErrorWindow(bool* draw_error_window, std::string& msg){
|
||||
ImGui::Begin("ERROR", draw_error_window);
|
||||
ImGui::Text("%s", msg.c_str());
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void GUI::draw_ui(){
|
||||
static std::string error_message;
|
||||
static bool draw_error_window = false;
|
||||
try {
|
||||
// Draw UI
|
||||
if(draw_error_window)
|
||||
ImGui_drawErrorWindow(&draw_error_window, error_message);
|
||||
else {
|
||||
draw_bg_window();
|
||||
draw_debug_window();
|
||||
node_editor->draw();
|
||||
}
|
||||
}
|
||||
catch(const std::exception& e){
|
||||
error_message = "Catched exception: " + std::string(e.what());
|
||||
draw_error_window = true;
|
||||
std::cerr<<error_message<<std::endl;
|
||||
}
|
||||
catch(const char* cstr){
|
||||
error_message = "Catched error message (const char*): " + std::string(cstr);
|
||||
draw_error_window = true;
|
||||
std::cerr<<error_message<<std::endl;
|
||||
}
|
||||
catch(const std::string& str){
|
||||
error_message = "Catched error message (std::string): " + str;
|
||||
draw_error_window = true;
|
||||
std::cerr<<error_message<<std::endl;
|
||||
}
|
||||
catch(...){
|
||||
error_message = "Catched unknown error";
|
||||
draw_error_window = true;
|
||||
std::cerr<<error_message<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::draw_frame(){
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// Draw UI
|
||||
draw_bg_window();
|
||||
draw_debug_window(io);
|
||||
node_editor->draw();
|
||||
draw_ui();
|
||||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
@ -230,12 +272,43 @@ void GUI::draw_bg_window(){
|
||||
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
||||
|
||||
// MenuBar
|
||||
//TODO
|
||||
if(ImGui::BeginMainMenuBar()){
|
||||
if(ImGui::BeginMenu("test")){
|
||||
if(ImGui::MenuItem("throw exception")){
|
||||
ImGui::EndMenu();
|
||||
ImGui::EndMainMenuBar();
|
||||
ImGui::End();
|
||||
throw UsefulException("example exception");
|
||||
}
|
||||
if(ImGui::MenuItem("throw const char*")){
|
||||
ImGui::EndMenu();
|
||||
ImGui::EndMainMenuBar();
|
||||
ImGui::End();
|
||||
throw "cptr";
|
||||
}
|
||||
if(ImGui::MenuItem("throw std::string")){
|
||||
ImGui::EndMenu();
|
||||
ImGui::EndMainMenuBar();
|
||||
ImGui::End();
|
||||
throw std::string("str");
|
||||
}
|
||||
if(ImGui::MenuItem("throw unknown")){
|
||||
ImGui::EndMenu();
|
||||
ImGui::EndMainMenuBar();
|
||||
ImGui::End();
|
||||
throw 111;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void GUI::draw_debug_window(ImGuiIO& io){
|
||||
void GUI::draw_debug_window(){
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImGui::Begin("Debug Options");
|
||||
ImGui::ColorEdit3("clear_color", (float*)&clear_color);
|
||||
ImGui::Checkbox("main_loop_wait_for_input", &main_loop_wait_for_input);
|
||||
|
||||
@ -48,7 +48,8 @@ private:
|
||||
void destroy();
|
||||
void poll_events(u16& frame_updates_requested, bool wait);
|
||||
void draw_frame();
|
||||
void draw_debug_window(ImGuiIO &io);
|
||||
void draw_ui();
|
||||
void draw_debug_window();
|
||||
void draw_bg_window();
|
||||
};
|
||||
|
||||
|
||||
13
src/main.cpp
13
src/main.cpp
@ -1,5 +1,6 @@
|
||||
#include "gui/gui.hpp"
|
||||
#include <iostream>
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
|
||||
// SDL for some reason redefines main
|
||||
#ifdef main
|
||||
@ -23,16 +24,16 @@ int main(const int argc, const char* const* argv){
|
||||
std::cerr<<"Catched exception: "<<e.what()<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch(const char* msg){
|
||||
std::cerr<<"Catched exception message: "<<msg<<std::endl;
|
||||
catch(const char* cstr){
|
||||
std::cerr<<"Catched error message (const char*): "<<cstr<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch(const std::string& msg){
|
||||
std::cerr<<"Catched exception message: "<<msg<<std::endl;
|
||||
catch(const std::string& str){
|
||||
std::cerr<<"Catched error message (std::string): "<<str<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch(...){
|
||||
std::cerr<<"Catched unknown exception"<<std::endl;
|
||||
std::cerr<<"Catched unknown error"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user