Mercurial > pidgin
comparison src/gtkwhiteboard.c @ 11802:2e3a6dcebaf3
[gaim-migrate @ 14093]
This should be it for the // -> /* */ for the doodle/whiteboard stuff. This could use a bit of cleaning yet....
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Mon, 24 Oct 2005 22:45:24 +0000 |
parents | 19941a47405c |
children | 4669e7461968 |
comparison
equal
deleted
inserted
replaced
11801:81806e9241be | 11802:2e3a6dcebaf3 |
---|---|
19 * along with this program; if not, write to the Free Software | 19 * along with this program; if not, write to the Free Software |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 * | 21 * |
22 */ | 22 */ |
23 | 23 |
24 // INCLUDES ============================================================================================ | |
25 | |
26 #include <stdlib.h> | 24 #include <stdlib.h> |
27 | 25 |
28 #include "blist.h" | 26 #include "blist.h" |
29 | 27 |
30 #include "gtkwhiteboard.h" | 28 #include "gtkwhiteboard.h" |
31 | 29 |
32 // GLOBALS ============================================================================================= | 30 /****************************************************************************** |
33 | 31 * Prototypes |
34 //GList *buttonList = NULL; | 32 *****************************************************************************/ |
35 | 33 static void gaim_gtk_whiteboard_create( GaimWhiteboard *wb ); |
36 //GdkColor DefaultColor[PALETTE_NUM_COLORS]; | 34 |
35 static void gaim_gtk_whiteboard_destroy( GaimWhiteboard *wb ); | |
36 static void gaim_gtk_whiteboard_exit( GtkWidget *widget, gpointer data ); | |
37 | |
38 /*static void gaim_gtkwhiteboard_button_start_press( GtkButton *button, gpointer data ); */ | |
39 | |
40 static gboolean gaim_gtk_whiteboard_configure_event( GtkWidget *widget, GdkEventConfigure *event, gpointer data ); | |
41 static gboolean gaim_gtk_whiteboard_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer data ); | |
42 | |
43 static gboolean gaim_gtk_whiteboard_brush_down( GtkWidget *widget, GdkEventButton *event, gpointer data ); | |
44 static gboolean gaim_gtk_whiteboard_brush_motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ); | |
45 static gboolean gaim_gtk_whiteboard_brush_up( GtkWidget *widget, GdkEventButton *event, gpointer data ); | |
46 | |
47 static void gaim_gtk_whiteboard_draw_brush_point( GaimWhiteboard *wb, | |
48 int x, int y, int color, int size ); | |
49 static void gaim_gtk_whiteboard_draw_brush_line( GaimWhiteboard *wb, | |
50 int x0, int y0, int x1, int y1, int color, int size ); | |
51 | |
52 static void gaim_gtk_whiteboard_set_dimensions( GaimWhiteboard *wb, int width, int height ); | |
53 static void gaim_gtk_whiteboard_clear( GaimWhiteboard *wb ); | |
54 | |
55 static void gaim_gtk_whiteboard_button_clear_press( GtkWidget *widget, gpointer data ); | |
56 static void gaim_gtk_whiteboard_button_save_press( GtkWidget *widget, gpointer data ); | |
57 | |
58 static void gaim_gtk_whiteboard_set_canvas_as_icon( GaimGtkWhiteboard *gtkwb ); | |
59 | |
60 static void gaim_gtk_whiteboard_rgb24_to_rgb48( int color_rgb, GdkColor *color ); | |
61 | |
62 /****************************************************************************** | |
63 * Globals | |
64 *****************************************************************************/ | |
65 /* | |
66 GList *buttonList = NULL; | |
67 GdkColor DefaultColor[PALETTE_NUM_COLORS]; | |
68 */ | |
37 | 69 |
38 static gboolean LocalShutdownRequest; | 70 static gboolean LocalShutdownRequest; |
39 | 71 |
40 static int LastX; // Tracks last position of the mouse when drawing | 72 static int LastX; // Tracks last position of the mouse when drawing |
41 static int LastY; | 73 static int LastY; |
50 gaim_gtk_whiteboard_draw_brush_point, | 82 gaim_gtk_whiteboard_draw_brush_point, |
51 gaim_gtk_whiteboard_draw_brush_line, | 83 gaim_gtk_whiteboard_draw_brush_line, |
52 gaim_gtk_whiteboard_clear | 84 gaim_gtk_whiteboard_clear |
53 }; | 85 }; |
54 | 86 |
55 // FUNCTIONS ============================================================================================ | 87 /****************************************************************************** |
56 | 88 * API |
89 *****************************************************************************/ | |
57 GaimWhiteboardUiOps *gaim_gtk_whiteboard_get_ui_ops( void ) | 90 GaimWhiteboardUiOps *gaim_gtk_whiteboard_get_ui_ops( void ) |
58 { | 91 { |
59 return( &ui_ops ); | 92 return( &ui_ops ); |
60 } | 93 } |
61 | 94 |
62 // ------------------------------------------------------------------------------------------------------ | |
63 | |
64 void gaim_gtk_whiteboard_create( GaimWhiteboard *wb ) | 95 void gaim_gtk_whiteboard_create( GaimWhiteboard *wb ) |
65 { | 96 { |
66 //g_print( "gaim_gtk_whiteboard_create()\n" ); | |
67 | |
68 int i; | 97 int i; |
69 | 98 |
70 GtkWidget *window; | 99 GtkWidget *window; |
71 GtkWidget *drawing_area; | 100 GtkWidget *drawing_area; |
72 | 101 |
73 GtkWidget *hbox_palette; | 102 GtkWidget *hbox_palette; |
74 GtkWidget *vbox_palette_above_canvas_and_controls; | 103 GtkWidget *vbox_palette_above_canvas_and_controls; |
75 GtkWidget *hbox_canvas_and_controls; | 104 GtkWidget *hbox_canvas_and_controls; |
76 GtkWidget *vbox_controls; | 105 GtkWidget *vbox_controls; |
77 | 106 |
78 // -------------------------- | 107 /* |
79 // |[][][][palette[][][][][]| | 108 -------------------------- |
80 // |------------------------| | 109 |[][][][palette[][][][][]| |
81 // | canvas | con | | 110 |------------------------| |
82 // | | trol| | 111 | canvas | con | |
83 // | | s | | 112 | | trol| |
84 // | | | | 113 | | s | |
85 // | | | | 114 | | | |
86 // -------------------------- | 115 | | | |
87 | 116 -------------------------- |
117 */ | |
88 GtkWidget *clear_button; | 118 GtkWidget *clear_button; |
89 GtkWidget *save_button; | 119 GtkWidget *save_button; |
90 | 120 |
91 GtkWidget *palette_color_box[PALETTE_NUM_COLORS]; | 121 GtkWidget *palette_color_box[PALETTE_NUM_COLORS]; |
92 /* GdkPixbuf *palette_color_area[PALETTE_NUM_COLORS]; */ | 122 /* GdkPixbuf *palette_color_area[PALETTE_NUM_COLORS]; */ |
93 | 123 |
94 GaimGtkWhiteboard *gtkwb = g_new0( GaimGtkWhiteboard, 1 ); | 124 GaimGtkWhiteboard *gtkwb = g_new0( GaimGtkWhiteboard, 1 ); |
95 | 125 |
96 const char *window_title; | 126 const char *window_title; |
97 | 127 |
98 gtkwb->wb = wb; | 128 gtkwb->wb = wb; |
99 wb->ui_data = gtkwb; | 129 wb->ui_data = gtkwb; |
100 | 130 |
101 // Get dimensions (default?) for the whiteboard canvas | 131 /* Get dimensions (default?) for the whiteboard canvas */ |
102 if( wb->prpl_ops && wb->prpl_ops->get_dimensions ) | 132 if( wb->prpl_ops && wb->prpl_ops->get_dimensions ) |
103 wb->prpl_ops->get_dimensions( wb, >kwb->width, >kwb->height ); | 133 wb->prpl_ops->get_dimensions( wb, >kwb->width, >kwb->height ); |
104 | 134 |
105 window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); | 135 window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
106 gtkwb->window = window; | 136 gtkwb->window = window; |
107 gtk_widget_set_name( window, wb->who ); | 137 gtk_widget_set_name( window, wb->who ); |
108 | 138 |
109 // Try and set window title as the name of the buddy, else just use their username | 139 /* Try and set window title as the name of the buddy, else just use their |
140 * username | |
141 */ | |
110 window_title = gaim_contact_get_alias( gaim_buddy_get_contact( gaim_find_buddy( wb->account, wb->who ) ) ); | 142 window_title = gaim_contact_get_alias( gaim_buddy_get_contact( gaim_find_buddy( wb->account, wb->who ) ) ); |
111 if( window_title ) | 143 if( window_title ) |
112 gtk_window_set_title( ( GtkWindow* )( window ), window_title ); | 144 gtk_window_set_title( ( GtkWindow* )( window ), window_title ); |
113 else | 145 else |
114 gtk_window_set_title( ( GtkWindow* )( window ), wb->who ); | 146 gtk_window_set_title( ( GtkWindow* )( window ), wb->who ); |
115 | 147 |
116 gtk_window_set_resizable( ( GtkWindow* )( window ), FALSE ); | 148 gtk_window_set_resizable( ( GtkWindow* )( window ), FALSE ); |
117 | 149 |
118 g_signal_connect( G_OBJECT( window ), "destroy", | 150 g_signal_connect( G_OBJECT( window ), "destroy", |
119 G_CALLBACK( gaim_gtk_whiteboard_exit ), ( gpointer )( gtkwb ) ); | 151 G_CALLBACK( gaim_gtk_whiteboard_exit ), ( gpointer )( gtkwb ) ); |
120 | 152 |
121 // Create vertical box to place palette above the canvas and controls | 153 /* Create vertical box to place palette above the canvas and controls */ |
122 vbox_palette_above_canvas_and_controls = gtk_vbox_new( FALSE, 0 ); | 154 vbox_palette_above_canvas_and_controls = gtk_vbox_new( FALSE, 0 ); |
123 gtk_container_add( GTK_CONTAINER( window ), vbox_palette_above_canvas_and_controls ); | 155 gtk_container_add( GTK_CONTAINER( window ), vbox_palette_above_canvas_and_controls ); |
124 gtk_widget_show( vbox_palette_above_canvas_and_controls ); | 156 gtk_widget_show( vbox_palette_above_canvas_and_controls ); |
125 | 157 |
126 // Create horizontal box for the palette and all its entries | 158 /* Create horizontal box for the palette and all its entries */ |
127 hbox_palette = gtk_hbox_new( FALSE, 0 ); | 159 hbox_palette = gtk_hbox_new( FALSE, 0 ); |
128 gtk_container_add( GTK_CONTAINER( vbox_palette_above_canvas_and_controls ), hbox_palette ); | 160 gtk_container_add( GTK_CONTAINER( vbox_palette_above_canvas_and_controls ), hbox_palette ); |
129 gtk_widget_show( hbox_palette ); | 161 gtk_widget_show( hbox_palette ); |
130 | 162 |
131 // Create horizontal box to seperate the canvas from the controls | 163 /* Create horizontal box to seperate the canvas from the controls */ |
132 hbox_canvas_and_controls = gtk_hbox_new( FALSE, 0 ); | 164 hbox_canvas_and_controls = gtk_hbox_new( FALSE, 0 ); |
133 gtk_container_add( GTK_CONTAINER( vbox_palette_above_canvas_and_controls ), hbox_canvas_and_controls ); | 165 gtk_container_add( GTK_CONTAINER( vbox_palette_above_canvas_and_controls ), hbox_canvas_and_controls ); |
134 gtk_widget_show( hbox_canvas_and_controls ); | 166 gtk_widget_show( hbox_canvas_and_controls ); |
135 | 167 |
136 for( i = 0; i < PALETTE_NUM_COLORS; i++ ) | 168 for( i = 0; i < PALETTE_NUM_COLORS; i++ ) |
137 { | 169 { |
138 //palette_color_area[i] = | 170 /* palette_color_area[i] = */ |
139 | 171 |
140 palette_color_box[i] = gtk_image_new_from_pixbuf( NULL ); | 172 palette_color_box[i] = gtk_image_new_from_pixbuf( NULL ); |
141 gtk_widget_set_size_request( palette_color_box[i], gtkwb->width / PALETTE_NUM_COLORS ,32 ); | 173 gtk_widget_set_size_request( palette_color_box[i], gtkwb->width / PALETTE_NUM_COLORS ,32 ); |
142 gtk_container_add( GTK_CONTAINER( hbox_palette ), palette_color_box[i] ); | 174 gtk_container_add( GTK_CONTAINER( hbox_palette ), palette_color_box[i] ); |
143 | 175 |
144 | |
145 | |
146 gtk_widget_show( palette_color_box[i] ); | 176 gtk_widget_show( palette_color_box[i] ); |
147 } | 177 } |
148 | 178 |
149 // Create the drawing area | 179 /* Create the drawing area */ |
150 drawing_area = gtk_drawing_area_new(); | 180 drawing_area = gtk_drawing_area_new(); |
151 gtkwb->drawing_area = drawing_area; | 181 gtkwb->drawing_area = drawing_area; |
152 gtk_widget_set_size_request( GTK_WIDGET( drawing_area ), gtkwb->width, gtkwb->height ); | 182 gtk_widget_set_size_request( GTK_WIDGET( drawing_area ), gtkwb->width, gtkwb->height ); |
153 gtk_box_pack_start( GTK_BOX( hbox_canvas_and_controls ), drawing_area, TRUE, TRUE, 8 ); | 183 gtk_box_pack_start( GTK_BOX( hbox_canvas_and_controls ), drawing_area, TRUE, TRUE, 8 ); |
154 | 184 |
155 gtk_widget_show( drawing_area ); | 185 gtk_widget_show( drawing_area ); |
156 | 186 |
157 // Signals used to handle backing pixmap | 187 /* Signals used to handle backing pixmap */ |
158 g_signal_connect( G_OBJECT( drawing_area ), "expose_event", | 188 g_signal_connect( G_OBJECT( drawing_area ), "expose_event", |
159 G_CALLBACK( gaim_gtk_whiteboard_expose_event ), ( gpointer )( gtkwb ) ); | 189 G_CALLBACK( gaim_gtk_whiteboard_expose_event ), ( gpointer )( gtkwb ) ); |
160 | 190 |
161 g_signal_connect( G_OBJECT( drawing_area ), "configure_event", | 191 g_signal_connect( G_OBJECT( drawing_area ), "configure_event", |
162 G_CALLBACK( gaim_gtk_whiteboard_configure_event ), ( gpointer )( gtkwb ) ); | 192 G_CALLBACK( gaim_gtk_whiteboard_configure_event ), ( gpointer )( gtkwb ) ); |
163 | 193 |
164 // Event signals | 194 /* Event signals */ |
165 g_signal_connect( G_OBJECT( drawing_area ), "button_press_event", | 195 g_signal_connect( G_OBJECT( drawing_area ), "button_press_event", |
166 G_CALLBACK( gaim_gtk_whiteboard_brush_down ), ( gpointer )( gtkwb ) ); | 196 G_CALLBACK( gaim_gtk_whiteboard_brush_down ), ( gpointer )( gtkwb ) ); |
167 | 197 |
168 g_signal_connect( G_OBJECT( drawing_area ), "motion_notify_event", | 198 g_signal_connect( G_OBJECT( drawing_area ), "motion_notify_event", |
169 G_CALLBACK( gaim_gtk_whiteboard_brush_motion ), ( gpointer )( gtkwb ) ); | 199 G_CALLBACK( gaim_gtk_whiteboard_brush_motion ), ( gpointer )( gtkwb ) ); |
170 | 200 |
171 g_signal_connect( G_OBJECT( drawing_area ), "button_release_event", | 201 g_signal_connect( G_OBJECT( drawing_area ), "button_release_event", |
172 G_CALLBACK( gaim_gtk_whiteboard_brush_up ), ( gpointer )( gtkwb ) ); | 202 G_CALLBACK( gaim_gtk_whiteboard_brush_up ), ( gpointer )( gtkwb ) ); |
173 | 203 |
174 gtk_widget_set_events( drawing_area, GDK_EXPOSURE_MASK | | 204 gtk_widget_set_events( drawing_area, GDK_EXPOSURE_MASK | |
175 GDK_LEAVE_NOTIFY_MASK | | 205 GDK_LEAVE_NOTIFY_MASK | |
176 GDK_BUTTON_PRESS_MASK | | 206 GDK_BUTTON_PRESS_MASK | |
177 GDK_POINTER_MOTION_MASK | | 207 GDK_POINTER_MOTION_MASK | |
178 GDK_BUTTON_RELEASE_MASK | | 208 GDK_BUTTON_RELEASE_MASK | |
179 GDK_POINTER_MOTION_HINT_MASK ); | 209 GDK_POINTER_MOTION_HINT_MASK ); |
180 | 210 |
181 // Create vertical box to contain the controls | 211 /* Create vertical box to contain the controls */ |
182 vbox_controls = gtk_vbox_new( FALSE, 0 ); | 212 vbox_controls = gtk_vbox_new( FALSE, 0 ); |
183 gtk_container_add( GTK_CONTAINER( hbox_canvas_and_controls ), vbox_controls ); | 213 gtk_container_add( GTK_CONTAINER( hbox_canvas_and_controls ), vbox_controls ); |
184 gtk_widget_show( vbox_controls ); | 214 gtk_widget_show( vbox_controls ); |
185 | 215 |
186 // Add a clear button | 216 /* Add a clear button */ |
187 clear_button = gtk_button_new_with_label( "Clear" ); | 217 clear_button = gtk_button_new_with_label( "Clear" ); |
188 gtk_widget_set_size_request( clear_button, 96 ,32 ); | 218 gtk_widget_set_size_request( clear_button, 96 ,32 ); |
189 gtk_box_pack_start( GTK_BOX( vbox_controls ), clear_button, FALSE, FALSE, 0 ); | 219 gtk_box_pack_start( GTK_BOX( vbox_controls ), clear_button, FALSE, FALSE, 0 ); |
190 gtk_widget_show( clear_button ); | 220 gtk_widget_show( clear_button ); |
191 | 221 |
192 g_signal_connect( G_OBJECT( clear_button ), "clicked", | 222 g_signal_connect( G_OBJECT( clear_button ), "clicked", |
193 G_CALLBACK( gaim_gtk_whiteboard_button_clear_press ), ( gpointer )( gtkwb ) ); | 223 G_CALLBACK( gaim_gtk_whiteboard_button_clear_press ), ( gpointer )( gtkwb ) ); |
194 | 224 |
195 // Add a save button | 225 /* Add a save button */ |
196 save_button = gtk_button_new_with_label( "Save" ); | 226 save_button = gtk_button_new_with_label( "Save" ); |
197 gtk_widget_set_size_request( save_button, 96 ,32 ); | 227 gtk_widget_set_size_request( save_button, 96 ,32 ); |
198 gtk_box_pack_start( GTK_BOX( vbox_controls ), save_button, FALSE, FALSE, 8 ); | 228 gtk_box_pack_start( GTK_BOX( vbox_controls ), save_button, FALSE, FALSE, 8 ); |
199 gtk_widget_show( save_button ); | 229 gtk_widget_show( save_button ); |
200 | 230 |
201 g_signal_connect( G_OBJECT( save_button ), "clicked", | 231 g_signal_connect( G_OBJECT( save_button ), "clicked", |
202 G_CALLBACK( gaim_gtk_whiteboard_button_save_press ), ( gpointer )( gtkwb ) ); | 232 G_CALLBACK( gaim_gtk_whiteboard_button_save_press ), ( gpointer )( gtkwb ) ); |
203 | 233 |
204 // Make all this (window) visible | 234 /* Make all this (window) visible */ |
205 gtk_widget_show( window ); | 235 gtk_widget_show( window ); |
206 | 236 |
207 gaim_gtk_whiteboard_set_canvas_as_icon( gtkwb ); | 237 gaim_gtk_whiteboard_set_canvas_as_icon( gtkwb ); |
208 | 238 |
209 // TODO Specific protocol/whiteboard assignment here? Needs a UI Op? | 239 /* TODO Specific protocol/whiteboard assignment here? Needs a UI Op? */ |
210 // Set default brush size and color | 240 /* Set default brush size and color */ |
211 //ds->brush_size = DOODLE_BRUSH_MEDIUM; | 241 /* |
212 //ds->brush_color = 0; // black | 242 ds->brush_size = DOODLE_BRUSH_MEDIUM; |
213 } | 243 ds->brush_color = 0; |
214 | 244 */ |
215 // ------------------------------------------------------------------------------------------------------ | 245 } |
216 | 246 |
217 void gaim_gtk_whiteboard_destroy( GaimWhiteboard *wb ) | 247 void gaim_gtk_whiteboard_destroy( GaimWhiteboard *wb ) |
218 { | 248 { |
219 //g_print( "gaim_gtk_whiteboard_destroy()\n" ); | |
220 | |
221 GaimGtkWhiteboard *gtkwb = wb->ui_data; | 249 GaimGtkWhiteboard *gtkwb = wb->ui_data; |
222 | 250 |
223 // TODO Ask if user wants to save picture before the session is closed | 251 /* TODO Ask if user wants to save picture before the session is closed */ |
224 | 252 |
225 // Clear graphical memory | 253 /* Clear graphical memory */ |
226 if( gtkwb->pixmap ) | 254 if( gtkwb->pixmap ) |
227 { | 255 { |
228 //g_print( "---gtkwb->pixmap = %p\n", gtkwb->pixmap ); | |
229 g_object_unref( gtkwb->pixmap ); | 256 g_object_unref( gtkwb->pixmap ); |
230 gtkwb->pixmap = NULL; | 257 gtkwb->pixmap = NULL; |
231 } | 258 } |
232 | 259 |
233 if( gtkwb->window ) | 260 if( gtkwb->window ) |
234 { | 261 { |
235 //g_print( "---gtkwb->window = %p\n", gtkwb->window ); | |
236 gtk_widget_destroy( gtkwb->window ); | 262 gtk_widget_destroy( gtkwb->window ); |
237 gtkwb->window = NULL; | 263 gtkwb->window = NULL; |
238 } | 264 } |
239 } | 265 } |
240 | 266 |
241 // ------------------------------------------------------------------------------------------------------ | |
242 | |
243 void gaim_gtk_whiteboard_exit( GtkWidget *widget, gpointer data ) | 267 void gaim_gtk_whiteboard_exit( GtkWidget *widget, gpointer data ) |
244 { | 268 { |
245 //g_print( "gaim_gtk_whiteboard_exit()\n" ); | |
246 | |
247 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 269 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
248 GaimWhiteboard *wb = gtkwb->wb; | 270 GaimWhiteboard *wb = gtkwb->wb; |
249 | 271 |
250 if( gtkwb->window && gtkwb->pixmap ) | 272 if( gtkwb->window && gtkwb->pixmap ) |
251 { | 273 { |
252 LocalShutdownRequest = TRUE; | 274 LocalShutdownRequest = TRUE; |
253 | 275 |
254 //g_print( "---gtkwb->window = %p\n", gtkwb->window ); | |
255 gaim_gtk_whiteboard_destroy( wb ); | 276 gaim_gtk_whiteboard_destroy( wb ); |
256 } | 277 } |
257 else | 278 else |
258 LocalShutdownRequest = FALSE; | 279 LocalShutdownRequest = FALSE; |
259 | 280 |
260 if( gtkwb ) | 281 if( gtkwb ) |
261 { | 282 { |
262 //g_print( "---gtkwb = %p\n", gtkwb ); | |
263 g_free( gtkwb ); | 283 g_free( gtkwb ); |
264 | 284 |
265 gtkwb = NULL; | 285 gtkwb = NULL; |
266 wb->ui_data = NULL; | 286 wb->ui_data = NULL; |
267 } | 287 } |
268 | 288 |
269 // Destroy whiteboard core, if the local user exited the whiteboard window | 289 /* Destroy whiteboard core, if the local user exited the whiteboard window */ |
270 if( wb && LocalShutdownRequest ) | 290 if( wb && LocalShutdownRequest ) |
271 { | 291 { |
272 //g_print( "---wb = %p\n", wb ); | |
273 gaim_whiteboard_destroy( wb ); | 292 gaim_whiteboard_destroy( wb ); |
274 wb = NULL; | 293 wb = NULL; |
275 } | 294 } |
276 } | 295 } |
277 | 296 |
278 // ------------------------------------------------------------------------------------------------------ | |
279 /* | 297 /* |
280 // Whiteboard start button on conversation window (move this code to gtkconv? and use new prpl_info member?) | 298 * Whiteboard start button on conversation window (move this code to gtkconv? |
299 * and use new prpl_info member?) | |
300 */ | |
301 #if 0 | |
281 void gaim_gtkwhiteboard_button_start_press( GtkButton *button, gpointer data ) | 302 void gaim_gtkwhiteboard_button_start_press( GtkButton *button, gpointer data ) |
282 { | 303 { |
283 GaimConversation *conv = data; | 304 GaimConversation *conv = data; |
284 GaimAccount *account = gaim_conversation_get_account( conv ); | 305 GaimAccount *account = gaim_conversation_get_account( conv ); |
285 GaimConnection *gc = gaim_account_get_connection( account ); | 306 GaimConnection *gc = gaim_account_get_connection( account ); |
286 char *to = ( char* )( gaim_conversation_get_name( conv ) ); | 307 char *to = ( char* )( gaim_conversation_get_name( conv ) ); |
287 | 308 |
288 // Only handle this if local client requested Doodle session (else local client would have sent one) | 309 /* Only handle this if local client requested Doodle session (else local |
310 * client would have sent one) | |
311 */ | |
289 GaimWhiteboard *wb = gaim_whiteboard_get( account, to ); | 312 GaimWhiteboard *wb = gaim_whiteboard_get( account, to ); |
290 | 313 |
291 // Write a local message to this conversation showing that | 314 /* Write a local message to this conversation showing that a request for a |
292 // a request for a Doodle session has been made | 315 * Doodle session has been made |
316 */ | |
293 gaim_conv_im_write( GAIM_CONV_IM( conv ), "", _("Sent Doodle request."), | 317 gaim_conv_im_write( GAIM_CONV_IM( conv ), "", _("Sent Doodle request."), |
294 GAIM_MESSAGE_NICK | GAIM_MESSAGE_RECV, time( NULL ) ); | 318 GAIM_MESSAGE_NICK | GAIM_MESSAGE_RECV, time( NULL ) ); |
295 | 319 |
296 yahoo_doodle_command_send_request( gc, to ); | 320 yahoo_doodle_command_send_request( gc, to ); |
297 yahoo_doodle_command_send_ready( gc, to ); | 321 yahoo_doodle_command_send_ready( gc, to ); |
298 | 322 |
299 // Insert this 'session' in the list. At this point, it's only a requested session. | 323 /* Insert this 'session' in the list. At this point, it's only a requested |
324 * session. | |
325 */ | |
300 wb = gaim_whiteboard_create( account, to, DOODLE_STATE_REQUESTING ); | 326 wb = gaim_whiteboard_create( account, to, DOODLE_STATE_REQUESTING ); |
301 } | 327 } |
302 */ | 328 #endif |
303 // ------------------------------------------------------------------------------------------------------ | |
304 | 329 |
305 gboolean gaim_gtk_whiteboard_configure_event( GtkWidget *widget, GdkEventConfigure *event, gpointer data ) | 330 gboolean gaim_gtk_whiteboard_configure_event( GtkWidget *widget, GdkEventConfigure *event, gpointer data ) |
306 { | 331 { |
307 //g_print( "gaim_gtk_whiteboard_configure_event | %s\n", ds->who ); | |
308 | |
309 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 332 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
310 | 333 |
311 GdkPixmap *pixmap = gtkwb->pixmap; | 334 GdkPixmap *pixmap = gtkwb->pixmap; |
312 | 335 |
313 if( pixmap ) | 336 if( pixmap ) |
314 g_object_unref( pixmap ); | 337 g_object_unref( pixmap ); |
315 | 338 |
316 pixmap = gdk_pixmap_new( widget->window, | 339 pixmap = gdk_pixmap_new( widget->window, |
317 widget->allocation.width, | 340 widget->allocation.width, |
318 widget->allocation.height, | 341 widget->allocation.height, |
319 -1 ); | 342 -1 ); |
320 | 343 |
321 gtkwb->pixmap = pixmap; | 344 gtkwb->pixmap = pixmap; |
322 | 345 |
323 gdk_draw_rectangle( pixmap, | 346 gdk_draw_rectangle( pixmap, |
324 widget->style->white_gc, | 347 widget->style->white_gc, |
325 TRUE, | 348 TRUE, |
326 0, 0, | 349 0, 0, |
327 widget->allocation.width, | 350 widget->allocation.width, |
328 widget->allocation.height ); | 351 widget->allocation.height ); |
329 | 352 |
330 return( TRUE ); | 353 return( TRUE ); |
331 } | 354 } |
332 | 355 |
333 // ------------------------------------------------------------------------------------------------------ | |
334 | |
335 gboolean gaim_gtk_whiteboard_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer data ) | 356 gboolean gaim_gtk_whiteboard_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer data ) |
336 { | 357 { |
337 //g_print( "gaim_gtk_whiteboard_expose_event | %s\n", ds->who ); | |
338 | |
339 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 358 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
340 GdkPixmap *pixmap = gtkwb->pixmap; | 359 GdkPixmap *pixmap = gtkwb->pixmap; |
341 | 360 |
342 gdk_draw_drawable( widget->window, | 361 gdk_draw_drawable( widget->window, |
343 widget->style->fg_gc[GTK_WIDGET_STATE( widget )], | 362 widget->style->fg_gc[GTK_WIDGET_STATE( widget )], |
344 pixmap, | 363 pixmap, |
345 event->area.x, event->area.y, | 364 event->area.x, event->area.y, |
346 event->area.x, event->area.y, | 365 event->area.x, event->area.y, |
347 event->area.width, event->area.height ); | 366 event->area.width, event->area.height ); |
348 | 367 |
349 return( FALSE ); | 368 return( FALSE ); |
350 } | 369 } |
351 | 370 |
352 // ------------------------------------------------------------------------------------------------------ | |
353 | |
354 gboolean gaim_gtk_whiteboard_brush_down( GtkWidget *widget, GdkEventButton *event, gpointer data ) | 371 gboolean gaim_gtk_whiteboard_brush_down( GtkWidget *widget, GdkEventButton *event, gpointer data ) |
355 { | 372 { |
356 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 373 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
357 //g_print( "gaim_gtk_whiteboard_brush_down | %s\n", gtkwb->wb->who ); | |
358 GdkPixmap *pixmap = gtkwb->pixmap; | 374 GdkPixmap *pixmap = gtkwb->pixmap; |
359 | 375 |
360 GaimWhiteboard *wb = gtkwb->wb; | 376 GaimWhiteboard *wb = gtkwb->wb; |
361 GList *draw_list = wb->draw_list; | 377 GList *draw_list = wb->draw_list; |
362 | 378 |
363 int *x0 = NULL; | 379 int *x0 = NULL; |
364 int *y0 = NULL; | 380 int *y0 = NULL; |
365 | 381 |
366 if( BrushState != BRUSH_STATE_UP ) | 382 if( BrushState != BRUSH_STATE_UP ) |
367 { | 383 { |
368 // Potential double-click DOWN to DOWN? | 384 /* Potential double-click DOWN to DOWN? */ |
369 | |
370 g_print( "***Bad brush state transition %d to DOWN\n", BrushState ); | |
371 | |
372 BrushState = BRUSH_STATE_DOWN; | 385 BrushState = BRUSH_STATE_DOWN; |
373 | 386 |
374 //return( FALSE ); | 387 /* return( FALSE ); */ |
375 } | 388 } |
376 | 389 |
377 BrushState = BRUSH_STATE_DOWN; | 390 BrushState = BRUSH_STATE_DOWN; |
378 | 391 |
379 if( event->button == 1 && pixmap != NULL ) | 392 if( event->button == 1 && pixmap != NULL ) |
380 { | 393 { |
381 // Check if draw_list has contents; if so, clear it | 394 /* Check if draw_list has contents; if so, clear it */ |
382 if( draw_list ) | 395 if( draw_list ) |
383 draw_list = gaim_whiteboard_draw_list_destroy( draw_list ); | 396 draw_list = gaim_whiteboard_draw_list_destroy( draw_list ); |
384 | 397 |
385 x0 = g_new0( int, 1 ); | 398 x0 = g_new0( int, 1 ); |
386 y0 = g_new0( int, 1 ); | 399 y0 = g_new0( int, 1 ); |
387 | 400 |
388 *x0 = event->x; | 401 *x0 = event->x; |
389 *y0 = event->y; | 402 *y0 = event->y; |
390 | 403 |
391 // Set tracking variables | 404 /* Set tracking variables */ |
392 LastX = *x0; | 405 LastX = *x0; |
393 LastY = *y0; | 406 LastY = *y0; |
394 | 407 |
395 MotionCount = 0; | 408 MotionCount = 0; |
396 | 409 |
397 draw_list = g_list_append( draw_list, ( gpointer )( x0 ) ); | 410 draw_list = g_list_append( draw_list, ( gpointer )( x0 ) ); |
398 draw_list = g_list_append( draw_list, ( gpointer )( y0 ) ); | 411 draw_list = g_list_append( draw_list, ( gpointer )( y0 ) ); |
399 | 412 |
400 gaim_gtk_whiteboard_draw_brush_point( gtkwb->wb, | 413 gaim_gtk_whiteboard_draw_brush_point( gtkwb->wb, |
401 event->x, event->y, | 414 event->x, event->y, |
402 0,5 );//gtkwb->brush_color, gtkwb->brush_size ); NOTE temp const prot uiop | 415 0,5 ); |
403 } | 416 /* gtkwb->brush_color, gtkwb->brush_size ); NOTE temp const prot uiop */ |
404 | 417 } |
418 | |
405 wb->draw_list = draw_list; | 419 wb->draw_list = draw_list; |
406 | 420 |
407 return( TRUE ); | 421 return( TRUE ); |
408 } | 422 } |
409 | 423 |
410 // ------------------------------------------------------------------------------------------------------ | |
411 | |
412 gboolean gaim_gtk_whiteboard_brush_motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ) | 424 gboolean gaim_gtk_whiteboard_brush_motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ) |
413 { | 425 { |
414 int x; | 426 int x; |
415 int y; | 427 int y; |
416 int *dx; | 428 int *dx; |
417 int *dy; | 429 int *dy; |
418 | 430 |
419 GdkModifierType state; | 431 GdkModifierType state; |
420 | 432 |
421 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 433 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
422 //g_print( "gaim_gtk_whiteboard_brush_motion | %s\n", gtkwb->wb->who ); | |
423 GdkPixmap *pixmap = gtkwb->pixmap; | 434 GdkPixmap *pixmap = gtkwb->pixmap; |
424 | 435 |
425 GaimWhiteboard *wb = gtkwb->wb; | 436 GaimWhiteboard *wb = gtkwb->wb; |
426 GList *draw_list = wb->draw_list; | 437 GList *draw_list = wb->draw_list; |
427 | 438 |
428 if( event->is_hint ) | 439 if( event->is_hint ) |
429 gdk_window_get_pointer( event->window, &x, &y, &state ); | 440 gdk_window_get_pointer( event->window, &x, &y, &state ); |
431 { | 442 { |
432 x = event->x; | 443 x = event->x; |
433 y = event->y; | 444 y = event->y; |
434 state = event->state; | 445 state = event->state; |
435 } | 446 } |
436 | 447 |
437 if( state & GDK_BUTTON1_MASK && pixmap != NULL ) | 448 if( state & GDK_BUTTON1_MASK && pixmap != NULL ) |
438 { | 449 { |
439 if( ( BrushState != BRUSH_STATE_DOWN ) && ( BrushState != BRUSH_STATE_MOTION ) ) | 450 if( ( BrushState != BRUSH_STATE_DOWN ) && ( BrushState != BRUSH_STATE_MOTION ) ) |
440 { | 451 { |
441 g_print( "***Bad brush state transition %d to MOTION\n", BrushState ); | 452 g_print( "***Bad brush state transition %d to MOTION\n", BrushState ); |
442 | 453 |
443 BrushState = BRUSH_STATE_MOTION; | 454 BrushState = BRUSH_STATE_MOTION; |
444 | 455 |
445 return( FALSE ); | 456 return( FALSE ); |
446 } | 457 } |
447 BrushState = BRUSH_STATE_MOTION; | 458 BrushState = BRUSH_STATE_MOTION; |
448 | 459 |
449 dx = g_new0( int, 1 ); | 460 dx = g_new0( int, 1 ); |
450 dy = g_new0( int, 1 ); | 461 dy = g_new0( int, 1 ); |
451 | 462 |
452 *dx = x - LastX; | 463 *dx = x - LastX; |
453 *dy = y - LastY; | 464 *dy = y - LastY; |
454 | 465 |
455 MotionCount++; | 466 MotionCount++; |
456 | 467 |
457 // NOTE 100 is a temporary constant for how many deltas/motions in a stroke (needs UI Ops?) | 468 /* NOTE 100 is a temporary constant for how many deltas/motions in a |
469 * stroke (needs UI Ops?) | |
470 */ | |
458 if( MotionCount == 100 ) | 471 if( MotionCount == 100 ) |
459 { | 472 { |
460 int *x0 = g_new0( int, 1 ); | 473 int *x0 = g_new0( int, 1 ); |
461 int *y0 = g_new0( int, 1 ); | 474 int *y0 = g_new0( int, 1 ); |
462 | 475 |
463 draw_list = g_list_append( draw_list, ( gpointer )( dx ) ); | 476 draw_list = g_list_append( draw_list, ( gpointer )( dx ) ); |
464 draw_list = g_list_append( draw_list, ( gpointer )( dy ) ); | 477 draw_list = g_list_append( draw_list, ( gpointer )( dy ) ); |
465 | 478 |
466 // Send draw list to prpl draw_list handler | 479 /* Send draw list to prpl draw_list handler */ |
467 if( gtkwb->wb->prpl_ops && gtkwb->wb->prpl_ops->send_draw_list ) | 480 if( gtkwb->wb->prpl_ops && gtkwb->wb->prpl_ops->send_draw_list ) |
468 gtkwb->wb->prpl_ops->send_draw_list( gtkwb->wb, draw_list ); | 481 gtkwb->wb->prpl_ops->send_draw_list( gtkwb->wb, draw_list ); |
469 | 482 |
470 // The brush stroke is finished, clear the list for another one | 483 /* The brush stroke is finished, clear the list for another one */ |
471 if( draw_list ) | 484 if( draw_list ) |
472 draw_list = gaim_whiteboard_draw_list_destroy( draw_list ); | 485 draw_list = gaim_whiteboard_draw_list_destroy( draw_list ); |
473 | 486 |
474 *x0 = LastX; | 487 *x0 = LastX; |
475 *y0 = LastY; | 488 *y0 = LastY; |
476 | 489 |
477 // Reset motion tracking | 490 /* Reset motion tracking */ |
478 MotionCount = 0; | 491 MotionCount = 0; |
479 | 492 |
480 draw_list = g_list_append( draw_list, ( gpointer )( x0 ) ); | 493 draw_list = g_list_append( draw_list, ( gpointer )( x0 ) ); |
481 draw_list = g_list_append( draw_list, ( gpointer )( y0 ) ); | 494 draw_list = g_list_append( draw_list, ( gpointer )( y0 ) ); |
482 | 495 |
483 dx = g_new0( int, 1 ); | 496 dx = g_new0( int, 1 ); |
484 dy = g_new0( int, 1 ); | 497 dy = g_new0( int, 1 ); |
485 | 498 |
486 *dx = x - LastX; | 499 *dx = x - LastX; |
487 *dy = y - LastY; | 500 *dy = y - LastY; |
488 } | 501 } |
489 | 502 |
490 draw_list = g_list_append( draw_list, ( gpointer )( dx ) ); | 503 draw_list = g_list_append( draw_list, ( gpointer )( dx ) ); |
491 draw_list = g_list_append( draw_list, ( gpointer )( dy ) ); | 504 draw_list = g_list_append( draw_list, ( gpointer )( dy ) ); |
492 | 505 |
493 gaim_gtk_whiteboard_draw_brush_line( gtkwb->wb, | 506 gaim_gtk_whiteboard_draw_brush_line( gtkwb->wb, |
494 LastX, LastY, | 507 LastX, LastY, |
495 x, y, | 508 x, y, |
496 0, 5 );//gtkwb->brush_color, gtkwb->brush_size ); temp const proto ui ops? | 509 0, 5 ); |
497 | 510 /*gtkwb->brush_color, gtkwb->brush_size ); temp const proto ui ops? */ |
498 // Set tracking variables | 511 |
512 /* Set tracking variables */ | |
499 LastX = x; | 513 LastX = x; |
500 LastY = y; | 514 LastY = y; |
501 } | 515 } |
502 | 516 |
503 wb->draw_list = draw_list; | 517 wb->draw_list = draw_list; |
504 | 518 |
505 return( TRUE ); | 519 return( TRUE ); |
506 } | 520 } |
507 | 521 |
508 // ------------------------------------------------------------------------------------------------------ | |
509 | |
510 gboolean gaim_gtk_whiteboard_brush_up( GtkWidget *widget, GdkEventButton *event, gpointer data ) | 522 gboolean gaim_gtk_whiteboard_brush_up( GtkWidget *widget, GdkEventButton *event, gpointer data ) |
511 { | 523 { |
512 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 524 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
513 //g_print( "gaim_gtk_whiteboard_brush_up | %s\n", gtkwb->wb->who ); | |
514 GdkPixmap *pixmap = gtkwb->pixmap; | 525 GdkPixmap *pixmap = gtkwb->pixmap; |
515 | 526 |
516 GaimWhiteboard *wb = gtkwb->wb; | 527 GaimWhiteboard *wb = gtkwb->wb; |
517 GList *draw_list = wb->draw_list; | 528 GList *draw_list = wb->draw_list; |
518 | 529 |
519 if( ( BrushState != BRUSH_STATE_DOWN ) && ( BrushState != BRUSH_STATE_MOTION ) ) | 530 if( ( BrushState != BRUSH_STATE_DOWN ) && ( BrushState != BRUSH_STATE_MOTION ) ) |
520 { | 531 { |
521 g_print( "***Bad brush state transition %d to UP\n", BrushState ); | 532 g_print( "***Bad brush state transition %d to UP\n", BrushState ); |
522 | 533 |
523 BrushState = BRUSH_STATE_UP; | 534 BrushState = BRUSH_STATE_UP; |
524 | 535 |
525 return( FALSE ); | 536 return( FALSE ); |
526 } | 537 } |
527 BrushState = BRUSH_STATE_UP; | 538 BrushState = BRUSH_STATE_UP; |
528 | 539 |
529 if( event->button == 1 && pixmap != NULL ) | 540 if( event->button == 1 && pixmap != NULL ) |
530 { | 541 { |
531 // If the brush was never moved, express two sets of two deltas | 542 /* If the brush was never moved, express two sets of two deltas That's a |
532 // That's a 'point,' but not for Yahoo! | 543 * 'point,' but not for Yahoo! |
533 //if( ( event->x == LastX ) && ( event->y == LastY ) ) | 544 */ |
545 /* if( ( event->x == LastX ) && ( event->y == LastY ) ) */ | |
534 if( MotionCount == 0 ) | 546 if( MotionCount == 0 ) |
535 { | 547 { |
536 int index; | 548 int index; |
537 | 549 |
538 for( index = 0; index < 2; index++ ) // NOTE Yahoo Doodle specific! | 550 for( index = 0; index < 2; index++ )/* NOTE Yahoo Doodle specific! */ |
539 { | 551 { |
540 int *x0 = NULL; | 552 int *x0 = NULL; |
541 int *y0 = NULL; | 553 int *y0 = NULL; |
542 | 554 |
543 x0 = g_new0( int, 1 ); | 555 x0 = g_new0( int, 1 ); |
544 y0 = g_new0( int, 1 ); | 556 y0 = g_new0( int, 1 ); |
545 | 557 |
546 draw_list = g_list_append( draw_list, ( gpointer )( x0 ) ); | 558 draw_list = g_list_append( draw_list, ( gpointer )( x0 ) ); |
547 draw_list = g_list_append( draw_list, ( gpointer )( y0 ) ); | 559 draw_list = g_list_append( draw_list, ( gpointer )( y0 ) ); |
548 } | 560 } |
549 } | 561 } |
550 //else | 562 /* |
551 // MotionCount = 0; | 563 else |
552 | 564 MotionCount = 0; |
553 // Send draw list to prpl draw_list handler | 565 */ |
566 | |
567 /* Send draw list to prpl draw_list handler */ | |
554 if( gtkwb->wb->prpl_ops && gtkwb->wb->prpl_ops->send_draw_list ) | 568 if( gtkwb->wb->prpl_ops && gtkwb->wb->prpl_ops->send_draw_list ) |
555 gtkwb->wb->prpl_ops->send_draw_list( gtkwb->wb, draw_list ); | 569 gtkwb->wb->prpl_ops->send_draw_list( gtkwb->wb, draw_list ); |
556 | 570 |
557 gaim_gtk_whiteboard_set_canvas_as_icon( gtkwb ); | 571 gaim_gtk_whiteboard_set_canvas_as_icon( gtkwb ); |
558 | 572 |
559 // The brush stroke is finished, clear the list for another one | 573 /* The brush stroke is finished, clear the list for another one */ |
560 if( draw_list ) | 574 if( draw_list ) |
561 draw_list = gaim_whiteboard_draw_list_destroy( draw_list ); | 575 draw_list = gaim_whiteboard_draw_list_destroy( draw_list ); |
562 | 576 |
563 wb->draw_list = draw_list; | 577 wb->draw_list = draw_list; |
564 } | 578 } |
565 | 579 |
566 return( TRUE ); | 580 return( TRUE ); |
567 } | 581 } |
568 | 582 |
569 // ------------------------------------------------------------------------------------------------------ | 583 /* void gaim_gtk_whiteboard_draw_brush_point( GtkWidget *widget, GaimGtkWhiteboard *gtkwb, |
570 | 584 int x, int y, int color, int size ) |
571 // void gaim_gtk_whiteboard_draw_brush_point( GtkWidget *widget, GaimGtkWhiteboard *gtkwb, | 585 */ |
572 // int x, int y, int color, int size ) | |
573 void gaim_gtk_whiteboard_draw_brush_point( GaimWhiteboard *wb, int x, int y, int color, int size ) | 586 void gaim_gtk_whiteboard_draw_brush_point( GaimWhiteboard *wb, int x, int y, int color, int size ) |
574 { | 587 { |
575 //g_print( "goodle_doodle_session_draw_brush | %s\n", ds->who ); | |
576 | |
577 GaimGtkWhiteboard *gtkwb = wb->ui_data; | 588 GaimGtkWhiteboard *gtkwb = wb->ui_data; |
578 GtkWidget *widget = gtkwb->drawing_area; | 589 GtkWidget *widget = gtkwb->drawing_area; |
579 GdkPixmap *pixmap = gtkwb->pixmap; | 590 GdkPixmap *pixmap = gtkwb->pixmap; |
580 | 591 |
581 GdkRectangle update_rect; | 592 GdkRectangle update_rect; |
582 | 593 |
583 GdkGC *gfx_con = gdk_gc_new( pixmap ); | 594 GdkGC *gfx_con = gdk_gc_new( pixmap ); |
584 GdkColor col; | 595 GdkColor col; |
585 | 596 |
586 update_rect.x = x - size / 2; | 597 update_rect.x = x - size / 2; |
587 update_rect.y = y - size / 2; | 598 update_rect.y = y - size / 2; |
588 update_rect.width = size; | 599 update_rect.width = size; |
589 update_rect.height = size; | 600 update_rect.height = size; |
590 | 601 |
591 // Interpret and convert color | 602 /* Interpret and convert color */ |
592 gaim_gtk_whiteboard_rgb24_to_rgb48( color, &col ); | 603 gaim_gtk_whiteboard_rgb24_to_rgb48( color, &col ); |
593 | 604 |
594 gdk_gc_set_rgb_fg_color( gfx_con, &col ); | 605 gdk_gc_set_rgb_fg_color( gfx_con, &col ); |
595 //gdk_gc_set_rgb_bg_color( gfx_con, &col ); | 606 /* gdk_gc_set_rgb_bg_color( gfx_con, &col ); */ |
596 | 607 |
597 // NOTE 5 is a size constant for now... this is because of how poorly the gdk_draw_arc draws small circles | 608 /* NOTE 5 is a size constant for now... this is because of how poorly the |
609 * gdk_draw_arc draws small circles | |
610 */ | |
598 if( size < 5 ) | 611 if( size < 5 ) |
599 { | 612 { |
600 // Draw a rectangle/square | 613 /* Draw a rectangle/square */ |
601 gdk_draw_rectangle( pixmap, | 614 gdk_draw_rectangle( pixmap, |
602 gfx_con, | 615 gfx_con, |
603 TRUE, | 616 TRUE, |
604 update_rect.x, update_rect.y, | 617 update_rect.x, update_rect.y, |
605 update_rect.width, update_rect.height ); | 618 update_rect.width, update_rect.height ); |
606 } | 619 } |
607 else | 620 else |
608 { | 621 { |
609 // Draw a circle | 622 /* Draw a circle */ |
610 gdk_draw_arc( pixmap, | 623 gdk_draw_arc( pixmap, |
611 gfx_con, | 624 gfx_con, |
612 TRUE, | 625 TRUE, |
613 update_rect.x, update_rect.y, | 626 update_rect.x, update_rect.y, |
614 update_rect.width, update_rect.height, | 627 update_rect.width, update_rect.height, |
615 0, FULL_CIRCLE_DEGREES ); | 628 0, FULL_CIRCLE_DEGREES ); |
616 } | 629 } |
617 | 630 |
618 gtk_widget_queue_draw_area( widget, | 631 gtk_widget_queue_draw_area( widget, |
619 update_rect.x, update_rect.y, | 632 update_rect.x, update_rect.y, |
620 update_rect.width, update_rect.height ); | 633 update_rect.width, update_rect.height ); |
621 | 634 |
622 gdk_gc_unref( gfx_con ); | 635 gdk_gc_unref( gfx_con ); |
623 } | 636 } |
624 | 637 |
625 // ------------------------------------------------------------------------------------------------------ | 638 /* Uses Bresenham's algorithm (as provided by Wikipedia) */ |
626 // Uses Bresenham's algorithm (as provided by Wikipedia) | 639 /* void gaim_gtk_whiteboard_draw_brush_line( GtkWidget *widget, GaimGtkWhiteboard *gtkwb, |
627 // void gaim_gtk_whiteboard_draw_brush_line( GtkWidget *widget, GaimGtkWhiteboard *gtkwb, | 640 int x0, int y0, int x1, int y1, int color, int size ) |
628 // int x0, int y0, int x1, int y1, int color, int size ) | 641 */ |
629 void gaim_gtk_whiteboard_draw_brush_line( GaimWhiteboard *wb, int x0, int y0, int x1, int y1, int color, int size ) | 642 void gaim_gtk_whiteboard_draw_brush_line( GaimWhiteboard *wb, int x0, int y0, int x1, int y1, int color, int size ) |
630 { | 643 { |
631 int temp; | 644 int temp; |
632 | 645 |
633 int xstep; | 646 int xstep; |
634 int ystep; | 647 int ystep; |
635 | 648 |
636 int dx; | 649 int dx; |
637 int dy; | 650 int dy; |
638 | 651 |
639 int error; | 652 int error; |
640 int derror; | 653 int derror; |
641 | 654 |
642 int x; | 655 int x; |
643 int y; | 656 int y; |
644 | 657 |
645 gboolean steep = abs( y1 - y0 ) > abs( x1 - x0 ); | 658 gboolean steep = abs( y1 - y0 ) > abs( x1 - x0 ); |
646 | 659 |
647 if( steep ) | 660 if( steep ) |
648 { | 661 { |
649 temp = x0; x0 = y0; y0 = temp; | 662 temp = x0; x0 = y0; y0 = temp; |
650 temp = x1; x1 = y1; y1 = temp; | 663 temp = x1; x1 = y1; y1 = temp; |
651 } | 664 } |
652 | 665 |
653 dx = abs( x1 - x0 ); | 666 dx = abs( x1 - x0 ); |
654 dy = abs( y1 - y0 ); | 667 dy = abs( y1 - y0 ); |
655 | 668 |
656 error = 0; | 669 error = 0; |
657 derror = dy; | 670 derror = dy; |
658 | 671 |
659 x = x0; | 672 x = x0; |
660 y = y0; | 673 y = y0; |
661 | 674 |
662 if( x0 < x1 ) | 675 if( x0 < x1 ) |
663 xstep = 1; | 676 xstep = 1; |
664 else | 677 else |
665 xstep = -1; | 678 xstep = -1; |
666 | 679 |
667 if( y0 < y1 ) | 680 if( y0 < y1 ) |
668 ystep = 1; | 681 ystep = 1; |
669 else | 682 else |
670 ystep = -1; | 683 ystep = -1; |
671 | 684 |
672 if( steep ) | 685 if( steep ) |
673 gaim_gtk_whiteboard_draw_brush_point( wb, y, x, color, size ); | 686 gaim_gtk_whiteboard_draw_brush_point( wb, y, x, color, size ); |
674 else | 687 else |
675 gaim_gtk_whiteboard_draw_brush_point( wb, x, y, color, size ); | 688 gaim_gtk_whiteboard_draw_brush_point( wb, x, y, color, size ); |
676 | 689 |
677 while( x != x1 ) | 690 while( x != x1 ) |
678 { | 691 { |
679 x = x + xstep; | 692 x = x + xstep; |
680 error = error + derror; | 693 error = error + derror; |
681 | 694 |
682 if( ( error * 2 ) >= dx ) | 695 if( ( error * 2 ) >= dx ) |
683 { | 696 { |
684 y = y + ystep; | 697 y = y + ystep; |
685 error = error - dx; | 698 error = error - dx; |
686 } | 699 } |
687 | 700 |
688 if( steep ) | 701 if( steep ) |
689 gaim_gtk_whiteboard_draw_brush_point( wb, y, x, color, size ); | 702 gaim_gtk_whiteboard_draw_brush_point( wb, y, x, color, size ); |
690 else | 703 else |
691 gaim_gtk_whiteboard_draw_brush_point( wb, x, y, color, size ); | 704 gaim_gtk_whiteboard_draw_brush_point( wb, x, y, color, size ); |
692 } | 705 } |
693 } | 706 } |
694 | 707 |
695 // ------------------------------------------------------------------------------------------------------ | |
696 | |
697 void gaim_gtk_whiteboard_set_dimensions( GaimWhiteboard *wb, int width, int height ) | 708 void gaim_gtk_whiteboard_set_dimensions( GaimWhiteboard *wb, int width, int height ) |
698 { | 709 { |
699 GaimGtkWhiteboard *gtkwb = wb->ui_data; | 710 GaimGtkWhiteboard *gtkwb = wb->ui_data; |
700 | 711 |
701 gtkwb->width = width; | 712 gtkwb->width = width; |
702 gtkwb->height = height; | 713 gtkwb->height = height; |
703 } | 714 } |
704 | |
705 // ------------------------------------------------------------------------------------------------------ | |
706 | 715 |
707 void gaim_gtk_whiteboard_clear( GaimWhiteboard *wb ) | 716 void gaim_gtk_whiteboard_clear( GaimWhiteboard *wb ) |
708 { | 717 { |
709 GaimGtkWhiteboard *gtkwb = wb->ui_data; | 718 GaimGtkWhiteboard *gtkwb = wb->ui_data; |
710 GdkPixmap *pixmap = gtkwb->pixmap; | 719 GdkPixmap *pixmap = gtkwb->pixmap; |
711 GtkWidget *drawing_area = gtkwb->drawing_area; | 720 GtkWidget *drawing_area = gtkwb->drawing_area; |
712 | 721 |
713 gdk_draw_rectangle( pixmap, | 722 gdk_draw_rectangle( pixmap, |
714 drawing_area->style->white_gc, | 723 drawing_area->style->white_gc, |
715 TRUE, | 724 TRUE, |
716 0, 0, | 725 0, 0, |
717 drawing_area->allocation.width, drawing_area->allocation.height ); | 726 drawing_area->allocation.width, drawing_area->allocation.height ); |
718 | 727 |
719 gtk_widget_queue_draw_area( drawing_area, | 728 gtk_widget_queue_draw_area( drawing_area, |
720 0, 0, | 729 0, 0, |
721 drawing_area->allocation.width, drawing_area->allocation.height ); | 730 drawing_area->allocation.width, drawing_area->allocation.height ); |
722 } | 731 } |
723 | 732 |
724 // ------------------------------------------------------------------------------------------------------ | |
725 | |
726 void gaim_gtk_whiteboard_button_clear_press( GtkWidget *widget, gpointer data ) | 733 void gaim_gtk_whiteboard_button_clear_press( GtkWidget *widget, gpointer data ) |
727 { | 734 { |
728 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 735 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
729 | 736 |
730 gaim_gtk_whiteboard_clear( gtkwb->wb ); | 737 gaim_gtk_whiteboard_clear( gtkwb->wb ); |
731 | 738 |
732 gaim_gtk_whiteboard_set_canvas_as_icon( gtkwb ); | 739 gaim_gtk_whiteboard_set_canvas_as_icon( gtkwb ); |
733 | 740 |
734 // Do protocol specific clearing procedures | 741 /* Do protocol specific clearing procedures */ |
735 if( gtkwb->wb->prpl_ops && gtkwb->wb->prpl_ops->clear ) | 742 if( gtkwb->wb->prpl_ops && gtkwb->wb->prpl_ops->clear ) |
736 gtkwb->wb->prpl_ops->clear( gtkwb->wb ); | 743 gtkwb->wb->prpl_ops->clear( gtkwb->wb ); |
737 } | 744 } |
738 | 745 |
739 // ------------------------------------------------------------------------------------------------------ | |
740 | |
741 void gaim_gtk_whiteboard_button_save_press( GtkWidget *widget, gpointer data ) | 746 void gaim_gtk_whiteboard_button_save_press( GtkWidget *widget, gpointer data ) |
742 { | 747 { |
743 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); | 748 GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data ); |
744 GdkPixbuf *pixbuf; | 749 GdkPixbuf *pixbuf; |
745 | 750 |
746 GtkWidget *dialog; | 751 GtkWidget *dialog; |
747 | 752 |
748 int result; | 753 int result; |
749 | 754 |
750 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | 755 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
751 dialog = gtk_file_chooser_dialog_new ("Save File", | 756 dialog = gtk_file_chooser_dialog_new ("Save File", |
752 GTK_WINDOW(gtkwb->window), | 757 GTK_WINDOW(gtkwb->window), |
753 GTK_FILE_CHOOSER_ACTION_SAVE, | 758 GTK_FILE_CHOOSER_ACTION_SAVE, |
754 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 759 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
755 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | 760 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
756 NULL ); | 761 NULL ); |
757 | 762 |
758 //gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER( dialog ), (gboolean)(TRUE) ); | 763 /* gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER( dialog ), (gboolean)(TRUE) ); */ |
759 | 764 |
760 // if( user_edited_a_new_document ) | 765 /* if( user_edited_a_new_document ) */ |
761 { | 766 { |
762 // gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), default_folder_for_saving ); | 767 /* gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), default_folder_for_saving ); */ |
763 gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER( dialog ), "whiteboard.jpg" ); | 768 gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER( dialog ), "whiteboard.jpg" ); |
764 } | 769 } |
765 // else | 770 /* |
766 // gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document); | 771 else |
772 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document); | |
773 */ | |
767 #else | 774 #else |
768 dialog = gtk_file_selection_new("Save File"); | 775 dialog = gtk_file_selection_new("Save File"); |
769 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), "whiteboard.jpg"); | 776 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), "whiteboard.jpg"); |
770 #endif | 777 #endif |
771 result = gtk_dialog_run( GTK_DIALOG( dialog ) ); | 778 result = gtk_dialog_run( GTK_DIALOG( dialog ) ); |
772 | 779 |
773 if( result == GTK_RESPONSE_ACCEPT ) | 780 if( result == GTK_RESPONSE_ACCEPT ) |
774 { | 781 { |
775 char *filename; | 782 char *filename; |
776 | 783 |
777 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | 784 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
778 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER( dialog ) ); | 785 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER( dialog ) ); |
779 #else | 786 #else |
780 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog))); | 787 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog))); |
781 #endif | 788 #endif |
782 gtk_widget_destroy( dialog ); | 789 gtk_widget_destroy( dialog ); |
783 | 790 |
784 // Makes an icon from the whiteboard's canvas 'image' | 791 /* Makes an icon from the whiteboard's canvas 'image' */ |
785 pixbuf = gdk_pixbuf_get_from_drawable( NULL, | 792 pixbuf = gdk_pixbuf_get_from_drawable( NULL, |
786 ( GdkDrawable* )( gtkwb->pixmap ), | 793 ( GdkDrawable* )( gtkwb->pixmap ), |
787 gdk_drawable_get_colormap( gtkwb->pixmap ), | 794 gdk_drawable_get_colormap( gtkwb->pixmap ), |
788 0, 0, | 795 0, 0, |
789 0, 0, | 796 0, 0, |
790 gtkwb->width, gtkwb->height ); | 797 gtkwb->width, gtkwb->height ); |
791 | 798 |
792 if( gdk_pixbuf_save( pixbuf, | 799 if( gdk_pixbuf_save( pixbuf, |
793 filename, | 800 filename, |
794 "jpeg", | 801 "jpeg", |
795 NULL, | 802 NULL, |
796 "quality", | 803 "quality", |
801 g_print( "File not Saved... Error\n" ); | 808 g_print( "File not Saved... Error\n" ); |
802 g_free(filename); | 809 g_free(filename); |
803 } | 810 } |
804 else | 811 else |
805 if( result == GTK_RESPONSE_CANCEL ) | 812 if( result == GTK_RESPONSE_CANCEL ) |
806 { | 813 { |
807 gtk_widget_destroy( dialog ); | 814 gtk_widget_destroy( dialog ); |
808 | 815 |
809 g_print( "File not Saved... Canceled\n" ); | 816 g_print( "File not Saved... Canceled\n" ); |
810 } | 817 } |
811 } | 818 } |
812 | 819 |
813 // ------------------------------------------------------------------------------------------------------ | |
814 | |
815 void gaim_gtk_whiteboard_set_canvas_as_icon( GaimGtkWhiteboard *gtkwb ) | 820 void gaim_gtk_whiteboard_set_canvas_as_icon( GaimGtkWhiteboard *gtkwb ) |
816 { | 821 { |
817 GdkPixbuf *pixbuf; | 822 GdkPixbuf *pixbuf; |
818 | 823 |
819 // Makes an icon from the whiteboard's canvas 'image' | 824 /* Makes an icon from the whiteboard's canvas 'image' */ |
820 pixbuf = gdk_pixbuf_get_from_drawable( NULL, | 825 pixbuf = gdk_pixbuf_get_from_drawable( NULL, |
821 ( GdkDrawable* )( gtkwb->pixmap ), | 826 ( GdkDrawable* )( gtkwb->pixmap ), |
822 gdk_drawable_get_colormap( gtkwb->pixmap ), | 827 gdk_drawable_get_colormap( gtkwb->pixmap ), |
823 0, 0, | 828 0, 0, |
824 0, 0, | 829 0, 0, |
825 gtkwb->width, gtkwb->height ); | 830 gtkwb->width, gtkwb->height ); |
826 | 831 |
827 gtk_window_set_icon( ( GtkWindow* )( gtkwb->window ), pixbuf ); | 832 gtk_window_set_icon( ( GtkWindow* )( gtkwb->window ), pixbuf ); |
828 } | 833 } |
829 | |
830 // ------------------------------------------------------------------------------------------------------ | |
831 | 834 |
832 void gaim_gtk_whiteboard_rgb24_to_rgb48( int color_rgb, GdkColor *color ) | 835 void gaim_gtk_whiteboard_rgb24_to_rgb48( int color_rgb, GdkColor *color ) |
833 { | 836 { |
834 color->red = ( color_rgb >> 8 ) | 0xFF; | 837 color->red = ( color_rgb >> 8 ) | 0xFF; |
835 color->green = ( color_rgb & 0xFF00 ) | 0xFF; | 838 color->green = ( color_rgb & 0xFF00 ) | 0xFF; |
836 color->blue = ( ( color_rgb & 0xFF ) << 8 ) | 0xFF; | 839 color->blue = ( ( color_rgb & 0xFF ) << 8 ) | 0xFF; |
837 } | 840 } |
838 | 841 |
839 // ------------------------------------------------------------------------------------------------------ | |
840 |