+2014-01-07
+ * fixed problems related to fullscreen switching and window scaling
+
+2014-01-06
+ * fixed inconsistent custom artwork contant numbering in src/main.h,
+ src/screen.c and src/conf_gfx.c (this really should be cleaned up)
+ (this bug caused custom artwork definition to set wrong variable)
+
2014-01-05
* fixed using fullscreen mode on Android instead of pseudo-window mode
* fixed keeping desktop fullscreen mode when changing viewport size
{ "menu.draw_yoffset.SETUP[SHORTCUTS_3]", "0" },
{ "menu.draw_xoffset.SETUP[SHORTCUTS_4]", "0" },
{ "menu.draw_yoffset.SETUP[SHORTCUTS_4]", "0" },
+ { "menu.draw_xoffset.SETUP[SHORTCUTS_5]", "0" },
+ { "menu.draw_yoffset.SETUP[SHORTCUTS_5]", "0" },
{ "menu.draw_xoffset.SETUP[CHOOSE_ARTWORK]", "0" },
{ "menu.draw_yoffset.SETUP[CHOOSE_ARTWORK]", "0" },
{ "menu.draw_xoffset.SETUP[CHOOSE_OTHER]", "0" },
"menu.draw_yoffset.SETUP[SHORTCUTS_4]",
&menu.draw_yoffset_setup[GFX_SPECIAL_ARG_SETUP_SHORTCUTS_4]
},
+ {
+ "menu.draw_xoffset.SETUP[SHORTCUTS_5]",
+ &menu.draw_xoffset_setup[GFX_SPECIAL_ARG_SETUP_SHORTCUTS_5]
+ },
+ {
+ "menu.draw_yoffset.SETUP[SHORTCUTS_5]",
+ &menu.draw_yoffset_setup[GFX_SPECIAL_ARG_SETUP_SHORTCUTS_5]
+ },
{
"menu.draw_xoffset.SETUP[CHOOSE_ARTWORK]",
&menu.draw_xoffset_setup[GFX_SPECIAL_ARG_SETUP_CHOOSE_ARTWORK]
-#define COMPILE_DATE_STRING "2014-01-05 22:41"
+#define COMPILE_DATE_STRING "2014-01-08 00:59"
break;
#if defined(TARGET_SDL2)
+ case SDL_WINDOWEVENT:
+ HandleWindowEvent((WindowEvent *) &event);
+ break;
+
case EVENT_FINGERPRESS:
case EVENT_FINGERRELEASE:
case EVENT_FINGERMOTION:
motion_status = TRUE;
+#if DEBUG_EVENTS
Error(ERR_DEBUG, "MOTION EVENT: button %d moved, x/y %d/%d\n",
button_status, event->x, event->y);
+#endif
HandleButton(event->x, event->y, button_status, button_status);
}
#if defined(TARGET_SDL2)
+void HandleWindowEvent(WindowEvent *event)
+{
+ int subtype = event->event;
+
+ char *event_name =
+ (subtype == SDL_WINDOWEVENT_SHOWN ? "SDL_WINDOWEVENT_SHOWN" :
+ subtype == SDL_WINDOWEVENT_HIDDEN ? "SDL_WINDOWEVENT_HIDDEN" :
+ subtype == SDL_WINDOWEVENT_EXPOSED ? "SDL_WINDOWEVENT_EXPOSED" :
+ subtype == SDL_WINDOWEVENT_MOVED ? "SDL_WINDOWEVENT_MOVED" :
+ subtype == SDL_WINDOWEVENT_SIZE_CHANGED ? "SDL_WINDOWEVENT_SIZE_CHANGED" :
+ subtype == SDL_WINDOWEVENT_RESIZED ? "SDL_WINDOWEVENT_RESIZED" :
+ subtype == SDL_WINDOWEVENT_MINIMIZED ? "SDL_WINDOWEVENT_MINIMIZED" :
+ subtype == SDL_WINDOWEVENT_MAXIMIZED ? "SDL_WINDOWEVENT_MAXIMIZED" :
+ subtype == SDL_WINDOWEVENT_RESTORED ? "SDL_WINDOWEVENT_RESTORED" :
+ subtype == SDL_WINDOWEVENT_ENTER ? "SDL_WINDOWEVENT_ENTER" :
+ subtype == SDL_WINDOWEVENT_LEAVE ? "SDL_WINDOWEVENT_LEAVE" :
+ subtype == SDL_WINDOWEVENT_FOCUS_GAINED ? "SDL_WINDOWEVENT_FOCUS_GAINED" :
+ subtype == SDL_WINDOWEVENT_FOCUS_LOST ? "SDL_WINDOWEVENT_FOCUS_LOST" :
+ subtype == SDL_WINDOWEVENT_CLOSE ? "SDL_WINDOWEVENT_CLOSE" :
+ "(UNKNOWN)");
+
+ Error(ERR_DEBUG, "WINDOW EVENT: '%s', %ld, %ld",
+ event_name, event->data1, event->data2);
+
+ if (event->event == SDL_WINDOWEVENT_EXPOSED)
+ SDLRedrawWindow();
+
+#if 0
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED)
+ {
+ // if game started in fullscreen mode, window will also get fullscreen size
+ if (!video.fullscreen_enabled && video.fullscreen_initial)
+ {
+ SDLSetWindowScaling(setup.window_scaling_percent);
+
+ // only do this correction once
+ video.fullscreen_initial = FALSE;
+ }
+ }
+#endif
+
+ if (event->event == SDL_WINDOWEVENT_RESIZED && !video.fullscreen_enabled)
+ {
+#if 1
+ int new_window_width = event->data1;
+ int new_window_height = event->data2;
+
+ printf("::: RESIZED from %d, %d to %d, %d\n",
+ video.window_width, video.window_height,
+ new_window_width, new_window_height);
+
+ // if window size has changed after resizing, calculate new scaling factor
+ if (new_window_width != video.window_width ||
+ new_window_height != video.window_height)
+ {
+ int new_xpercent = (100 * new_window_width / video.width);
+ int new_ypercent = (100 * new_window_height / video.height);
+
+ setup.window_scaling_percent = video.window_scaling_percent =
+ MIN(MAX(MIN_WINDOW_SCALING_PERCENT, MIN(new_xpercent, new_ypercent)),
+ MAX_WINDOW_SCALING_PERCENT);
+
+ video.window_width = new_window_width;
+ video.window_height = new_window_height;
+
+ printf("::: setup.window_scaling_percent set to %d\n",
+ setup.window_scaling_percent);
+ }
+#else
+ // prevent slightly wrong scaling factor due to rounding differences
+ float scaling_factor = (float)setup.window_scaling_percent / 100;
+ int old_xsize = (int)(scaling_factor * video.width);
+ int old_ysize = (int)(scaling_factor * video.height);
+ int new_xsize = event->data1;
+ int new_ysize = event->data2;
+
+ // window size is unchanged when going from fullscreen to window mode,
+ // but reverse calculation of scaling factor might result in a scaling
+ // factor that is slightly different due to rounding differences;
+ // therefore compare old/new window size and not old/new scaling factor
+ if (old_xsize != new_xsize ||
+ old_ysize != new_ysize)
+ {
+ int new_xpercent = (100 * new_xsize / video.width);
+ int new_ypercent = (100 * new_ysize / video.height);
+
+ setup.window_scaling_percent = MIN(new_xpercent, new_ypercent);
+
+ if (setup.window_scaling_percent < MIN_WINDOW_SCALING_PERCENT)
+ setup.window_scaling_percent = MIN_WINDOW_SCALING_PERCENT;
+ else if (setup.window_scaling_percent > MAX_WINDOW_SCALING_PERCENT)
+ setup.window_scaling_percent = MAX_WINDOW_SCALING_PERCENT;
+
+ printf("::: setup.window_scaling_percent set to %d\n",
+ setup.window_scaling_percent);
+ }
+#endif
+ }
+}
+
void HandleFingerEvent(FingerEvent *event)
{
#if 0
if (IS_WHEEL_BUTTON(button_nr))
return;
+#if 0
Error(ERR_DEBUG, "::: game_status == %d", game_status);
+#endif
switch (game_status)
{
{
setup.fullscreen = !setup.fullscreen;
+ printf("::: %d\n", setup.window_scaling_percent);
+
+ ToggleFullscreenIfNeeded();
+
+ if (game_status == GAME_MODE_SETUP)
+ RedrawSetupScreenAfterFullscreenToggle();
+
+ return;
+ }
+
+ if ((key == KSYM_minus || key == KSYM_plus || key == KSYM_0) &&
+ (GetKeyModState() & KMOD_Control) && video.window_scaling_available &&
+ !video.fullscreen_enabled)
+ {
+ if (key == KSYM_0)
+ setup.window_scaling_percent = STD_WINDOW_SCALING_PERCENT;
+ else
+ setup.window_scaling_percent +=
+ (key == KSYM_minus ? -1 : +1) * STEP_WINDOW_SCALING_PERCENT;
+
+ if (setup.window_scaling_percent < MIN_WINDOW_SCALING_PERCENT)
+ setup.window_scaling_percent = MIN_WINDOW_SCALING_PERCENT;
+ else if (setup.window_scaling_percent > MAX_WINDOW_SCALING_PERCENT)
+ setup.window_scaling_percent = MAX_WINDOW_SCALING_PERCENT;
+
ToggleFullscreenIfNeeded();
if (game_status == GAME_MODE_SETUP)
void HandleButtonEvent(ButtonEvent *);
void HandleMotionEvent(MotionEvent *);
#if defined(TARGET_SDL2)
+void HandleWindowEvent(WindowEvent *);
void HandleFingerEvent(FingerEvent *);
void HandleTextEvent(TextEvent *);
#endif
InitSetup();
-#if 1
- Error(ERR_INFO, "::: MARK 1: setup.fullscreen == %d", setup.fullscreen);
-#endif
-
print_timestamp_time("[init setup/config stuff (1)]");
InitGameInfo();
print_timestamp_time("[init setup/config stuff]");
-#if 1
- Error(ERR_INFO, "::: MARK 2: setup.fullscreen == %d", setup.fullscreen);
-#endif
-
InitVideoDisplay();
InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
SDL_Surface *new_surface = NULL;
static boolean fullscreen_enabled = FALSE;
- int surface_flags_window = SURFACE_FLAGS;
#if defined(TARGET_SDL2)
-
+ int surface_flags_window = SURFACE_FLAGS | SDL_WINDOW_RESIZABLE;
#if USE_DESKTOP_FULLSCREEN
int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN_DESKTOP;
#else
#endif
#else
+ int surface_flags_window = SURFACE_FLAGS;
int surface_flags_fullscreen = SURFACE_FLAGS | SDL_FULLSCREEN;
#endif
int surface_flags = (fullscreen ? surface_flags_fullscreen :
surface_flags_window);
+ // default window size is unscaled
+ video.window_width = video.width;
+ video.window_height = video.height;
+
#if defined(TARGET_SDL2)
+ // store if initial screen mode on game start is fullscreen mode
+ if (sdl_window == NULL)
+ {
+ printf("::: GAME STARTS WITH FULLSCREEN %d\n", fullscreen);
+
+ video.fullscreen_initial = fullscreen;
+ }
+
#if USE_RENDERER
float window_scaling_factor = (float)setup.window_scaling_percent / 100;
float screen_scaling_factor = (fullscreen ? 1 : window_scaling_factor);
+ video.window_width = window_scaling_factor * width;
+ video.window_height = window_scaling_factor * height;
+
#if 1
printf("::: use window scaling factor %f\n", screen_scaling_factor);
#endif
}
}
+#if 0
Error(ERR_INFO, "::: checking 'sdl_window' ...");
if (sdl_window == NULL)
Error(ERR_INFO, "::: calling SDL_CreateWindow() [%d, %d, %d] ...",
setup.fullscreen, fullscreen, fullscreen_enabled);
+#endif
if (sdl_window == NULL)
sdl_window = SDL_CreateWindow(program.window_title,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
+#if USE_DESKTOP_FULLSCREEN
+ video.window_width,
+ video.window_height,
+#else
(int)(screen_scaling_factor * width),
(int)(screen_scaling_factor * height),
+#endif
surface_flags);
if (sdl_window != NULL)
}
#if defined(TARGET_SDL2)
- UpdateScreen(NULL); // map window
+ SDLRedrawWindow(); // map window
+ // UpdateScreen(NULL); // map window
#endif
#if 1
return success;
}
+#if defined(TARGET_SDL2)
+void SDLSetWindowScaling(int window_scaling_percent)
+{
+ if (sdl_window == NULL)
+ return;
+
+ float window_scaling_factor = (float)window_scaling_percent / 100;
+ int new_window_width = (int)(window_scaling_factor * video.width);
+ int new_window_height = (int)(window_scaling_factor * video.height);
+
+ Error(ERR_DEBUG, "::: SDLSetWindowScaling(%d) ...", window_scaling_percent);
+
+ SDL_SetWindowSize(sdl_window, new_window_width, new_window_height);
+
+ video.window_scaling_percent = window_scaling_percent;
+ video.window_width = new_window_width;
+ video.window_height = new_window_height;
+}
+
+void SDLSetWindowFullscreen(boolean fullscreen)
+{
+ if (sdl_window == NULL)
+ return;
+
+#if USE_DESKTOP_FULLSCREEN
+ int flags = (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+#else
+ int flags = (fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
+#endif
+
+ Error(ERR_DEBUG, "::: SDL_SetWindowFullscreen(%d) ...", fullscreen);
+
+ if (SDL_SetWindowFullscreen(sdl_window, flags) == 0)
+ video.fullscreen_enabled = fullscreen;
+
+ printf("::: SDLSetWindowFullscreen: %d, %d\n",
+ fullscreen, video.fullscreen_initial);
+
+#if 1
+ // if game started in fullscreen mode, window will also get fullscreen size
+ if (!fullscreen && video.fullscreen_initial)
+ {
+ SDLSetWindowScaling(setup.window_scaling_percent);
+ SDL_SetWindowPosition(sdl_window,
+ SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
+
+ video.fullscreen_initial = FALSE;
+ }
+#endif
+}
+
+void SDLRedrawWindow()
+{
+ UpdateScreen(NULL);
+}
+#endif
+
void SDLCreateBitmapContent(Bitmap *new_bitmap, int width, int height,
int depth)
{
#if defined(TARGET_SDL2)
typedef SDL_TouchFingerEvent FingerEvent;
typedef SDL_TextInputEvent TextEvent;
+typedef SDL_WindowEvent WindowEvent;
#endif
typedef SDL_KeyboardEvent KeyEvent;
typedef SDL_Event ExposeEvent;
#if defined(TARGET_SDL2)
SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
+void SDLSetWindowScaling(int);
+void SDLSetWindowFullscreen(boolean);
+void SDLRedrawWindow();
#endif
void SDLInitVideoDisplay(void);
void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
{
-#if 0
- static boolean initialized = FALSE;
-#endif
+ printf("::: InitVideoBuffer\n");
video.width = width;
video.height = height;
video.fullscreen_available = FULLSCREEN_STATUS;
video.fullscreen_enabled = FALSE;
+ // video.fullscreen_initial = FALSE;
#if 0
video.fullscreen_mode_current = NULL;
video.fullscreen_modes = NULL;
video.window_scaling_available = WINDOW_SCALING_STATUS;
-#if 0
-#if defined(PLATFORM_ANDROID)
- if (!initialized)
- video.fullscreen_enabled = TRUE;
-#endif
-#endif
-
#if defined(TARGET_SDL)
SDLInitVideoBuffer(&backbuffer, &window, fullscreen);
#else
#endif
drawto = backbuffer;
-
-#if 0
- initialized = TRUE;
-#endif
}
inline static void FreeBitmapPointers(Bitmap *bitmap)
#define WINDOW_SCALING_NOT_AVAILABLE FALSE
#define WINDOW_SCALING_AVAILABLE TRUE
-#define MIN_WINDOW_SCALING_PERCENT 10
+#define MIN_WINDOW_SCALING_PERCENT 50
#define STD_WINDOW_SCALING_PERCENT 100
#define MAX_WINDOW_SCALING_PERCENT 300
+#define STEP_WINDOW_SCALING_PERCENT 10
/* default input keys */
#define DEFAULT_KEY_LEFT KSYM_Left
{
int default_depth;
int width, height, depth;
+ int window_width, window_height;
boolean fullscreen_available;
boolean fullscreen_enabled;
+ boolean fullscreen_initial;
struct ScreenModeInfo *fullscreen_modes;
char *fullscreen_mode_current;
#define NUM_SPECIAL_GFX_INFO_ARGS 8
/* these additional definitions are currently only used for draw offsets */
+/* (must match SETUP_MODE_* values as defined in src/screens.c) */
+/* (should also match corresponding entries in src/conf_gfx.c) */
#define GFX_SPECIAL_ARG_SETUP_MAIN 0
#define GFX_SPECIAL_ARG_SETUP_GAME 1
#define GFX_SPECIAL_ARG_SETUP_EDITOR 2
#define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_2 9
#define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_3 10
#define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_4 11
-#define GFX_SPECIAL_ARG_SETUP_CHOOSE_ARTWORK 12
-#define GFX_SPECIAL_ARG_SETUP_CHOOSE_OTHER 13
+#define GFX_SPECIAL_ARG_SETUP_SHORTCUTS_5 12
+#define GFX_SPECIAL_ARG_SETUP_CHOOSE_ARTWORK 13
+#define GFX_SPECIAL_ARG_SETUP_CHOOSE_OTHER 14
-#define NUM_SPECIAL_GFX_SETUP_ARGS 14
+#define NUM_SPECIAL_GFX_SETUP_ARGS 15
/* values for image configuration suffixes */
#define MAX_INFO_MODES 8
/* screens on the setup screen */
+/* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
+/* (should also match corresponding entries in src/conf_gfx.c) */
#define SETUP_MODE_MAIN 0
#define SETUP_MODE_GAME 1
#define SETUP_MODE_EDITOR 2
void RedrawSetupScreenAfterFullscreenToggle()
{
+#if 0
+ if (setup_mode == SETUP_MODE_GRAPHICS ||
+ setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
+ {
+ if (window_sizes != NULL)
+ {
+ /* set current window size value to configured window size value */
+ window_size_current =
+ getTreeInfoFromIdentifier(window_sizes,
+ i_to_a(setup.window_scaling_percent));
+
+ /* if that fails, set current window size to reliable default value */
+ if (window_size_current == NULL)
+ window_size_current =
+ getTreeInfoFromIdentifier(window_sizes,
+ i_to_a(STD_WINDOW_SCALING_PERCENT));
+
+ /* if that also fails, set current window size to first available value */
+ if (window_size_current == NULL)
+ window_size_current = window_sizes;
+ }
+
+ setup.window_scaling_percent = atoi(window_size_current->identifier);
+
+ /* needed for displaying window size text instead of identifier */
+ window_size_text = window_size_current->name;
+
+ DrawSetupScreen();
+ }
+#else
if (setup_mode == SETUP_MODE_GRAPHICS)
DrawSetupScreen();
+#endif
}
void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
if (!change_window_scaling_percent && !video.fullscreen_available)
return;
+#if defined(TARGET_SDL2)
+ if (change_window_scaling_percent)
+ {
+ SDLSetWindowScaling(setup.window_scaling_percent);
+
+ return;
+ }
+ else if (change_fullscreen)
+ {
+ SDLSetWindowFullscreen(setup.fullscreen);
+
+ /* set setup value according to successfully changed fullscreen mode */
+ setup.fullscreen = video.fullscreen_enabled;
+
+ return;
+ }
+#endif
+
if (change_fullscreen ||
change_fullscreen_mode ||
change_window_scaling_percent)
/* toggle fullscreen */
ChangeVideoModeIfNeeded(setup.fullscreen);
- /* set setup value according to successfully enabled fullscreen mode */
+ /* set setup value according to successfully changed fullscreen mode */
setup.fullscreen = video.fullscreen_enabled;
/* restore backbuffer content from temporary backbuffer backup bitmap */