GTK: In mouse-grab mode, accumulate partial pixels.

This commit is contained in:
Brandon Wright 2019-03-02 16:10:00 -06:00
parent 7b310a0cf4
commit 92f2a9510f
4 changed files with 17 additions and 16 deletions

View File

@ -135,8 +135,8 @@ bool S9xPollAxis (uint32 id, int16 *value)
bool S9xPollPointer (uint32 id, int16 *x, int16 *y) bool S9xPollPointer (uint32 id, int16 *x, int16 *y)
{ {
*x = top_level->mouse_loc_x; *x = top_level->snes_mouse_x;
*y = top_level->mouse_loc_y; *y = top_level->snes_mouse_y;
return true; return true;
} }

View File

@ -312,6 +312,7 @@ gboolean S9xIdleFunc (gpointer data)
} }
S9xCheckPointerTimer (); S9xCheckPointerTimer ();
S9xProcessEvents (true); S9xProcessEvents (true);
if (!S9xDisplayDriverIsReady ()) if (!S9xDisplayDriverIsReady ())

View File

@ -235,12 +235,12 @@ event_motion_notify (GtkWidget *widget,
if (window->mouse_grabbed) if (window->mouse_grabbed)
{ {
if (event->x_root == window->mouse_reported_x && if (event->x_root == window->gdk_mouse_x &&
event->y_root == window->mouse_reported_y) event->y_root == window->gdk_mouse_y)
return false; return false;
window->mouse_loc_x += (event->x_root - window->mouse_reported_x); window->snes_mouse_x += (event->x_root - window->gdk_mouse_x);
window->mouse_loc_y += (event->y_root - window->mouse_reported_y); window->snes_mouse_y += (event->y_root - window->gdk_mouse_y);
window->center_mouse (); window->center_mouse ();
return false; return false;
@ -252,11 +252,11 @@ event_motion_notify (GtkWidget *widget,
int scale_factor = 1; int scale_factor = 1;
#endif #endif
window->mouse_loc_x = (uint16) window->snes_mouse_x = (uint16)
((int) (event->x * scale_factor) - window->mouse_region_x) * 256 / ((int) (event->x * scale_factor) - window->mouse_region_x) * 256 /
(window->mouse_region_width <= 0 ? 1 : window->mouse_region_width); (window->mouse_region_width <= 0 ? 1 : window->mouse_region_width);
window->mouse_loc_y = (uint16) window->snes_mouse_y = (uint16)
((int) (event->y * scale_factor) - window->mouse_region_y) * (gui_config->overscan ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT) / ((int) (event->y * scale_factor) - window->mouse_region_y) * (gui_config->overscan ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT) /
(window->mouse_region_height <= 0 ? 1 : window->mouse_region_height); (window->mouse_region_height <= 0 ? 1 : window->mouse_region_height);
@ -1814,17 +1814,17 @@ Snes9xWindow::center_mouse ()
w = gdk_window_get_width (gdk_window); w = gdk_window_get_width (gdk_window);
h = gdk_window_get_height (gdk_window); h = gdk_window_get_height (gdk_window);
mouse_reported_x = x + w / 2; gdk_mouse_x = x + w / 2;
mouse_reported_y = y + h / 2; gdk_mouse_y = y + h / 2;
#if GTK_MAJOR_VERSION < 3 #if GTK_MAJOR_VERSION < 3
gdk_display_warp_pointer (gdk_display, gdk_screen, mouse_reported_x, gdk_display_warp_pointer (gdk_display, gdk_screen, gdk_mouse_x,
mouse_reported_y); gdk_mouse_y);
#else #else
GdkSeat *seat = gdk_display_get_default_seat (gdk_display); GdkSeat *seat = gdk_display_get_default_seat (gdk_display);
GdkDevice *pointer = gdk_seat_get_pointer (seat); GdkDevice *pointer = gdk_seat_get_pointer (seat);
gdk_device_warp (pointer, gdk_screen, mouse_reported_x, mouse_reported_y); gdk_device_warp (pointer, gdk_screen, gdk_mouse_x, gdk_mouse_y);
#endif #endif
} }
@ -1860,7 +1860,7 @@ Snes9xWindow::toggle_grab_mouse ()
#endif #endif
S9xReportPointer (BINDING_MOUSE_POINTER, 0, 0); S9xReportPointer (BINDING_MOUSE_POINTER, 0, 0);
mouse_loc_x = 0; mouse_loc_y = 0; snes_mouse_x = 0.0; snes_mouse_y = 0.0;
mouse_grabbed = !mouse_grabbed; mouse_grabbed = !mouse_grabbed;
if (mouse_grabbed) if (mouse_grabbed)
center_mouse (); center_mouse ();

View File

@ -82,8 +82,8 @@ class Snes9xWindow : public GtkBuilderWindow
int maximized_state; int maximized_state;
bool focused; bool focused;
bool paused_from_focus_loss; bool paused_from_focus_loss;
uint16 mouse_loc_x, mouse_loc_y; double snes_mouse_x, snes_mouse_y;
uint16 mouse_reported_x, mouse_reported_y; double gdk_mouse_x, gdk_mouse_y;
bool mouse_grabbed; bool mouse_grabbed;
GdkPixbuf *icon, *splash; GdkPixbuf *icon, *splash;
GdkCursor *default_cursor, *empty_cursor; GdkCursor *default_cursor, *empty_cursor;