If resolution is set to (0,0) then a fullscreen app is created.legacy
@@ -41,7 +41,7 @@ public: | |||||
virtual ~null_display() {} | virtual ~null_display() {} | ||||
protected: | protected: | ||||
void SetResolution(ivec2) {} | |||||
void set_resolution(ivec2) {} | |||||
void SetPosition(ivec2) {} | void SetPosition(ivec2) {} | ||||
void Enable() {} | void Enable() {} | ||||
@@ -63,28 +63,11 @@ class ApplicationDisplayData | |||||
{ | { | ||||
friend class ApplicationDisplay; | friend class ApplicationDisplay; | ||||
ApplicationDisplayData(char const *name, ivec2 resolution) | |||||
: display(name, resolution) | |||||
ApplicationDisplayData(char const *name, ivec2 res) | |||||
: display(name, res) | |||||
{ } | { } | ||||
protected: | protected: | ||||
void SetResolution(ivec2 resolution) | |||||
{ | |||||
display.SetResolution(resolution); | |||||
} | |||||
void SetPosition(ivec2 position) | |||||
{ | |||||
display.SetPosition(position); | |||||
} | |||||
void Enable() | |||||
{ | |||||
display.Enable(); | |||||
} | |||||
void Disable() | |||||
{ | |||||
display.Disable(); | |||||
} | |||||
#if __native_client__ | #if __native_client__ | ||||
//NOT HANDLED YET | //NOT HANDLED YET | ||||
#elif __ANDROID__ | #elif __ANDROID__ | ||||
@@ -99,9 +82,9 @@ protected: | |||||
#endif | #endif | ||||
}; | }; | ||||
ApplicationDisplay::ApplicationDisplay(char const *name, ivec2 resolution) | |||||
ApplicationDisplay::ApplicationDisplay(char const *name, ivec2 res) | |||||
{ | { | ||||
data = new ApplicationDisplayData(name, resolution); | |||||
data = new ApplicationDisplayData(name, res); | |||||
} | } | ||||
ApplicationDisplay::~ApplicationDisplay() | ApplicationDisplay::~ApplicationDisplay() | ||||
@@ -109,29 +92,35 @@ ApplicationDisplay::~ApplicationDisplay() | |||||
delete data; | delete data; | ||||
} | } | ||||
void ApplicationDisplay::SetResolution(ivec2 resolution) | |||||
ivec2 ApplicationDisplay::resolution() const | |||||
{ | { | ||||
super::SetResolution(resolution); | |||||
return data->display.resolution(); | |||||
} | |||||
data->SetResolution(resolution); | |||||
void ApplicationDisplay::set_resolution(ivec2 res) | |||||
{ | |||||
super::set_resolution(res); | |||||
data->display.set_resolution(res); | |||||
} | } | ||||
void ApplicationDisplay::SetPosition(ivec2 position) | void ApplicationDisplay::SetPosition(ivec2 position) | ||||
{ | { | ||||
super::SetPosition(position); | super::SetPosition(position); | ||||
data->SetPosition(position); | |||||
data->display.SetPosition(position); | |||||
} | } | ||||
void ApplicationDisplay::Enable() | void ApplicationDisplay::Enable() | ||||
{ | { | ||||
super::Enable(); | super::Enable(); | ||||
data->Enable(); | |||||
data->display.Enable(); | |||||
} | } | ||||
void ApplicationDisplay::Disable() | void ApplicationDisplay::Disable() | ||||
{ | { | ||||
data->Disable(); | |||||
data->display.Disable(); | |||||
super::Disable(); | super::Disable(); | ||||
} | } | ||||
@@ -141,8 +130,8 @@ class ApplicationData | |||||
{ | { | ||||
friend class Application; | friend class Application; | ||||
ApplicationData(char const *name, ivec2 resolution, float framerate) | |||||
: app(name, resolution, framerate) | |||||
ApplicationData(char const *name, ivec2 res, float framerate) | |||||
: app(name, res, framerate) | |||||
{ } | { } | ||||
#if __native_client__ | #if __native_client__ | ||||
@@ -172,10 +161,11 @@ static void AppCallback() | |||||
* Public Application class | * Public Application class | ||||
*/ | */ | ||||
Application::Application(char const *name, ivec2 resolution, float framerate) | |||||
Application::Application(char const *name, ivec2 res, float framerate) | |||||
{ | { | ||||
SceneDisplay::Add(new ApplicationDisplay(name, resolution)); | |||||
data = new ApplicationData(name, resolution, framerate); | |||||
auto app_display = new ApplicationDisplay(name, res); | |||||
SceneDisplay::Add(app_display); | |||||
data = new ApplicationData(name, app_display->resolution(), framerate); | |||||
} | } | ||||
bool Application::MustTick() | bool Application::MustTick() | ||||
@@ -31,7 +31,9 @@ public: | |||||
virtual ~ApplicationDisplay(); | virtual ~ApplicationDisplay(); | ||||
/* pos/size/... methods */ | /* pos/size/... methods */ | ||||
virtual void SetResolution(ivec2 resolution); | |||||
virtual void set_resolution(ivec2 resolution); | |||||
virtual ivec2 resolution() const; | |||||
virtual void SetPosition(ivec2 position); | virtual void SetPosition(ivec2 position); | ||||
protected: | protected: | ||||
@@ -54,7 +54,6 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
ivec2 window_size = res; | ivec2 window_size = res; | ||||
ivec2 screen_size = res; | |||||
/* Initialise SDL */ | /* Initialise SDL */ | ||||
if (!SDL_WasInit(0)) | if (!SDL_WasInit(0)) | ||||
@@ -66,15 +65,16 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||||
} | } | ||||
} | } | ||||
#if LOL_USE_SDL | |||||
/* This seems to fix the swap context bug. | /* This seems to fix the swap context bug. | ||||
* However, perfs warning have been may occur. */ | * However, perfs warning have been may occur. */ | ||||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); | SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); | ||||
data->m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, | |||||
SDL_WINDOWPOS_UNDEFINED, | |||||
window_size.x, window_size.y, | |||||
SDL_WINDOW_OPENGL); | |||||
int flags = SDL_WINDOW_OPENGL; | |||||
if (window_size == ivec2(0)) | |||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | |||||
data->m_window = SDL_CreateWindow(title, | |||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, | |||||
window_size.x, window_size.y, flags); | |||||
if (!data->m_window) | if (!data->m_window) | ||||
{ | { | ||||
msg::error("cannot create rendering window: %s\n", SDL_GetError()); | msg::error("cannot create rendering window: %s\n", SDL_GetError()); | ||||
@@ -84,7 +84,6 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||||
SDL_GetWindowSize(data->m_window, &res.x, &res.y); | SDL_GetWindowSize(data->m_window, &res.x, &res.y); | ||||
data->m_glcontext = SDL_GL_CreateContext(data->m_window); | data->m_glcontext = SDL_GL_CreateContext(data->m_window); | ||||
#endif | |||||
/* Initialise everything */ | /* Initialise everything */ | ||||
Video::Setup(res); //TODO ?? Should it be here ? | Video::Setup(res); //TODO ?? Should it be here ? | ||||
@@ -104,12 +103,22 @@ SdlAppDisplay::~SdlAppDisplay() | |||||
delete data; | delete data; | ||||
} | } | ||||
void SdlAppDisplay::SetResolution(ivec2 resolution) | |||||
ivec2 SdlAppDisplay::resolution() const | |||||
{ | |||||
ivec2 ret(0); | |||||
#if LOL_USE_SDL | |||||
SDL_GetWindowSize(data->m_window, &ret.x, &ret.y); | |||||
#endif | |||||
return ret; | |||||
} | |||||
void SdlAppDisplay::set_resolution(ivec2 resolution) | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
SDL_SetWindowSize(data->m_window, resolution.x, resolution.y); | SDL_SetWindowSize(data->m_window, resolution.x, resolution.y); | ||||
#endif | #endif | ||||
} | } | ||||
void SdlAppDisplay::SetPosition(ivec2 position) | void SdlAppDisplay::SetPosition(ivec2 position) | ||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
@@ -25,13 +25,16 @@ class SdlAppDisplayData; | |||||
class SdlAppDisplay | class SdlAppDisplay | ||||
{ | { | ||||
friend class ApplicationDisplayData; | |||||
friend class ApplicationDisplay; | |||||
public: | public: | ||||
SdlAppDisplay(char const *title, ivec2 resolution); | SdlAppDisplay(char const *title, ivec2 resolution); | ||||
virtual ~SdlAppDisplay(); | virtual ~SdlAppDisplay(); | ||||
protected: | protected: | ||||
void SetResolution(ivec2 resolution); | |||||
virtual void set_resolution(ivec2 resolution); | |||||
virtual ivec2 resolution() const; | |||||
void SetPosition(ivec2 position); | void SetPosition(ivec2 position); | ||||
void Enable(); | void Enable(); | ||||
@@ -68,7 +68,9 @@ public: | |||||
virtual ~SceneDisplay() { } | virtual ~SceneDisplay() { } | ||||
/* pos/size/... methods */ | /* pos/size/... methods */ | ||||
virtual void SetResolution(ivec2 resolution) { UNUSED(resolution); } | |||||
virtual void set_resolution(ivec2 resolution) { UNUSED(resolution); } | |||||
virtual ivec2 resolution() const { return ivec2(0); } | |||||
virtual void SetPosition(ivec2 position) { UNUSED(position); } | virtual void SetPosition(ivec2 position) { UNUSED(position); } | ||||
/* TODO: Should that be there or in Video ? */ | /* TODO: Should that be there or in Video ? */ | ||||