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