mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-13 01:38:20 +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,41 +142,42 @@ 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 (params.keepAspect)
|
if (state.haveSrcSize)
|
||||||
{
|
{
|
||||||
const float srcAspect = (float)state.srcSize.y / (float)state.srcSize.x;
|
if (params.keepAspect)
|
||||||
const float wndAspect = (float)h / (float)w;
|
|
||||||
if (wndAspect < srcAspect)
|
|
||||||
{
|
{
|
||||||
state.dstRect.w = (float)h / srcAspect;
|
const float srcAspect = (float)state.srcSize.y / (float)state.srcSize.x;
|
||||||
state.dstRect.h = h;
|
const float wndAspect = (float)h / (float)w;
|
||||||
state.dstRect.x = (w >> 1) - (state.dstRect.w >> 1);
|
if (wndAspect < srcAspect)
|
||||||
state.dstRect.y = 0;
|
{
|
||||||
|
state.dstRect.w = (float)h / srcAspect;
|
||||||
|
state.dstRect.h = h;
|
||||||
|
state.dstRect.x = (w >> 1) - (state.dstRect.w >> 1);
|
||||||
|
state.dstRect.y = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.dstRect.w = w;
|
||||||
|
state.dstRect.h = (float)w * srcAspect;
|
||||||
|
state.dstRect.x = 0;
|
||||||
|
state.dstRect.y = (h >> 1) - (state.dstRect.h >> 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
state.dstRect.w = w;
|
|
||||||
state.dstRect.h = (float)w * srcAspect;
|
|
||||||
state.dstRect.x = 0;
|
state.dstRect.x = 0;
|
||||||
state.dstRect.y = (h >> 1) - (state.dstRect.h >> 1);
|
state.dstRect.y = 0;
|
||||||
|
state.dstRect.w = w;
|
||||||
|
state.dstRect.h = h;
|
||||||
}
|
}
|
||||||
}
|
state.dstRect.valid = true;
|
||||||
else
|
|
||||||
{
|
|
||||||
state.dstRect.x = 0;
|
|
||||||
state.dstRect.y = 0;
|
|
||||||
state.dstRect.w = w;
|
|
||||||
state.dstRect.h = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,7 +221,9 @@ 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;
|
||||||
memcpy(&this->destRect, &destRect, sizeof(LG_RendererRect));
|
|
||||||
|
if (destRect.valid)
|
||||||
|
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();
|
||||||
glTranslatef(this->destRect.x, this->destRect.y, 0.0f);
|
|
||||||
glScalef(
|
if (this->destRect.valid)
|
||||||
(float)this->destRect.w / (float)this->format.width,
|
{
|
||||||
(float)this->destRect.h / (float)this->format.height,
|
glTranslatef(this->destRect.x, this->destRect.y, 0.0f);
|
||||||
1.0f
|
glScalef(
|
||||||
);
|
(float)this->destRect.w / (float)this->format.width,
|
||||||
|
(float)this->destRect.h / (float)this->format.height,
|
||||||
|
1.0f
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this->resizeWindow = false;
|
this->resizeWindow = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user