-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDLDriver.cpp
More file actions
46 lines (38 loc) · 1.06 KB
/
SDLDriver.cpp
File metadata and controls
46 lines (38 loc) · 1.06 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
#include "SDLDriver.h"
SDLDriver::SDLDriver(int w, int h) {
sdlTimer = NULL;
width = w;
height = h;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
sdlScreen = SDL_SetVideoMode(width, height, 0, SDL_ANYFORMAT);
if ( !sdlScreen ) {
throw "SDL screen error!";
}
SDL_WM_SetCaption("SDL particle simulator", "SDL particle simulator");
}
SDLDriver::~SDLDriver() {
SDL_Quit();
}
void SDLDriver::AddTimer(int interval, SDL_NewTimerCallback callback, void *param) {
RemoveTimer();
sdlTimer = SDL_AddTimer(interval, callback, param);
}
void SDLDriver::RemoveTimer() {
if ( sdlTimer != NULL ) {
SDL_RemoveTimer(sdlTimer);
sdlTimer = NULL;
}
}
void SDLDriver::DrawParticle(const Particle *p) {
filledCircleColor(sdlScreen, p->pos.x, p->pos.y, p->radius, p->getColor());
}
void SDLDriver::ClearScreen() {
boxRGBA(sdlScreen, 0, 0, width, height, 0, 0, 0, 255);
}
void SDLDriver::Draw() {
SDL_Flip(sdlScreen);
}
void SDLDriver::WaitQuit() {
SDL_Event sdlEvent;
while ( SDL_WaitEvent(&sdlEvent) && sdlEvent.type!=SDL_QUIT );
}