summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-12-22 12:50:59 +0100
committerChristian Soffke <christian.soffke@gmail.com>2024-12-25 08:34:40 -0500
commit7aaa722a5da170dc40eaa6e2df2aa79f892f1d9d (patch)
tree48719bc5ce97bd6bbb5f30ab9571bb8c923bc2fa
parent759cbf4e5f3acf55245b5d181bfe9fa2bbb8a472 (diff)
downloadrockbox-7aaa722a5d.tar.gz
rockbox-7aaa722a5d.zip
simulator: Adjust scaling using keyboard shortcuts
Press 0-3 to to adjust current zoom level to 50% (0), 100% (1), 200% (2), or 300% (3). Press 4 to switch between "best" (linear) and nearest pixel sampling. Change-Id: Id10d361659855a0ad9c97e6b341f498f72709ef5
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c24
-rw-r--r--firmware/target/hosted/sdl/lcd-sdl.c46
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c1
3 files changed, 52 insertions, 19 deletions
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index d10e681b15..9c46279a15 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -351,6 +351,30 @@ static void button_event(int key, bool pressed)
switch (key)
{
#ifdef SIMULATOR
+ case SDLK_0:
+ display_zoom = 0.5;
+ case SDLK_1:
+ display_zoom = display_zoom ?: 1;
+ case SDLK_2:
+ display_zoom = display_zoom ?: 2;
+ case SDLK_3:
+ display_zoom = display_zoom ?: 3;
+ case SDLK_4:
+ if (pressed)
+ {
+ display_zoom = 0;
+ return;
+ }
+ if (!display_zoom)
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,
+ strcmp(SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY) ?:
+ "best", "best") ? "best": "nearest");
+
+ sdl_window_needs_update();
+#if !defined(__WIN32) && !defined (__APPLE__)
+ button_queue_post(SDLK_UNKNOWN, 0); /* update window on main thread */
+#endif
+ return;
case USB_KEY:
if (!pressed)
{
diff --git a/firmware/target/hosted/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c
index 212d35b88c..596d3ec1f0 100644
--- a/firmware/target/hosted/sdl/lcd-sdl.c
+++ b/firmware/target/hosted/sdl/lcd-sdl.c
@@ -65,37 +65,45 @@ static inline void sdl_render(void)
#define SNAP_MARGIN 50
int sdl_update_window(void)
{
+ int w, h;
+
if (!window_needs_update)
return false;
window_needs_update = false;
-#if defined (__APPLE__) || defined(__WIN32) /* Constrain aspect ratio */
+ sdl_get_window_dimensions(&w, &h);
+
if (!(SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN)))
{
- float aspect_ratio;
- int w, h;
-
- sdl_get_window_dimensions(&w, &h);
- aspect_ratio = (float) h / w;
+ if (display_zoom)
+ {
+ SDL_SetWindowSize(window, display_zoom * w, display_zoom * h);
+ }
+#if defined(__APPLE__) || defined(__WIN32)
+ else /* Constrain aspect ratio on Windows and MacOS */
+ {
- int original_height = h;
- int original_width = w;
+ float aspect_ratio = (float) h / w;
+ int original_height = h;
+ int original_width = w;
- SDL_GetWindowSize(window, &w, &h);
- if (w != original_width || h != original_height)
- {
- if (abs(original_width - w) < SNAP_MARGIN)
+ SDL_GetWindowSize(window, &w, &h);
+ if (w != original_width || h != original_height)
{
- w = original_width;
- h = original_height;
+ if (abs(original_width - w) < SNAP_MARGIN)
+ {
+ w = original_width;
+ h = original_height;
+ }
+ else
+ h = w * aspect_ratio;
+
+ SDL_SetWindowSize(window, w, h);
}
- else
- h = w * aspect_ratio;
-
- SDL_SetWindowSize(window, w, h);
}
- }
#endif
+ }
+ display_zoom = 0;
sdl_render();
return true;
}
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index f135cc7b55..b90f59f216 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -113,6 +113,7 @@ static void sdl_window_setup(void)
panicf("%s", SDL_GetError());
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, display_zoom == 1 ? "best" : "nearest");
+ display_zoom = 0; /* keeps track of user requesting a scale level change */
SDL_RenderSetLogicalSize(sdlRenderer, width, height);
if ((gui_surface = SDL_CreateRGBSurface(0, width, height, depth,