diff --git a/app/airbrush.c b/app/airbrush.c index 0b13f9a564..10277fbb27 100644 --- a/app/airbrush.c +++ b/app/airbrush.c @@ -178,6 +178,7 @@ tools_new_airbrush () private = (PaintCore *) tool->private; private->paint_func = airbrush_paint_func; + private->pick_colors = TRUE; return tool; } @@ -198,10 +199,10 @@ airbrush_paint_func (PaintCore *paint_core, case INIT_PAINT : /* timer_state = OFF; */ if (timer_state == ON) - { - g_warning (_("killing stray timer, please report to lewing@gimp.org")); - gtk_timeout_remove (timer); - } + { + g_warning (_("killing stray timer, please report to lewing@gimp.org")); + gtk_timeout_remove (timer); + } timer_state = OFF; break; @@ -213,13 +214,13 @@ airbrush_paint_func (PaintCore *paint_core, airbrush_motion (paint_core, drawable, airbrush_options->pressure); if (airbrush_options->rate != 0.0) - { - airbrush_timeout.paint_core = paint_core; - airbrush_timeout.drawable = drawable; - timer = gtk_timeout_add ((10000 / airbrush_options->rate), - airbrush_time_out, NULL); - timer_state = ON; - } + { + airbrush_timeout.paint_core = paint_core; + airbrush_timeout.drawable = drawable; + timer = gtk_timeout_add ((10000 / airbrush_options->rate), + airbrush_time_out, NULL); + timer_state = ON; + } break; case FINISH_PAINT : diff --git a/app/color_picker.c b/app/color_picker.c index 63fdb8a080..dc05e86c2d 100644 --- a/app/color_picker.c +++ b/app/color_picker.c @@ -23,6 +23,7 @@ #include "draw_core.h" #include "drawable.h" #include "gdisplay.h" +#include "cursorutil.h" #include "info_dialog.h" #include "palette.h" #include "tool_options_ui.h" @@ -371,7 +372,7 @@ color_picker_cursor_update (Tool *tool, gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE); if (gimage_pick_correlate_layer (gdisp->gimage, x, y)) - gdisplay_install_tool_cursor (gdisp, GDK_TCROSS); + gdisplay_install_tool_cursor (gdisp, GIMP_COLOR_PICKER_CURSOR); else gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW); } diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c index 48177dfeff..da0127b29c 100644 --- a/app/core/gimpprojection.c +++ b/app/core/gimpprojection.c @@ -1473,31 +1473,14 @@ gdisplay_untransform_coords_f (GDisplay *gdisp, } -/* install and remove tool gimp cursor from gdisplay... */ -void -gdisplay_install_gimp_tool_cursor (GDisplay *gdisp, - int cursor_type) -{ - if (gdisp->current_cursor != (int)cursor_type || gdisp->cursor_type != 1) - { - gdisp->current_cursor = (int)cursor_type; - gdisp->cursor_type = 1; - if (!gdisp->using_override_cursor) - { - gimp_change_win_cursor (gdisp->canvas->window, cursor_type); - } - } -} - /* install and remove tool cursor from gdisplay... */ void gdisplay_install_tool_cursor (GDisplay *gdisp, GdkCursorType cursor_type) { - if (gdisp->current_cursor != (int)cursor_type || gdisp->cursor_type != 0) + if (gdisp->current_cursor != (int)cursor_type) { gdisp->current_cursor = (int)cursor_type; - gdisp->cursor_type = 0; if (!gdisp->using_override_cursor) { change_win_cursor (gdisp->canvas->window, cursor_type); diff --git a/app/core/gimpprojection.h b/app/core/gimpprojection.h index 1046c43a4f..420be2d098 100644 --- a/app/core/gimpprojection.h +++ b/app/core/gimpprojection.h @@ -138,7 +138,7 @@ struct _GDisplay GSList *display_areas; /* Display areas list */ int current_cursor; /* Currently installed cursor */ - short cursor_type; /* Currently installed cursor type */ + GdkCursorType override_cursor; /* Overriding cursor (ie. hourglass) */ short draw_cursor; /* should we draw software cursor ? */ diff --git a/app/cursorutil.c b/app/cursorutil.c index 38c2b1bc2c..7b5192e0a7 100644 --- a/app/cursorutil.c +++ b/app/cursorutil.c @@ -27,6 +27,8 @@ #include "../cursors/mouse1_mmsk" #include "../cursors/bigcirc" #include "../cursors/bigcircmsk" +#include "../cursors/dropper" +#include "../cursors/droppermsk" typedef struct { @@ -48,6 +50,8 @@ static BM_Cursor gimp_cursors[] = mouse1_m_x_hot, mouse1_m_y_hot, NULL}, { bigcirc_bits, bigcircmsk_bits, bigcirc_width, bigcirc_height, bigcirc_x_hot, bigcirc_y_hot, NULL}, + { dropper_bits, droppermsk_bits, dropper_width, dropper_height, + dropper_x_hot, dropper_y_hot, NULL}, }; @@ -82,12 +86,13 @@ create_cursor(BM_Cursor *bmcursor) g_return_if_fail (bmcursor->cursor != NULL); } -void +static void gimp_change_win_cursor(GdkWindow *win, GimpCursorType curtype) { GdkCursor *cursor; g_return_if_fail (curtype < GIMP_LAST_CURSOR_ENTRY); + curtype -= GIMP_MOUSE1_CURSOR; if (!gimp_cursors[(int)curtype].cursor) create_cursor (&gimp_cursors[(int)curtype]); cursor = gimp_cursors[(int)curtype].cursor; @@ -101,7 +106,12 @@ change_win_cursor (win, cursortype) GdkCursorType cursortype; { GdkCursor *cursor; - + + if (cursortype > GDK_LAST_CURSOR) + { + gimp_change_win_cursor(win, (GimpCursorType)cursortype); + return; + } cursor = gdk_cursor_new (cursortype); gdk_window_set_cursor (win, cursor); gdk_cursor_destroy (cursor); diff --git a/app/cursorutil.h b/app/cursorutil.h index c352d1368a..d44170e67a 100644 --- a/app/cursorutil.h +++ b/app/cursorutil.h @@ -22,16 +22,16 @@ typedef enum { - GIMP_MOUSE1_CURSOR, + GIMP_MOUSE1_CURSOR = (GDK_LAST_CURSOR + 2), GIMP_MOUSE1P_CURSOR, GIMP_MOUSE1M_CURSOR, GIMP_BIGCIRC_CURSOR, + GIMP_COLOR_PICKER_CURSOR, GIMP_LAST_CURSOR_ENTRY } GimpCursorType; void change_win_cursor (GdkWindow *, GdkCursorType); void unset_win_cursor (GdkWindow *); -void gimp_change_win_cursor (GdkWindow *, GimpCursorType); void gimp_add_busy_cursors_until_idle (void); void gimp_add_busy_cursors (void); diff --git a/app/display/gimpdisplay.c b/app/display/gimpdisplay.c index 48177dfeff..da0127b29c 100644 --- a/app/display/gimpdisplay.c +++ b/app/display/gimpdisplay.c @@ -1473,31 +1473,14 @@ gdisplay_untransform_coords_f (GDisplay *gdisp, } -/* install and remove tool gimp cursor from gdisplay... */ -void -gdisplay_install_gimp_tool_cursor (GDisplay *gdisp, - int cursor_type) -{ - if (gdisp->current_cursor != (int)cursor_type || gdisp->cursor_type != 1) - { - gdisp->current_cursor = (int)cursor_type; - gdisp->cursor_type = 1; - if (!gdisp->using_override_cursor) - { - gimp_change_win_cursor (gdisp->canvas->window, cursor_type); - } - } -} - /* install and remove tool cursor from gdisplay... */ void gdisplay_install_tool_cursor (GDisplay *gdisp, GdkCursorType cursor_type) { - if (gdisp->current_cursor != (int)cursor_type || gdisp->cursor_type != 0) + if (gdisp->current_cursor != (int)cursor_type) { gdisp->current_cursor = (int)cursor_type; - gdisp->cursor_type = 0; if (!gdisp->using_override_cursor) { change_win_cursor (gdisp->canvas->window, cursor_type); diff --git a/app/display/gimpdisplay.h b/app/display/gimpdisplay.h index 1046c43a4f..420be2d098 100644 --- a/app/display/gimpdisplay.h +++ b/app/display/gimpdisplay.h @@ -138,7 +138,7 @@ struct _GDisplay GSList *display_areas; /* Display areas list */ int current_cursor; /* Currently installed cursor */ - short cursor_type; /* Currently installed cursor type */ + GdkCursorType override_cursor; /* Overriding cursor (ie. hourglass) */ short draw_cursor; /* should we draw software cursor ? */ diff --git a/app/gdisplay.c b/app/gdisplay.c index 48177dfeff..da0127b29c 100644 --- a/app/gdisplay.c +++ b/app/gdisplay.c @@ -1473,31 +1473,14 @@ gdisplay_untransform_coords_f (GDisplay *gdisp, } -/* install and remove tool gimp cursor from gdisplay... */ -void -gdisplay_install_gimp_tool_cursor (GDisplay *gdisp, - int cursor_type) -{ - if (gdisp->current_cursor != (int)cursor_type || gdisp->cursor_type != 1) - { - gdisp->current_cursor = (int)cursor_type; - gdisp->cursor_type = 1; - if (!gdisp->using_override_cursor) - { - gimp_change_win_cursor (gdisp->canvas->window, cursor_type); - } - } -} - /* install and remove tool cursor from gdisplay... */ void gdisplay_install_tool_cursor (GDisplay *gdisp, GdkCursorType cursor_type) { - if (gdisp->current_cursor != (int)cursor_type || gdisp->cursor_type != 0) + if (gdisp->current_cursor != (int)cursor_type) { gdisp->current_cursor = (int)cursor_type; - gdisp->cursor_type = 0; if (!gdisp->using_override_cursor) { change_win_cursor (gdisp->canvas->window, cursor_type); diff --git a/app/gdisplay.h b/app/gdisplay.h index 1046c43a4f..420be2d098 100644 --- a/app/gdisplay.h +++ b/app/gdisplay.h @@ -138,7 +138,7 @@ struct _GDisplay GSList *display_areas; /* Display areas list */ int current_cursor; /* Currently installed cursor */ - short cursor_type; /* Currently installed cursor type */ + GdkCursorType override_cursor; /* Overriding cursor (ie. hourglass) */ short draw_cursor; /* should we draw software cursor ? */ diff --git a/app/paint/gimpairbrush.c b/app/paint/gimpairbrush.c index 0b13f9a564..10277fbb27 100644 --- a/app/paint/gimpairbrush.c +++ b/app/paint/gimpairbrush.c @@ -178,6 +178,7 @@ tools_new_airbrush () private = (PaintCore *) tool->private; private->paint_func = airbrush_paint_func; + private->pick_colors = TRUE; return tool; } @@ -198,10 +199,10 @@ airbrush_paint_func (PaintCore *paint_core, case INIT_PAINT : /* timer_state = OFF; */ if (timer_state == ON) - { - g_warning (_("killing stray timer, please report to lewing@gimp.org")); - gtk_timeout_remove (timer); - } + { + g_warning (_("killing stray timer, please report to lewing@gimp.org")); + gtk_timeout_remove (timer); + } timer_state = OFF; break; @@ -213,13 +214,13 @@ airbrush_paint_func (PaintCore *paint_core, airbrush_motion (paint_core, drawable, airbrush_options->pressure); if (airbrush_options->rate != 0.0) - { - airbrush_timeout.paint_core = paint_core; - airbrush_timeout.drawable = drawable; - timer = gtk_timeout_add ((10000 / airbrush_options->rate), - airbrush_time_out, NULL); - timer_state = ON; - } + { + airbrush_timeout.paint_core = paint_core; + airbrush_timeout.drawable = drawable; + timer = gtk_timeout_add ((10000 / airbrush_options->rate), + airbrush_time_out, NULL); + timer_state = ON; + } break; case FINISH_PAINT : diff --git a/app/paint_core.c b/app/paint_core.c index 8e9a1c49bc..7d84851411 100644 --- a/app/paint_core.c +++ b/app/paint_core.c @@ -34,6 +34,7 @@ #include "selection.h" #include "tools.h" #include "undo.h" +#include "cursorutil.h" #include "libgimp/gimpintl.h" @@ -129,6 +130,23 @@ static const int subsample[5][5][9] = { }, }; +static void +paint_core_sample_color(GimpDrawable *drawable, int x, int y, int state) +{ + unsigned char *color; + if ((color = gimp_drawable_get_color_at(drawable, x, y))) + { + if ((state & GDK_CONTROL_MASK)) + palette_set_foreground (color[RED_PIX], color[GREEN_PIX], + color [BLUE_PIX]); + else + palette_set_background (color[RED_PIX], color[GREEN_PIX], + color [BLUE_PIX]); + g_free(color); + } +} + + void paint_core_button_press (tool, bevent, gdisp_ptr) Tool *tool; @@ -200,6 +218,16 @@ paint_core_button_press (tool, bevent, gdisp_ptr) /* Let the specific painting function initialize itself */ (* paint_core->paint_func) (paint_core, drawable, INIT_PAINT); + if (paint_core->pick_colors + && (bevent->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) + { + paint_core_sample_color(drawable, x, y, bevent->state); + paint_core->pick_state = TRUE; + return; + } + else + paint_core->pick_state = FALSE; + /* Paint to the image */ if (draw_line) { @@ -242,6 +270,8 @@ paint_core_button_release (tool, bevent, gdisp_ptr) /* Set tool state to inactive -- no longer painting */ tool->state = INACTIVE; + paint_core->pick_state = FALSE; + paint_core_finish (paint_core, gimage_active_drawable (gdisp->gimage), tool->ID); gdisplays_flush (); } @@ -260,6 +290,15 @@ paint_core_motion (tool, mevent, gdisp_ptr) gdisplay_untransform_coords_f (gdisp, (double) mevent->x, (double) mevent->y, &paint_core->curx, &paint_core->cury, TRUE); + + if (paint_core->pick_state) + { + paint_core_sample_color(gimage_active_drawable (gdisp->gimage), + paint_core->curx, paint_core->cury, mevent->state); + return; + } + + paint_core->curpressure = mevent->pressure; paint_core->curxtilt = mevent->xtilt; paint_core->curytilt = mevent->ytilt; @@ -284,17 +323,26 @@ paint_core_cursor_update (tool, mevent, gdisp_ptr) { GDisplay *gdisp; Layer *layer; + PaintCore * paint_core; GdkCursorType ctype = GDK_TOP_LEFT_ARROW; int x, y; gdisp = (GDisplay *) gdisp_ptr; + paint_core = (PaintCore *) tool->private; - gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE); + gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, + FALSE, FALSE); if ((layer = gimage_get_active_layer (gdisp->gimage))) { int off_x, off_y; drawable_offsets (GIMP_DRAWABLE(layer), &off_x, &off_y); - if (x >= off_x && y >= off_y && + + if (paint_core->pick_colors + && (mevent->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) + { + ctype = GIMP_COLOR_PICKER_CURSOR; + } + else if (x >= off_x && y >= off_y && x < (off_x + drawable_width (GIMP_DRAWABLE(layer))) && y < (off_y + drawable_height (GIMP_DRAWABLE(layer)))) { @@ -357,6 +405,7 @@ paint_core_new (type) private = (PaintCore *) g_malloc (sizeof (PaintCore)); private->core = draw_core_new (paint_core_no_draw); + private->pick_colors = FALSE; tool->type = type; tool->state = INACTIVE; diff --git a/app/paint_core.h b/app/paint_core.h index 9f863a6129..f483f1123e 100644 --- a/app/paint_core.h +++ b/app/paint_core.h @@ -89,6 +89,9 @@ struct _paint_core GimpBrush * brush; /* current brush */ PaintFunc paint_func; /* painting function */ + + int pick_colors; /* pick color if ctl or alt is pressed */ + int pick_state; /* was ctl or alt pressed when clicked? */ }; extern PaintCore non_gui_paint_core; diff --git a/app/paintbrush.c b/app/paintbrush.c index 876bfe9471..16c4e2c638 100644 --- a/app/paintbrush.c +++ b/app/paintbrush.c @@ -296,46 +296,15 @@ paintbrush_paint_func (PaintCore *paint_core, timer = g_timer_new(); g_timer_start(timer); #endif /* TIMED_BRUSH */ - if ((paint_core->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) - { - unsigned char *color; - if ((color = gimp_drawable_get_color_at(drawable, paint_core->curx, - paint_core->cury))) - { - if ((paint_core->state & GDK_CONTROL_MASK)) - palette_set_foreground (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - else - palette_set_background (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - g_free(color); - } - } break; case MOTION_PAINT : - if ((paint_core->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) - { - unsigned char *color; - if ((color = gimp_drawable_get_color_at(drawable, paint_core->curx, - paint_core->cury))) - { - if ((paint_core->state & GDK_CONTROL_MASK)) - palette_set_foreground (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - else - palette_set_background (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - g_free(color); - } - } - else - paintbrush_motion (paint_core, drawable, - paintbrush_options->fade_out, - paintbrush_options->use_gradient ? - exp(paintbrush_options->gradient_length/10) : 0, - paintbrush_options->incremental, - paintbrush_options->gradient_type); + paintbrush_motion (paint_core, drawable, + paintbrush_options->fade_out, + paintbrush_options->use_gradient ? + exp(paintbrush_options->gradient_length/10) : 0, + paintbrush_options->incremental, + paintbrush_options->gradient_type); break; case FINISH_PAINT : @@ -378,6 +347,7 @@ tools_new_paintbrush () private = (PaintCore *) tool->private; private->paint_func = paintbrush_paint_func; + private->pick_colors = TRUE; return tool; } diff --git a/app/rect_select.c b/app/rect_select.c index 0b8967814e..d1068d8ef1 100644 --- a/app/rect_select.c +++ b/app/rect_select.c @@ -491,13 +491,13 @@ rect_select_cursor_update (Tool *tool, switch (rect_sel->op) { case SELECTION_ADD: - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_MOUSE1P_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE1P_CURSOR); break; case SELECTION_SUB: - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_MOUSE1M_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE1M_CURSOR); break; case SELECTION_INTERSECT: /* need a real cursor for this one */ - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_BIGCIRC_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_BIGCIRC_CURSOR); break; case SELECTION_REPLACE: gdisplay_install_tool_cursor (gdisp, GDK_TCROSS); diff --git a/app/tools/airbrush.c b/app/tools/airbrush.c index 0b13f9a564..10277fbb27 100644 --- a/app/tools/airbrush.c +++ b/app/tools/airbrush.c @@ -178,6 +178,7 @@ tools_new_airbrush () private = (PaintCore *) tool->private; private->paint_func = airbrush_paint_func; + private->pick_colors = TRUE; return tool; } @@ -198,10 +199,10 @@ airbrush_paint_func (PaintCore *paint_core, case INIT_PAINT : /* timer_state = OFF; */ if (timer_state == ON) - { - g_warning (_("killing stray timer, please report to lewing@gimp.org")); - gtk_timeout_remove (timer); - } + { + g_warning (_("killing stray timer, please report to lewing@gimp.org")); + gtk_timeout_remove (timer); + } timer_state = OFF; break; @@ -213,13 +214,13 @@ airbrush_paint_func (PaintCore *paint_core, airbrush_motion (paint_core, drawable, airbrush_options->pressure); if (airbrush_options->rate != 0.0) - { - airbrush_timeout.paint_core = paint_core; - airbrush_timeout.drawable = drawable; - timer = gtk_timeout_add ((10000 / airbrush_options->rate), - airbrush_time_out, NULL); - timer_state = ON; - } + { + airbrush_timeout.paint_core = paint_core; + airbrush_timeout.drawable = drawable; + timer = gtk_timeout_add ((10000 / airbrush_options->rate), + airbrush_time_out, NULL); + timer_state = ON; + } break; case FINISH_PAINT : diff --git a/app/tools/color_picker.c b/app/tools/color_picker.c index 63fdb8a080..dc05e86c2d 100644 --- a/app/tools/color_picker.c +++ b/app/tools/color_picker.c @@ -23,6 +23,7 @@ #include "draw_core.h" #include "drawable.h" #include "gdisplay.h" +#include "cursorutil.h" #include "info_dialog.h" #include "palette.h" #include "tool_options_ui.h" @@ -371,7 +372,7 @@ color_picker_cursor_update (Tool *tool, gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE); if (gimage_pick_correlate_layer (gdisp->gimage, x, y)) - gdisplay_install_tool_cursor (gdisp, GDK_TCROSS); + gdisplay_install_tool_cursor (gdisp, GIMP_COLOR_PICKER_CURSOR); else gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW); } diff --git a/app/tools/gimpairbrushtool.c b/app/tools/gimpairbrushtool.c index 0b13f9a564..10277fbb27 100644 --- a/app/tools/gimpairbrushtool.c +++ b/app/tools/gimpairbrushtool.c @@ -178,6 +178,7 @@ tools_new_airbrush () private = (PaintCore *) tool->private; private->paint_func = airbrush_paint_func; + private->pick_colors = TRUE; return tool; } @@ -198,10 +199,10 @@ airbrush_paint_func (PaintCore *paint_core, case INIT_PAINT : /* timer_state = OFF; */ if (timer_state == ON) - { - g_warning (_("killing stray timer, please report to lewing@gimp.org")); - gtk_timeout_remove (timer); - } + { + g_warning (_("killing stray timer, please report to lewing@gimp.org")); + gtk_timeout_remove (timer); + } timer_state = OFF; break; @@ -213,13 +214,13 @@ airbrush_paint_func (PaintCore *paint_core, airbrush_motion (paint_core, drawable, airbrush_options->pressure); if (airbrush_options->rate != 0.0) - { - airbrush_timeout.paint_core = paint_core; - airbrush_timeout.drawable = drawable; - timer = gtk_timeout_add ((10000 / airbrush_options->rate), - airbrush_time_out, NULL); - timer_state = ON; - } + { + airbrush_timeout.paint_core = paint_core; + airbrush_timeout.drawable = drawable; + timer = gtk_timeout_add ((10000 / airbrush_options->rate), + airbrush_time_out, NULL); + timer_state = ON; + } break; case FINISH_PAINT : diff --git a/app/tools/gimprectselecttool.c b/app/tools/gimprectselecttool.c index 0b8967814e..d1068d8ef1 100644 --- a/app/tools/gimprectselecttool.c +++ b/app/tools/gimprectselecttool.c @@ -491,13 +491,13 @@ rect_select_cursor_update (Tool *tool, switch (rect_sel->op) { case SELECTION_ADD: - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_MOUSE1P_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE1P_CURSOR); break; case SELECTION_SUB: - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_MOUSE1M_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE1M_CURSOR); break; case SELECTION_INTERSECT: /* need a real cursor for this one */ - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_BIGCIRC_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_BIGCIRC_CURSOR); break; case SELECTION_REPLACE: gdisplay_install_tool_cursor (gdisp, GDK_TCROSS); diff --git a/app/tools/paint_core.c b/app/tools/paint_core.c index 8e9a1c49bc..7d84851411 100644 --- a/app/tools/paint_core.c +++ b/app/tools/paint_core.c @@ -34,6 +34,7 @@ #include "selection.h" #include "tools.h" #include "undo.h" +#include "cursorutil.h" #include "libgimp/gimpintl.h" @@ -129,6 +130,23 @@ static const int subsample[5][5][9] = { }, }; +static void +paint_core_sample_color(GimpDrawable *drawable, int x, int y, int state) +{ + unsigned char *color; + if ((color = gimp_drawable_get_color_at(drawable, x, y))) + { + if ((state & GDK_CONTROL_MASK)) + palette_set_foreground (color[RED_PIX], color[GREEN_PIX], + color [BLUE_PIX]); + else + palette_set_background (color[RED_PIX], color[GREEN_PIX], + color [BLUE_PIX]); + g_free(color); + } +} + + void paint_core_button_press (tool, bevent, gdisp_ptr) Tool *tool; @@ -200,6 +218,16 @@ paint_core_button_press (tool, bevent, gdisp_ptr) /* Let the specific painting function initialize itself */ (* paint_core->paint_func) (paint_core, drawable, INIT_PAINT); + if (paint_core->pick_colors + && (bevent->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) + { + paint_core_sample_color(drawable, x, y, bevent->state); + paint_core->pick_state = TRUE; + return; + } + else + paint_core->pick_state = FALSE; + /* Paint to the image */ if (draw_line) { @@ -242,6 +270,8 @@ paint_core_button_release (tool, bevent, gdisp_ptr) /* Set tool state to inactive -- no longer painting */ tool->state = INACTIVE; + paint_core->pick_state = FALSE; + paint_core_finish (paint_core, gimage_active_drawable (gdisp->gimage), tool->ID); gdisplays_flush (); } @@ -260,6 +290,15 @@ paint_core_motion (tool, mevent, gdisp_ptr) gdisplay_untransform_coords_f (gdisp, (double) mevent->x, (double) mevent->y, &paint_core->curx, &paint_core->cury, TRUE); + + if (paint_core->pick_state) + { + paint_core_sample_color(gimage_active_drawable (gdisp->gimage), + paint_core->curx, paint_core->cury, mevent->state); + return; + } + + paint_core->curpressure = mevent->pressure; paint_core->curxtilt = mevent->xtilt; paint_core->curytilt = mevent->ytilt; @@ -284,17 +323,26 @@ paint_core_cursor_update (tool, mevent, gdisp_ptr) { GDisplay *gdisp; Layer *layer; + PaintCore * paint_core; GdkCursorType ctype = GDK_TOP_LEFT_ARROW; int x, y; gdisp = (GDisplay *) gdisp_ptr; + paint_core = (PaintCore *) tool->private; - gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE); + gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, + FALSE, FALSE); if ((layer = gimage_get_active_layer (gdisp->gimage))) { int off_x, off_y; drawable_offsets (GIMP_DRAWABLE(layer), &off_x, &off_y); - if (x >= off_x && y >= off_y && + + if (paint_core->pick_colors + && (mevent->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) + { + ctype = GIMP_COLOR_PICKER_CURSOR; + } + else if (x >= off_x && y >= off_y && x < (off_x + drawable_width (GIMP_DRAWABLE(layer))) && y < (off_y + drawable_height (GIMP_DRAWABLE(layer)))) { @@ -357,6 +405,7 @@ paint_core_new (type) private = (PaintCore *) g_malloc (sizeof (PaintCore)); private->core = draw_core_new (paint_core_no_draw); + private->pick_colors = FALSE; tool->type = type; tool->state = INACTIVE; diff --git a/app/tools/paint_core.h b/app/tools/paint_core.h index 9f863a6129..f483f1123e 100644 --- a/app/tools/paint_core.h +++ b/app/tools/paint_core.h @@ -89,6 +89,9 @@ struct _paint_core GimpBrush * brush; /* current brush */ PaintFunc paint_func; /* painting function */ + + int pick_colors; /* pick color if ctl or alt is pressed */ + int pick_state; /* was ctl or alt pressed when clicked? */ }; extern PaintCore non_gui_paint_core; diff --git a/app/tools/paintbrush.c b/app/tools/paintbrush.c index 876bfe9471..16c4e2c638 100644 --- a/app/tools/paintbrush.c +++ b/app/tools/paintbrush.c @@ -296,46 +296,15 @@ paintbrush_paint_func (PaintCore *paint_core, timer = g_timer_new(); g_timer_start(timer); #endif /* TIMED_BRUSH */ - if ((paint_core->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) - { - unsigned char *color; - if ((color = gimp_drawable_get_color_at(drawable, paint_core->curx, - paint_core->cury))) - { - if ((paint_core->state & GDK_CONTROL_MASK)) - palette_set_foreground (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - else - palette_set_background (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - g_free(color); - } - } break; case MOTION_PAINT : - if ((paint_core->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) - { - unsigned char *color; - if ((color = gimp_drawable_get_color_at(drawable, paint_core->curx, - paint_core->cury))) - { - if ((paint_core->state & GDK_CONTROL_MASK)) - palette_set_foreground (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - else - palette_set_background (color[RED_PIX], color[GREEN_PIX], - color [BLUE_PIX]); - g_free(color); - } - } - else - paintbrush_motion (paint_core, drawable, - paintbrush_options->fade_out, - paintbrush_options->use_gradient ? - exp(paintbrush_options->gradient_length/10) : 0, - paintbrush_options->incremental, - paintbrush_options->gradient_type); + paintbrush_motion (paint_core, drawable, + paintbrush_options->fade_out, + paintbrush_options->use_gradient ? + exp(paintbrush_options->gradient_length/10) : 0, + paintbrush_options->incremental, + paintbrush_options->gradient_type); break; case FINISH_PAINT : @@ -378,6 +347,7 @@ tools_new_paintbrush () private = (PaintCore *) tool->private; private->paint_func = paintbrush_paint_func; + private->pick_colors = TRUE; return tool; } diff --git a/app/tools/rect_select.c b/app/tools/rect_select.c index 0b8967814e..d1068d8ef1 100644 --- a/app/tools/rect_select.c +++ b/app/tools/rect_select.c @@ -491,13 +491,13 @@ rect_select_cursor_update (Tool *tool, switch (rect_sel->op) { case SELECTION_ADD: - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_MOUSE1P_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE1P_CURSOR); break; case SELECTION_SUB: - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_MOUSE1M_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE1M_CURSOR); break; case SELECTION_INTERSECT: /* need a real cursor for this one */ - gdisplay_install_gimp_tool_cursor (gdisp, GIMP_BIGCIRC_CURSOR); + gdisplay_install_tool_cursor (gdisp, GIMP_BIGCIRC_CURSOR); break; case SELECTION_REPLACE: gdisplay_install_tool_cursor (gdisp, GDK_TCROSS); diff --git a/app/widgets/gimpcursor.c b/app/widgets/gimpcursor.c index 38c2b1bc2c..7b5192e0a7 100644 --- a/app/widgets/gimpcursor.c +++ b/app/widgets/gimpcursor.c @@ -27,6 +27,8 @@ #include "../cursors/mouse1_mmsk" #include "../cursors/bigcirc" #include "../cursors/bigcircmsk" +#include "../cursors/dropper" +#include "../cursors/droppermsk" typedef struct { @@ -48,6 +50,8 @@ static BM_Cursor gimp_cursors[] = mouse1_m_x_hot, mouse1_m_y_hot, NULL}, { bigcirc_bits, bigcircmsk_bits, bigcirc_width, bigcirc_height, bigcirc_x_hot, bigcirc_y_hot, NULL}, + { dropper_bits, droppermsk_bits, dropper_width, dropper_height, + dropper_x_hot, dropper_y_hot, NULL}, }; @@ -82,12 +86,13 @@ create_cursor(BM_Cursor *bmcursor) g_return_if_fail (bmcursor->cursor != NULL); } -void +static void gimp_change_win_cursor(GdkWindow *win, GimpCursorType curtype) { GdkCursor *cursor; g_return_if_fail (curtype < GIMP_LAST_CURSOR_ENTRY); + curtype -= GIMP_MOUSE1_CURSOR; if (!gimp_cursors[(int)curtype].cursor) create_cursor (&gimp_cursors[(int)curtype]); cursor = gimp_cursors[(int)curtype].cursor; @@ -101,7 +106,12 @@ change_win_cursor (win, cursortype) GdkCursorType cursortype; { GdkCursor *cursor; - + + if (cursortype > GDK_LAST_CURSOR) + { + gimp_change_win_cursor(win, (GimpCursorType)cursortype); + return; + } cursor = gdk_cursor_new (cursortype); gdk_window_set_cursor (win, cursor); gdk_cursor_destroy (cursor); diff --git a/app/widgets/gimpcursor.h b/app/widgets/gimpcursor.h index c352d1368a..d44170e67a 100644 --- a/app/widgets/gimpcursor.h +++ b/app/widgets/gimpcursor.h @@ -22,16 +22,16 @@ typedef enum { - GIMP_MOUSE1_CURSOR, + GIMP_MOUSE1_CURSOR = (GDK_LAST_CURSOR + 2), GIMP_MOUSE1P_CURSOR, GIMP_MOUSE1M_CURSOR, GIMP_BIGCIRC_CURSOR, + GIMP_COLOR_PICKER_CURSOR, GIMP_LAST_CURSOR_ENTRY } GimpCursorType; void change_win_cursor (GdkWindow *, GdkCursorType); void unset_win_cursor (GdkWindow *); -void gimp_change_win_cursor (GdkWindow *, GimpCursorType); void gimp_add_busy_cursors_until_idle (void); void gimp_add_busy_cursors (void); diff --git a/cursors/dropper b/cursors/dropper new file mode 100644 index 0000000000..c6972632b2 --- /dev/null +++ b/cursors/dropper @@ -0,0 +1,11 @@ +#define dropper_width 22 +#define dropper_height 22 +#define dropper_x_hot 2 +#define dropper_y_hot 20 +static unsigned char dropper_bits[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc, + 0xff, 0x3f, 0xf8, 0xff, 0x3f, 0xf4, 0xff, 0x87, 0xf7, 0xff, 0x6f, 0xf7, + 0xff, 0x97, 0xf8, 0xff, 0x8b, 0xfe, 0xff, 0x65, 0xfe, 0xff, 0xb2, 0xfe, + 0x7f, 0xd9, 0xff, 0xbf, 0xec, 0xff, 0x5f, 0xf6, 0xff, 0x2f, 0xfb, 0xff, + 0x97, 0xfd, 0xff, 0xcb, 0xfe, 0xff, 0x6b, 0xff, 0xff, 0xbd, 0xff, 0xff, + 0xc7, 0xff, 0xff, 0xf7, 0xff, 0xff}; diff --git a/cursors/droppermsk b/cursors/droppermsk new file mode 100644 index 0000000000..2b6289b7bc --- /dev/null +++ b/cursors/droppermsk @@ -0,0 +1,9 @@ +#define droppermsk_width 22 +#define droppermsk_height 22 +static unsigned char droppermsk_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, + 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x0f, 0x00, 0xf8, 0x0f, 0x00, 0xf0, 0x0f, + 0x00, 0xf8, 0x07, 0x00, 0xfc, 0x01, 0x00, 0xfe, 0x01, 0x00, 0x7f, 0x01, + 0x80, 0x3f, 0x00, 0xc0, 0x1f, 0x00, 0xe0, 0x0f, 0x00, 0xf0, 0x07, 0x00, + 0xf8, 0x03, 0x00, 0xfc, 0x01, 0x00, 0xfc, 0x00, 0x00, 0x7e, 0x00, 0x00, + 0x3c, 0x00, 0x00, 0x08, 0x00, 0x00};