From 12af4c021cd5633ad2616e4364eb85a30cea31c3 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 15 Mar 2015 15:21:56 +0100 Subject: [PATCH] Add eyedrop tool. The treeview will scroll to the selection. --- gui/Makefile.am | 2 +- gui/buttons/b_pick.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ gui/buttons/convert | 2 +- gui/buttons/pick.bmp | Bin 0 -> 1262 bytes gui/main.c | 22 ++++++++++--- gui/main.h | 2 +- gui/palette.c | 62 +++++++++++++++++++++++++++++++++---- gui/palette.h | 1 + gui/toolbar.c | 49 +++++++++++++++++++++++------ gui/toolbar.h | 1 + 10 files changed, 203 insertions(+), 23 deletions(-) create mode 100644 gui/buttons/b_pick.c create mode 100644 gui/buttons/pick.bmp diff --git a/gui/Makefile.am b/gui/Makefile.am index adaa3f4..df2e182 100644 --- a/gui/Makefile.am +++ b/gui/Makefile.am @@ -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 index 0000000..abf8c30 --- /dev/null +++ b/gui/buttons/b_pick.c @@ -0,0 +1,85 @@ +#include +/* 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"}; + + diff --git a/gui/buttons/convert b/gui/buttons/convert index 7ab9246..1eea667 100644 --- a/gui/buttons/convert +++ b/gui/buttons/convert @@ -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 " >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 index 0000000000000000000000000000000000000000..7abdebdd5130f518405e343814b75e92b945d8f0 GIT binary patch literal 1262 zcmb7@v1`IW6vo@qt)oja?v_II#=iSxX+!@ zQU`G5tC|(>v%XJKfxF!<_zYRkaq5Ou%C}2-_u2MFoKJjz3KRZJh6B1SpHONlnMa7v6Kc26N^YU z&8iysh&inq*ml*hTMdcCASzdE2vFKeRvzgp7N1tf^d2f!y-YnyPc{?5G6t#T6uaKA z*M7fMak>_ta0tmBV~Z4H(X_5ocV66Z;lsl)UMZ(c&LnB^oN4Cd5f6$ri?9e^sRpU9 zg#XoVd=3OZRuWGp*ZaLJNhfi1tr5N1%i@-B+=g>sj2SAy=rl!}zgXOgxojK(+jSVs zy; 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; diff --git a/gui/main.h b/gui/main.h index 6070051..f5acee4 100644 --- a/gui/main.h +++ b/gui/main.h @@ -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; diff --git a/gui/palette.c b/gui/palette.c index 8d55689..667214f 100644 --- a/gui/palette.c +++ b/gui/palette.c @@ -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); + } } } diff --git a/gui/palette.h b/gui/palette.h index 1733279..8f569d9 100644 --- a/gui/palette.h +++ b/gui/palette.h @@ -4,4 +4,5 @@ extern int mark_selected; void create_palette(void); void update_color(int entry); +void pick_color(int x, int y); diff --git a/gui/toolbar.c b/gui/toolbar.c index eb25b4e..ac30e92 100644 --- a/gui/toolbar.c +++ b/gui/toolbar.c @@ -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); diff --git a/gui/toolbar.h b/gui/toolbar.h index 7075aa7..4c526e0 100644 --- a/gui/toolbar.h +++ b/gui/toolbar.h @@ -5,4 +5,5 @@ extern GtkToggleButton *show_flow_button; #endif void create_toolbar(GtkWidget *tool_bar); +void release_pick_mode(void); -- 2.13.6