mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
759cbf4e5f
commit
7aaa722a5d
3 changed files with 55 additions and 22 deletions
|
@ -351,6 +351,30 @@ static void button_event(int key, bool pressed)
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
#ifdef SIMULATOR
|
#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:
|
case USB_KEY:
|
||||||
if (!pressed)
|
if (!pressed)
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,37 +65,45 @@ static inline void sdl_render(void)
|
||||||
#define SNAP_MARGIN 50
|
#define SNAP_MARGIN 50
|
||||||
int sdl_update_window(void)
|
int sdl_update_window(void)
|
||||||
{
|
{
|
||||||
|
int w, h;
|
||||||
|
|
||||||
if (!window_needs_update)
|
if (!window_needs_update)
|
||||||
return false;
|
return false;
|
||||||
window_needs_update = 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)))
|
if (!(SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN)))
|
||||||
{
|
{
|
||||||
float aspect_ratio;
|
if (display_zoom)
|
||||||
int w, h;
|
|
||||||
|
|
||||||
sdl_get_window_dimensions(&w, &h);
|
|
||||||
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_SetWindowSize(window, display_zoom * w, display_zoom * h);
|
||||||
{
|
}
|
||||||
w = original_width;
|
#if defined(__APPLE__) || defined(__WIN32)
|
||||||
h = original_height;
|
else /* Constrain aspect ratio on Windows and MacOS */
|
||||||
}
|
{
|
||||||
else
|
|
||||||
h = w * aspect_ratio;
|
float aspect_ratio = (float) h / w;
|
||||||
|
int original_height = h;
|
||||||
SDL_SetWindowSize(window, w, h);
|
int original_width = w;
|
||||||
|
|
||||||
|
SDL_GetWindowSize(window, &w, &h);
|
||||||
|
if (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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
display_zoom = 0;
|
||||||
sdl_render();
|
sdl_render();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,7 @@ static void sdl_window_setup(void)
|
||||||
panicf("%s", SDL_GetError());
|
panicf("%s", SDL_GetError());
|
||||||
|
|
||||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, display_zoom == 1 ? "best" : "nearest");
|
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);
|
SDL_RenderSetLogicalSize(sdlRenderer, width, height);
|
||||||
|
|
||||||
if ((gui_surface = SDL_CreateRGBSurface(0, width, height, depth,
|
if ((gui_surface = SDL_CreateRGBSurface(0, width, height, depth,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue