summaryrefslogtreecommitdiff
path: root/src/window.cpp
blob: 39cbc3d2cc42447761e845e35e354d11542b9256 (plain)
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
#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_;
}