/
SDLWindow.cpp
executable file
·64 lines (52 loc) · 1.34 KB
/
SDLWindow.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
#include "SDLWindow.hpp"
//--- Standard includes -------------------------------------------------
#include <stdexcept>
//-----------------------------------------------------------------------
SDLWindow::SDLWindow(int width, int height)
:m_width(0)
,m_height(0)
,m_xcenter(0)
,m_ycenter(0)
,m_pScreen(NULL)
,m_bRunning(true)
{
if (SDL_Init(SDL_INIT_VIDEO) == -1)
throw std::runtime_error(SDL_GetError());
atexit(SDL_Quit);
m_pScreen = SDL_SetVideoMode(width, height, 16, SDL_HWSURFACE);
if (!m_pScreen)
throw std::runtime_error(SDL_GetError());
m_width = width;
m_height = height;
m_xcenter = width >> 1;
m_ycenter = height >> 1;
}
//-----------------------------------------------------------------------
void SDLWindow::MainLoop()
{
while (m_bRunning)
{
Render();
PollMessages();
}
}
//-----------------------------------------------------------------------
SDL_Surface *SDLWindow::Surface()
{
return m_pScreen;
}
//-----------------------------------------------------------------------
int SDLWindow::GetWidth() const
{
return m_width;
}
//-----------------------------------------------------------------------
int SDLWindow::GetHeight() const
{
return m_height;
}
//-----------------------------------------------------------------------
void SDLWindow::ExitMainLoop()
{
m_bRunning = false;
}