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