Code

replace single toggle button with less confusing pick-alpha and set-alpha options
authorbuliabyak <buliabyak@users.sourceforge.net>
Wed, 5 Jul 2006 20:14:31 +0000 (20:14 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Wed, 5 Jul 2006 20:14:31 +0000 (20:14 +0000)
share/icons/icons.svg
src/dropper-context.cpp
src/preferences-skeleton.h
src/widgets/toolbox.cpp

index 20e4026e28484d080c02290865ffc00efc033d40..2b7c4ff34e8b029434a8ea4e81a7b6d7e6b17dba 100644 (file)
@@ -12579,90 +12579,6 @@ http://www.inkscape.org/</dc:description>
        width="1250"
        height="1250" />
   </g>
-  <g
-     style="display:inline"
-     id="pick_color"
-     inkscape:label="#pick_color"
-     transform="matrix(0.733489,0,0,0.73376,-24.77719,216.6863)">
-    <rect
-       y="266"
-       x="706"
-       height="14"
-       width="14"
-       id="rect4449"
-       style="opacity:1;color:black;fill:#cbcbcb;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;display:inline" />
-    <use
-       x="0"
-       y="0"
-       xlink:href="#rect4443"
-       id="use5676"
-       transform="matrix(1.022446,0,0,1.022155,-7.665778,2.4658)"
-       width="1250"
-       height="1250" />
-    <use
-       x="0"
-       y="0"
-       xlink:href="#rect4443"
-       id="use5672"
-       transform="matrix(1.022485,0,0,1.022114,-15.87384,2.290699)"
-       width="1250"
-       height="1250" />
-    <rect
-       y="-280"
-       x="718"
-       height="1.552415"
-       width="1.6339413"
-       id="rect4480"
-       style="opacity:1;color:black;fill:#7b7b7b;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;display:inline"
-       transform="scale(1,-1)" />
-    <rect
-       y="265.50055"
-       x="705.31903"
-       height="14.9994"
-       width="14.988559"
-       id="rect4441"
-       style="opacity:1;color:black;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:black;stroke-width:1.36309421;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;display:inline"
-       ry="0" />
-    <rect
-       y="266.18201"
-       x="706"
-       height="4.0885305"
-       width="4"
-       id="rect4443"
-       style="opacity:1;color:black;fill:#7b7b7b;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;display:inline" />
-    <use
-       x="0"
-       y="0"
-       xlink:href="#rect4443"
-       id="use5674"
-       transform="matrix(1.022483,0,0,1.022154,-11.78238,-1.808479)"
-       width="1250"
-       height="1250" />
-    <path
-       style="fill:black;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       d="M 706,266 L 720,266 L 720,280 L 706,266 z "
-       id="path4466" />
-    <rect
-       y="278.44757"
-       x="710.09052"
-       height="1.3628577"
-       width="4.0900383"
-       id="rect4474"
-       style="opacity:1;color:black;fill:#7b7b7b;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;display:inline" />
-    <path
-       style="fill:url(#linearGradient8677);fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient8679);stroke-width:1.36309433px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
-       d="M 718.95227,266.86342 L 708.95227,266.86342"
-       id="path4507" />
-    <path
-       style="fill:url(#linearGradient8681);fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient8683);stroke-width:1.36309433px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
-       d="M 718.95227,266.86342 L 718.95227,276.86342"
-       id="path4525" />
-    <path
-       style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#c80000;stroke-width:1.36309433px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
-       d="M 705.3188,265.50057 L 720.31561,280.49185"
-       id="path4482"
-       sodipodi:nodetypes="cc" />
-  </g>
   <use
      style="display:inline"
      x="0"
index ba9949b8b4b4ba4645efaa7a706253097754d03b..731db1403fd55f98b1af6330a42b5cdfbedf552b 100644 (file)
@@ -158,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;
@@ -227,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:
@@ -344,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
@@ -375,10 +379,12 @@ 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!
index f8759d8c2a301c1c1e3b7cb7518d445854b0126b..111fc6bf1f5c463ad674e97b7da320caaef28b51 100644 (file)
@@ -69,7 +69,7 @@ static char const preferences_skeleton[] =
 "    <eventcontext id=\"nodes\" selcue=\"1\" gradientdrag=\"1\" show_handles=\"1\" sculpting_profile=\"1\" />\n"
 "    <eventcontext id=\"gradient\" selcue=\"1\"/>\n"
 "    <eventcontext id=\"zoom\" selcue=\"1\" gradientdrag=\"0\"/>\n"
-"    <eventcontext id=\"dropper\" selcue=\"1\" gradientdrag=\"1\"/>\n"
+"    <eventcontext id=\"dropper\" selcue=\"1\" gradientdrag=\"1\" pick=\"1\" setalpha=\"1\"/>\n"
 "    <eventcontext id=\"select\" selcue=\"1\" gradientdrag=\"0\"/>\n"
 "    <eventcontext id=\"connector\" style=\"fill:none;fill-rule:evenodd;stroke:black;stroke-opacity:1;stroke-linejoin:miter;stroke-width:1px;stroke-linecap:butt;\" selcue=\"1\"/>\n"
 "  </group>\n"
index 495c620ac8b00a01635b31f7124105a60335f5ef..6862794b33034a292283e46ff6514188c1050a55 100644 (file)
@@ -2535,10 +2535,22 @@ sp_arc_toolbox_new(SPDesktop *desktop)
 //##      Dropper       ##
 //########################
 
-static void toggle_dropper_color_pick (GtkWidget *button, gpointer data) {
+static void toggle_dropper_pick_alpha (GtkWidget *button, gpointer tbl) {
     prefs_set_int_attribute ("tools.dropper", "pick", 
-        // 0 and 1 are backwards here because of pref
-        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? 0 : 1);
+        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
+    GtkWidget *set_checkbox = (GtkWidget*) g_object_get_data(G_OBJECT(tbl), "set_checkbox");
+    if (set_checkbox) {
+        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
+            gtk_widget_set_sensitive (GTK_WIDGET (set_checkbox), TRUE);
+        } else {
+            gtk_widget_set_sensitive (GTK_WIDGET (set_checkbox), FALSE);
+        }
+    }
+}
+
+static void toggle_dropper_set_alpha (GtkWidget *button, gpointer data) {
+    prefs_set_int_attribute ("tools.dropper", "setalpha", 
+        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? 1 : 0);
 }
 
 
@@ -2721,26 +2733,43 @@ sp_dropper_toolbox_new(SPDesktop *desktop)
     
     {
         GtkWidget *hb = gtk_hbox_new(FALSE, 1);
-        
-        GtkWidget *button = 
-            sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
-                                     SP_BUTTON_TYPE_TOGGLE,
-                                     NULL,
-                                     "pick_color",
-                                     _("When pressed, picks visible color "
-                                      "without alpha and when not pressed, "
-                                      "picks color including its "
-                                      "alpha"),
-                                     tt);
 
+        GtkWidget *button = gtk_check_button_new_with_label(_("Pick alpha"));
+        gtk_tooltips_set_tip(tt, button, _("Pick both the color and the alpha (transparency) under cursor; otherwise, pick only the visible color premultiplied by alpha"), NULL);
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), 
+                                      prefs_get_int_attribute ("tools.dropper", 
+                                                               "pick", 1));
         gtk_widget_show(button);
         gtk_container_add (GTK_CONTAINER (hb), button);
