1 #include "SDL2GL.h"
2
3 namespace Upp {
4
GetOptions()5 dword SDL2GUI::GetOptions()
6 {
7 return GUI_SETMOUSECURSOR;
8 }
9
GetSize()10 Size SDL2GUI::GetSize()
11 {
12 int w, h;
13 SDL_GetWindowSize(win, &w, &h);
14 return Size(w, h);
15 }
16
Create(const Rect & rect,const char * title)17 bool SDL2GUI::Create(const Rect& rect, const char *title)
18 {
19 SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER);
20
21 win = SDL_CreateWindow(title, rect.left, rect.top, rect.GetWidth(), rect.GetHeight(),
22 SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL|SDL_WINDOW_BORDERLESS);
23 if(!win)
24 return false;
25 MemoryIgnoreLeaksBegin();
26 glcontext = SDL_GL_CreateContext(win);
27 MemoryIgnoreLeaksEnd();
28 if(!glcontext) {
29 Destroy();
30 return false;
31 }
32 return true;
33 }
34
35 extern SDL_TimerID waketimer_id;
36
Destroy()37 void SDL2GUI::Destroy()
38 {
39 if(glcontext) {
40 SDL_GL_DeleteContext(glcontext);
41 glcontext = NULL;
42 GLDraw::ResetCache();
43 }
44 if(win) {
45 SDL_RemoveTimer(waketimer_id);
46 SDL_DestroyWindow(win);
47 win = NULL;
48 }
49 }
50
Attach(SDL_Window * win_,SDL_GLContext glcontext_)51 void SDL2GUI::Attach(SDL_Window *win_, SDL_GLContext glcontext_)
52 {
53 win = win_;
54 glcontext = glcontext_;
55 }
56
Detach()57 void SDL2GUI::Detach()
58 {
59 win = NULL;
60 glcontext = NULL;
61 }
62
SDL2GUI()63 SDL2GUI::SDL2GUI()
64 {
65 glcontext = NULL;
66 win = NULL;
67 }
68
~SDL2GUI()69 SDL2GUI::~SDL2GUI()
70 {
71 Destroy();
72 }
73
Quit()74 void SDL2GUI::Quit()
75 {
76 SDL_Quit();
77 }
78
79 }