From e9bb12b9916f5cdc3834e83a8e0b2569545630cb Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Wed, 10 Mar 2021 06:03:11 +0100 Subject: [PATCH] radiant/cursor: get/set cursor position from widget instead of window --- libs/gtkutil/cursor.cpp | 26 +++++++++++++------------- libs/gtkutil/cursor.h | 10 +++++----- radiant/camwindow.cpp | 6 +++--- radiant/texwindow.cpp | 4 ++-- radiant/xywindow.cpp | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/libs/gtkutil/cursor.cpp b/libs/gtkutil/cursor.cpp index d1428635..9ada67e6 100644 --- a/libs/gtkutil/cursor.cpp +++ b/libs/gtkutil/cursor.cpp @@ -45,11 +45,11 @@ void default_cursor( ui::Widget widget ){ gdk_window_set_cursor( gtk_widget_get_window( widget ), NULL ); } -void Sys_GetCursorPos( ui::Window window, int *x, int *y ){ +void Sys_GetCursorPos( ui::Widget widget, int *x, int *y ){ gdk_display_get_pointer( gdk_display_get_default(), 0, x, y, 0 ); } -void Sys_SetCursorPos( ui::Window window, int x, int y ){ +void Sys_SetCursorPos( ui::Widget widget, int x, int y ){ GdkScreen *screen; gdk_display_get_pointer( gdk_display_get_default(), &screen, 0, 0, 0 ); gdk_display_warp_pointer( gdk_display_get_default(), screen, x, y ); @@ -61,18 +61,18 @@ gboolean DeferredMotion::gtk_motion(ui::Widget widget, GdkEventMotion *event, De return FALSE; } -gboolean FreezePointer::motion_delta(ui::Window widget, GdkEventMotion *event, FreezePointer *self) +gboolean FreezePointer::motion_delta(ui::Widget widget, GdkEventMotion *event, FreezePointer *self) { int current_x, current_y; Sys_GetCursorPos( widget, ¤t_x, ¤t_y ); int dx = current_x - self->last_x; int dy = current_y - self->last_y; - int ddx = current_x - self->recorded_x; - int ddy = current_y - self->recorded_y; self->last_x = current_x; self->last_y = current_y; if ( dx != 0 || dy != 0 ) { //globalOutputStream() << "motion x: " << dx << ", y: " << dy << "\n"; + int ddx = current_x - self->recorded_x; + int ddy = current_y - self->recorded_y; if (ddx < -32 || ddx > 32 || ddy < -32 || ddy > 32) { Sys_SetCursorPos( widget, self->recorded_x, self->recorded_y ); self->last_x = self->recorded_x; @@ -83,7 +83,7 @@ gboolean FreezePointer::motion_delta(ui::Window widget, GdkEventMotion *event, F return FALSE; } -void FreezePointer::freeze_pointer(ui::Window window, FreezePointer::MotionDeltaFunction function, void *data) +void FreezePointer::freeze_pointer(ui::Widget widget, FreezePointer::MotionDeltaFunction function, void *data) { ASSERT_MESSAGE( m_function == 0, "can't freeze pointer" ); @@ -99,12 +99,12 @@ void FreezePointer::freeze_pointer(ui::Window window, FreezePointer::MotionDelta GdkCursor* cursor = create_blank_cursor(); //GdkGrabStatus status = - gdk_pointer_grab( gtk_widget_get_window(window), TRUE, mask, 0, cursor, GDK_CURRENT_TIME ); + gdk_pointer_grab( gtk_widget_get_window( widget ), TRUE, mask, 0, cursor, GDK_CURRENT_TIME ); gdk_cursor_unref( cursor ); - Sys_GetCursorPos( window, &recorded_x, &recorded_y ); + Sys_GetCursorPos( widget, &recorded_x, &recorded_y ); - Sys_SetCursorPos( window, recorded_x, recorded_y ); + Sys_SetCursorPos( widget, recorded_x, recorded_y ); last_x = recorded_x; last_y = recorded_y; @@ -112,17 +112,17 @@ void FreezePointer::freeze_pointer(ui::Window window, FreezePointer::MotionDelta m_function = function; m_data = data; - handle_motion = window.connect( "motion_notify_event", G_CALLBACK( motion_delta ), this ); + handle_motion = widget.connect( "motion_notify_event", G_CALLBACK( motion_delta ), this ); } -void FreezePointer::unfreeze_pointer(ui::Window window) +void FreezePointer::unfreeze_pointer(ui::Widget widget) { - g_signal_handler_disconnect( G_OBJECT( window ), handle_motion ); + g_signal_handler_disconnect( G_OBJECT( widget ), handle_motion ); m_function = 0; m_data = 0; - Sys_SetCursorPos( window, recorded_x, recorded_y ); + Sys_SetCursorPos( widget, recorded_x, recorded_y ); gdk_pointer_ungrab( GDK_CURRENT_TIME ); } diff --git a/libs/gtkutil/cursor.h b/libs/gtkutil/cursor.h index db44d2a4..77cb7761 100644 --- a/libs/gtkutil/cursor.h +++ b/libs/gtkutil/cursor.h @@ -34,8 +34,8 @@ GdkCursor* create_blank_cursor(); void set_cursor( ui::Widget widget, GdkCursorType cursor_type ); void blank_cursor( ui::Widget widget ); void default_cursor( ui::Widget widget ); -void Sys_GetCursorPos( ui::Window window, int *x, int *y ); -void Sys_SetCursorPos( ui::Window window, int x, int y ); +void Sys_GetCursorPos( ui::Widget widget, int *x, int *y ); +void Sys_SetCursorPos( ui::Widget widget, int x, int y ); class DeferredMotion { @@ -114,11 +114,11 @@ void* m_data; public: FreezePointer() : handle_motion( 0 ), m_function( 0 ), m_data( 0 ){ } -static gboolean motion_delta( ui::Window widget, GdkEventMotion *event, FreezePointer* self ); +static gboolean motion_delta( ui::Widget widget, GdkEventMotion *event, FreezePointer* self ); -void freeze_pointer( ui::Window window, MotionDeltaFunction function, void* data ); +void freeze_pointer( ui::Widget widget, MotionDeltaFunction function, void* data ); -void unfreeze_pointer( ui::Window window ); +void unfreeze_pointer( ui::Widget widget ); }; #endif diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 04110ee7..d3dbf3c5 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -1264,7 +1264,7 @@ void CamWnd::Cam_PositionDrag(){ CamWnd_Update( camwnd ); CameraMovedNotify(); - Sys_SetCursorPos( m_parent, m_PositionDragCursorX, m_PositionDragCursorY ); + Sys_SetCursorPos( m_gl_widget, m_PositionDragCursorX, m_PositionDragCursorY ); } } #endif @@ -1289,7 +1289,7 @@ void CamWnd::EnableFreeMove(){ gtk_window_set_focus( m_parent, m_gl_widget ); m_freemove_handle_focusout = m_gl_widget.connect( "focus_out_event", G_CALLBACK( camwindow_freemove_focusout ), this ); - m_freezePointer.freeze_pointer( m_parent, Camera_motionDelta, &m_Camera ); + m_freezePointer.freeze_pointer( m_gl_widget, Camera_motionDelta, &m_Camera ); CamWnd_Update( *this ); } @@ -1304,7 +1304,7 @@ void CamWnd::DisableFreeMove(){ CamWnd_Remove_Handlers_FreeMove( *this ); CamWnd_Add_Handlers_Move( *this ); - m_freezePointer.unfreeze_pointer( m_parent ); + m_freezePointer.unfreeze_pointer( m_gl_widget ); g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_freemove_handle_focusout ); CamWnd_Update( *this ); diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 49c912b6..b9dd7b44 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -1117,11 +1117,11 @@ void TextureBrowser_trackingDelta( int x, int y, unsigned int state, void* data } void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){ - textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, TextureBrowser_trackingDelta, &textureBrowser ); + textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser ); } void TextureBrowser_Tracking_MouseUp( TextureBrowser& textureBrowser ){ - textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_parent ); + textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_gl_widget ); } void TextureBrowser_Selection_MouseDown( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy ){ diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index c5608373..a39fed7b 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -1183,13 +1183,13 @@ void XYWnd::Move_Begin(){ Move_End(); } m_move_started = true; - g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this ); + g_xywnd_freezePointer.freeze_pointer( m_gl_widget, XYWnd_moveDelta, this ); m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this ); } void XYWnd::Move_End(){ m_move_started = false; - g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow() ); + g_xywnd_freezePointer.unfreeze_pointer( m_gl_widget ); g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut ); } -- 2.39.2