| 278 g_return_if_fail(gtkwb != NULL); |
278 g_return_if_fail(gtkwb != NULL); |
| 279 |
279 |
| 280 /* TODO Ask if user wants to save picture before the session is closed */ |
280 /* TODO Ask if user wants to save picture before the session is closed */ |
| 281 |
281 |
| 282 /* Clear graphical memory */ |
282 /* Clear graphical memory */ |
| 283 if(gtkwb->pixmap) |
283 if(gtkwb->pixbuf) |
| 284 { |
284 { |
| 285 cairo_t *cr = g_object_get_data(G_OBJECT(gtkwb->pixmap), "cairo-context"); |
285 cairo_t *cr = g_object_get_data(G_OBJECT(gtkwb->pixbuf), "cairo-context"); |
| 286 if (cr) |
286 if (cr) |
| 287 cairo_destroy(cr); |
287 cairo_destroy(cr); |
| 288 g_object_unref(gtkwb->pixmap); |
288 g_object_unref(gtkwb->pixbuf); |
| 289 gtkwb->pixmap = NULL; |
289 gtkwb->pixbuf = NULL; |
| 290 } |
290 } |
| 291 |
291 |
| 292 colour_dialog = g_object_get_data(G_OBJECT(gtkwb->window), "colour-dialog"); |
292 colour_dialog = g_object_get_data(G_OBJECT(gtkwb->window), "colour-dialog"); |
| 293 if (colour_dialog) { |
293 if (colour_dialog) { |
| 294 gtk_widget_destroy(colour_dialog); |
294 gtk_widget_destroy(colour_dialog); |
| 354 #endif |
354 #endif |
| 355 |
355 |
| 356 static gboolean pidgin_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) |
356 static gboolean pidgin_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) |
| 357 { |
357 { |
| 358 PidginWhiteboard *gtkwb = (PidginWhiteboard*)data; |
358 PidginWhiteboard *gtkwb = (PidginWhiteboard*)data; |
| 359 GdkPixmap *pixmap = gtkwb->pixmap; |
359 GdkPixbuf *pixbuf = gtkwb->pixbuf; |
| 360 cairo_t *cr; |
360 cairo_t *cr; |
| 361 |
361 GdkWindow *window = gtk_widget_get_window(widget); |
| 362 if (pixmap) { |
362 GtkAllocation allocation; |
| 363 cr = g_object_get_data(G_OBJECT(pixmap), "cairo-context"); |
363 |
| |
364 if (pixbuf) { |
| |
365 cr = g_object_get_data(G_OBJECT(pixbuf), "cairo-context"); |
| 364 if (cr) |
366 if (cr) |
| 365 cairo_destroy(cr); |
367 cairo_destroy(cr); |
| 366 g_object_unref(pixmap); |
368 g_object_unref(pixbuf); |
| 367 } |
369 } |
| 368 |
370 |
| 369 pixmap = gdk_pixmap_new(widget->window, |
371 gtk_widget_get_allocation(widget, &allocation); |
| 370 widget->allocation.width, |
372 |
| 371 widget->allocation.height, |
373 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, |
| 372 -1); |
374 FALSE, |
| 373 gtkwb->pixmap = pixmap; |
375 gdk_visual_get_depth(GDK_VISUAL(window)), |
| 374 |
376 allocation.width, allocation.height); |
| 375 cr = gdk_cairo_create(GDK_DRAWABLE(pixmap)); |
377 |
| 376 g_object_set_data(G_OBJECT(pixmap), "cairo-context", cr); |
378 gtkwb->pixbuf = pixbuf; |
| 377 gdk_cairo_set_source_color(cr, &widget->style->white); |
379 |
| |
380 cr = gdk_cairo_create(GDK_DRAWABLE(pixbuf)); |
| |
381 g_object_set_data(G_OBJECT(pixbuf), "cairo-context", cr); |
| |
382 gdk_cairo_set_source_color(cr, >k_widget_get_style(widget)->white); |
| 378 cairo_rectangle(cr, |
383 cairo_rectangle(cr, |
| 379 0, 0, |
384 0, 0, |
| 380 widget->allocation.width, widget->allocation.height); |
385 allocation.width, allocation.height); |
| 381 cairo_fill(cr); |
386 cairo_fill(cr); |
| 382 |
387 |
| 383 return TRUE; |
388 return TRUE; |
| 384 } |
389 } |
| 385 |
390 |
| 386 static gboolean pidgin_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) |
391 static gboolean pidgin_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) |
| 387 { |
392 { |
| 388 PidginWhiteboard *gtkwb = (PidginWhiteboard*)(data); |
393 PidginWhiteboard *gtkwb = (PidginWhiteboard*)(data); |
| 389 GdkPixmap *pixmap = gtkwb->pixmap; |
394 GdkPixbuf *pixbuf = gtkwb->pixbuf; |
| 390 cairo_t *cr; |
395 cairo_t *cr; |
| 391 |
396 |
| 392 cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
397 cr = gdk_cairo_create(GDK_DRAWABLE(gtk_widget_get_window(widget))); |
| 393 gdk_cairo_set_source_pixmap(cr, pixmap, 0, 0); |
398 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); |
| 394 cairo_rectangle(cr, |
399 cairo_rectangle(cr, |
| 395 event->area.x, event->area.y, |
400 event->area.x, event->area.y, |
| 396 event->area.width, event->area.height); |
401 event->area.width, event->area.height); |
| 397 cairo_fill(cr); |
402 cairo_fill(cr); |
| 398 cairo_destroy(cr); |
403 cairo_destroy(cr); |
| 401 } |
406 } |
| 402 |
407 |
| 403 static gboolean pidgin_whiteboard_brush_down(GtkWidget *widget, GdkEventButton *event, gpointer data) |
408 static gboolean pidgin_whiteboard_brush_down(GtkWidget *widget, GdkEventButton *event, gpointer data) |
| 404 { |
409 { |
| 405 PidginWhiteboard *gtkwb = (PidginWhiteboard*)data; |
410 PidginWhiteboard *gtkwb = (PidginWhiteboard*)data; |
| 406 GdkPixmap *pixmap = gtkwb->pixmap; |
411 GdkPixbuf *pixbuf = gtkwb->pixbuf; |
| 407 |
412 |
| 408 PurpleWhiteboard *wb = gtkwb->wb; |
413 PurpleWhiteboard *wb = gtkwb->wb; |
| 409 GList *draw_list = wb->draw_list; |
414 GList *draw_list = wb->draw_list; |
| 410 |
415 |
| 411 if(BrushState != BRUSH_STATE_UP) |
416 if(BrushState != BRUSH_STATE_UP) |
| 534 } |
539 } |
| 535 |
540 |
| 536 static gboolean pidgin_whiteboard_brush_up(GtkWidget *widget, GdkEventButton *event, gpointer data) |
541 static gboolean pidgin_whiteboard_brush_up(GtkWidget *widget, GdkEventButton *event, gpointer data) |
| 537 { |
542 { |
| 538 PidginWhiteboard *gtkwb = (PidginWhiteboard*)data; |
543 PidginWhiteboard *gtkwb = (PidginWhiteboard*)data; |
| 539 GdkPixmap *pixmap = gtkwb->pixmap; |
544 GdkPixbuf *pixbuf = gtkwb->pixbuf; |
| 540 |
545 |
| 541 PurpleWhiteboard *wb = gtkwb->wb; |
546 PurpleWhiteboard *wb = gtkwb->wb; |
| 542 GList *draw_list = wb->draw_list; |
547 GList *draw_list = wb->draw_list; |
| 543 |
548 |
| 544 if((BrushState != BRUSH_STATE_DOWN) && (BrushState != BRUSH_STATE_MOTION)) |
549 if((BrushState != BRUSH_STATE_DOWN) && (BrushState != BRUSH_STATE_MOTION)) |
| 591 |
596 |
| 592 static void pidgin_whiteboard_draw_brush_point(PurpleWhiteboard *wb, int x, int y, int color, int size) |
597 static void pidgin_whiteboard_draw_brush_point(PurpleWhiteboard *wb, int x, int y, int color, int size) |
| 593 { |
598 { |
| 594 PidginWhiteboard *gtkwb = wb->ui_data; |
599 PidginWhiteboard *gtkwb = wb->ui_data; |
| 595 GtkWidget *widget = gtkwb->drawing_area; |
600 GtkWidget *widget = gtkwb->drawing_area; |
| 596 GdkPixmap *pixmap = gtkwb->pixmap; |
601 GdkPixbuf *pixbuf = gtkwb->pixbuf; |
| 597 |
602 |
| 598 cairo_t *gfx_con = g_object_get_data(G_OBJECT(pixmap), "cairo-context"); |
603 cairo_t *gfx_con = g_object_get_data(G_OBJECT(pixbuf), "cairo-context"); |
| 599 GdkColor col; |
604 GdkColor col; |
| 600 |
605 |
| 601 /* Interpret and convert color */ |
606 /* Interpret and convert color */ |
| 602 pidgin_whiteboard_rgb24_to_rgb48(color, &col); |
607 pidgin_whiteboard_rgb24_to_rgb48(color, &col); |
| 603 |
608 |
| 699 } |
704 } |
| 700 |
705 |
| 701 static void pidgin_whiteboard_clear(PurpleWhiteboard *wb) |
706 static void pidgin_whiteboard_clear(PurpleWhiteboard *wb) |
| 702 { |
707 { |
| 703 PidginWhiteboard *gtkwb = wb->ui_data; |
708 PidginWhiteboard *gtkwb = wb->ui_data; |
| 704 GdkPixmap *pixmap = gtkwb->pixmap; |
709 GdkPixbuf *pixbuf = gtkwb->pixbuf; |
| 705 GtkWidget *drawing_area = gtkwb->drawing_area; |
710 GtkWidget *drawing_area = gtkwb->drawing_area; |
| 706 cairo_t *cr = g_object_get_data(G_OBJECT(pixmap), "cairo-context"); |
711 cairo_t *cr = g_object_get_data(G_OBJECT(pixbuf), "cairo-context"); |
| 707 |
712 GtkAllocation allocation; |
| 708 gdk_cairo_set_source_color(cr, &drawing_area->style->white); |
713 |
| |
714 gtk_widget_get_allocation(drawing_area, &allocation); |
| |
715 |
| |
716 gdk_cairo_set_source_color(cr, >k_widget_get_style(drawing_area)->white); |
| 709 cairo_rectangle(cr, |
717 cairo_rectangle(cr, |
| 710 0, 0, |
718 0, 0, |
| 711 drawing_area->allocation.width, |
719 allocation.width, |
| 712 drawing_area->allocation.height); |
720 allocation.height); |
| 713 cairo_fill(cr); |
721 cairo_fill(cr); |
| 714 |
722 |
| 715 gtk_widget_queue_draw_area(drawing_area, |
723 gtk_widget_queue_draw_area(drawing_area, |
| 716 0, 0, |
724 0, 0, |
| 717 drawing_area->allocation.width, |
725 allocation.width, |
| 718 drawing_area->allocation.height); |
726 allocation.height); |
| 719 } |
727 } |
| 720 |
728 |
| 721 static void pidgin_whiteboard_button_clear_press(GtkWidget *widget, gpointer data) |
729 static void pidgin_whiteboard_button_clear_press(GtkWidget *widget, gpointer data) |
| 722 { |
730 { |
| 723 PidginWhiteboard *gtkwb = (PidginWhiteboard*)(data); |
731 PidginWhiteboard *gtkwb = (PidginWhiteboard*)(data); |
| 779 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
787 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
| 780 |
788 |
| 781 gtk_widget_destroy(dialog); |
789 gtk_widget_destroy(dialog); |
| 782 |
790 |
| 783 /* Makes an icon from the whiteboard's canvas 'image' */ |
791 /* Makes an icon from the whiteboard's canvas 'image' */ |
| |
792 pixbuf = gtkwb->pixbuf; |
| |
793 /* |
| 784 pixbuf = gdk_pixbuf_get_from_drawable(NULL, |
794 pixbuf = gdk_pixbuf_get_from_drawable(NULL, |
| 785 (GdkDrawable*)(gtkwb->pixmap), |
795 (GdkDrawable*)(gtkwb->pixmap), |
| 786 gdk_drawable_get_colormap(gtkwb->pixmap), |
796 gdk_drawable_get_colormap(gtkwb->pixmap), |
| 787 0, 0, |
797 0, 0, |
| 788 0, 0, |
798 0, 0, |
| 789 gtkwb->width, gtkwb->height); |
799 gtkwb->width, gtkwb->height); |
| |
800 */ |
| 790 |
801 |
| 791 if(gdk_pixbuf_save(pixbuf, filename, "jpeg", NULL, "quality", "100", NULL)) |
802 if(gdk_pixbuf_save(pixbuf, filename, "jpeg", NULL, "quality", "100", NULL)) |
| 792 purple_debug_info("gtkwhiteboard", "File Saved...\n"); |
803 purple_debug_info("gtkwhiteboard", "File Saved...\n"); |
| 793 else |
804 else |
| 794 purple_debug_info("gtkwhiteboard", "File not Saved... Error\n"); |
805 purple_debug_info("gtkwhiteboard", "File not Saved... Error\n"); |
| 805 static void pidgin_whiteboard_set_canvas_as_icon(PidginWhiteboard *gtkwb) |
816 static void pidgin_whiteboard_set_canvas_as_icon(PidginWhiteboard *gtkwb) |
| 806 { |
817 { |
| 807 GdkPixbuf *pixbuf; |
818 GdkPixbuf *pixbuf; |
| 808 |
819 |
| 809 /* Makes an icon from the whiteboard's canvas 'image' */ |
820 /* Makes an icon from the whiteboard's canvas 'image' */ |
| |
821 pixbuf = gtkwb->pixbuf; |
| |
822 /* |
| 810 pixbuf = gdk_pixbuf_get_from_drawable(NULL, |
823 pixbuf = gdk_pixbuf_get_from_drawable(NULL, |
| 811 (GdkDrawable*)(gtkwb->pixmap), |
824 (GdkDrawable*)(gtkwb->pixmap), |
| 812 gdk_drawable_get_colormap(gtkwb->pixmap), |
825 gdk_drawable_get_colormap(gtkwb->pixmap), |
| 813 0, 0, |
826 0, 0, |
| 814 0, 0, |
827 0, 0, |
| 815 gtkwb->width, gtkwb->height); |
828 gtkwb->width, gtkwb->height); |
| |
829 */ |
| 816 |
830 |
| 817 gtk_window_set_icon((GtkWindow*)(gtkwb->window), pixbuf); |
831 gtk_window_set_icon((GtkWindow*)(gtkwb->window), pixbuf); |
| 818 } |
832 } |
| 819 |
833 |
| 820 static void pidgin_whiteboard_rgb24_to_rgb48(int color_rgb, GdkColor *color) |
834 static void pidgin_whiteboard_rgb24_to_rgb48(int color_rgb, GdkColor *color) |
| 851 |
865 |
| 852 static void color_select_dialog(GtkWidget *widget, PidginWhiteboard *gtkwb) |
866 static void color_select_dialog(GtkWidget *widget, PidginWhiteboard *gtkwb) |
| 853 { |
867 { |
| 854 GdkColor color; |
868 GdkColor color; |
| 855 GtkColorSelectionDialog *dialog; |
869 GtkColorSelectionDialog *dialog; |
| 856 |
870 GtkWidget *ok_button; |
| |
871 |
| 857 dialog = (GtkColorSelectionDialog *)gtk_color_selection_dialog_new(_("Select color")); |
872 dialog = (GtkColorSelectionDialog *)gtk_color_selection_dialog_new(_("Select color")); |
| 858 g_object_set_data(G_OBJECT(gtkwb->window), "colour-dialog", dialog); |
873 g_object_set_data(G_OBJECT(gtkwb->window), "colour-dialog", dialog); |
| 859 |
874 |
| 860 g_signal_connect(G_OBJECT(dialog->colorsel), "color-changed", |
875 g_signal_connect(G_OBJECT(gtk_color_selection_dialog_get_color_selection(dialog)), |
| |
876 "color-changed", |
| 861 G_CALLBACK(change_color_cb), gtkwb); |
877 G_CALLBACK(change_color_cb), gtkwb); |
| 862 |
878 |
| |
879 /* |
| 863 gtk_widget_destroy(dialog->cancel_button); |
880 gtk_widget_destroy(dialog->cancel_button); |
| 864 gtk_widget_destroy(dialog->help_button); |
881 gtk_widget_destroy(dialog->help_button); |
| 865 |
882 */ |
| 866 g_signal_connect(G_OBJECT(dialog->ok_button), "clicked", |
883 g_object_get(G_OBJECT(dialog), "ok-button", &ok_button, NULL); |
| |
884 |
| |
885 g_signal_connect(G_OBJECT(ok_button), "clicked", |
| 867 G_CALLBACK(color_selection_dialog_destroy), gtkwb); |
886 G_CALLBACK(color_selection_dialog_destroy), gtkwb); |
| 868 |
887 |
| 869 gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(dialog->colorsel), TRUE); |
888 gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(gtk_color_selection_dialog_get_color_selection(dialog)), TRUE); |
| 870 |
889 |
| 871 pidgin_whiteboard_rgb24_to_rgb48(gtkwb->brush_color, &color); |
890 pidgin_whiteboard_rgb24_to_rgb48(gtkwb->brush_color, &color); |
| 872 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(dialog->colorsel), &color); |
891 gtk_color_selection_set_current_color( |
| |
892 GTK_COLOR_SELECTION(gtk_color_selection_dialog_get_color_selection(dialog)), &color); |
| 873 |
893 |
| 874 gtk_widget_show_all(GTK_WIDGET(dialog)); |
894 gtk_widget_show_all(GTK_WIDGET(dialog)); |
| 875 } |
895 } |
| 876 |
896 |