mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-14 01:58:25 +00:00
[client] allow window resize event's before startup
This commit is contained in:
parent
9f8c20c3e7
commit
eb6ee8ea46
@ -85,6 +85,7 @@ LG_RendererFormat;
|
|||||||
|
|
||||||
typedef struct LG_RendererRect
|
typedef struct LG_RendererRect
|
||||||
{
|
{
|
||||||
|
bool valid;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
unsigned int w;
|
unsigned int w;
|
||||||
|
@ -53,6 +53,7 @@ struct AppState
|
|||||||
|
|
||||||
TTF_Font * font;
|
TTF_Font * font;
|
||||||
TTF_Font * alertFont;
|
TTF_Font * alertFont;
|
||||||
|
bool haveSrcSize;
|
||||||
SDL_Point srcSize;
|
SDL_Point srcSize;
|
||||||
LG_RendererRect dstRect;
|
LG_RendererRect dstRect;
|
||||||
SDL_Point cursor;
|
SDL_Point cursor;
|
||||||
@ -141,12 +142,11 @@ struct AppParams params =
|
|||||||
|
|
||||||
static inline void updatePositionInfo()
|
static inline void updatePositionInfo()
|
||||||
{
|
{
|
||||||
if (!state.started)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_GetWindowSize(state.window, &w, &h);
|
SDL_GetWindowSize(state.window, &w, &h);
|
||||||
|
|
||||||
|
if (state.haveSrcSize)
|
||||||
|
{
|
||||||
if (params.keepAspect)
|
if (params.keepAspect)
|
||||||
{
|
{
|
||||||
const float srcAspect = (float)state.srcSize.y / (float)state.srcSize.x;
|
const float srcAspect = (float)state.srcSize.y / (float)state.srcSize.x;
|
||||||
@ -173,9 +173,11 @@ static inline void updatePositionInfo()
|
|||||||
state.dstRect.w = w;
|
state.dstRect.w = w;
|
||||||
state.dstRect.h = h;
|
state.dstRect.h = h;
|
||||||
}
|
}
|
||||||
|
state.dstRect.valid = true;
|
||||||
|
|
||||||
state.scaleX = (float)state.srcSize.y / (float)state.dstRect.h;
|
state.scaleX = (float)state.srcSize.y / (float)state.dstRect.h;
|
||||||
state.scaleY = (float)state.srcSize.x / (float)state.dstRect.w;
|
state.scaleY = (float)state.srcSize.x / (float)state.dstRect.w;
|
||||||
|
}
|
||||||
|
|
||||||
if (state.lgr)
|
if (state.lgr)
|
||||||
state.lgr->on_resize(state.lgrData, w, h, state.dstRect);
|
state.lgr->on_resize(state.lgrData, w, h, state.dstRect);
|
||||||
@ -379,6 +381,7 @@ int frameThread(void * unused)
|
|||||||
{
|
{
|
||||||
state.srcSize.x = header.width;
|
state.srcSize.x = header.width;
|
||||||
state.srcSize.y = header.height;
|
state.srcSize.y = header.height;
|
||||||
|
state.haveSrcSize = true;
|
||||||
if (params.autoResize)
|
if (params.autoResize)
|
||||||
SDL_SetWindowSize(state.window, header.width, header.height);
|
SDL_SetWindowSize(state.window, header.width, header.height);
|
||||||
updatePositionInfo();
|
updatePositionInfo();
|
||||||
|
@ -221,6 +221,8 @@ void opengl_on_resize(void * opaque, const int width, const int height, const LG
|
|||||||
|
|
||||||
this->window.x = width;
|
this->window.x = width;
|
||||||
this->window.y = height;
|
this->window.y = height;
|
||||||
|
|
||||||
|
if (destRect.valid)
|
||||||
memcpy(&this->destRect, &destRect, sizeof(LG_RendererRect));
|
memcpy(&this->destRect, &destRect, sizeof(LG_RendererRect));
|
||||||
|
|
||||||
this->resizeWindow = true;
|
this->resizeWindow = true;
|
||||||
@ -407,12 +409,16 @@ bool opengl_render(void * opaque, SDL_Window * window)
|
|||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
if (this->destRect.valid)
|
||||||
|
{
|
||||||
glTranslatef(this->destRect.x, this->destRect.y, 0.0f);
|
glTranslatef(this->destRect.x, this->destRect.y, 0.0f);
|
||||||
glScalef(
|
glScalef(
|
||||||
(float)this->destRect.w / (float)this->format.width,
|
(float)this->destRect.w / (float)this->format.width,
|
||||||
(float)this->destRect.h / (float)this->format.height,
|
(float)this->destRect.h / (float)this->format.height,
|
||||||
1.0f
|
1.0f
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this->resizeWindow = false;
|
this->resizeWindow = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user