1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
3 |
#include <string.h> |
4 |
#include "SdlSetup.h" |
5 |
#include "../Screen/ScreenData.h"
|
6 |
|
7 |
SdlSetup::SdlSetup(){}
|
8 |
SdlSetup::~SdlSetup(){}
|
9 |
|
10 |
void SdlSetup::setupScreen()
|
11 |
{ |
12 |
mousex=0;
|
13 |
mousey=0;
|
14 |
mousebutton=0;
|
15 |
done=true;
|
16 |
|
17 |
// Initialize SDL |
18 |
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) |
19 |
{ |
20 |
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
21 |
exit(1); |
22 |
} |
23 |
else
|
24 |
{
|
25 |
atexit(SDL_Quit); |
26 |
}
|
27 |
|
28 |
video_bpp = ScreenData::getBitPlan(); |
29 |
videoflags = SDL_SWSURFACE; |
30 |
|
31 |
// videoflags = SDL_FULLSCREEN;
|
32 |
|
33 |
// Set video mode
|
34 |
|
35 |
if ( (screen=SDL_SetVideoMode(ScreenData::getWidth(),ScreenData::getHeight(),video_bpp,videoflags)) == NULL )
|
36 |
{ |
37 |
fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",video_bpp, SDL_GetError()); |
38 |
exit(2); |
39 |
} |
40 |
|
41 |
ScreenData::setChunkyBuffer((int*)screen->pixels);
|
42 |
ScreenData::setWidth(screen->w);
|
43 |
ScreenData::setHeight(screen->h);
|
44 |
|
45 |
// Set the surface pixels and refresh! |
46 |
|
47 |
if ( SDL_LockSurface(screen) < 0 )
|
48 |
{ |
49 |
fprintf(stderr, "Couldn't lock the display surface: %s\n", SDL_GetError()); |
50 |
exit(2); |
51 |
} |
52 |
}
|
53 |
|
54 |
|
55 |
void SdlSetup::updateScreen()
|
56 |
{ |
57 |
SDL_UnlockSurface(screen); |
58 |
SDL_UpdateRect(screen, 0, 0, 0, 0); |
59 |
}
|
60 |
|
61 |
void SdlSetup::quit()
|
62 |
{
|
63 |
//exit(0);
|
64 |
|
65 |
} |
66 |
|
67 |
void SdlSetup::events()
|
68 |
{
|
69 |
if ( SDL_PollEvent(&event) )
|
70 |
{
|
71 |
switch (event.type)
|
72 |
{
|
73 |
case SDL_KEYDOWN:
|
74 |
done = false;
|
75 |
break;
|
76 |
|
77 |
case SDL_QUIT:
|
78 |
done = false;
|
79 |
break;
|
80 |
|
81 |
case SDL_MOUSEMOTION:
|
82 |
mousex = event.motion.x;
|
83 |
mousey = event.motion.y;
|
84 |
break;
|
85 |
|
86 |
case SDL_MOUSEBUTTONDOWN:
|
87 |
mousebutton=1;
|
88 |
break;
|
89 |
|
90 |
//case SDL_MOUSEBUTTONUP:
|
91 |
//mousebutton=0;
|
92 |
//break;
|
93 |
|
94 |
default:
|
95 |
break;
|
96 |
}
|
97 |
}
|
98 |
}
|
99 |
|
100 |
bool SdlSetup::getDone()
|
101 |
{
|
102 |
return done;
|
103 |
}
|
104 |
|
105 |
int SdlSetup::getMousex()
|
106 |
{
|
107 |
return mousex;
|
108 |
}
|
109 |
|
110 |
int SdlSetup::getMousey()
|
111 |
{
|
112 |
return mousey;
|
113 |
}
|
114 |
|
115 |
|