Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_gradient.cpp
index f4f1963..c8461b5 100644 (file)
@@ -6,6 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**  Copyright (c) 2008 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -51,6 +52,8 @@
 #include "widget_enum.h"
 #include <synfigapp/main.h>
 
+#include "general.h"
+
 #endif
 
 /* === U S I N G =========================================================== */
@@ -96,7 +99,9 @@ class studio::StateGradient_Context : public sigc::trackable
        Gtk::Table options_table;
        Gtk::Entry entry_id;
        Widget_Enum enum_type;
+#ifdef BLEND_METHOD_IN_TOOL_OPTIONS
        Widget_Enum     enum_blend;
+#endif // BLEND_METHOD_IN_TOOL_OPTIONS
 
 public:
        synfig::String get_id()const { return entry_id.get_text(); }
@@ -105,8 +110,10 @@ public:
        int get_type()const { return enum_type.get_value(); }
        void set_type(int x) { return enum_type.set_value(x); }
 
+#ifdef BLEND_METHOD_IN_TOOL_OPTIONS
        int get_blend()const { return enum_blend.get_value(); }
        void set_blend(int x) { return enum_blend.set_value(x); }
+#endif // BLEND_METHOD_IN_TOOL_OPTIONS
 
        Smach::event_result event_stop_handler(const Smach::event& x);
 
@@ -178,10 +185,12 @@ StateGradient_Context::load_settings()
        else
                set_type(GRADIENT_INTERPOLATION_LINEAR);
 
+#ifdef BLEND_METHOD_IN_TOOL_OPTIONS
        if(settings.get_value("gradient.blend",value))
                set_blend(atoi(value.c_str()));
        else
                set_blend(Color::BLEND_COMPOSITE);
+#endif // BLEND_METHOD_IN_TOOL_OPTIONS
 }
 
 void
@@ -189,7 +198,9 @@ StateGradient_Context::save_settings()
 {
        settings.set_value("gradient.id",get_id().c_str());
        settings.set_value("gradient.type",strprintf("%d",get_type()));
+#ifdef BLEND_METHOD_IN_TOOL_OPTIONS
        settings.set_value("gradient.blend",strprintf("%d",get_blend()));
+#endif // BLEND_METHOD_IN_TOOL_OPTIONS
 }
 
 void
@@ -214,7 +225,10 @@ StateGradient_Context::increment_id()
        if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
        {
                // figure out how many digits it is
-               for(digits=0;(int)id.size()-1>=digits && id[id.size()-1-digits]<='9' && id[id.size()-1-digits]>='0';digits++)while(false);
+               for (digits = 0;
+                        (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
+                        digits++)
+                       ;
 
                String str_number;
                str_number=String(id,id.size()-digits,id.size());
@@ -250,8 +264,8 @@ StateGradient_Context::StateGradient_Context(CanvasView* canvas_view):
 {
        egress_on_selection_change=true;
        // Set up the tool options dialog
-       ///options_table.attach(*manage(new Gtk::Label(_("Gradient Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(*manage(new Gtk::Label(_("Gradient Tool"))),       0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(entry_id,                                                                          0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
 
        enum_type.set_param_desc(ParamDesc("type")
                .set_local_name(_("Gradient Type"))
@@ -262,14 +276,18 @@ StateGradient_Context::StateGradient_Context(CanvasView* canvas_view):
                .add_enum_value(GRADIENT_CONICAL,"conical",_("Conical"))
                .add_enum_value(GRADIENT_SPIRAL,"spiral",_("Spiral")));
 
+#ifdef BLEND_METHOD_IN_TOOL_OPTIONS
        enum_blend.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method")
                .set_local_name(_("Blend Method"))
                .set_description(_("The blend method the gradient will use")));
+#endif // BLEND_METHOD_IN_TOOL_OPTIONS
 
        load_settings();
 
        options_table.attach(enum_type, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+#ifdef BLEND_METHOD_IN_TOOL_OPTIONS
        options_table.attach(enum_blend, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+#endif // BLEND_METHOD_IN_TOOL_OPTIONS
 
        options_table.show_all();
        refresh_tool_options();
@@ -337,6 +355,8 @@ StateGradient_Context::~StateGradient_Context()
        // Refresh the work area
        get_work_area()->queue_draw();
 
+       get_canvas_view()->queue_rebuild_ducks();
+
        //get_canvas_view()->show_tables();
 
        get_work_area()->refresh_cursor();
@@ -384,6 +404,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2)
        case GRADIENT_INTERPOLATION_LINEAR:
 
                layer=get_canvas_interface()->add_layer_to("linear_gradient",canvas,depth);
+               if (!layer)
+               {
+                       get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
+                       group.cancel();
+                       return;
+               }
                layer->set_param("p1",p1);
                get_canvas_interface()->signal_layer_param_changed()(layer,"p1");
                layer->set_param("p2",p2);
@@ -391,6 +417,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2)
                break;
        case GRADIENT_RADIAL:
                layer=get_canvas_interface()->add_layer_to("radial_gradient",canvas,depth);
+               if (!layer)
+               {
+                       get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
+                       group.cancel();
+                       return;
+               }
                layer->set_param("center",p1);
                get_canvas_interface()->signal_layer_param_changed()(layer,"center");
                layer->set_param("radius",(p2-p1).mag());
@@ -398,6 +430,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2)
                break;
        case GRADIENT_CONICAL:
                layer=get_canvas_interface()->add_layer_to("conical_gradient",canvas,depth);
+               if (!layer)
+               {
+                       get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
+                       group.cancel();
+                       return;
+               }
                layer->set_param("center",p1);
                get_canvas_interface()->signal_layer_param_changed()(layer,"center");
                {
@@ -408,6 +446,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2)
                break;
        case GRADIENT_SPIRAL:
                layer=get_canvas_interface()->add_layer_to("spiral_gradient",canvas,depth);
+               if (!layer)
+               {
+                       get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
+                       group.cancel();
+                       return;
+               }
                layer->set_param("center",p1);
                get_canvas_interface()->signal_layer_param_changed()(layer,"center");
                layer->set_param("radius",(p2-p1).mag());
@@ -423,15 +467,21 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2)
                return;
        }
 
+#ifdef BLEND_METHOD_IN_TOOL_OPTIONS
        layer->set_param("blend_method",get_blend());
        get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
+#endif // BLEND_METHOD_IN_TOOL_OPTIONS
 
        layer->set_description(get_id());
        get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
 
        egress_on_selection_change=false;
+       synfigapp::SelectionManager::LayerList layer_selection;
+       if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
+               layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
        get_canvas_interface()->get_selection_manager()->clear_selected_layers();
-       get_canvas_interface()->get_selection_manager()->set_selected_layer(layer);
+       layer_selection.push_back(layer);
+       get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
        egress_on_selection_change=true;
 
        reset();
@@ -468,6 +518,7 @@ StateGradient_Context::event_mouse_click_handler(const Smach::event& x)
 
        if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
        {
+               if (!point2_duck) return Smach::RESULT_OK;
                point2_duck->set_point(get_work_area()->snap_point_to_grid(event.pos));
                get_work_area()->queue_draw();
                return Smach::RESULT_ACCEPT;