Add eyedrop tool. The treeview will scroll to the selection.
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 15 Mar 2015 14:21:56 +0000 (15:21 +0100)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 15 Mar 2015 14:34:35 +0000 (15:34 +0100)
gui/Makefile.am
gui/buttons/b_pick.c [new file with mode: 0644]
gui/buttons/convert
gui/buttons/pick.bmp [new file with mode: 0644]
gui/main.c
gui/main.h
gui/palette.c
gui/palette.h
gui/toolbar.c
gui/toolbar.h

index adaa3f4..df2e182 100644 (file)
@@ -29,7 +29,7 @@ colorize_gtk_SOURCES = \
        level.c \
        fill.c \
        buttons/b_size_1.c buttons/b_size_3.c buttons/b_size_5.c buttons/b_size_9.c \
-       buttons/b_size_11.c buttons/b_size_19.c buttons/b_move.c \
+       buttons/b_size_11.c buttons/b_size_19.c buttons/b_move.c buttons/b_pick.c \
        buttons/b_zoomin.c buttons/b_zoomout.c \
        buttons/b_highlight.c buttons/b_eye.c buttons/b_pal.c buttons/b_col.c \
        buttons/b_bc.c buttons/b_preview.c buttons/b_flow.c buttons/b_fill.c \
diff --git a/gui/buttons/b_pick.c b/gui/buttons/b_pick.c
new file mode 100644 (file)
index 0000000..abf8c30
--- /dev/null
@@ -0,0 +1,85 @@
+#include <gtk/gtk.h>
+/* GdkPixbuf RGB C-Source image dump */
+
+#ifdef __SUNPRO_C
+#pragma align 4 (img_pick)
+#endif
+#ifdef __GNUC__
+const guint8 img_pick[] __attribute__ ((__aligned__ (4))) = 
+#else
+const guint8 img_pick[] = 
+#endif
+{ ""
+  /* Pixbuf magic (0x47646b50) */
+  "GdkP"
+  /* length: header (24) + pixel_data (1140) */
+  "\0\0\4\214"
+  /* pixdata_type (0x1010001) */
+  "\1\1\0\1"
+  /* rowstride (60) */
+  "\0\0\0<"
+  /* width (19) */
+  "\0\0\0\23"
+  /* height (19) */
+  "\0\0\0\23"
+  /* pixel_data: */
+  "\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333"
+  "\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336"
+  "\333\326\336\333\326\234\236\234)41)41)41{}{\377\377\3770\12\"\336\333"
+  "\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336"
+  "\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326"
+  "\336\333\326)41)AZ1e\2451Q{)41\377\377\377fin\336\333\326\336\333\326"
+  "\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333"
+  "\326\336\333\326\336\333\326\336\333\326\336\333\326\245\246\245)411"
+  "e\245)Ec)41)41\377\377\377\"\12\"\336\333\326\336\333\326\336\333\326"
+  "\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333"
+  "\326\336\333\326)41)41)Ec)AZ1Mk)41)41)41\377\377\377\0""00\336\333\326"
+  "\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333"
+  "\326\336\333\326\336\333\326\336\333\326\306\303\275)411e\245)41)41)"
+  "41)41\245\246\245\377\377\377\"\12\"\336\333\326\336\333\326\336\333"
+  "\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336"
+  "\333\326\306\303\275\214\212\204\377\377\377)41)41)41\214\216\214\336"
+  "\333\326\336\333\326\377\377\377map\336\333\326\336\333\326\336\333\326"
+  "\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\306\303"
+  "\275\214\212\204\377\377\377\326\333\347\265\276\316)41)41\336\333\326"
+  "\336\333\326\336\333\326\377\377\377\40\"\40\336\333\326\336\333\326"
+  "\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326\306\307"
+  "\306\214\212\204\377\377\377\326\333\347\275\303\316\214\212\204\316"
+  "\313\306)41\336\333\326\336\333\326\336\333\326\377\377\377\"\"\40\336"
+  "\333\326\336\333\326\336\333\326\336\333\326\336\333\326\336\333\326"
+  "\306\303\275\214\212\204\377\377\377\275\307\326\245\262\306\214\212"
+  "\204\316\313\306\336\333\326\336\333\326\336\333\326\336\333\326\336"
+  "\333\326\377\377\37700\12\336\333\326\336\333\326\336\333\326\336\333"
+  "\326\336\333\326\306\303\275\214\212\204s\236\3161e\2451e\245\214\212"
+  "\204\316\307\306\336\333\326\336\333\326\336\333\326\336\333\326\336"
+  "\333\326\336\333\326\377\377\377\40\0m\336\333\326\336\333\326\336\333"
+  "\326\336\333\326\336\333\326\214\212\204s\236\3161e\2451e\245\214\212"
+  "\204\306\303\275\336\333\326\336\333\326\336\333\326\336\333\326\336"
+  "\333\326\336\333\326\336\333\326\377\377\3770\12\"\336\333\326\336\333"
+  "\326\336\333\326\336\333\326\306\303\275\214\212\2041e\2451e\245\214"
+  "\212\204\306\303\275\326\327\316\326\327\316\336\333\326\336\333\326"
+  "\336\333\326\336\333\326\336\333\326\336\333\326\377\377\377e/x\336\333"
+  "\326\336\333\326\336\333\326\336\333\326\214\212\204\275\313\326\214"
+  "\212\204\214\212\204\306\303\275\326\317\316\326\317\316\326\317\316"
+  "\336\327\326\336\327\326\336\327\326\336\327\326\336\327\326\336\333"
+  "\326\377\377\377\12\"i\336\333\326\336\333\326\336\333\326\224\226\245"
+  "Ji\224s}\204\265\266\265\316\313\306\316\307\306\316\307\306\316\307"
+  "\306\316\307\306\326\323\316\326\323\316\326\323\316\326\327\316\336"
+  "\327\326\336\327\326\377\377\377\40\"\40\336\333\326\336\333\326\336"
+  "\327\326cmsJu\255BYs\306\276\275\306\303\275\306\276\275\306\276\275"
+  "\306\276\275\306\303\275\326\317\316\326\323\316\326\323\316\326\323"
+  "\316\336\327\326\336\327\326\377\377\377\40""10\336\333\326\336\333\326"
+  "\245\256\265Ri\204c\216\3069MkZi{\275\272\265\275\266\265\275\272\265"
+  "\275\272\265\275\276\275\316\313\306\326\317\316\326\323\316\326\323"
+  "\316\326\327\316\336\327\326\377\377\377L\"\12\336\327\326\336\333\326"
+  "Zm\204\275\317\347c\216\306R\202\265)AZ\265\256\255\265\262\255\275\266"
+  "\265\275\272\265\275\272\265\316\313\306\316\317\316\326\323\316\326"
+  "\323\316\336\327\326\336\333\326\377\377\377mat\377\377\377\336\327\326"
+  "J]{s\236\316c\216\3069e\2349Ic\255\252\245\265\256\255\275\266\265\275"
+  "\272\265\306\276\275\316\307\306\316\317\306\326\323\316\326\323\316"
+  "\336\327\326\336\333\326\377\377\377\"/*\377\377\377\326\323\316\204"
+  "\216\2459Y\204!As!Ak{\206\214\265\256\255\275\266\265\275\276\275\306"
+  "\276\275\306\303\275\316\307\306\316\317\316\326\323\316\336\327\326"
+  "\336\333\326\336\333\326\377\377\377\0\0\0"};
+
+
index 7ab9246..1eea667 100644 (file)
@@ -1,4 +1,4 @@
-for i in size_1 size_3 size_5 size_9 size_11 size_19 move eye pal col highlight zoomin zoomout bc preview flow fill
+for i in size_1 size_3 size_5 size_9 size_11 size_19 move eye pal col highlight zoomin zoomout bc preview flow fill pick
 do
        echo "#include <gtk/gtk.h>" >b_$i.c
        gdk-pixbuf-csource --raw --name=img_$i $i.bmp | sed -e 's/static //g' >>b_$i.c
diff --git a/gui/buttons/pick.bmp b/gui/buttons/pick.bmp
new file mode 100644 (file)
index 0000000..7abdebd
Binary files /dev/null and b/gui/buttons/pick.bmp differ
index df656ff..dd75769 100644 (file)
@@ -35,7 +35,7 @@ GtkToggleButton *show_flow_button;
 #endif
 int button_down = 0, button_down_x = -1000, button_down_y = -1000, shift_pressed = 0, button_num = 1;
 int brush_size;
-int highlight = 0, preview = 0, rendered = 0, move_mode = 0, fill_mode = 0, flowview = 0;
+int highlight = 0, preview = 0, rendered = 0, draw_mode = 1, move_mode = 0, fill_mode = 0, pick_mode = 0, flowview = 0;
 int mouse_over_palette_area = 0, mouse_over_drawing_area = 0, mouse_over_timeline_area = 0;
 #define min(x,y) ((x < y) ? x : y)
 #define abs(x,y) ((x < y) ? y - x : x - y)
@@ -283,15 +283,21 @@ static gint motion_notify_event( GtkWidget *widget,
        }
 
        if ((state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) {
-               if (button_down) {
+               if (button_down && pick_mode) {
+                       pick_color(x, y);
+               }
+               if (button_down && !pick_mode) {
                        if (move_mode) {
                                move_mark((x-button_down_x)*16/img_scale_x, (y-button_down_y)*16/img_scale_y);
                                draw_image(0, 0, -1, -1);
-                       } else {
+                       } else
+                       if (draw_mode) {
                                draw_line(x, y, button_num == 1);
                        }
                }
        } else {
+               if (button_down && pick_mode)
+                       release_pick_mode();
                button_down = 0;
        }
                                                                                   
@@ -307,9 +313,14 @@ static gint button_press_event (GtkWidget *widget, GdkEventButton *event)
        y = event->y;
        button_num = event->button;
 
-       if (!button_down)
+       if (!button_down && !pick_mode)
                copy_mark_to_undo();
+       if (pick_mode) {
+               pick_color(x, y);
+       } else
        if (fill_mode) {
+               if (button_down)
+                       return TRUE;
                fill(x, y, event->button != 1);
                draw_image(0, 0, -1, -1);
        } else
@@ -318,7 +329,8 @@ static gint button_press_event (GtkWidget *widget, GdkEventButton *event)
                        return TRUE;
                button_down_x = x;
                button_down_y = y;
-       } else {
+       } else
+       if (draw_mode) {
                /* if not shift, draw a dot and not a line */
                if (!shift_pressed || button_down_x == -1000) {
                        button_down_x = x;
index 6070051..f5acee4 100644 (file)
@@ -26,5 +26,5 @@ enum toggle_label {
 void set_button_toggel_by_label(enum toggle_label label, gboolean active);
 
 extern int brush_size;
-extern int highlight, preview, rendered, move_mode, fill_mode, flowview;
+extern int highlight, preview, rendered, draw_mode, move_mode, fill_mode, pick_mode, flowview;
 
index 8d55689..667214f 100644 (file)
@@ -6,6 +6,7 @@
 #include "../src/yuv.h"
 #include "palette.h"
 #include "timeline.h"
+#include "image.h"
 
 int mark_selected = 0;
 
@@ -154,8 +155,12 @@ void create_palette(void)
                g_object_unref(color);
                if (i == mark_selected) {
                        GtkTreeSelection *selection;
+                       GtkTreePath *path;
                        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(palette_treeview));
                        gtk_tree_selection_select_iter(selection, &iter);
+                       path = gtk_tree_model_get_path(GTK_TREE_MODEL(palette_store), &iter);
+                       gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(palette_treeview), path, NULL, FALSE, 0,0);
+                       gtk_tree_path_free(path);
                }
        }
 
@@ -163,20 +168,65 @@ void create_palette(void)
 
 }
 
