Add eyedrop tool. The treeview will scroll to the selection.
[colorize.git] / gui / toolbar.c
index eb25b4e..ac30e92 100644 (file)
@@ -33,25 +33,29 @@ extern const guint8 img_size_11[];
 extern const guint8 img_size_19[];
 extern const guint8 img_fill[];
 extern const guint8 img_move[];
+extern const guint8 img_pick[];
 
 struct paint_buttons {
        const guint8 *data;
        GtkToggleButton *button;
        int toggle_state;
        int size;
+       int draw;
        int move;
        int fill;
+       int pick;
        const char *tooltip;
 } paint_buttons[] = {
-       { img_size_1, NULL, FALSE, 1, 0, 0, "Set pen size to 1" },
-       { img_size_3, NULL, TRUE, 2, 0, 0, "Set pen size to 3" },
-       { img_size_5, NULL, FALSE, 3, 0, 0, "Set pen size to 5" },
-       { img_size_9, NULL, FALSE, 5, 0, 0, "Set pen size to 9" },
-       { img_size_11, NULL, FALSE, 6, 0, 0, "Set pen size to 11" },
-       { img_size_19, NULL, FALSE, 10, 0, 0, "Set pen size to 19" },
-       { img_fill, NULL, FALSE, 0, 0, 1, "FILL marked area" },
-       { img_move, NULL, FALSE, 0, 1, 0, "Move marked pixles" },
-       { NULL, NULL, 0, 0, 0, 0, NULL },
+       { img_size_1,   NULL, FALSE, 1,  1, 0, 0, 0, "Set pen size to 1" },
+       { img_size_3,   NULL, TRUE,  2,  1, 0, 0, 0, "Set pen size to 3" },
+       { img_size_5,   NULL, FALSE, 3,  1, 0, 0, 0, "Set pen size to 5" },
+       { img_size_9,   NULL, FALSE, 5,  1, 0, 0, 0, "Set pen size to 9" },
+       { img_size_11,  NULL, FALSE, 6,  1, 0, 0, 0, "Set pen size to 11" },
+       { img_size_19,  NULL, FALSE, 10, 1, 0, 0, 0, "Set pen size to 19" },
+       { img_fill,     NULL, FALSE, 0,  0, 0, 1, 0, "FILL marked area" },
+       { img_move,     NULL, FALSE, 0,  0, 1, 0, 0, "Move marked pixles" },
+       { img_pick,     NULL, FALSE, 0,  0, 0, 0, 1, "Pick color from marked area" },
+       { NULL,         NULL, FALSE, 0,  0, 0, 0, 0, NULL },
 };
 
 void paint_button_toggled(GtkToggleButton *togglebutton, gpointer index)
@@ -62,13 +66,27 @@ void paint_button_toggled(GtkToggleButton *togglebutton, gpointer index)
                return;
        }
 
+       /* picker just toggles */
+       if (paint_buttons[(long)index].pick) {
+               i = (long)index;
+               if (paint_buttons[i].toggle_state == FALSE) {
+                       paint_buttons[i].toggle_state = TRUE;
+                       gtk_toggle_button_set_active(paint_buttons[i].button, TRUE);
+                       pick_mode = 1;
+               } else
+                       release_pick_mode();
+               return;
+       }
+
        for (i = 0; paint_buttons[i].button; i++) {
                if ((long)index == i) {
                        paint_buttons[i].toggle_state = TRUE;
                        gtk_toggle_button_set_active(paint_buttons[i].button, TRUE);
                        brush_size = paint_buttons[i].size;
+                       draw_mode = paint_buttons[i].draw;
                        move_mode = paint_buttons[i].move;
                        fill_mode = paint_buttons[i].fill;
+                       pick_mode = 0;
                } else {
                        paint_buttons[i].toggle_state = FALSE;
                        gtk_toggle_button_set_active(paint_buttons[i].button, FALSE);
@@ -77,6 +95,19 @@ void paint_button_toggled(GtkToggleButton *togglebutton, gpointer index)
 
 }
 
+void release_pick_mode(void)
+{
+       int i;
+
+       pick_mode = 0;
+       for (i = 0; paint_buttons[i].button; i++) {
+               if (paint_buttons[i].pick) {
+                       paint_buttons[i].toggle_state = FALSE;
+                       gtk_toggle_button_set_active(paint_buttons[i].button, FALSE);
+               }
+       }
+}
+
 void zoomin_button_clicked(GtkButton *button, gpointer index)
 {
        zoom_in_event(NULL);