summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-12-27 19:02:46 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2024-12-29 16:43:21 -0500
commit8884284da4321e2e1599c59b868385b1e9dfdd8f (patch)
treeb8668606839b94917037981bbed5da0a3d19b927
parentfc26ba3f206e4d28479ac5733ac5b5dc1a3c9108 (diff)
downloadrockbox-8884284da4.tar.gz
rockbox-8884284da4.zip
simulator hand icon on button region mouse over
add a hand pointing cursor over the buttons Change-Id: Idb54e084b5b768de845a94c5bb13e4435d9b82e5
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c72
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c9
-rw-r--r--firmware/target/hosted/sdl/window-sdl.c18
3 files changed, 88 insertions, 11 deletions
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index f83f1d6693..7364aefd3a 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -69,7 +69,14 @@ int remote_type(void)
static int btn = 0; /* Hopefully keeps track of currently pressed keys... */
+#ifdef SIMULATOR
+static bool cursor_isfocus = false;
+SDL_Cursor *sdl_focus_cursor = NULL;
+SDL_Cursor *sdl_arrow_cursor = NULL;
+#endif
+
int sdl_app_has_input_focus = 1;
+
#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
static int n900_updown_key_pressed = 0;
#endif
@@ -254,6 +261,19 @@ static bool event_handler(SDL_Event *event)
last_tick = current_tick;
#endif
}
+#ifdef SIMULATOR
+ if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST
+ || event->window.event == SDL_WINDOWEVENT_LEAVE
+ || event->window.event == SDL_WINDOWEVENT_RESIZED
+ || event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
+ {
+ if (cursor_isfocus)
+ {
+ cursor_isfocus = false;
+ SDL_SetCursor(sdl_arrow_cursor);
+ }
+ }
+#endif
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
@@ -282,17 +302,59 @@ static bool event_handler(SDL_Event *event)
#endif
button_event(ev_key, event->type == SDL_KEYDOWN);
break;
-#ifdef HAVE_TOUCHSCREEN
+
+
+
case SDL_MOUSEMOTION:
+ {
+#ifdef SIMULATOR
+ static uint32_t next_check = 0;
+ if (background && sdl_app_has_input_focus
+ && (TIME_AFTER(event->motion.timestamp, next_check)))
+ {
+ int x = event->motion.x;
+ int y = event->motion.y;
+
+ extern struct button_map bm[];
+ int i;
+ for (i = 0; bm[i].button; i++)
+ {
+ int xd = (x-bm[i].x)*(x-bm[i].x);
+ int yd = (y-bm[i].y)*(y-bm[i].y);
+ /* check distance from center of button < radius */
+ if ( xd + yd < bm[i].radius*bm[i].radius ) {
+ break;
+ }
+ }
+
+ if (bm[i].button)
+ {
+ if (!cursor_isfocus)
+ {
+ cursor_isfocus = true;
+ SDL_SetCursor(sdl_focus_cursor);
+ }
+ }
+ else if (cursor_isfocus)
+ {
+ cursor_isfocus = false;
+ SDL_SetCursor(sdl_arrow_cursor);
+ }
+
+ next_check = event->motion.timestamp + 10; /* ms */
+ }
+#endif
+#ifdef HAVE_TOUCHSCREEN
if (event->motion.state & SDL_BUTTON(1))
{
int x = event->motion.x;
int y = event->motion.y;
touchscreen_event(x, y);
}
- break;
#endif
+ break;
+ }
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
{
@@ -560,4 +622,10 @@ int button_read_device(void)
void button_init_device(void)
{
+#ifdef SIMULATOR
+ if (!sdl_focus_cursor)
+ sdl_focus_cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
+ if (!sdl_arrow_cursor)
+ sdl_arrow_cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
+#endif
}
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index d3ec12b909..98e610b3b1 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -177,6 +177,15 @@ void power_off(void)
void sim_do_exit()
{
+#ifdef SIMULATOR
+ extern SDL_Cursor *sdl_focus_cursor;
+ extern SDL_Cursor *sdl_arrow_cursor;
+ if (sdl_focus_cursor)
+ SDL_FreeCursor(sdl_focus_cursor);
+ if (sdl_arrow_cursor)
+ SDL_FreeCursor(sdl_arrow_cursor);
+#endif
+
sim_kernel_shutdown();
SDL_UnlockMutex(window_mutex);
SDL_DestroyMutex(window_mutex);
diff --git a/firmware/target/hosted/sdl/window-sdl.c b/firmware/target/hosted/sdl/window-sdl.c
index 11b3880c59..763c6df37a 100644
--- a/firmware/target/hosted/sdl/window-sdl.c
+++ b/firmware/target/hosted/sdl/window-sdl.c
@@ -35,7 +35,7 @@ SDL_Surface *sim_lcd_surface;
SDL_mutex *window_mutex;
-static SDL_Window *window;
+SDL_Window *sdlWindow;
static SDL_Renderer *sdlRenderer;
static SDL_Surface *picture_surface;
@@ -74,11 +74,11 @@ static void restore_aspect_ratio(int w, int h)
int original_height = h;
int original_width = w;
- if ((SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN))
+ if ((SDL_GetWindowFlags(sdlWindow) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN))
|| display_zoom)
return;
- SDL_GetWindowSize(window, &w, &h);
+ SDL_GetWindowSize(sdlWindow, &w, &h);
if (w != original_width || h != original_height)
{
if (abs(original_width - w) < SNAP_MARGIN)
@@ -89,7 +89,7 @@ static void restore_aspect_ratio(int w, int h)
else
h = w * aspect_ratio;
- SDL_SetWindowSize(window, w, h);
+ SDL_SetWindowSize(sdlWindow, w, h);
}
}
@@ -104,7 +104,7 @@ static void rebuild_gui_texture(void)
0, 0, 0, 0), SDL_TEXTUREACCESS_STREAMING, w, h)) == NULL)
panicf("%s", SDL_GetError());
- if (SDL_GetWindowFlags(window) & SDL_WINDOW_RESIZABLE)
+ if (SDL_GetWindowFlags(sdlWindow) & SDL_WINDOW_RESIZABLE)
restore_aspect_ratio(w, h);
if (background && picture_surface &&
@@ -153,10 +153,10 @@ bool sdl_window_adjust(void)
get_window_dimensions(&w, &h);
- if (!(SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN))
+ if (!(SDL_GetWindowFlags(sdlWindow) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN))
&& display_zoom)
{
- SDL_SetWindowSize(window, display_zoom * w, display_zoom * h);
+ SDL_SetWindowSize(sdlWindow, display_zoom * w, display_zoom * h);
}
#if defined(__APPLE__) || defined(__WIN32)
restore_aspect_ratio(w, h);
@@ -200,11 +200,11 @@ void sdl_window_setup(void)
get_window_dimensions(&width, &height);
- if ((window = SDL_CreateWindow(UI_TITLE, SDL_WINDOWPOS_CENTERED,
+ if ((sdlWindow = SDL_CreateWindow(UI_TITLE, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, width * display_zoom,
height * display_zoom , flags)) == NULL)
panicf("%s", SDL_GetError());
- if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
+ if ((sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
panicf("%s", SDL_GetError());
/* Surface for LCD content only. Needs to fit largest LCD */