dropper-context.cpp revision 3955580a5a68a873b098921626f5b9d841b964ec
#define __SP_DROPPER_CONTEXT_C__
/*
* Tool for picking colors from drawing
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* 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 <gtkmm/clipboard.h>
#include <gdk/gdkkeysyms.h>
#include "libnr/n-art-bpath.h"
#include "macros.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "svg/svg-color.h"
#include "color.h"
#include "color-rgba.h"
#include "desktop-style.h"
#include "prefs-utils.h"
#include "sp-namedview.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
#include "document.h"
#include "pixmaps/cursor-dropper.xpm"
#include "dropper-context.h"
#include "message-context.h"
#include "libnr/nr-scale-translate-ops.h"
#define C1 0.552
static NArtBpath const spdc_circle[] = {
{ NR_MOVETO, 0, 0, 0, 0, -1, 0 },
{ NR_END, 0, 0, 0, 0, 0, 0 }
};
static SPEventContextClass *parent_class;
{
if (!type) {
sizeof(SPDropperContextClass),
sizeof(SPDropperContext),
4,
NULL, /* value_table */
};
}
return type;
}
{
}
{
}
{
}
sp_curve_unref(c);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
ec->enableSelectionCue();
}
ec->enableGrDrag();
}
}
{
ec->enableGrDrag(false);
}
}
/**
* Copies the current context color to the clipboard.
*/
{
gchar c[64];
text += c;
{
}
}
/**
* Makes a copy of the current desktop color to the clipboard.
*/
{
gchar c[64];
text += c;
}
}
/**
* Makes a copy of the current color as a hex value. This should always compute
* the current color without alpha, but the on-screen representation.
*/
{
/*
int pick = prefs_get_int_attribute ("tools.dropper", "pick",
SP_DROPPER_PICK_VISIBLE);
if ( pick == SP_DROPPER_PICK_ACTUAL )
; // process c32 so that it computes against page
// else just can cut off that last 2 hex digits....
*/
gchar c[48];
text += c;
}
}
{
case GDK_BUTTON_PRESS:
}
break;
case GDK_MOTION_NOTIFY:
// pass on middle-drag
break;
} else if (!event_context->space_panning) {
// otherwise, constantly calculate color no matter is any button pressed or not
double rw = 0.0;
double W(0), R(0), G(0), B(0), A(0);
// calculate average
// radius
if (rw == 0) { // happens sometimes, little idea why...
break;
}
/* Get buffer */
/* fixme: (Lauris) */
W += w;
R += w * s[0];
G += w * s[1];
B += w * s[2];
A += w * s[3];
s += 4;
}
}
R = (R + 0.001) / (255.0 * W);
G = (G + 0.001) / (255.0 * W);
B = (B + 0.001) / (255.0 * W);
A = (A + 0.001) / (255.0 * W);
}
} else {
// pick single pixel
const unsigned char *s = NR_PIXBLOCK_PX(&pb);
R = s[0] / 255.0;
G = s[1] / 255.0;
B = s[2] / 255.0;
A = s[3] / 255.0;
}
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
dc->R = R;
dc->G = G;
dc->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 = dc->dragging ? g_strdup_printf(_(", averaged with radius %d"), (int) rw) : g_strdup_printf(_(" under cursor"));
// message, to show in the statusbar
const gchar *message = dc->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:
{
// do the actual color setting
ColorRGBA(1 - dc->R, 1 - dc->G, 1 - dc->B, alpha_to_set) : ColorRGBA(dc->R, dc->G, dc->B, alpha_to_set),
// REJON: set aux. toolbar input to hex color!
_("Set picked color"));
}
}
break;
case GDK_KEY_PRESS:
case GDK_Up:
case GDK_Down:
case GDK_KP_Up:
case GDK_KP_Down:
// prevent the zoom field from activation
if (!MOD__CTRL_ONLY) {
}
break;
case GDK_Escape:
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 :