-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleWindow.cpp
69 lines (53 loc) · 1.49 KB
/
ModuleWindow.cpp
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
#include "ModuleWindow.h"
#include "Application.h"
#include "SDL.h"
ModuleWindow::ModuleWindow(bool startEnabled) : Module(startEnabled) {
name = "window";
}
ModuleWindow::~ModuleWindow() {
}
bool ModuleWindow::Init() {
LOG("Init Window-----");
bool ret = true;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
LOG("SDL_VIDEO has not been initialized! SDL_Error: \n", SDL_GetError());
ret = false;
}
else {
windowIcon = SDL_LoadBMP(WINDOW_ICON_PATH);
int width = SCREEN_WIDTH * SCREEN_SIZE;
int height = SCREEN_HEIGHT * SCREEN_SIZE;
Uint32 flags = SDL_WINDOW_SHOWN;
if (WIN_FULLSCREEN == true)
flags |= SDL_WINDOW_FULLSCREEN;
if (WIN_BORDERLESS == true)
flags |= SDL_WINDOW_BORDERLESS;
if (WIN_RESIZABLE == true)
flags |= SDL_WINDOW_RESIZABLE;
if (WIN_FULLSCREEN_DESKTOP == true)
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
sdlWindow = SDL_CreateWindow(WIN_TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
SDL_SetWindowIcon(sdlWindow, windowIcon);
//SDL_FreeSurface(windowIcon);
if (sdlWindow == NULL) {
LOG("Window has not been created! SDL_Error: %s\n", SDL_GetError());
ret = false;
}
else {
screenSurface = SDL_GetWindowSurface(sdlWindow);
}
}
return ret;
}
bool ModuleWindow::CleanUp()
{
LOG("Destroying SDL window and quitting all SDL systems");
//Destroy window
if (sdlWindow != NULL)
SDL_DestroyWindow(sdlWindow);
if (windowIcon != NULL)
SDL_FreeSurface(windowIcon);
//Quit SDL subsystems
SDL_Quit();
return true;
}