all repos — mgba @ ecee71cfa1ccd99ce3de8a0ebb38ba37292439bb

mGBA Game Boy Advance Emulator

Resizing of SDL2 windows
Jeffrey Pfau jeffrey@endrift.com
Wed, 09 Jul 2014 00:03:05 -0700
commit

ecee71cfa1ccd99ce3de8a0ebb38ba37292439bb

parent

548793e551129f09a6c410d21d592a88ace852bf

3 files changed, 22 insertions(+), 5 deletions(-)

jump to
M src/platform/sdl/gl-main.csrc/platform/sdl/gl-main.c

@@ -74,6 +74,7 @@ renderer.viewportWidth = graphicsOpts.width;

renderer.viewportHeight = graphicsOpts.height; #if SDL_VERSION_ATLEAST(2, 0, 0) renderer.events.fullscreen = graphicsOpts.fullscreen; + renderer.events.windowUpdated = 0; #endif if (!_GBASDLInit(&renderer)) {

@@ -138,7 +139,7 @@ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

#endif #if SDL_VERSION_ATLEAST(2, 0, 0) - renderer->window = SDL_CreateWindow("GBAc", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->events.fullscreen)); + renderer->window = SDL_CreateWindow("GBAc", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->events.fullscreen)); SDL_GL_CreateContext(renderer->window); SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); renderer->events.window = renderer->window;

@@ -199,15 +200,13 @@ SDL_GL_SwapBuffers();

#endif while (SDL_PollEvent(&event)) { -#if SDL_VERSION_ATLEAST(2, 0, 0) - int fullscreen = renderer->events.fullscreen; -#endif GBASDLHandleEvent(context, &renderer->events, &event); #if SDL_VERSION_ATLEAST(2, 0, 0) // Event handling can change the size of the screen - if (renderer->events.fullscreen != fullscreen) { + if (renderer->events.windowUpdated) { SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight); + renderer->events.windowUpdated = 0; } #endif }
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -107,6 +107,7 @@ #if SDL_VERSION_ATLEAST(2, 0, 0)

case SDLK_f: SDL_SetWindowFullscreen(sdlContext->window, sdlContext->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); sdlContext->fullscreen = !sdlContext->fullscreen; + sdlContext->windowUpdated = 1; break; #endif case SDLK_p:

@@ -205,6 +206,17 @@ context->activeKeys &= ~((1 << GBA_KEY_UP) | (1 << GBA_KEY_LEFT) | (1 << GBA_KEY_DOWN) | (1 << GBA_KEY_RIGHT));

context->activeKeys |= key; } +#if SDL_VERSION_ATLEAST(2, 0, 0) +static void _GBASDLHandleWindowEvent(struct GBAThread* context, struct GBASDLEvents* sdlContext, const struct SDL_WindowEvent* event) { + (void) (context); + switch (event->event) { + case SDL_WINDOWEVENT_SIZE_CHANGED: + sdlContext->windowUpdated = 1; + break; + } +} +#endif + void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContext, const union SDL_Event* event) { switch (event->type) { case SDL_QUIT:

@@ -217,6 +229,11 @@ context->state = THREAD_EXITING;

ConditionWake(&context->stateCond); MutexUnlock(&context->stateMutex); break; +#if SDL_VERSION_ATLEAST(2, 0, 0) + case SDL_WINDOWEVENT: + _GBASDLHandleWindowEvent(context, sdlContext, &event->window); + break; +#endif case SDL_KEYDOWN: case SDL_KEYUP: _GBASDLHandleKeypress(context, sdlContext, &event->key);
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -12,6 +12,7 @@ SDL_Joystick* joystick;

#if SDL_VERSION_ATLEAST(2, 0, 0) SDL_Window* window; int fullscreen; + int windowUpdated; #endif };