Skip to content
Snippets Groups Projects
Commit 91a590ad authored by bartvbl's avatar bartvbl
Browse files

Hopefully fix window closing issues on MacOS (and hopefully not break it on windows/linux)

parent 410e62af
No related branches found
No related tags found
No related merge requests found
...@@ -41,10 +41,12 @@ class AnimationWindow { ...@@ -41,10 +41,12 @@ class AnimationWindow {
private: private:
void show_frame(); void show_frame();
void update_gui(); void update_gui();
void pump_events();
TDT4102::Point getWindowDimensions() const; TDT4102::Point getWindowDimensions() const;
void startNuklearDraw(TDT4102::Point location, std::string uniqueWindowName, unsigned int width = 0, unsigned int height = 0); void startNuklearDraw(TDT4102::Point location, std::string uniqueWindowName, unsigned int width = 0, unsigned int height = 0);
void endNuklearDraw(); void endNuklearDraw();
void destroy(); void destroy();
bool destroyed = false;
// If set to true, new shapes will be drawn on top of the old ones. Can create some neat effects. // If set to true, new shapes will be drawn on top of the old ones. Can create some neat effects.
// However, note that GUI elements such as buttons will not draw themselves correctly if you use this. // However, note that GUI elements such as buttons will not draw themselves correctly if you use this.
......
...@@ -60,6 +60,8 @@ TDT4102::AnimationWindow::~AnimationWindow() { ...@@ -60,6 +60,8 @@ TDT4102::AnimationWindow::~AnimationWindow() {
} }
void TDT4102::AnimationWindow::destroy() { void TDT4102::AnimationWindow::destroy() {
this->destroyed = true;
// Free SDL resources depending on how much ended up being initialised in the constructor // Free SDL resources depending on how much ended up being initialised in the constructor
if (rendererHandle != nullptr) { if (rendererHandle != nullptr) {
SDL_DestroyRenderer(rendererHandle); SDL_DestroyRenderer(rendererHandle);
...@@ -73,14 +75,16 @@ void TDT4102::AnimationWindow::destroy() { ...@@ -73,14 +75,16 @@ void TDT4102::AnimationWindow::destroy() {
nk_free(context); nk_free(context);
context = nullptr; context = nullptr;
} }
// Needed for MacOS
// Window does not close unless the events are pumped
// after requesting that
pump_events();
} }
void TDT4102::AnimationWindow::show_frame() { void TDT4102::AnimationWindow::pump_events() {
SDL_RenderPresent(rendererHandle);
deltaMouseWheel = 0;
SDL_Event event; SDL_Event event;
nk_input_begin(context); SDL_PumpEvents();
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) { if (event.type == SDL_QUIT) {
closeRequested = true; closeRequested = true;
...@@ -107,8 +111,18 @@ void TDT4102::AnimationWindow::show_frame() { ...@@ -107,8 +111,18 @@ void TDT4102::AnimationWindow::show_frame() {
deltaMouseWheel = event.wheel.preciseY; // The amount scrolled vertically, positive away from the user and negative toward the user deltaMouseWheel = event.wheel.preciseY; // The amount scrolled vertically, positive away from the user and negative toward the user
} }
nk_sdl_handle_event(&event); if(!destroyed) {
nk_sdl_handle_event(&event);
}
} }
}
void TDT4102::AnimationWindow::show_frame() {
SDL_RenderPresent(rendererHandle);
deltaMouseWheel = 0;
nk_input_begin(context);
pump_events();
nk_input_end(context); nk_input_end(context);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment