Code

We were disconnecting the wrong signal, resulting on the old object's
[inkscape.git] / src / dropper-context.cpp
index b998b1b15f779c7531766aef65874f54c6a84280..731db1403fd55f98b1af6330a42b5cdfbedf552b 100644 (file)
@@ -27,7 +27,7 @@
 #include "display/canvas-bpath.h"
 #include "display/canvas-arena.h"
 #include "display/curve.h"
-#include "svg/svg.h"
+#include "svg/svg-color.h"
 #include "color.h"
 #include "color-rgba.h"
 #include "desktop-style.h"
@@ -39,6 +39,7 @@
 #include "document.h"
 
 #include "pixmaps/cursor-dropper.xpm"
+#include "pixmaps/cursor-dropper.pixbuf"
 
 #include "dropper-context.h"
 #include "message-context.h"
@@ -99,6 +100,11 @@ static void sp_dropper_context_init(SPDropperContext *dc)
 {
     SPEventContext *event_context = SP_EVENT_CONTEXT(dc);
     event_context->cursor_shape = cursor_dropper_xpm;
+    event_context->cursor_pixbuf = gdk_pixbuf_new_from_inline(
+            -1,
+            cursor_dropper_pixbuf,
+            FALSE,
+            NULL);  
     event_context->hot_x = 7;
     event_context->hot_y = 7;
 }
@@ -111,8 +117,8 @@ static void sp_dropper_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) parent_class)->setup(ec);
     }
 
-    SPCurve *c = sp_curve_new_from_static_bpath(spdc_circle);
-    dc->area = sp_canvas_bpath_new(SP_DT_CONTROLS(ec->desktop), c);
+    SPCurve *c = sp_curve_new_from_foreign_bpath(spdc_circle);
+    dc->area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c);
     sp_curve_unref(c);
     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);
@@ -152,9 +158,11 @@ void sp_dropper_context_copy(SPEventContext *ec)
     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? SP_COLOR_F_TO_U(dc->alpha) : 255);
+               (pick == SP_DROPPER_PICK_ACTUAL && setalpha)? SP_COLOR_F_TO_U(dc->alpha) : 255);
 
     Glib::ustring text;
     text += c;
@@ -221,6 +229,7 @@ static gint sp_dropper_context_root_handler(SPEventContext *ec, GdkEvent *event)
     int ret = FALSE;
 
     int pick = prefs_get_int_attribute("tools.dropper", "pick", SP_DROPPER_PICK_VISIBLE);
+    int setalpha = prefs_get_int_attribute("tools.dropper", "setalpha", 1);
 
     switch (event->type) {
        case GDK_BUTTON_PRESS:
@@ -268,7 +277,7 @@ static gint sp_dropper_context_root_handler(SPEventContext *ec, GdkEvent *event)
                         NRPixBlock pb;
                         nr_pixblock_setup_fast(&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, x0, y0, x1, y1, TRUE);
                         /* fixme: (Lauris) */
-                        sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(SP_DT_DRAWING(ec->desktop)), &pb);
+                        sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(sp_desktop_drawing(ec->desktop)), &pb);
                         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++) {
@@ -302,7 +311,7 @@ static gint sp_dropper_context_root_handler(SPEventContext *ec, GdkEvent *event)
                     int x = (int) floor(event->button.x);
                     int y = (int) floor(event->button.y);
                     nr_pixblock_setup_fast(&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, x, y, x+1, y+1, TRUE);
-                    sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(SP_DT_DRAWING(ec->desktop)), &pb);
+                    sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(sp_desktop_drawing(ec->desktop)), &pb);
                     const unsigned char *s = NR_PIXBLOCK_PX(&pb);
 
                     R = s[0] / 255.0;
@@ -313,7 +322,7 @@ static gint sp_dropper_context_root_handler(SPEventContext *ec, GdkEvent *event)
 
                 if (pick == SP_DROPPER_PICK_VISIBLE) {
                     // compose with page color
-                    guint32 bg = SP_DT_NAMEDVIEW(ec->desktop)->pagecolor;
+                    guint32 bg = sp_desktop_namedview(ec->desktop)->pagecolor;
                     R = R + (SP_RGBA32_R_F(bg)) * (1 - A);
                     G = G + (SP_RGBA32_G_F(bg)) * (1 - A);
                     B = B + (SP_RGBA32_B_F(bg)) * (1 - A);
@@ -338,14 +347,15 @@ static gint sp_dropper_context_root_handler(SPEventContext *ec, GdkEvent *event)
                 dc->alpha = A;
 
                 // status message
-                guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, A);
+                double alpha_to_set = setalpha? dc->alpha : 1.0;
+                guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, alpha_to_set);
 
                 gchar c[64];
                 sp_svg_write_color(c, 64, 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
-                gchar *alpha = g_strdup_printf(_(" alpha %.3g"), A);
+                gchar *alpha = g_strdup_printf(_(" alpha %.3g"), alpha_to_set);
                 // 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
@@ -369,17 +379,20 @@ static gint sp_dropper_context_root_handler(SPEventContext *ec, GdkEvent *event)
                 sp_canvas_item_hide(dc->area);
                 dc->dragging = FALSE;
 
+                double alpha_to_set = setalpha? dc->alpha : 1.0;
+
                 // do the actual color setting
                 sp_desktop_set_color(ec->desktop,
                                      (event->button.state & GDK_MOD1_MASK)?
-                                     ColorRGBA(1 - dc->R, 1 - dc->G, 1 - dc->B, dc->alpha) : ColorRGBA(dc->R, dc->G, dc->B, dc->alpha),
+                                     ColorRGBA(1 - dc->R, 1 - dc->G, 1 - dc->B, alpha_to_set) : ColorRGBA(dc->R, dc->G, dc->B, alpha_to_set),
                                      false,  !(event->button.state & GDK_SHIFT_MASK));
 
                 // REJON: set aux. toolbar input to hex color!
 
 
-                if (!(SP_DT_SELECTION(ec->desktop)->isEmpty())) {
-                    sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+                if (!(sp_desktop_selection(ec->desktop)->isEmpty())) {
+                    sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_DROPPER, 
+                                     /* TODO: annotate */ "dropper-context.cpp:389");
                 }
 
                 ret = TRUE;
@@ -397,7 +410,7 @@ static gint sp_dropper_context_root_handler(SPEventContext *ec, GdkEvent *event)
                     }
                     break;
                case GDK_Escape:
-                    SP_DT_SELECTION(ec->desktop)->clear();
+                    sp_desktop_selection(ec->desktop)->clear();
                default:
                     break;
             }