index 5c11aa50c5a554b0c3cfc118214bd5e6641b8ae9..b7344889ff67836fe81fac969ca6db79a291d001 100644 (file)
--- a/src/dropper-context.cpp
+++ b/src/dropper-context.cpp
-#define __SP_DROPPER_CONTEXT_C__
-
/*
* 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
*
#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 "color.h"
#include "color-rgba.h"
#include "desktop-style.h"
-#include "prefs-utils.h"
+#include "preferences.h"
#include "sp-namedview.h"
#include "desktop.h"
#include "desktop-handles.h"
#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_CURVETO, -1, C1, -C1, 1, 0, 1 },
- { NR_CURVETO, C1, 1, 1, C1, 1, 0 },
- { NR_CURVETO, 1, -C1, C1, -1, 0, -1 },
- { NR_CURVETO, -C1, -1, -1, -C1, -1, 0 },
- { NR_END, 0, 0, 0, 0, 0, 0 }
-};
-#undef C1
+//#include "libnr/nr-scale-translate-ops.h"
+
+using Inkscape::DocumentUndo;
static void sp_dropper_context_class_init(SPDropperContextClass *klass);
static void sp_dropper_context_init(SPDropperContext *dc);
((SPEventContextClass *) parent_class)->setup(ec);
}
- SPCurve *c = sp_curve_new_from_foreign_bpath(spdc_circle);
+ /* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
+ SPCurve *c = new SPCurve();
+ const double C1 = 0.552;
+ c->moveto(-1,0);
+ c->curveto(-1, C1, -C1, 1, 0, 1 );
+ c->curveto(C1, 1, 1, C1, 1, 0 );
+ c->curveto(1, -C1, C1, -1, 0, -1 );
+ c->curveto(-C1, -1, -1, -C1, -1, 0 );
+ c->closepath();
dc->area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c);
- sp_curve_unref(c);
+ c->unref();
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(dc->area), 0x00000000,(SPWindRule)0);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_item_hide(dc->area);
- if (prefs_get_int_attribute("tools.dropper", "selcue", 0) != 0) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ if (prefs->getBool("/tools/dropper/selcue")) {
ec->enableSelectionCue();
}
- if (prefs_get_int_attribute("tools.dropper", "gradientdrag", 0) != 0) {
+ if (prefs->getBool("/tools/dropper/gradientdrag")) {
ec->enableGrDrag();
}
}
SPDropperContext *dc = SP_DROPPER_CONTEXT(ec);
ec->enableGrDrag(false);
+
+ if (dc->grabbed) {
+ sp_canvas_item_ungrab(dc->grabbed, GDK_CURRENT_TIME);
+ dc->grabbed = NULL;
+ }
if (dc->area) {
gtk_object_destroy(GTK_OBJECT(dc->area));
/**
- * Copies the current context color to the clipboard.
+ * Returns the current dropper context icc-color.
*/
-void sp_dropper_context_copy(SPEventContext *ec)
+SPColor* sp_dropper_context_get_icc_color(SPEventContext */*ec*/)
{
- SPDropperContext *dc = SP_DROPPER_CONTEXT(ec);
-
- guint32 const c32 = SP_RGBA32_F_COMPOSE(dc->R, dc->G, dc->B, dc->alpha);
-
- int pick = prefs_get_int_attribute("tools.dropper", "pick",
- SP_DROPPER_PICK_VISIBLE);
-
- int setalpha = prefs_get_int_attribute("tools.dropper", "setalpha", 1);
-
- gchar c[64];
- g_snprintf(c, 64, "%06x%02x", c32 >> 8,
- (pick == SP_DROPPER_PICK_ACTUAL && setalpha)? SP_COLOR_F_TO_U(dc->alpha) : 255);
-
- Glib::ustring text;
- text += c;
- if (!text.empty())
- {
- Glib::RefPtr<Gtk::Clipboard> refClipboard =
- Gtk::Clipboard::get();
- refClipboard->set_text(text);
- }
-}
+ //TODO: implement-me!
-/**
- * Makes a copy of the current desktop color to the clipboard.
- */
-void sp_dropper_c32_color_copy(guint32 c32)
-{
- int const pick = prefs_get_int_attribute("tools.dropper", "pick",
- SP_DROPPER_PICK_VISIBLE);
-
- gchar c[64];
- g_snprintf(c, 64, "%06x%02x", c32 >> 8,
- pick == SP_DROPPER_PICK_ACTUAL? SP_RGBA32_A_U(c32) : 255);
-
- Glib::ustring text;
- text += c;
- if (!text.empty()) {
- Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
- refClipboard->set_text(text);
- }
+ return 0; // At least we will cause a clean crash, instead of random corruption.
}
-
/**
- * 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.
+ * Returns the current dropper context color.
*/
-void sp_dropper_c32_color_copy_hex(guint32 c32)
+guint32 sp_dropper_context_get_color(SPEventContext *ec)
{
- /*
- 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....
-
- */
+ SPDropperContext *dc = SP_DROPPER_CONTEXT(ec);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gchar c[48];
- g_snprintf(c, 48, "%06x", c32 >> 8);
+ int pick = prefs->getInt("/tools/dropper/pick",
+ SP_DROPPER_PICK_VISIBLE);
+ bool setalpha = prefs->getBool("/tools/dropper/setalpha", true);
- Glib::ustring text;
- text += c;
- if (!text.empty()) {
- Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
- refClipboard->set_text(text);
- }
+ return SP_RGBA32_F_COMPOSE(dc->R, dc->G, dc->B,
+ (pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? dc->alpha : 1.0);
}
@@ -222,17 +175,24 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv
SPDropperContext *dc = (SPDropperContext *) event_context;
int ret = FALSE;
SPDesktop *desktop = event_context->desktop;
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- int pick = prefs_get_int_attribute("tools.dropper", "pick", SP_DROPPER_PICK_VISIBLE);
- int setalpha = prefs_get_int_attribute("tools.dropper", "setalpha", 1);
+ int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE);
+ bool setalpha = prefs->getBool("/tools/dropper/setalpha", true);
switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button == 1 && !event_context->space_panning) {
- dc->centre = NR::Point(event->button.x, event->button.y);
+ dc->centre = Geom::Point(event->button.x, event->button.y);
dc->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);
+ dc->grabbed = SP_CANVAS_ITEM(desktop->acetate);
+
break;
case GDK_MOTION_NOTIFY:
if (event->motion.state & GDK_BUTTON2_MASK) {
@@ -249,24 +209,24 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv
// calculate average
// radius
- rw = std::min(NR::L2(NR::Point(event->button.x, event->button.y) - dc->centre), 400.0);
+ rw = std::min(Geom::L2(Geom::Point(event->button.x, event->button.y) - dc->centre), 400.0);
if (rw == 0) { // happens sometimes, little idea why...
break;
}
- NR::Point const cd = desktop->w2d(dc->centre);
- NR::Matrix const w2dt = desktop->w2d();
- const double scale = rw * NR_MATRIX_DF_EXPANSION(&w2dt);
- NR::Matrix const sm( NR::scale(scale, scale) * NR::translate(cd) );
+ Geom::Point const cd = desktop->w2d(dc->centre);
+ Geom::Matrix const w2dt = desktop->w2d();
+ const double scale = rw * w2dt.descrim();
+ Geom::Matrix const sm( Geom::Scale(scale, scale) * Geom::Translate(cd) );
sp_canvas_item_affine_absolute(dc->area, sm);
sp_canvas_item_show(dc->area);
/* Get buffer */
- const int x0 = (int) floor(dc->centre[NR::X] - rw);
- const int y0 = (int) floor(dc->centre[NR::Y] - rw);
- const int x1 = (int) ceil(dc->centre[NR::X] + rw);
- const int y1 = (int) ceil(dc->centre[NR::Y] + rw);
+ const int x0 = (int) floor(dc->centre[Geom::X] - rw);
+ const int y0 = (int) floor(dc->centre[Geom::Y] - rw);
+ const int x1 = (int) ceil(dc->centre[Geom::X] + rw);
+ const int y1 = (int) ceil(dc->centre[Geom::Y] + rw);
if ((x1 > x0) && (y1 > y0)) {
NRPixBlock pb;
@@ -276,8 +236,8 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv
for (int y = y0; y < y1; y++) {
const unsigned char *s = NR_PIXBLOCK_PX(&pb) + (y - y0) * pb.rs;
for (int x = x0; x < x1; x++) {
- const double dx = x - dc->centre[NR::X];
- const double dy = y - dc->centre[NR::Y];
+ const double dx = x - dc->centre[Geom::X];
+ const double dy = y - dc->centre[Geom::Y];
const double w = exp(-((dx * dx) + (dy * dy)) / (rw * rw));
W += w;
R += w * s[0];
@@ -373,6 +333,11 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv
{
sp_canvas_item_hide(dc->area);
dc->dragging = FALSE;
+
+ if (dc->grabbed) {
+ sp_canvas_item_ungrab(dc->grabbed, event->button.time);
+ dc->grabbed = NULL;
+ }
double alpha_to_set = setalpha? dc->alpha : 1.0;
@@ -386,8 +351,8 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv
if (!(sp_desktop_selection(desktop)->isEmpty())) {
- sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_DROPPER,
- _("Set picked color"));
+ DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_DROPPER,
+ _("Set picked color"));
}
ret = TRUE;