ultimatepp/rainbow/SDL2GUI/Window.cpp
cxl a060346fdd developing VirtualGui
git-svn-id: svn://ultimatepp.org/upp/trunk@11906 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2018-04-23 14:36:55 +00:00

75 lines
No EOL
1.2 KiB
C++

#include "SDL2GUI.h"
namespace Upp {
Size SDL2GUI::GetSize()
{
int w, h;
SDL_GetWindowSize(win, &w, &h);
return Size(w, h);
}
bool SDL2GUI::Create(const Rect& rect, const char *title)
{
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER);
win = SDL_CreateWindow(title, rect.left, rect.top, rect.GetWidth(), rect.GetHeight(),
SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL|SDL_WINDOW_BORDERLESS);
if(!win)
return false;
MemoryIgnoreLeaksBegin();
glcontext = SDL_GL_CreateContext(win);
MemoryIgnoreLeaksEnd();
if(!glcontext) {
Destroy();
return false;
}
return true;
}
extern SDL_TimerID waketimer_id;
void SDL2GUI::Destroy()
{
if(glcontext) {
SDL_GL_DeleteContext(glcontext);
glcontext = NULL;
GLDraw::ResetCache();
}
if(win) {
SDL_RemoveTimer(waketimer_id);
SDL_DestroyWindow(win);
win = NULL;
}
}
void SDL2GUI::Attach(SDL_Window *win_, SDL_GLContext glcontext_)
{
win = win_;
glcontext = glcontext_;
}
void SDL2GUI::Detach()
{
win = NULL;
glcontext = NULL;
}
SDL2GUI::SDL2GUI()
{
glcontext = NULL;
win = NULL;
}
SDL2GUI::~SDL2GUI()
{
Destroy();
SDL_Quit();
}
void SDL2GUI::Quit()
{
// SDL_Quit();
}
}