-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModuleWindow.cpp
127 lines (105 loc) · 2.5 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "Globals.h"
#include "Application.h"
#include "ModuleWindow.h"
#include "SDL.h"
ModuleWindow::ModuleWindow(Application* app, bool start_enabled) : Module(app, start_enabled)
{
window = NULL;
screen_surface = NULL;
}
// Destructor
ModuleWindow::~ModuleWindow()
{
}
// Called before render is available
bool ModuleWindow::Init()
{
LOG("Init SDL window & surface");
LOGC("Starting Window module");
bool ret = true;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
LOG("SDL_VIDEO could not initialize! SDL_Error: %s\n", SDL_GetError());
ret = false;
}
else
{
//Create window
int width = SCREEN_WIDTH * SCREEN_SIZE;
int height = SCREEN_HEIGHT * SCREEN_SIZE;
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
//Use OpenGL 2.1
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
if (WIN_FULLSCREEN == true)
{
flags |= SDL_WINDOW_FULLSCREEN;
}
if (WIN_RESIZABLE == true)
{
flags |= SDL_WINDOW_RESIZABLE;
}
if (WIN_BORDERLESS == true)
{
flags |= SDL_WINDOW_BORDERLESS;
}
if (WIN_FULLSCREEN_DESKTOP == true)
{
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
if (WIN_DOUBLE_BUFFERING == true) {
flags |= GL_DOUBLEBUFFER;
}
window = SDL_CreateWindow(TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
if (window == NULL)
{
LOG("Window could not be created! SDL_Error: %s\n", SDL_GetError());
ret = false;
}
else
{
//Get window surface
screen_surface = SDL_GetWindowSurface(window);
}
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
return ret;
}
// Called before quitting
bool ModuleWindow::CleanUp()
{
LOG("Destroying SDL window and quitting all SDL systems");
//Destroy window
if (window != NULL)
{
SDL_DestroyWindow(window);
}
//Quit SDL subsystems
SDL_Quit();
return true;
}
void ModuleWindow::SetTitle(const char* title)
{
SDL_SetWindowTitle(window, title);
}
void ModuleWindow::SetFullscreen(bool active) {
if (active)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
else
SDL_SetWindowFullscreen(window, SDL_WINDOW_MINIMIZED);
}
void ModuleWindow::SetBorderless(bool active) {
if (active)
SDL_SetWindowBordered(window, SDL_FALSE);
else
SDL_SetWindowBordered(window, SDL_TRUE);
}
void ModuleWindow::SetResizable(bool active) {
if (active)
SDL_SetWindowResizable(window, SDL_TRUE);
else
SDL_SetWindowResizable(window, SDL_FALSE);
}
void ModuleWindow::SetWindowSize(int width, int height) {
SDL_SetWindowSize(window, width, height);
}