-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdlwin.hpp
62 lines (58 loc) · 1.6 KB
/
sdlwin.hpp
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
#ifndef SDLWIN_HEADER
#define SDLWIN_HEADER
#include "graphics.hpp"
#include <iostream>
#include <string>
#include <SDL/SDL.h>
namespace rcl{
class sdl_window{
private:
SDL_Surface* scrp;
unsigned int w,h;
std::string caption;
bool refresh;
public:
sdl_window(){
//std::cout << "SDL Window declared" << std::endl;
scrp=NULL;
w=0;
h=0;
refresh=false;
return;
}
bool init(const unsigned int& x,const unsigned int& y){
//std::cout << "SDL Have:"<< w << "x" << h << " called with " << x << "x" << y << std::endl;
if (w!=x) quit();
if (h!=y) quit();
if (w==x) if (h==y) return true;
w=x;
h=y;
return init();
}
bool init(){
quit();
if(SDL_Init(SDL_INIT_VIDEO) < 0){std::cout << "error, SDL video init failed" << std::endl; return true;}
scrp = SDL_SetVideoMode(w,h, 32, SDL_HWSURFACE);
if(!scrp) { std::cout << "error, no SDL screen" << std::endl; return true; }
refresh=false;
return false;
}
void quit(){if (scrp!=NULL) {SDL_Quit(); scrp=NULL;} return;}
void set_caption(const std::string& c) { caption = c; return;}
void update_caption(const std::string& c) {caption=c; update_caption(); return;}
void update_caption(){SDL_WM_SetCaption(caption.c_str(), NULL); return;}
void copy_window(const rcl::image32& img);
void update_win(){
if (!refresh) {
/*std::cout << "Refreshed window" << std::endl;*/
SDL_UpdateRect(scrp,0,0,0,0);
}
refresh=true;
return;
}
~sdl_window(){quit();}
SDL_Surface*& get_surface(){return scrp;}
SDL_Surface *operator->() { return scrp; }
};
}
#endif