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