Commit a9ea4743 authored by Enrico Lumetti's avatar Enrico Lumetti

Improve insertion of multiple annotations in sequence

Color and annotation type changes are reflected while inserting
annotations into the document. Color changes when a multi-path
ink annotation is being drawn are applied to all the preceeding
annotations.
The Add/Done mechanics is now slightly useless, but it's still
there because removing a multipath annotation while drawing
causes a crash. This may be changed in future commits.
parent 1e6d4fe0
......@@ -227,6 +227,14 @@ get_annot_color (PopplerAnnot *poppler_annot)
return NULL;
}
static void
set_poppler_color_from_rgba_color (PopplerColor *dest, const GdkRGBA* src)
{
dest->red = CLAMP ((guint) (src->red * 65535), 0, 65535);
dest->green = CLAMP ((guint) (src->green * 65535), 0, 65535);
dest->blue = CLAMP ((guint) (src->blue * 65535), 0, 65535);
}
gchar *
get_markup_date (PopplerAnnotMarkup *poppler_annot)
{
......@@ -374,20 +382,12 @@ static void
pgd_annots_start_add_annot (GtkWidget *button,
PgdAnnotsDemo *demo)
{
GtkTreeModel *model;
GtkTreeIter iter;
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (demo->type_selector), &iter);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (demo->type_selector));
gtk_tree_model_get (model, &iter,
SELECTED_TYPE_COLUMN, &(demo->annot_type),
-1);
demo->mode = MODE_ADD;
pgd_annots_update_cursor (demo, CURSOR_DRAWING);
}
static void pgd_annots_done (PgdAnnotsDemo *demo);
static void pgd_annots_ink_annots_done (PgdAnnotsDemo *demo);
static void
pgd_annots_start_toggle_annot (GtkWidget *button,
......@@ -398,7 +398,8 @@ pgd_annots_start_toggle_annot (GtkWidget *button,
case MODE_NORMAL: {
gtk_button_set_label (GTK_BUTTON (button), "Done");
gtk_widget_hide (demo->timer_label);
gtk_widget_show (demo->single_ink_path_check);
if (demo->annot_type == POPPLER_ANNOT_INK)
gtk_widget_show (demo->single_ink_path_check);
pgd_annots_start_add_annot (button, demo);
}
break;
......@@ -503,6 +504,39 @@ pgd_annot_color_changed (GtkButton *button,
PgdAnnotsDemo *demo)
{
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &demo->annot_color);
/* if the ink annot is multi-path, change the color of all the previous strokes */
if (demo->annot_type == POPPLER_ANNOT_INK && !demo->single_path_per_annot) {
PopplerColor color;
set_poppler_color_from_rgba_color (&color, &(demo->annot_color));
poppler_annot_set_color (demo->active_annot, &color);
pgd_annots_viewer_queue_redraw (demo);
}
}
static void
pgd_annot_type_selection_changed (GtkComboBox *combo,
PgdAnnotsDemo *demo)
{
GtkTreeModel *model;
GtkTreeIter iter;
guint annot_type;
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (demo->type_selector), &iter);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (demo->type_selector));
gtk_tree_model_get (model, &iter,
SELECTED_TYPE_COLUMN, &annot_type,
-1);
if (demo->mode == MODE_ADD && annot_type != demo->annot_type) {
pgd_annots_ink_annots_done (demo);
gtk_widget_set_visible (demo->single_ink_path_check, annot_type == POPPLER_ANNOT_INK);
}
demo->annot_type = annot_type;
}
static void
......@@ -566,14 +600,21 @@ pgd_annot_view_set_annot_free_text (GtkWidget *table,
}
static void
pgd_single_ink_annot_changed (GtkToggleButton *button,
PgdAnnotsDemo *demo)
pgd_annots_single_ink_annot_changed (GtkToggleButton *button,
PgdAnnotsDemo *demo)
{
if (demo->mode != MODE_NORMAL)
/* don't change path saving mechanism while drawing */
if (demo->mode != MODE_NORMAL && demo->mode != MODE_ADD)
return;
demo->single_path_per_annot = gtk_toggle_button_get_active(button);
gboolean val;
val = gtk_toggle_button_get_active (button);
if (val != demo->single_path_per_annot && demo->ink_annot_paths != NULL) {
pgd_annots_ink_annots_done (demo);
}
demo->single_path_per_annot = val;
}
static void
......@@ -988,9 +1029,7 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo)
rect.x2 = demo->stop.x;
rect.y2 = height - demo->stop.y;
color.red = CLAMP ((guint) (demo->annot_color.red * 65535), 0, 65535);
color.green = CLAMP ((guint) (demo->annot_color.green * 65535), 0, 65535);
color.blue = CLAMP ((guint) (demo->annot_color.blue * 65535), 0, 65535);
set_poppler_color_from_rgba_color (&color, &(demo->annot_color));
switch (demo->annot_type) {
case POPPLER_ANNOT_TEXT:
......@@ -1057,7 +1096,6 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo)
}
gtk_widget_set_sensitive(demo->remove_button, FALSE);
gtk_widget_set_sensitive(demo->single_ink_path_check, FALSE);
demo->active_annot = annot;
......@@ -1068,28 +1106,35 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo)
}
static void
pgd_annots_done (PgdAnnotsDemo *demo)
pgd_annots_ink_annots_done (PgdAnnotsDemo *demo)
{
g_assert (demo->mode == MODE_ADD || demo->mode == MODE_DRAWING);
demo->mode = MODE_NORMAL;
demo->start.x = -1;
pgd_annots_update_cursor(demo, CURSOR_NORMAL);
pgd_annots_viewer_queue_redraw (demo);
if (!demo->single_path_per_annot && demo->ink_annot_paths != NULL) {
if (demo->ink_annot_paths != NULL) {
guint n_paths = demo->ink_annot_paths->len;
for (guint i = 0; i < n_paths; i++) {
GArray* path_ptr = g_ptr_array_index (demo->ink_annot_paths, i);
g_array_free (path_ptr, TRUE);
}
g_ptr_array_free (demo->ink_annot_paths, FALSE);
}
demo->current_ink_path = NULL;
demo->ink_annot_paths = NULL;
}
static void
pgd_annots_done (PgdAnnotsDemo *demo)
{
g_assert (demo->mode == MODE_ADD || demo->mode == MODE_DRAWING);
demo->mode = MODE_NORMAL;
demo->start.x = -1;
pgd_annots_update_cursor (demo, CURSOR_NORMAL);
pgd_annots_viewer_queue_redraw (demo);
pgd_annots_ink_annots_done (demo);
gtk_widget_set_sensitive (demo->remove_button, TRUE);
gtk_widget_set_sensitive (demo->single_ink_path_check, TRUE);
gtk_widget_hide (demo->single_ink_path_check);
gtk_label_set_text (GTK_LABEL (demo->timer_label), NULL);
......@@ -1101,11 +1146,8 @@ pgd_annots_register_annot (PgdAnnotsDemo *demo)
{
g_assert (demo->mode == MODE_DRAWING);
if (demo->annot_type == POPPLER_ANNOT_INK) {
if (demo->single_path_per_annot) {
g_array_free (demo->current_ink_path, TRUE);
demo->current_ink_path = NULL;
}
if (demo->annot_type == POPPLER_ANNOT_INK && demo->single_path_per_annot) {
pgd_annots_ink_annots_done (demo);
}
demo->mode = MODE_ADD;
......@@ -1197,7 +1239,7 @@ pgd_annot_update_ink_path (PgdAnnotsDemo *demo,
gdouble x,
gdouble y)
{
PopplerPoint p = { .x = (gdouble) x, .y = (gdouble) y };
PopplerPoint p = { .x = x, .y = y };
g_array_append_val (demo->current_ink_path, p);
......@@ -1304,7 +1346,10 @@ pgd_annots_drawing_area_button_press (GtkWidget *area,
demo->start.y = event->y;
demo->stop = demo->start;
if (demo->single_path_per_annot || demo->ink_annot_paths == NULL) {
if (demo->annot_type != POPPLER_ANNOT_INK
|| demo->single_path_per_annot
|| demo->ink_annot_paths == NULL)
{
pgd_annots_add_annot (demo);
}
......@@ -1462,6 +1507,9 @@ pgd_annots_create_widget (PopplerDocument *document)
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (demo->type_selector), renderer,
"text", SELECTED_LABEL_COLUMN,
NULL);
g_signal_connect (demo->type_selector, "changed",
G_CALLBACK (pgd_annot_type_selection_changed),
(gpointer) demo);
gtk_combo_box_set_active (GTK_COMBO_BOX (demo->type_selector), 0);
gtk_box_pack_end (GTK_BOX (hbox), demo->type_selector, FALSE, FALSE, 0);
gtk_widget_show (demo->type_selector);
......@@ -1487,7 +1535,7 @@ pgd_annots_create_widget (PopplerDocument *document)
demo->single_ink_path_check = gtk_check_button_new_with_label ("Use one path per ink annotation");
gtk_widget_set_halign(demo->single_ink_path_check, GTK_ALIGN_END);
g_signal_connect (demo->single_ink_path_check, "toggled",
G_CALLBACK (pgd_single_ink_annot_changed),
G_CALLBACK (pgd_annots_single_ink_annot_changed),
(gpointer) demo);
gtk_box_pack_start( GTK_BOX (vbox), demo->single_ink_path_check, FALSE, TRUE, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment