From: Thomas Debesse Date: Wed, 10 Mar 2021 05:03:11 +0000 (+0100) Subject: radiant/cursor: factorise a bit the code X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=31840ff32f2e289baa16542fa45d1b5219bb2359;p=xonotic%2Fnetradiant.git radiant/cursor: factorise a bit the code --- diff --git a/libs/gtkutil/cursor.cpp b/libs/gtkutil/cursor.cpp index 999621f1..d1428635 100644 --- a/libs/gtkutil/cursor.cpp +++ b/libs/gtkutil/cursor.cpp @@ -27,21 +27,23 @@ #include #include - GdkCursor* create_blank_cursor(){ - return gdk_cursor_new(GDK_BLANK_CURSOR); + return gdk_cursor_new( GDK_BLANK_CURSOR ); } -void blank_cursor( ui::Widget widget ){ - GdkCursor* cursor = create_blank_cursor(); - gdk_window_set_cursor( gtk_widget_get_window(widget), cursor ); +void set_cursor( ui::Widget widget, GdkCursorType cursor_type ){ + GdkCursor* cursor = gdk_cursor_new( cursor_type ); + gdk_window_set_cursor( gtk_widget_get_window( widget ), cursor ); gdk_cursor_unref( cursor ); } -void default_cursor( ui::Widget widget ){ - gdk_window_set_cursor( gtk_widget_get_window(widget), 0 ); +void blank_cursor( ui::Widget widget ){ + set_cursor( widget, GDK_BLANK_CURSOR ); } +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 ){ gdk_display_get_pointer( gdk_display_get_default(), 0, x, y, 0 ); diff --git a/libs/gtkutil/cursor.h b/libs/gtkutil/cursor.h index 2d16142e..db44d2a4 100644 --- a/libs/gtkutil/cursor.h +++ b/libs/gtkutil/cursor.h @@ -22,6 +22,7 @@ #if !defined( INCLUDED_GTKUTIL_CURSOR_H ) #define INCLUDED_GTKUTIL_CURSOR_H +#include #include #include "debugging/debugging.h" @@ -30,13 +31,12 @@ typedef struct _GdkCursor GdkCursor; typedef struct _GdkEventMotion GdkEventMotion; 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 ); - - class DeferredMotion { guint m_handler; diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 6788f044..c5608373 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -58,6 +58,7 @@ #include "gtkutil/widget.h" #include "gtkutil/glwidget.h" #include "gtkutil/filechooser.h" +#include "gtkutil/cursor.h" #include "gtkmisc.h" #include "select.h" #include "csg.h" @@ -945,14 +946,11 @@ void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){ Vector3 mousePosition; XY_ToPoint( x, y, mousePosition ); if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) { - GdkCursor *cursor; - cursor = gdk_cursor_new( GDK_CROSSHAIR ); - gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor ); - gdk_cursor_unref( cursor ); + set_cursor ( m_gl_widget, GDK_CROSSHAIR ); } else { - gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), 0 ); + default_cursor( m_gl_widget ); } }