forked from CostardRouge/Cuby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDLDisplay.cpp
More file actions
141 lines (116 loc) · 3.09 KB
/
Copy pathSDLDisplay.cpp
File metadata and controls
141 lines (116 loc) · 3.09 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "SDLDisplay.hpp"
SDL_Surface *MainScreen = NULL;
SDLDisplay::SDLDisplay(const std::string & title, Settings * settings)
{
// Temporary variables
int flags;
int inits;
SDL_putenv("SDL_VIDEO_CENTERED=center");
// Init temporary variables
flags = SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_NOFRAME;
inits = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
// Init Attributes
this->setFullscreen(settings->getFullscreen());
this->setHeight(settings->getHeight());
this->setWidth(settings->getWidth());
// Init SDL
if (SDL_Init(inits) == -1)
throw Exception(SDL_GetError());
this->hardware = (SDL_VideoInfo *)SDL_GetVideoInfo();
/*if (TTF_Init() == -1)
throw Exception("TTF Init failed. :(");
if (!(this->font = TTF_OpenFont("./media/font.ttf", 40)))
exit_msg(1, "Cannot open the requested font. :(");*/
/*
this->hardware = (SDL_VideoInfo *)SDL_GetVideoInfo();
this->monitor_height = this->hardware->current_h;
this->monitor_width = this->hardware->current_w;*/
//SDL_WM_SetIcon(SDL_LoadBMP("./media/icon.bmp"), NULL);
if (this->fullscreen)
{
this->screen = SDL_SetVideoMode(this->hardware->current_w, this->hardware->current_h, 32, flags);
settings->setHeight(this->hardware->current_h);
settings->setWidth(this->hardware->current_w);
this->setHeight(this->hardware->current_h);
this->setWidth(this->hardware->current_w);
}
else
this->screen = SDL_SetVideoMode(this->getWidth(), this->getHeight(), 32, flags);
if (!this->screen)
throw Exception(SDL_GetError());
MainScreen = this->screen;
SDL_WM_SetCaption(title.c_str(), NULL);
//SDL_ShowCursor(SDL_DISABLE);
}
SDLDisplay::~SDLDisplay()
{
SDL_FreeSurface(this->screen);
/*TTF_CloseFont(this->font);
TTF_Quit();*/
SDL_Quit();
}
void SDLDisplay::EnableTransparentWindows(void)
{
SDL_SysWMinfo info;
HWND hwnd;
SDL_VERSION(&info.version);
if (SDL_GetWMInfo(&info))
hwnd = info.window;
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 1, LWA_COLORKEY);
}
void SDLDisplay::Clear(void)
{
SDL_FillRect(this->screen, NULL, SDL_MapRGB(this->screen->format, 0, 0, 0));
}
void SDLDisplay::Refresh(void)
{
SDL_Flip(this->screen);
SDL_Delay(10);
}
eEvent SDLDisplay::HandleEvents(void)
{
SDL_PollEvent(&this->event);
if (this->event.type == SDL_QUIT)
return (QUIT);
if (this->event.type == SDL_VIDEORESIZE)
return (RESIZE);
return (NOEVENT);
}
eKey SDLDisplay::PressedKey(void)
{
Uint8 *keys;
if (this->event.type == SDL_KEYDOWN)
{
keys = SDL_GetKeyState(NULL);
if (keys[SDLK_ESCAPE])
return (ESC);
}
return (NOKEY);
}
// Getters
bool SDLDisplay::getFullscreen(void) const
{
return (this->fullscreen);
}
unsigned int SDLDisplay::getHeight(void) const
{
return (this->height);
}
unsigned int SDLDisplay::getWidth(void) const
{
return (this->width);
}
// Setters
void SDLDisplay::setFullscreen(bool value)
{
this->fullscreen = value;
}
void SDLDisplay::setHeight(unsigned int value)
{
this->height = value;
}
void SDLDisplay::setWidth(unsigned int value)
{
this->width = value;
}