Ability to fullscreen the window in SDL2

This commit is contained in:
Jeffrey Pfau 2014-02-02 03:05:30 -08:00
parent 19142a2881
commit 243cf2236b
3 changed files with 23 additions and 5 deletions

View File

@ -132,6 +132,8 @@ static int _GBASDLInit(struct GLSoftwareRenderer* renderer) {
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 @@ static void _GBASDLRunloop(struct GBAThread* context, struct GLSoftwareRenderer*
#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);
}
}
}
}

View File

@ -33,7 +33,7 @@ static void _pauseAfterFrame(struct GBAThread* context) {
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 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke
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 @@ static void _GBASDLHandleJoyHat(struct GBAThread* context, const struct SDL_JoyH
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 @@ void GBASDLHandleEvent(struct GBAThread* context, const union SDL_Event* event)
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
_GBASDLHandleKeypress(context, &event->key);
_GBASDLHandleKeypress(context, sdlContext, &event->key);
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:

View File

@ -7,11 +7,15 @@
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