+        gtk_object_set_data(GTK_OBJECT(tbl), "pick_checkbox", button);
+        g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (toggle_dropper_pick_alpha), tbl);
+        gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, 
+                   AUX_BETWEEN_BUTTON_GROUPS);
+    }
 
-        g_signal_connect_after (G_OBJECT (button), "clicked", 
-                                G_CALLBACK (toggle_dropper_color_pick), NULL);
+    {
+        GtkWidget *hb = gtk_hbox_new(FALSE, 1);
+
+        GtkWidget *button = gtk_check_button_new_with_label(_("Set alpha"));
+        gtk_tooltips_set_tip(tt, button, _("If alpha was picked, assign it to selection as fill or stroke transparency"), NULL);
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), 
-                                      !prefs_get_int_attribute ("tools.dropper", 
-                                                               "pick", 0));
+                                      prefs_get_int_attribute ("tools.dropper", 
+                                                               "setalpha", 1));
+        gtk_widget_show(button);
+        gtk_container_add (GTK_CONTAINER (hb), button);
+        gtk_object_set_data(GTK_OBJECT(tbl), "set_checkbox", button);
+        g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (toggle_dropper_set_alpha), tbl);
+
+        // make sure it's disabled if we're not picking alpha
+        GtkWidget *pick_checkbox = (GtkWidget*) g_object_get_data(G_OBJECT(tbl), "pick_checkbox");
+        if (pick_checkbox) {
+            if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pick_checkbox))) {
+                gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
+            } else {
+                gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
+            }
+        }
+
         gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, 
                    AUX_BETWEEN_BUTTON_GROUPS);
     }