]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/cursor.h
Add some notes about NetRadiantCustom alternative code
[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 #include <gdk/gdk.h>
26 #include <uilib/uilib.h>
27
28 #include "debugging/debugging.h"
29
30 typedef struct _GdkCursor GdkCursor;
31 typedef struct _GdkEventMotion GdkEventMotion;
32
33 // Note: NetRadiantCustom disables them but we still make use of them.
34 #if 1
35 GdkCursor* create_blank_cursor();
36 void set_cursor( ui::Widget widget, GdkCursorType cursor_type );
37 void blank_cursor( ui::Widget widget );
38 void default_cursor( ui::Widget widget );
39 #endif
40 void Sys_GetCursorPos( ui::Widget widget, int *x, int *y );
41 void Sys_SetCursorPos( ui::Widget widget, int x, int y );
42
43 class DeferredMotion
44 {
45 guint m_handler;
46 typedef void ( *MotionFunction )( gdouble x, gdouble y, guint state, void* data );
47 MotionFunction m_function;
48 void* m_data;
49 gdouble m_x;
50 gdouble m_y;
51 guint m_state;
52
53 static gboolean deferred( DeferredMotion* self ){
54         self->m_handler = 0;
55         self->m_function( self->m_x, self->m_y, self->m_state, self->m_data );
56         return FALSE;
57 }
58 public:
59 DeferredMotion( MotionFunction function, void* data ) : m_handler( 0 ), m_function( function ), m_data( data ){
60 }
61 void motion( gdouble x, gdouble y, guint state ){
62         m_x = x;
63         m_y = y;
64         m_state = state;
65         if ( m_handler == 0 ) {
66                 m_handler = g_idle_add( (GSourceFunc)deferred, this );
67         }
68 }
69 static gboolean gtk_motion( ui::Widget widget, GdkEventMotion *event, DeferredMotion* self );
70 };
71
72 class DeferredMotionDelta
73 {
74 int m_delta_x;
75 int m_delta_y;
76 guint m_motion_handler;
77 typedef void ( *MotionDeltaFunction )( int x, int y, void* data );
78 MotionDeltaFunction m_function;
79 void* m_data;
80
81 static gboolean deferred_motion( gpointer data ){
82         reinterpret_cast<DeferredMotionDelta*>( data )->m_function(
83                 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_x,
84                 reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_y,
85                 reinterpret_cast<DeferredMotionDelta*>( data )->m_data
86                 );
87         reinterpret_cast<DeferredMotionDelta*>( data )->m_motion_handler = 0;
88         reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_x = 0;
89         reinterpret_cast<DeferredMotionDelta*>( data )->m_delta_y = 0;
90         return FALSE;
91 }
92 public:
93 DeferredMotionDelta( MotionDeltaFunction function, void* data ) : m_delta_x( 0 ), m_delta_y( 0 ), m_motion_handler( 0 ), m_function( function ), m_data( data ){
94 }
95 void flush(){
96         if ( m_motion_handler != 0 ) {
97                 g_source_remove( m_motion_handler );
98                 deferred_motion( this );
99         }
100 }
101 void motion_delta( int x, int y, unsigned int state ){
102         m_delta_x += x;
103         m_delta_y += y;
104         if ( m_motion_handler == 0 ) {
105                 m_motion_handler = g_idle_add( deferred_motion, this );
106         }
107 }
108 };
109
110 class FreezePointer
111 {
112 unsigned int handle_motion;
113 int recorded_x, recorded_y, last_x, last_y, center_x, center_y;
114 typedef void ( *MotionDeltaFunction )( int x, int y, unsigned int state, void* data );
115 MotionDeltaFunction m_function;
116 void* m_data;
117 public:
118 FreezePointer() : handle_motion( 0 ), m_function( 0 ), m_data( 0 ){
119 }
120 static gboolean motion_delta( ui::Widget widget, GdkEventMotion *event, FreezePointer* self );
121
122 void freeze_pointer( ui::Widget widget, MotionDeltaFunction function, void* data );
123
124 void unfreeze_pointer( ui::Widget widget );
125 };
126
127 #endif