]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/cursor.h
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / libs / gtkutil / cursor.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_GTKUTIL_CURSOR_H )
23 #define INCLUDED_GTKUTIL_CURSOR_H
24
25 // This is probably removable if set_cursor is not used.
26 #include <gdk/gdk.h>
27 #include <uilib/uilib.h>
28
29 #include "debugging/debugging.h"
30
31 typedef struct _GdkCursor GdkCursor;
32 typedef struct _GdkEventMotion GdkEventMotion;
33
34 // NetRadiantCustom disables them but we still make use of them.
35 #if 1
36 GdkCursor* create_blank_cursor();
37 void set_cursor( ui::Widget widget, GdkCursorType cursor_type );
38 void blank_cursor( ui::Widget widget );
39 void default_cursor( ui::Widget widget );
40 #endif
41 void Sys_GetCursorPos( ui::Widget widget, int *x, int *y );
42 void Sys_SetCursorPos( ui::Widget widget, int x, int y );
43
44 class DeferredMotion
45 {
46 guint m_handler;
47 typedef void ( *MotionFunction )( gdouble x, gdouble y, guint state, void* data );
48 MotionFunction m_function;
49 void* m_data;
50 gdouble m_x;
51 gdouble m_y;
52 guint m_state;
53
54 static gboolean deferred( DeferredMotion* self ){
55         self->m_handler = 0;
56         self->m_function( self->m_x, self->m_y, self->m_state, self->m_data );
57         return FALSE;
58 }
59 public:
60 DeferredMotion( MotionFunction function, void* data ) : m_handler( 0 ), m_function( function ), m_data( data ){
61 }
62 void motion( gdouble x, gdouble y, guint state ){
63         m_x = x;
64         m_y = y;
65         m_state = state;
66         if ( m_handler == 0 ) {
67                 m_handler = g_idle_add( (GSourceFunc)deferred, this );
68         }
69 }
70 static gboolean gtk_motion( ui::Widget widget, GdkEventMotion *event, DeferredMotion* self );
71 };
72
73 class DeferredMotionDelta
74 {
75 int m_delta_x;
76 int m_delta_y;
77 guint m_motion_handler;
78 typedef void ( *MotionDeltaFunction )( int x, int y, void* data );
79 MotionDeltaFunction m_function;
80 void* m_data;
81
82 static gboolean deferred_motion( gpointer data ){
83         reinterpret_cast<DeferredMotionDelta*>( data )->m_function(
84                 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_x,
85                 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_y,
86                 reinterpret_cast<DeferredMotionDelta*>( data )->m_data
87                 );
88         reinterpret_cast<DeferredMotionDelta*>( data )->m_motion_handler = 0;
89         reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_x = 0;
90         reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_y = 0;
91         return FALSE;
92 }
93 public:
94 DeferredMotionDelta( MotionDeltaFunction function, void* data ) : m_delta_x( 0 ), m_delta_y( 0 ), m_motion_handler( 0 ), m_function( function ), m_data( data ){
95 }
96 void flush(){
97         if ( m_motion_handler != 0 ) {
98                 g_source_remove( m_motion_handler );
99                 deferred_motion( this );
100         }
101 }
102 void motion_delta( int x, int y, unsigned int state ){
103         m_delta_x += x;
104         m_delta_y += y;
105         if ( m_motion_handler == 0 ) {
106                 m_motion_handler = g_idle_add( deferred_motion, this );
107         }
108 }
109 };
110
111 class FreezePointer
112 {
113 unsigned int handle_motion;
114 int recorded_x, recorded_y, last_x, last_y, center_x, center_y;
115 ui::Widget m_weedjet{ui::null};
116 typedef void ( *MotionDeltaFunction )( int x, int y, unsigned int state, void* data );
117 MotionDeltaFunction m_function;
118 void* m_data;
119 public:
120 FreezePointer() : handle_motion( 0 ), m_function( 0 ), m_data( 0 ){
121 }
122 /* NetRadiantCustom does this instead:
123 static gboolean motion_delta( ui::Window widget, GdkEventMotion *event, FreezePointer* self ); */
124 static gboolean motion_delta( ui::Widget widget, GdkEventMotion *event, FreezePointer* self );
125
126 /* NetRadiantCustom does this instead:
127 void freeze_pointer( ui::Window window, ui::Widget widget, MotionDeltaFunction function, void* data ); */
128 void freeze_pointer( ui::Widget widget, MotionDeltaFunction function, void* data );
129
130 /* NetRadiantCustom does this instead:
131 void unfreeze_pointer( ui::Window window, bool centerize ); */
132 void unfreeze_pointer( ui::Widget widget, bool centerize );
133 };
134
135 #endif