From c0761467951096c6c8b270b4c9ad554194e88a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Poo-Caama=C3=B1o?= Date: Mon, 18 Nov 2013 00:48:13 -0800 Subject: [PATCH] glib-demo: add color selection for new annotations https://bugs.freedesktop.org/show_bug.cgi?id=71727 --- glib/demo/annots.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/glib/demo/annots.c b/glib/demo/annots.c index c5c3643..af70225 100644 --- a/glib/demo/annots.c +++ b/glib/demo/annots.c @@ -67,6 +67,7 @@ typedef struct { ModeType mode; cairo_surface_t *surface; + PopplerColor *annot_color; GdkPoint start; GdkPoint stop; @@ -96,6 +97,11 @@ pgd_annots_free (PgdAnnotsDemo *demo) demo->model = NULL; } + if (demo->annot_color) { + g_free (demo->annot_color); + demo->annot_color = NULL; + } + g_free (demo); } @@ -433,6 +439,23 @@ pgd_annot_view_set_annot_text (GtkWidget *table, } static void +pgd_annot_color_changed (GtkButton *button, + GParamSpec *pspec, + PgdAnnotsDemo *demo) +{ + GdkRGBA color; + +#if GTK_CHECK_VERSION(3,4,0) + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &color); +#else + gtk_color_button_get_rgba (GTK_COLOR_BUTTON (button), &color); +#endif + demo->annot_color->red = CLAMP ((guint) (color.red * 65535), 0, 65535); + demo->annot_color->green = CLAMP ((guint) (color.green * 65535), 0, 65535); + demo->annot_color->blue = CLAMP ((guint) (color.blue * 65535), 0, 65535); +} + +static void pgd_annot_view_set_annot_free_text (GtkWidget *table, PopplerAnnotFreeText *annot, gint *row) @@ -822,12 +845,12 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo) switch (demo->annot_type) { case POPPLER_ANNOT_TEXT: annot = poppler_annot_text_new (demo->doc, &rect); - break; default: g_assert_not_reached (); } + poppler_annot_set_color (annot, demo->annot_color); poppler_page_add_annot (demo->page, annot); pgd_annots_add_annot_to_model (demo, annot, rect); g_object_unref (annot); @@ -958,6 +981,8 @@ pgd_annots_drawing_area_button_release (GtkWidget *area, pgd_annots_finish_add_annot (demo); + demo->start.x = -1; + return TRUE; } @@ -977,6 +1002,7 @@ pgd_annots_create_widget (PopplerDocument *document) GtkTreeViewColumn *column; GtkListStore *model; GtkTreeIter iter; + GdkRGBA rgba; gchar *str; gint n_pages; @@ -1034,6 +1060,7 @@ pgd_annots_create_widget (PopplerDocument *document) SELECTED_TYPE_COLUMN, POPPLER_ANNOT_TEXT, SELECTED_LABEL_COLUMN, "Text", -1); + demo->type_selector = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (model); @@ -1046,6 +1073,27 @@ pgd_annots_create_widget (PopplerDocument *document) gtk_box_pack_end (GTK_BOX (hbox), demo->type_selector, FALSE, FALSE, 0); gtk_widget_show (demo->type_selector); + demo->annot_color = poppler_color_new (); + demo->annot_color->red = 65535; + demo->annot_color->green = 0; + demo->annot_color->blue = 0; + rgba.red = demo->annot_color->red; + rgba.green = demo->annot_color->green; + rgba.blue = demo->annot_color->blue; + rgba.alpha = 1.0; + + button = gtk_color_button_new (); +#if GTK_CHECK_VERSION(3,4,0) + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), &rgba); +#else + gtk_color_button_set_rgba (GTK_COLOR_BUTTON (button), &rgba); +#endif + g_signal_connect (button, "notify::color", + G_CALLBACK (pgd_annot_color_changed), + (gpointer)demo); + gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, TRUE, 0); + gtk_widget_show (button); + gtk_widget_show (hbox); demo->timer_label = gtk_label_new (NULL); -- 1.7.9.5