From f55448431e934bf29bb9a983711d204614db7cc7 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 30 Jun 2017 05:58:14 +0200 Subject: Hackfest: Refactor cursors so the hot spot is inside the xpm --- src/ui/tools/dropper-tool.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ui/tools/dropper-tool.cpp') diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 99177dc75..bd341262b 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -60,7 +60,7 @@ const std::string& DropperTool::getPrefsPath() { const std::string DropperTool::prefsPath = "/tools/dropper"; DropperTool::DropperTool() - : ToolBase(cursor_dropper_f_xpm, 5, 5) + : ToolBase(cursor_dropper_f_xpm) , R(0) , G(0) , B(0) @@ -70,8 +70,8 @@ DropperTool::DropperTool() , area(NULL) , centre(0, 0) { - cursor_dropper_fill = sp_cursor_new_from_xpm(cursor_dropper_f_xpm , 5, 5); - cursor_dropper_stroke = sp_cursor_new_from_xpm(cursor_dropper_s_xpm , 5, 5); + cursor_dropper_fill = sp_cursor_from_xpm(cursor_dropper_f_xpm); + cursor_dropper_stroke = sp_cursor_from_xpm(cursor_dropper_s_xpm); } DropperTool::~DropperTool() { -- cgit v1.2.3 From c4243660541b1b36d24048d4296bc3d5b5bf6d94 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 30 Jun 2017 06:49:48 +0200 Subject: Hackfest: Show dropper color in cursor, while moving the mouse. --- src/ui/tools/dropper-tool.cpp | 73 ++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) (limited to 'src/ui/tools/dropper-tool.cpp') diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index bd341262b..a409e249e 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -46,9 +46,6 @@ using Inkscape::DocumentUndo; -static GdkCursor *cursor_dropper_fill = NULL; -static GdkCursor *cursor_dropper_stroke = NULL; - namespace Inkscape { namespace UI { namespace Tools { @@ -70,8 +67,6 @@ DropperTool::DropperTool() , area(NULL) , centre(0, 0) { - cursor_dropper_fill = sp_cursor_from_xpm(cursor_dropper_f_xpm); - cursor_dropper_stroke = sp_cursor_from_xpm(cursor_dropper_s_xpm); } DropperTool::~DropperTool() { @@ -117,16 +112,6 @@ void DropperTool::finish() { this->area = NULL; } - if (cursor_dropper_fill) { - g_object_unref(cursor_dropper_fill); - cursor_dropper_fill = NULL; - } - - if (cursor_dropper_stroke) { - g_object_unref(cursor_dropper_stroke); - cursor_dropper_fill = NULL; - } - ToolBase::finish(); } @@ -149,6 +134,7 @@ bool DropperTool::root_handler(GdkEvent* event) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int ret = FALSE; + int draw_cursor = DONT_REDRAW_CURSOR; int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE); bool setalpha = prefs->getBool("/tools/dropper/setalpha", true); @@ -174,14 +160,6 @@ bool DropperTool::root_handler(GdkEvent* event) { break; } else if (!this->space_panning) { // otherwise, constantly calculate color no matter is any button pressed or not - - // If one time pick with stroke set the pixmap - if (prefs->getBool("/tools/dropper/onetimepick", false) && prefs->getInt("/dialogs/fillstroke/page", 0) == 1) { - //TODO Only set when not set already - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); - gdk_window_set_cursor(window, cursor_dropper_stroke); - } - double rw = 0.0; double R(0), G(0), B(0), A(0); @@ -242,10 +220,17 @@ bool DropperTool::root_handler(GdkEvent* event) { } // remember color - this->R = R; - this->G = G; - this->B = B; - this->alpha = A; + if(R != this->R || G != this->G || B != this->B || A != this->alpha) { + this->R = R; + this->G = G; + this->B = B; + this->alpha = A; + if(!(event->button.state & GDK_SHIFT_MASK)) { + draw_cursor = DRAW_FILL_CURSOR; + } else { + draw_cursor = DRAW_STROKE_CURSOR; + } + } // status message double alpha_to_set = setalpha? this->alpha : 1.0; @@ -278,11 +263,10 @@ bool DropperTool::root_handler(GdkEvent* event) { if (event->button.button == 1 && !this->space_panning) { sp_canvas_item_hide(this->area); this->dragging = false; - - if (this->grabbed) { - sp_canvas_item_ungrab(this->grabbed, event->button.time); - this->grabbed = NULL; - } + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; + } double alpha_to_set = setalpha? this->alpha : 1.0; @@ -302,8 +286,7 @@ bool DropperTool::root_handler(GdkEvent* event) { // REJON: set aux. toolbar input to hex color! if (event->button.state & GDK_SHIFT_MASK) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); - gdk_window_set_cursor(window, cursor_dropper_stroke); + draw_cursor = DRAW_STROKE_CURSOR; } if (!(desktop->getSelection()->isEmpty())) { @@ -340,11 +323,7 @@ bool DropperTool::root_handler(GdkEvent* event) { desktop->getSelection()->clear(); case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - if (!desktop->isWaitingCursor() && !prefs->getBool("/tools/dropper/onetimepick", false)) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); - gdk_window_set_cursor(window, cursor_dropper_stroke); - } - + draw_cursor = DRAW_STROKE_CURSOR; break; default: break; @@ -355,10 +334,7 @@ bool DropperTool::root_handler(GdkEvent* event) { switch (get_group0_keyval(&event->key)) { case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - if (!desktop->isWaitingCursor() && !prefs->getBool("/tools/dropper/onetimepick", false)) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); - gdk_window_set_cursor(window, cursor_dropper_fill); - } + draw_cursor = DRAW_FILL_CURSOR; break; default: @@ -370,6 +346,17 @@ bool DropperTool::root_handler(GdkEvent* event) { break; } + if(draw_cursor != DONT_REDRAW_CURSOR && !desktop->isWaitingCursor() && !prefs->getBool("/tools/dropper/onetimepick", false)) { + GdkCursor *cursor; + if(draw_cursor == DRAW_FILL_CURSOR) { + cursor = sp_cursor_from_xpm(cursor_dropper_f_xpm, NULL, NULL, this->get_color()); + } else if(draw_cursor == DRAW_STROKE_CURSOR) { + cursor = sp_cursor_from_xpm(cursor_dropper_s_xpm, NULL, NULL, this->get_color()); + } + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); + gdk_window_set_cursor(window, cursor); + } + if (!ret) { ret = ToolBase::root_handler(event); } -- cgit v1.2.3 From 0848c709fc65a83c22cab9f10c73b1fa0c1196ef Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 30 Jun 2017 17:41:17 +0200 Subject: Hackfest: Add start of dropping tool --- src/ui/tools/dropper-tool.cpp | 108 ++++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 35 deletions(-) (limited to 'src/ui/tools/dropper-tool.cpp') diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index a409e249e..4524d2445 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -39,6 +39,8 @@ #include "pixmaps/cursor-dropper-f.xpm" #include "pixmaps/cursor-dropper-s.xpm" +#include "pixmaps/cursor-dropping-f.xpm" +#include "pixmaps/cursor-dropping-s.xpm" #include "ui/tools/dropper-tool.h" #include "message-context.h" @@ -134,10 +136,29 @@ bool DropperTool::root_handler(GdkEvent* event) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int ret = FALSE; - int draw_cursor = DONT_REDRAW_CURSOR; - int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE); bool setalpha = prefs->getBool("/tools/dropper/setalpha", true); + bool fill = !(event->button.state & GDK_SHIFT_MASK); // Stroke if Shift key held + bool apply = event->button.state & GDK_CONTROL_MASK; // Apply if Ctrl key held + int draw_cursor = fill ? DRAW_FILL_CURSOR : DRAW_STROKE_CURSOR; + + // Get color from selected object instead. + guint32 apply_color = 0; + if(apply) { + Inkscape::Selection *selection = desktop->getSelection(); + g_assert(selection); + for (auto& obj: selection->objects()) { + if(obj->style) { + if(obj->style->fill.set) { + double opacity = 1.0; + if(obj->style->fill_opacity.set) { + opacity = obj->style->fill_opacity.value; + } + apply_color = obj->style->fill.value.color.toRGBA32(opacity); + } + } + } + } switch (event->type) { case GDK_BUTTON_PRESS: @@ -146,11 +167,12 @@ bool DropperTool::root_handler(GdkEvent* event) { this->dragging = true; ret = TRUE; } - - sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), - GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, - NULL, event->button.time); - this->grabbed = SP_CANVAS_ITEM(desktop->acetate); + + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, + NULL, event->button.time); + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); break; case GDK_MOTION_NOTIFY: @@ -225,11 +247,6 @@ bool DropperTool::root_handler(GdkEvent* event) { this->G = G; this->B = B; this->alpha = A; - if(!(event->button.state & GDK_SHIFT_MASK)) { - draw_cursor = DRAW_FILL_CURSOR; - } else { - draw_cursor = DRAW_STROKE_CURSOR; - } } // status message @@ -261,34 +278,47 @@ bool DropperTool::root_handler(GdkEvent* event) { case GDK_BUTTON_RELEASE: if (event->button.button == 1 && !this->space_panning) { - sp_canvas_item_hide(this->area); - this->dragging = false; - if (this->grabbed) { - sp_canvas_item_ungrab(this->grabbed, event->button.time); - this->grabbed = NULL; - } - double alpha_to_set = setalpha? this->alpha : 1.0; + sp_canvas_item_hide(this->area); + this->dragging = false; + + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; + } + + if(apply) { + Geom::Point const button_w(event->button.x, event->button.y); + // remember clicked item, disregarding groups, honoring Alt + this->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE); + + // Change selected object to object under cursor + if (this->item_to_select) { + Inkscape::Selection *selection = desktop->getSelection(); + g_assert(selection); + selection->set(this->item_to_select); + } - bool fill = !(event->button.state & GDK_SHIFT_MASK); // Stroke if Shift key held + this->R = SP_RGBA32_R_F(apply_color); + this->G = SP_RGBA32_G_F(apply_color); + this->B = SP_RGBA32_B_F(apply_color); + this->alpha = SP_RGBA32_A_F(apply_color); + alpha_to_set = this->alpha; - if (prefs->getBool("/tools/dropper/onetimepick", false)) { - // "One time" pick from Fill/Stroke dialog stroke page, always apply fill or stroke (ignore key) - fill = (prefs->getInt("/dialogs/fillstroke/page", 0) == 0) ? true : false; + } else { + if (prefs->getBool("/tools/dropper/onetimepick", false)) { + // "One time" pick from Fill/Stroke dialog stroke page, always apply fill or stroke (ignore key) + fill = (prefs->getInt("/dialogs/fillstroke/page", 0) == 0) ? true : false; + } } // do the actual color setting sp_desktop_set_color(desktop, - (event->button.state & GDK_MOD1_MASK)? - ColorRGBA(1 - this->R, 1 - this->G, 1 - this->B, alpha_to_set) : ColorRGBA(this->R, this->G, this->B, alpha_to_set), - false, fill); + (event->button.state & GDK_MOD1_MASK)? + ColorRGBA(1 - this->R, 1 - this->G, 1 - this->B, alpha_to_set) : ColorRGBA(this->R, this->G, this->B, alpha_to_set), + false, fill); // REJON: set aux. toolbar input to hex color! - - if (event->button.state & GDK_SHIFT_MASK) { - draw_cursor = DRAW_STROKE_CURSOR; - } - if (!(desktop->getSelection()->isEmpty())) { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_DROPPER, _("Set picked color")); @@ -348,10 +378,18 @@ bool DropperTool::root_handler(GdkEvent* event) { if(draw_cursor != DONT_REDRAW_CURSOR && !desktop->isWaitingCursor() && !prefs->getBool("/tools/dropper/onetimepick", false)) { GdkCursor *cursor; - if(draw_cursor == DRAW_FILL_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropper_f_xpm, NULL, NULL, this->get_color()); - } else if(draw_cursor == DRAW_STROKE_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropper_s_xpm, NULL, NULL, this->get_color()); + if(apply) { + if(draw_cursor == DRAW_FILL_CURSOR) { + cursor = sp_cursor_from_xpm(cursor_dropping_f_xpm, NULL, NULL, apply_color); + } else if(draw_cursor == DRAW_STROKE_CURSOR) { + cursor = sp_cursor_from_xpm(cursor_dropping_s_xpm, NULL, NULL, apply_color); + } + } else { + if(draw_cursor == DRAW_FILL_CURSOR) { + cursor = sp_cursor_from_xpm(cursor_dropper_f_xpm, NULL, NULL, this->get_color()); + } else if(draw_cursor == DRAW_STROKE_CURSOR) { + cursor = sp_cursor_from_xpm(cursor_dropper_s_xpm, NULL, NULL, this->get_color()); + } } GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); gdk_window_set_cursor(window, cursor); -- cgit v1.2.3 From 58f3f347f828b8bfe0fb01ba3194ee5ec3a8c961 Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Thu, 6 Jul 2017 00:57:09 +0200 Subject: cursors: rm deprecated gtkstyle custom black/white --- src/ui/tools/dropper-tool.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ui/tools/dropper-tool.cpp') diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 4524d2445..9b37aed17 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -380,15 +380,15 @@ bool DropperTool::root_handler(GdkEvent* event) { GdkCursor *cursor; if(apply) { if(draw_cursor == DRAW_FILL_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropping_f_xpm, NULL, NULL, apply_color); + cursor = sp_cursor_from_xpm(cursor_dropping_f_xpm, apply_color); } else if(draw_cursor == DRAW_STROKE_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropping_s_xpm, NULL, NULL, apply_color); + cursor = sp_cursor_from_xpm(cursor_dropping_s_xpm, apply_color); } } else { if(draw_cursor == DRAW_FILL_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropper_f_xpm, NULL, NULL, this->get_color()); + cursor = sp_cursor_from_xpm(cursor_dropper_f_xpm, this->get_color()); } else if(draw_cursor == DRAW_STROKE_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropper_s_xpm, NULL, NULL, this->get_color()); + cursor = sp_cursor_from_xpm(cursor_dropper_s_xpm, this->get_color()); } } GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); -- cgit v1.2.3 From 81f8acdd523508c1006e9041590152aff86f6075 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 5 Jul 2017 19:27:24 -0400 Subject: Upgrade dropper with fixed for each of the modes --- src/ui/tools/dropper-tool.cpp | 204 ++++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 105 deletions(-) (limited to 'src/ui/tools/dropper-tool.cpp') diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 9b37aed17..53a99e481 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -64,6 +64,10 @@ DropperTool::DropperTool() , G(0) , B(0) , alpha(0) + , radius(0) + , invert(false) + , stroke(false) + , dropping(false) , dragging(false) , grabbed(NULL) , area(NULL) @@ -120,16 +124,17 @@ void DropperTool::finish() { /** * Returns the current dropper context color. */ -guint32 DropperTool::get_color() { +guint32 DropperTool::get_color(bool invert) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE); bool setalpha = prefs->getBool("/tools/dropper/setalpha", true); - return SP_RGBA32_F_COMPOSE(this->R, - this->G, - this->B, - (pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? this->alpha : 1.0); + return SP_RGBA32_F_COMPOSE( + fabs(invert - this->R), + fabs(invert - this->G), + fabs(invert - this->B), + (pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? this->alpha : 1.0); } bool DropperTool::root_handler(GdkEvent* event) { @@ -137,26 +142,58 @@ bool DropperTool::root_handler(GdkEvent* event) { int ret = FALSE; int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE); - bool setalpha = prefs->getBool("/tools/dropper/setalpha", true); - bool fill = !(event->button.state & GDK_SHIFT_MASK); // Stroke if Shift key held - bool apply = event->button.state & GDK_CONTROL_MASK; // Apply if Ctrl key held - int draw_cursor = fill ? DRAW_FILL_CURSOR : DRAW_STROKE_CURSOR; + + // Decide first what kind of 'mode' we're in. + if (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE) { + switch (event->key.keyval) { + case GDK_KEY_Shift_L: + case GDK_KEY_Shift_R: + this->stroke = event->type == GDK_KEY_PRESS; + break; + case GDK_KEY_Control_L: + case GDK_KEY_Control_R: + this->dropping = event->type == GDK_KEY_PRESS; + break; + case GDK_KEY_Alt_L: + case GDK_KEY_Alt_R: + this->invert = event->type == GDK_KEY_PRESS; + break; + } + } // Get color from selected object instead. - guint32 apply_color = 0; - if(apply) { + if(this->dropping) { Inkscape::Selection *selection = desktop->getSelection(); g_assert(selection); + guint32 apply_color; + bool apply_set = false; for (auto& obj: selection->objects()) { - if(obj->style) { - if(obj->style->fill.set) { - double opacity = 1.0; - if(obj->style->fill_opacity.set) { - opacity = obj->style->fill_opacity.value; - } - apply_color = obj->style->fill.value.color.toRGBA32(opacity); + if(obj->style) { + double opacity = 1.0; + if(!this->stroke && obj->style->fill.set) { + if(obj->style->fill_opacity.set) { + opacity = obj->style->fill_opacity.value; + } + apply_color = obj->style->fill.value.color.toRGBA32(opacity); + apply_set = true; + } else if(this->stroke && obj->style->stroke.set) { + if(obj->style->stroke_opacity.set) { + opacity = obj->style->stroke_opacity.value; + } + apply_color = obj->style->stroke.value.color.toRGBA32(opacity); + apply_set = true; + } } - } + } + if(apply_set) { + this->R = SP_RGBA32_R_F(apply_color); + this->G = SP_RGBA32_G_F(apply_color); + this->B = SP_RGBA32_B_F(apply_color); + this->alpha = SP_RGBA32_A_F(apply_color); + } else { + // This means that having no selection or some other error + // we will default back to normal dropper mode. + this->dropping = false; } } @@ -190,10 +227,10 @@ bool DropperTool::root_handler(GdkEvent* event) { // radius rw = std::min(Geom::L2(Geom::Point(event->button.x, event->button.y) - this->centre), 400.0); - if (rw == 0) { // happens sometimes, little idea why... break; } + this->radius = rw; Geom::Point const cd = desktop->w2d(this->centre); Geom::Affine const w2dt = desktop->w2d(); @@ -242,43 +279,18 @@ bool DropperTool::root_handler(GdkEvent* event) { } // remember color - if(R != this->R || G != this->G || B != this->B || A != this->alpha) { + if(!this->dropping && (R != this->R || G != this->G || B != this->B || A != this->alpha)) { this->R = R; this->G = G; this->B = B; this->alpha = A; } - - // status message - double alpha_to_set = setalpha? this->alpha : 1.0; - guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, alpha_to_set); - - gchar c[64]; - sp_svg_write_color(c, sizeof(c), c32); - - // alpha of color under cursor, to show in the statusbar - // locale-sensitive printf is OK, since this goes to the UI, not into SVG - gchar *alpha = g_strdup_printf(_(" alpha %.3g"), alpha_to_set); - // where the color is picked, to show in the statusbar - gchar *where = this->dragging ? g_strdup_printf(_(", averaged with radius %d"), (int) rw) : g_strdup_printf("%s", _(" under cursor")); - // message, to show in the statusbar - const gchar *message = this->dragging ? _("Release mouse to set color.") : _("Click to set fill, Shift+click to set stroke; drag to average color in area; with Alt to pick inverse color; Ctrl+C to copy the color under mouse to clipboard"); - - this->defaultMessageContext()->setF( - Inkscape::NORMAL_MESSAGE, - "%s%s%s. %s", c, - (pick == SP_DROPPER_PICK_VISIBLE) ? "" : alpha, where, message); - - g_free(where); - g_free(alpha); - ret = TRUE; } break; case GDK_BUTTON_RELEASE: if (event->button.button == 1 && !this->space_panning) { - double alpha_to_set = setalpha? this->alpha : 1.0; sp_canvas_item_hide(this->area); this->dragging = false; @@ -287,42 +299,37 @@ bool DropperTool::root_handler(GdkEvent* event) { this->grabbed = NULL; } - if(apply) { + Inkscape::Selection *selection = desktop->getSelection(); + g_assert(selection); + std::vector old_selection(selection->items().begin(), selection->items().end()); + if(this->dropping) { Geom::Point const button_w(event->button.x, event->button.y); // remember clicked item, disregarding groups, honoring Alt this->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE); // Change selected object to object under cursor if (this->item_to_select) { - Inkscape::Selection *selection = desktop->getSelection(); - g_assert(selection); + std::vector vec(selection->items().begin(), selection->items().end()); selection->set(this->item_to_select); } - - this->R = SP_RGBA32_R_F(apply_color); - this->G = SP_RGBA32_G_F(apply_color); - this->B = SP_RGBA32_B_F(apply_color); - this->alpha = SP_RGBA32_A_F(apply_color); - alpha_to_set = this->alpha; - } else { if (prefs->getBool("/tools/dropper/onetimepick", false)) { // "One time" pick from Fill/Stroke dialog stroke page, always apply fill or stroke (ignore key) - fill = (prefs->getInt("/dialogs/fillstroke/page", 0) == 0) ? true : false; + //fill = (prefs->getInt("/dialogs/fillstroke/page", 0) == 0) ? true : false; } } // do the actual color setting - sp_desktop_set_color(desktop, - (event->button.state & GDK_MOD1_MASK)? - ColorRGBA(1 - this->R, 1 - this->G, 1 - this->B, alpha_to_set) : ColorRGBA(this->R, this->G, this->B, alpha_to_set), - false, fill); + sp_desktop_set_color(desktop, ColorRGBA(this->get_color(this->invert)), false, !this->stroke); // REJON: set aux. toolbar input to hex color! if (!(desktop->getSelection()->isEmpty())) { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_DROPPER, _("Set picked color")); } + if(this->dropping) { + selection->setList(old_selection); + } if (prefs->getBool("/tools/dropper/onetimepick", false)) { prefs->setBool("/tools/dropper/onetimepick", false); @@ -339,61 +346,48 @@ bool DropperTool::root_handler(GdkEvent* event) { case GDK_KEY_PRESS: switch (get_group0_keyval(&event->key)) { - case GDK_KEY_Up: - case GDK_KEY_Down: - case GDK_KEY_KP_Up: - case GDK_KEY_KP_Down: + case GDK_KEY_Up: + case GDK_KEY_Down: + case GDK_KEY_KP_Up: + case GDK_KEY_KP_Down: // prevent the zoom field from activation if (!MOD__CTRL_ONLY(event)) { ret = TRUE; } break; - - case GDK_KEY_Escape: + case GDK_KEY_Escape: desktop->getSelection()->clear(); - case GDK_KEY_Shift_L: - case GDK_KEY_Shift_R: - draw_cursor = DRAW_STROKE_CURSOR; - break; - default: break; } break; - - case GDK_KEY_RELEASE: - switch (get_group0_keyval(&event->key)) { - case GDK_KEY_Shift_L: - case GDK_KEY_Shift_R: - draw_cursor = DRAW_FILL_CURSOR; - break; - - default: - break; - } - break; - - default: - break; } - if(draw_cursor != DONT_REDRAW_CURSOR && !desktop->isWaitingCursor() && !prefs->getBool("/tools/dropper/onetimepick", false)) { - GdkCursor *cursor; - if(apply) { - if(draw_cursor == DRAW_FILL_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropping_f_xpm, apply_color); - } else if(draw_cursor == DRAW_STROKE_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropping_s_xpm, apply_color); - } - } else { - if(draw_cursor == DRAW_FILL_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropper_f_xpm, this->get_color()); - } else if(draw_cursor == DRAW_STROKE_CURSOR) { - cursor = sp_cursor_from_xpm(cursor_dropper_s_xpm, this->get_color()); - } - } - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); - gdk_window_set_cursor(window, cursor); - } + // set the status message to the right text. + gchar c[64]; + sp_svg_write_color(c, sizeof(c), this->get_color(this->invert)); + + // alpha of color under cursor, to show in the statusbar + // locale-sensitive printf is OK, since this goes to the UI, not into SVG + gchar *alpha = g_strdup_printf(_(" alpha %.3g"), this->alpha); + // where the color is picked, to show in the statusbar + gchar *where = this->dragging ? g_strdup_printf(_(", averaged with radius %d"), (int) this->radius) : g_strdup_printf("%s", _(" under cursor")); + // message, to show in the statusbar + const gchar *message = this->dragging ? _("Release mouse to set color.") : _("Click to set fill, Shift+click to set stroke; drag to average color in area; with Alt to pick inverse color; Ctrl+C to copy the color under mouse to clipboard"); + + this->defaultMessageContext()->setF( + Inkscape::NORMAL_MESSAGE, + "%s%s%s. %s", c, + (pick == SP_DROPPER_PICK_VISIBLE) ? "" : alpha, where, message); + + g_free(where); + g_free(alpha); + + // Set the right cursor for the mode and apply the special Fill color + auto xpm = (this->dropping ? (this->stroke ? cursor_dropping_s_xpm : cursor_dropping_f_xpm) : + (this->stroke ? cursor_dropper_s_xpm : cursor_dropper_f_xpm)); + GdkCursor *cursor = sp_cursor_from_xpm(xpm, this->get_color(this->invert)); + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); + gdk_window_set_cursor(window, cursor); if (!ret) { ret = ToolBase::root_handler(event); -- cgit v1.2.3