dropper-tool.cpp revision 7411554fef5193b20c0d988a51c44ef27a3866cb
/*
* Tool for picking colors from drawing
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Abhishek Sharma
*
* Copyright (C) 1999-2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gdk/gdkkeysyms.h>
#include "macros.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "display/cairo-utils.h"
#include "svg/svg-color.h"
#include "color.h"
#include "color-rgba.h"
#include "desktop-style.h"
#include "preferences.h"
#include "sp-namedview.h"
#include "sp-cursor.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
#include "document.h"
#include "document-undo.h"
#include "pixmaps/cursor-dropper-f.xpm"
#include "pixmaps/cursor-dropper-s.xpm"
#include "ui/tools/dropper-tool.h"
#include "message-context.h"
#include "verbs.h"
#include "ui/tools/tool-base.h"
using Inkscape::DocumentUndo;
#include "tool-factory.h"
namespace Inkscape {
namespace UI {
namespace Tools {
namespace {
return new DropperTool();
}
bool dropperContextRegistered = ToolFactory::instance().registerObject("/tools/dropper", createDropperContext);
}
return DropperTool::prefsPath;
}
this->R = 0;
this->G = 0;
this->B = 0;
this->alpha = 0;
this->dragging = false;
this->grabbed = 0;
this->area = 0;
this->cursor_shape = cursor_dropper_f_xpm;
this->hot_x = 7;
this->hot_y = 7;
}
DropperTool::~DropperTool() {
}
void DropperTool::setup() {
/* TODO: have a look at CalligraphicTool::setup where the same is done.. generalize? */
c->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_item_hide(this->area);
this->enableSelectionCue();
}
this->enableGrDrag();
}
}
void DropperTool::finish() {
this->enableGrDrag(false);
if (this->grabbed) {
}
if (this->area) {
sp_canvas_item_destroy(this->area);
}
if (cursor_dropper_fill) {
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
if (cursor_dropper_stroke) {
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
}
/**
* Returns the current dropper context color.
*/
return SP_RGBA32_F_COMPOSE(this->R,
this->G,
this->B,
}
case GDK_BUTTON_PRESS:
this->dragging = true;
}
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,
break;
case GDK_MOTION_NOTIFY:
// pass on middle and right drag
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
}
double rw = 0.0;
double R(0), G(0), B(0), A(0);
if (this->dragging) {
// calculate average
// radius
if (rw == 0) { // happens sometimes, little idea why...
break;
}
sp_canvas_item_show(this->area);
/* Get buffer */
if (!r.hasZeroArea()) {
ink_cairo_surface_average_color_premul(s, R, G, B, A);
}
} else {
// pick single pixel
Geom::IntRect area = Geom::IntRect::from_xywh(floor(event->button.x), floor(event->button.y), 1, 1);
ink_cairo_surface_average_color_premul(s, R, G, B, A);
}
if (pick == SP_DROPPER_PICK_VISIBLE) {
// compose with page color
A = 1.0;
} else {
// un-premultiply color channels
if (A > 0) {
R /= A;
G /= A;
B /= A;
}
}
if (fabs(A) < 1e-4) {
A = 0; // suppress exponentials, CSS does not allow that
}
// remember color
this->R = R;
this->G = G;
this->B = B;
this->alpha = A;
// status message
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
// 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 ? _("<b>Release mouse</b> to set color.") : _("<b>Click</b> to set fill, <b>Shift+click</b> to set stroke; <b>drag</b> to average color in area; with <b>Alt</b> to pick inverse color; <b>Ctrl+C</b> to copy the color under mouse to clipboard");
this->defaultMessageContext()->setF(
"<b>%s%s</b>%s. %s", c,
}
break;
case GDK_BUTTON_RELEASE:
sp_canvas_item_hide(this->area);
this->dragging = false;
if (this->grabbed) {
}
// "One time" pick from Fill/Stroke dialog stroke page, always apply fill or stroke (ignore <Shift> key)
}
// do the actual color setting
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!
}
_("Set picked color"));
}
}
}
break;
case GDK_KEY_PRESS:
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)) {
}
break;
case GDK_KEY_Escape:
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
}
break;
default:
break;
}
break;
case GDK_KEY_RELEASE:
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
}
break;
default:
break;
}
break;
default:
break;
}
if (!ret) {
}
return ret;
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :