43
42
#include "dropper-context.h"
44
43
#include "message-context.h"
45
#include "libnr/nr-scale-translate-ops.h"
48
static NArtBpath const spdc_circle[] = {
49
{ NR_MOVETO, 0, 0, 0, 0, -1, 0 },
50
{ NR_CURVETO, -1, C1, -C1, 1, 0, 1 },
51
{ NR_CURVETO, C1, 1, 1, C1, 1, 0 },
52
{ NR_CURVETO, 1, -C1, C1, -1, 0, -1 },
53
{ NR_CURVETO, -C1, -1, -1, -C1, -1, 0 },
54
{ NR_END, 0, 0, 0, 0, 0, 0 }
44
//#include "libnr/nr-scale-translate-ops.h"
58
46
static void sp_dropper_context_class_init(SPDropperContextClass *klass);
59
47
static void sp_dropper_context_init(SPDropperContext *dc);
111
99
((SPEventContextClass *) parent_class)->setup(ec);
114
SPCurve *c = sp_curve_new_from_foreign_bpath(spdc_circle);
102
/* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
103
SPCurve *c = new SPCurve();
104
const double C1 = 0.552;
106
c->curveto(-1, C1, -C1, 1, 0, 1 );
107
c->curveto(C1, 1, 1, C1, 1, 0 );
108
c->curveto(1, -C1, C1, -1, 0, -1 );
109
c->curveto(-C1, -1, -1, -C1, -1, 0 );
115
111
dc->area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c);
117
113
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(dc->area), 0x00000000,(SPWindRule)0);
118
114
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
119
115
sp_canvas_item_hide(dc->area);
121
if (prefs_get_int_attribute("tools.dropper", "selcue", 0) != 0) {
117
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
118
if (prefs->getBool("/tools/dropper/selcue")) {
122
119
ec->enableSelectionCue();
125
if (prefs_get_int_attribute("tools.dropper", "gradientdrag", 0) != 0) {
122
if (prefs->getBool("/tools/dropper/gradientdrag")) {
126
123
ec->enableGrDrag();
144
* Copies the current context color to the clipboard.
141
* Returns the current dropper context color.
146
void sp_dropper_context_copy(SPEventContext *ec)
143
guint32 sp_dropper_context_get_color(SPEventContext *ec)
148
145
SPDropperContext *dc = SP_DROPPER_CONTEXT(ec);
150
guint32 const c32 = SP_RGBA32_F_COMPOSE(dc->R, dc->G, dc->B, dc->alpha);
152
int pick = prefs_get_int_attribute("tools.dropper", "pick",
146
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
148
int pick = prefs->getInt("/tools/dropper/pick",
153
149
SP_DROPPER_PICK_VISIBLE);
155
int setalpha = prefs_get_int_attribute("tools.dropper", "setalpha", 1);
158
g_snprintf(c, 64, "%06x%02x", c32 >> 8,
159
(pick == SP_DROPPER_PICK_ACTUAL && setalpha)? SP_COLOR_F_TO_U(dc->alpha) : 255);
165
Glib::RefPtr<Gtk::Clipboard> refClipboard =
166
Gtk::Clipboard::get();
167
refClipboard->set_text(text);
172
* Makes a copy of the current desktop color to the clipboard.
174
void sp_dropper_c32_color_copy(guint32 c32)
176
int const pick = prefs_get_int_attribute("tools.dropper", "pick",
177
SP_DROPPER_PICK_VISIBLE);
180
g_snprintf(c, 64, "%06x%02x", c32 >> 8,
181
pick == SP_DROPPER_PICK_ACTUAL? SP_RGBA32_A_U(c32) : 255);
186
Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
187
refClipboard->set_text(text);
193
* Makes a copy of the current color as a hex value. This should always compute
194
* the current color without alpha, but the on-screen representation.
196
void sp_dropper_c32_color_copy_hex(guint32 c32)
199
int pick = prefs_get_int_attribute ("tools.dropper", "pick",
200
SP_DROPPER_PICK_VISIBLE);
202
if ( pick == SP_DROPPER_PICK_ACTUAL )
203
; // process c32 so that it computes against page
204
// else just can cut off that last 2 hex digits....
209
g_snprintf(c, 48, "%06x", c32 >> 8);
214
Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
215
refClipboard->set_text(text);
150
bool setalpha = prefs->getBool("/tools/dropper/setalpha", true);
152
return SP_RGBA32_F_COMPOSE(dc->R, dc->G, dc->B,
153
(pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? dc->alpha : 1.0);
222
159
SPDropperContext *dc = (SPDropperContext *) event_context;
224
161
SPDesktop *desktop = event_context->desktop;
162
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
226
int pick = prefs_get_int_attribute("tools.dropper", "pick", SP_DROPPER_PICK_VISIBLE);
227
int setalpha = prefs_get_int_attribute("tools.dropper", "setalpha", 1);
164
int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE);
165
bool setalpha = prefs->getBool("/tools/dropper/setalpha", true);
229
167
switch (event->type) {
230
168
case GDK_BUTTON_PRESS:
231
169
if (event->button.button == 1 && !event_context->space_panning) {
232
dc->centre = NR::Point(event->button.x, event->button.y);
170
dc->centre = Geom::Point(event->button.x, event->button.y);
233
171
dc->dragging = TRUE;
249
187
// calculate average
252
rw = std::min(NR::L2(NR::Point(event->button.x, event->button.y) - dc->centre), 400.0);
190
rw = std::min(Geom::L2(Geom::Point(event->button.x, event->button.y) - dc->centre), 400.0);
254
192
if (rw == 0) { // happens sometimes, little idea why...
258
NR::Point const cd = desktop->w2d(dc->centre);
259
NR::Matrix const w2dt = desktop->w2d();
260
const double scale = rw * NR_MATRIX_DF_EXPANSION(&w2dt);
261
NR::Matrix const sm( NR::scale(scale, scale) * NR::translate(cd) );
196
Geom::Point const cd = desktop->w2d(dc->centre);
197
Geom::Matrix const w2dt = desktop->w2d();
198
const double scale = rw * w2dt.descrim();
199
Geom::Matrix const sm( Geom::Scale(scale, scale) * Geom::Translate(cd) );
262
200
sp_canvas_item_affine_absolute(dc->area, sm);
263
201
sp_canvas_item_show(dc->area);
266
const int x0 = (int) floor(dc->centre[NR::X] - rw);
267
const int y0 = (int) floor(dc->centre[NR::Y] - rw);
268
const int x1 = (int) ceil(dc->centre[NR::X] + rw);
269
const int y1 = (int) ceil(dc->centre[NR::Y] + rw);
204
const int x0 = (int) floor(dc->centre[Geom::X] - rw);
205
const int y0 = (int) floor(dc->centre[Geom::Y] - rw);
206
const int x1 = (int) ceil(dc->centre[Geom::X] + rw);
207
const int y1 = (int) ceil(dc->centre[Geom::Y] + rw);
271
209
if ((x1 > x0) && (y1 > y0)) {
276
214
for (int y = y0; y < y1; y++) {
277
215
const unsigned char *s = NR_PIXBLOCK_PX(&pb) + (y - y0) * pb.rs;
278
216
for (int x = x0; x < x1; x++) {
279
const double dx = x - dc->centre[NR::X];
280
const double dy = y - dc->centre[NR::Y];
217
const double dx = x - dc->centre[Geom::X];
218
const double dy = y - dc->centre[Geom::Y];
281
219
const double w = exp(-((dx * dx) + (dy * dy)) / (rw * rw));