Code

Set up toolbox so that paint bucket defaults can be reset
authorjohncoswell <johncoswell@users.sourceforge.net>
Wed, 25 Apr 2007 22:52:27 +0000 (22:52 +0000)
committerjohncoswell <johncoswell@users.sourceforge.net>
Wed, 25 Apr 2007 22:52:27 +0000 (22:52 +0000)
src/flood-context.cpp
src/flood-context.h
src/widgets/toolbox.cpp

index dbfc6df8ebba429ba99087695c2452594d60b9e7..3b7cc8d741d01c39e7c0f1efae6cf39237fb5740 100644 (file)
@@ -238,17 +238,6 @@ inline unsigned char * get_pixel(guchar *px, int x, int y, int width) {
     return px + (x + y * width) * 4;
 }
 
-enum PaintBucketChannels {
-    FLOOD_CHANNELS_RGB,
-    FLOOD_CHANNELS_R,
-    FLOOD_CHANNELS_G,
-    FLOOD_CHANNELS_B,
-    FLOOD_CHANNELS_H,
-    FLOOD_CHANNELS_S,
-    FLOOD_CHANNELS_L,
-    FLOOD_CHANNELS_ALPHA
-};
-
 GList * flood_channels_dropdown_items_list() {
     GList *glist = NULL;
 
index fd26403b5d79e345812b74885bdd1e5ef3a02b9f..10de77896360ee64c25a9e97a7eef92c34fe493b 100644 (file)
@@ -52,4 +52,15 @@ GtkType sp_flood_context_get_type (void);
 GList* flood_channels_dropdown_items_list (void);
 void flood_channels_set_channels( gint channels );
 
+enum PaintBucketChannels {
+    FLOOD_CHANNELS_RGB,
+    FLOOD_CHANNELS_R,
+    FLOOD_CHANNELS_G,
+    FLOOD_CHANNELS_B,
+    FLOOD_CHANNELS_H,
+    FLOOD_CHANNELS_S,
+    FLOOD_CHANNELS_L,
+    FLOOD_CHANNELS_ALPHA
+};
+
 #endif
index 6d486b9021efbdbe6e6fe6ebc29e6678ade75e97..91b94fe4d4756e4e3983d6e9081b6786f828d5eb 100644 (file)
@@ -324,6 +324,8 @@ static gchar const * ui_descr =
         "    <separator />"
         "    <toolitem action='OffsetAction' />"
         "    <toolitem action='PaintbucketUnitsAction' />"
+        "    <separator />"
+        "    <toolitem action='PaintbucketResetAction' />"
         "  </toolbar>"
 
         "  <toolbar name='DropperToolbar'>"
@@ -4280,6 +4282,29 @@ static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl)
     prefs_set_double_attribute("tools.paintbucket", "offset", (gdouble)sp_units_get_pixels(adj->value, *unit));
 }
 
+static void paintbucket_defaults(GtkWidget *, GObject *dataKludge)
+{
+    // FIXME: make defaults settable via Inkscape Options
+    struct KeyValue {
+        char const *key;
+        double value;
+    } const key_values[] = {
+        {"threshold", 15},
+        {"offset", 0.0}
+    };
+
+    for (unsigned i = 0; i < G_N_ELEMENTS(key_values); ++i) {
+        KeyValue const &kv = key_values[i];
+        GtkAdjustment* adj = static_cast<GtkAdjustment *>(g_object_get_data(dataKludge, kv.key));
+        if ( adj ) {
+            gtk_adjustment_set_value(adj, kv.value);
+        }
+    }
+    
+    EgeSelectOneAction* channels_action = EGE_SELECT_ONE_ACTION( g_object_get_data( dataKludge, "channels_action" ) );
+    ege_select_one_action_set_active( channels_action, FLOOD_CHANNELS_RGB );
+}
+
 static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
 {
     EgeAdjustmentAction* eact = 0;
@@ -4302,6 +4327,7 @@ static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
         ege_select_one_action_set_active( act1, prefs_get_int_attribute("tools.paintbucket", "channels", 0) );
         g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(paintbucket_channels_changed), holder );
         gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
+        g_object_set_data( holder, "channels_action", act1 );
     }
 
     // Spacing spinbox
@@ -4341,6 +4367,18 @@ static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
 
         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
     }
+    
+    /* Reset */
+    {
+        GtkAction* act = gtk_action_new( "PaintbucketResetAction",
+                                          _("Defaults"),
+                                          _("Reset paint bucket parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
+                                          GTK_STOCK_CLEAR );
+        g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(paintbucket_defaults), holder );
+        gtk_action_group_add_action( mainActions, act );
+        gtk_action_set_sensitive( act, TRUE );
+    }
+
 }
 
 /*