all repos — mgba @ 243cf2236b7e7f9c39585a65c6940c61935b9dfa

mGBA Game Boy Advance Emulator

Ability to fullscreen the window in SDL2
Jeffrey Pfau jeffrey@endrift.com
Sun, 02 Feb 2014 03:05:30 -0800
commit

243cf2236b7e7f9c39585a65c6940c61935b9dfa

parent

19142a288101cfe8265b332e4a51db7b379102ce

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

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

@@ -132,6 +132,8 @@ #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_GL_CreateContext(renderer->window); SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); + renderer->events.window = renderer->window; + renderer->events.fullscreen = 0; #else #ifdef COLOR_16_BIT SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL);

@@ -189,7 +191,13 @@ SDL_GL_SwapBuffers();

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

@@ -33,7 +33,7 @@ context->frameCallback = 0;

GBAThreadPause(context); } -static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_KeyboardEvent* event) { +static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents* sdlContext, const struct SDL_KeyboardEvent* event) { enum GBAKey key = 0; int isPaused = GBAThreadIsPaused(context); switch (event->keysym.sym) {

@@ -87,6 +87,12 @@ default:

if (event->type == SDL_KEYDOWN) { if (event->keysym.mod & GUI_MOD) { switch (event->keysym.sym) { +#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; + break; +#endif case SDLK_p: GBAThreadTogglePause(context); break;

@@ -210,7 +216,7 @@ context->activeKeys &= ~((1 << GBA_KEY_UP) | (1 << GBA_KEY_LEFT) | (1 << GBA_KEY_DOWN) | (1 << GBA_KEY_RIGHT));

context->activeKeys |= key; } -void GBASDLHandleEvent(struct GBAThread* context, const union SDL_Event* event) { +void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContext, const union SDL_Event* event) { switch (event->type) { case SDL_QUIT: // FIXME: this isn't thread-safe

@@ -224,7 +230,7 @@ MutexUnlock(&context->stateMutex);

break; case SDL_KEYDOWN: case SDL_KEYUP: - _GBASDLHandleKeypress(context, &event->key); + _GBASDLHandleKeypress(context, sdlContext, &event->key); break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP:
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -7,11 +7,15 @@ #include <SDL.h>

struct GBASDLEvents { SDL_Joystick* joystick; +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_Window* window; + int fullscreen; +#endif }; int GBASDLInitEvents(struct GBASDLEvents*); void GBASDLDeinitEvents(struct GBASDLEvents*); -void GBASDLHandleEvent(struct GBAThread* context, const union SDL_Event* event); +void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContext, const union SDL_Event* event); #endif