-void update_color(int entry)
+int get_iter_by_path_name(GtkTreeIter *iter, GtkTreeModel *model, int entry)
 {
-       GdkPixbuf *color;
+       char path_name[10];
 
-       color = draw_pixpuf(entry);
+       sprintf(path_name, "%d", entry);
+        if (gtk_tree_model_get_iter_from_string(model, iter, path_name))
+               return 1;
+       return 0;
+}
 
+void update_color(int entry)
+{
+       GdkPixbuf *color;
        GtkTreeIter iter;
        GtkTreeModel *model;
-       char path[10];
 
-       sprintf(path, "%d", entry);
+       color = draw_pixpuf(entry);
+
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(palette_treeview));
-        if (gtk_tree_model_get_iter_from_string(model, &iter, path)) {
+       if (get_iter_by_path_name(&iter, model, entry))
                gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, color, 2, mark_palette[entry].name, -1);
+}
+
+void pick_color(int x, int y)
+{
+       GdkDrawable *draw = gtk_widget_get_window(img_drawing_area);
+       int window_width, window_height;
+       unsigned char c;
+       gdk_drawable_get_size (draw, &window_width, &window_height);
+
+       if (!img_mark_buffer)
+               return;
+
+       /* we need to calculate an offset, since the drawing area is now larger */
+       x -= (window_width - img_width*img_scale_x/16) / 2;
+       y -= (window_height - img_height*img_scale_y/16) / 2;
+
+       x = x*16/img_scale_x;
+       y = y*16/img_scale_y;
+
+       if (x < 0 || x >= img_width || y < 0 || y >= img_height)
+               return;
+
+       c = img_mark_buffer[img_width*y+x];
+       if (c > 0) {
+               GtkTreeIter iter;
+               GtkTreeModel *model;
+               GtkTreeSelection *selection;
+               GtkTreePath *path;
+
+               mark_selected = c - 1;
+               model = gtk_tree_view_get_model(GTK_TREE_VIEW(palette_treeview));
+               selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(palette_treeview));
+               if (get_iter_by_path_name(&iter, model, mark_selected)) {
+                       gtk_tree_selection_select_iter(selection, &iter);
+                       path = gtk_tree_model_get_path(model, &iter);
+                       gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(palette_treeview), path, NULL, FALSE, 0,0);
+                       gtk_tree_path_free(path);
+               }
        }
 }
 
index 1733279..8f569d9 100644 (file)
@@ -4,4 +4,5 @@ extern int mark_selected;
 
 void create_palette(void);
 void update_color(int entry);
+void pick_color(int x, int y);
 
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);
index 7075aa7..4c526e0 100644 (file)
@@ -5,4 +5,5 @@ extern GtkToggleButton *show_flow_button;
 #endif
 
 void create_toolbar(GtkWidget *tool_bar);
+void release_pick_mode(void);