]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant/cursor: get/set cursor position from widget instead of window
authorThomas Debesse <dev@illwieckz.net>
Wed, 10 Mar 2021 05:03:11 +0000 (06:03 +0100)
committerThomas Debesse <dev@illwieckz.net>
Wed, 10 Mar 2021 10:50:59 +0000 (11:50 +0100)
libs/gtkutil/cursor.cpp
libs/gtkutil/cursor.h
radiant/camwindow.cpp
radiant/texwindow.cpp
radiant/xywindow.cpp

index d14286359eafd32ab570328884cdd6915a3b811b..9ada67e66e5ade147f052bf26be2bd944ac9d83e 100644 (file)
@@ -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, &current_x, &current_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 );
 }
index db44d2a46e7134ef1212c6e7e722b64e969b25ca..77cb776123d7a03621f64fd32b66af2a17951497 100644 (file)
@@ -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
index 04110ee7ab11f13fca10b49e36c77857ee31fe50..d3dbf3c5828c8ecb562ecf3497fa0cdb26e34513 100644 (file)
@@ -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 );
index 49c912b6fac703099a052212db30449c5264cb38..b9dd7b4440a01239c75dccdaac1bffebdbc6c855 100644 (file)
@@ -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 ){
index c56083735f4f07f837be805b19dd9dcbff25e603..a39fed7b0e1243f4159ff334b6c4fe7cb90fce1c 100644 (file)
@@ -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 );
 }