diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2021-12-23 20:52:49 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2021-12-23 20:52:49 +0100 |
commit | 35465f27ed87646a18cd9298eae861f14385300e (patch) | |
tree | 7f0256d28fa6fd5368b7a39500d080456e70be8e /src/window.cpp |
First commit: moves a simple thing on the screen
Diffstat (limited to 'src/window.cpp')
-rw-r--r-- | src/window.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..39cbc3d --- /dev/null +++ b/src/window.cpp @@ -0,0 +1,58 @@ +#include "window.h" + +Window::Window( const char* title, int w, int h, int x, int y ) + : closed_ {false}, + focused_ {true} { + window_ = SDL_CreateWindow( title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); + if( window_ == NULL ) + { + printf( "Window could not be created: %s\n", SDL_GetError() ); + } +} + +Window::~Window(){ + SDL_DestroyWindow( window_ ); +} + +SDL_Window* Window::window(){ + return window_; +} + +void Window::toggleFullscreen(){ + auto togg = SDL_TRUE; + if( fullscreen_ ){ + togg = SDL_FALSE; + } + SDL_SetWindowFullscreen( window_, togg ); + printf("toggling fullscreen\n"); + fullscreen_ = !fullscreen_; +} + +void Window::handleEvent(SDL_Event e){ + switch( e.window.event ){ + case SDL_WINDOWEVENT_CLOSE: + closed_ = true; + printf("CLOSE!"); + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + focused_ = true; + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + focused_ = false; + break; + } +} + +Point Window::getSize(){ + Point size; + SDL_GetWindowSize(window_, &size.x, &size.y); + return size; +} + +bool Window::focused(){ + return focused_; +} + +bool Window::closed(){ + return closed_; +} |