Commit 9b0d56d4 authored by Enrico Lumetti's avatar Enrico Lumetti

Draw multiple paths on a single ink annotation

parent de940ab4
......@@ -89,7 +89,9 @@ typedef struct {
GdkCursorType cursor;
guint annotations_idle;
GArray *ink_annot_points; // array of PopplerPoint
GPtrArray *ink_annot_paths; // array of GArray of PopplerPoint
GArray *current_ink_path;
gboolean single_path_per_annot;
} PgdAnnotsDemo;
static void pgd_annots_viewer_queue_redraw (PgdAnnotsDemo *demo);
......@@ -378,6 +380,30 @@ pgd_annots_start_add_annot (GtkWidget *button,
pgd_annots_update_cursor (demo, GDK_TCROSS);
}
static void pgd_annots_done (PgdAnnotsDemo *demo);
static void
pgd_annots_start_toggle_annot (GtkWidget *button, PgdAnnotsDemo *demo)
{
switch (demo->mode)
{
case MODE_NORMAL: {
gtk_button_set_label(GTK_BUTTON(button), "Done");
pgd_annots_start_add_annot(button, demo);
}
break;
case MODE_ADD: {
gtk_button_set_label(GTK_BUTTON(button), "Add");
pgd_annots_done(demo);
}
break;
default:
return;
}
}
static void
pgd_annots_remove_annot (GtkWidget *button,
PgdAnnotsDemo *demo)
......@@ -985,7 +1011,7 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo)
case POPPLER_ANNOT_INK: {
annot = poppler_annot_ink_new (demo->doc, &rect);
demo->ink_annot_points = g_array_new(FALSE, TRUE, sizeof(PopplerPoint));
demo->ink_annot_paths = g_ptr_array_new();
}
break;
default:
......@@ -1001,17 +1027,43 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo)
}
static void
pgd_annots_finish_add_annot (PgdAnnotsDemo *demo)
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, GDK_LAST_CURSOR);
pgd_annots_viewer_queue_redraw (demo);
if (!demo->single_path_per_annot && 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;
gtk_label_set_text (GTK_LABEL (demo->timer_label), NULL);
}
static void
pgd_annots_register_annot (PgdAnnotsDemo *demo)
{
g_assert (demo->mode == MODE_DRAWING);
if (demo->annot_type == POPPLER_ANNOT_INK) {
g_array_free(demo->ink_annot_points, TRUE);
if (demo->single_path_per_annot) {
g_array_free(demo->current_ink_path, TRUE);
demo->current_ink_path = NULL;
}
}
demo->mode = MODE_NORMAL;
demo->mode = MODE_ADD;
demo->start.x = -1;
pgd_annots_update_cursor (demo, GDK_LAST_CURSOR);
pgd_annots_viewer_queue_redraw (demo);
gtk_label_set_text (GTK_LABEL (demo->timer_label), NULL);
......@@ -1099,9 +1151,9 @@ pgd_annot_update_ink_path (PgdAnnotsDemo *demo, gdouble x, gdouble y)
{
PopplerAnnotInk* annot = (PopplerAnnotInk*) demo->active_annot;
PopplerPoint p = { .x = (gdouble) x, .y = (gdouble) y };
g_array_append_val(demo->ink_annot_points, p);
g_array_append_val(demo->current_ink_path, p);
poppler_annot_ink_set_single_path(annot, demo->ink_annot_points);
poppler_annot_ink_set_ink_list(annot, demo->ink_annot_paths);
}
/* Render area */
......@@ -1204,7 +1256,15 @@ pgd_annots_drawing_area_button_press (GtkWidget *area,
demo->start.y = event->y;
demo->stop = demo->start;
pgd_annots_add_annot (demo);
if (demo->single_path_per_annot || demo->ink_annot_paths == NULL) {
pgd_annots_add_annot (demo);
}
if (demo->annot_type == POPPLER_ANNOT_INK) {
demo->current_ink_path = g_array_new(FALSE, TRUE, sizeof(PopplerPoint));
g_ptr_array_add(demo->ink_annot_paths, demo->current_ink_path);
}
pgd_annots_viewer_queue_redraw (demo);
demo->mode = MODE_DRAWING;
......@@ -1263,7 +1323,7 @@ pgd_annots_drawing_area_button_release (GtkWidget *area,
if (!demo->page || demo->mode != MODE_DRAWING || event->button != 1)
return FALSE;
pgd_annots_finish_add_annot (demo);
pgd_annots_register_annot (demo);
return TRUE;
}
......@@ -1293,6 +1353,7 @@ pgd_annots_create_widget (PopplerDocument *document)
demo->doc = g_object_ref (document);
demo->cursor = GDK_LAST_CURSOR;
demo->mode = MODE_NORMAL;
demo->single_path_per_annot = FALSE;
n_pages = poppler_document_get_n_pages (document);
......@@ -1328,9 +1389,9 @@ pgd_annots_create_widget (PopplerDocument *document)
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
button = gtk_button_new_with_mnemonic ("_Add");
button = gtk_button_new_with_label ("Add");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (pgd_annots_start_add_annot),
G_CALLBACK (pgd_annots_start_toggle_annot),
(gpointer) demo);
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
......
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