dropper-context.cpp revision 1137482ecab2928952d08127515e9d0fc31a29d4
/*
* 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 "dropper-context.h"
#include "message-context.h"
#include "verbs.h"
#include "event-context.h"
using Inkscape::DocumentUndo;
//typedef struct
//{
// double R;
// double G;
// double B;
// double alpha;
//
// unsigned int dragging : 1;
//
// SPCanvasItem *grabbed;
// SPCanvasItem *area;
// Geom::Point centre;
//} SPDropperContextPrivate;
//
//#define SP_DROPPER_CONTEXT_GET_PRIVATE(dc) \
// G_TYPE_INSTANCE_GET_PRIVATE(dc, SP_TYPE_DROPPER_CONTEXT, SPDropperContextPrivate)
#include "tool-factory.h"
namespace {
return new SPDropperContext();
}
bool dropperContextRegistered = ToolFactory::instance().registerObject("/tools/dropper", createDropperContext);
}
return SPDropperContext::prefsPath;
}
SPDropperContext* dc = this;
dc->R = 0;
dc->G = 0;
dc->B = 0;
}
}
void SPDropperContext::setup() {
SPEventContext* ec = this;
// if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) {
// (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec);
// }
SPEventContext::setup();
/* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
const double C1 = 0.552;
c->moveto(-1,0);
c->closepath();
c->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(priv->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
ec->enableSelectionCue();
}
ec->enableGrDrag();
}
}
void SPDropperContext::finish() {
SPEventContext* ec = this;
ec->enableGrDrag(false);
}
}
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
}
//Inkscape::Preferences *prefs = Inkscape::Preferences::get();
//prefs->setBool("/tools/dropper/onetimepick", false);
}
/**
* Returns the current dropper context color.
*/
{
return SP_RGBA32_F_COMPOSE(priv->R,
priv->G,
priv->B,
: 1.0);
}
SPEventContext* event_context = this;
case GDK_BUTTON_PRESS:
}
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 (!event_context->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);
// calculate average
// radius
if (rw == 0) { // happens sometimes, little idea why...
break;
}
/* 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
priv->R = R;
priv->G = G;
priv->B = B;
// 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 = priv->dragging ? g_strdup_printf(_(", averaged with radius %d"), (int) rw) : g_strdup_printf(_(" under cursor"));
// message, to show in the statusbar
const gchar *message = priv->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");
"<b>%s%s</b>%s. %s", c,
);
}
break;
case GDK_BUTTON_RELEASE:
{
}
// "One time" pick from Fill/Stroke dialog stroke page, always apply fill or stroke (ignore <Shift> key)
}
// do the actual color setting
ColorRGBA(1 - priv->R, 1 - priv->G, 1 - priv->B, alpha_to_set) : ColorRGBA(priv->R, priv->G, priv->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) {
}
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) {
// if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) {
// ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event);
// }
}
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 :