Add a star tool. For drawing stars.
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 8 Apr 2008 01:21:53 +0000 (01:21 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 8 Apr 2008 01:21:53 +0000 (01:21 +0000)
git-svn-id: http://svn.voria.com/code@1983 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-studio/trunk/src/gtkmm/Makefile.am
synfig-studio/trunk/src/gtkmm/app.cpp
synfig-studio/trunk/src/gtkmm/iconcontroller.cpp
synfig-studio/trunk/src/gtkmm/state_star.cpp [new file with mode: 0644]
synfig-studio/trunk/src/gtkmm/state_star.h [new file with mode: 0644]

index bfee19f..4eb2186 100644 (file)
@@ -55,11 +55,11 @@ WIDGET_CC = \
 STATE_HH = \
        state_bline.h   state_circle.h   state_draw.h   state_eyedrop.h   state_fill.h   state_gradient.h               \
        state_normal.h   state_polygon.h   state_rectangle.h   state_rotate.h   state_scale.h   state_sketch.h          \
-       state_smoothmove.h   state_stroke.h   state_text.h   state_width.h   state_zoom.h
+       state_smoothmove.h   state_star.h   state_stroke.h   state_text.h   state_width.h   state_zoom.h
 STATE_CC = \
        state_bline.cpp state_circle.cpp state_draw.cpp state_eyedrop.cpp state_fill.cpp state_gradient.cpp             \
        state_normal.cpp state_polygon.cpp state_rectangle.cpp state_rotate.cpp state_scale.cpp state_sketch.cpp        \
-       state_smoothmove.cpp state_stroke.cpp state_text.cpp state_width.cpp state_zoom.cpp
+       state_smoothmove.cpp state_star.cpp state_stroke.cpp state_text.cpp state_width.cpp state_zoom.cpp
 
 TREEVIEW_HH = \
        childrentree.h   keyframetree.h   layergrouptree.h   layertree.h
index ec2697e..0d5fa82 100644 (file)
@@ -89,6 +89,7 @@
 #include "state_rectangle.h"
 #include "state_smoothmove.h"
 #include "state_scale.h"
+#include "state_star.h"
 #include "state_text.h"
 #include "state_width.h"
 #include "state_rotate.h"
@@ -1020,6 +1021,7 @@ init_ui_manager()
        ACCEL("<Actions>//state-mirror",      "<Mod1>m");
 
        ACCEL("<Actions>//state-text",        "<Mod1>x");
+       ACCEL("<Actions>//state-star",        "<Mod1>q");
 
        ACCEL("<Actions>//canvas-zoom-fit","<Control><Shift>z");
 
@@ -1199,6 +1201,7 @@ App::App(int *argc, char ***argv):
                state_manager->add_state(&state_zoom);
 
                state_manager->add_state(&state_text);
+               state_manager->add_state(&state_star);
 
                // Disabled by default - it doesn't work properly?
                if(getenv("SYNFIG_ENABLE_WIDTH"    )) state_manager->add_state(&state_width);
index 5c8bc35..34f2ef1 100644 (file)
@@ -159,7 +159,6 @@ IconController::IconController(const synfig::String& /*basepath*/)
        INIT_STOCK_ICON(saveall,"saveall_icon."IMAGE_EXT,_("Save All"));
        INIT_STOCK_ICON(layer,"layer_icon."IMAGE_EXT,_("Layer"));
        INIT_STOCK_ICON(layer_pastecanvas,"pastecanvas_icon."IMAGE_EXT,_("Paste Canvas"));
-       INIT_STOCK_ICON(star,"star_icon."IMAGE_EXT,"");
        INIT_STOCK_ICON(plant,"plant_icon."IMAGE_EXT,"");
        INIT_STOCK_ICON(group,"group_icon."IMAGE_EXT,_("Group"));
        INIT_STOCK_ICON(grid_enable,"grid_enable_icon."IMAGE_EXT,_("Show Grid"));
@@ -209,6 +208,7 @@ IconController::IconController(const synfig::String& /*basepath*/)
        INIT_STOCK_ICON(mirror,"mirror_icon."IMAGE_EXT,_("Mirror Tool"));
        INIT_STOCK_ICON(text,"text_icon."IMAGE_EXT,"Text Tool");
        INIT_STOCK_ICON(gradient,"gradient_icon."IMAGE_EXT,_("Gradient Tool"));
+       INIT_STOCK_ICON(star,"star_icon."IMAGE_EXT,_("Star Tool"));
 
        icon_factory->add_default();
 
diff --git a/synfig-studio/trunk/src/gtkmm/state_star.cpp b/synfig-studio/trunk/src/gtkmm/state_star.cpp
new file mode 100644 (file)
index 0000000..3234810
--- /dev/null
@@ -0,0 +1,896 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file state_star.cpp
+**     \brief Template File
+**
+**     $Id$
+**
+**     \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
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
+**
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
+**     \endlegal
+*/
+/* ========================================================================= */
+
+/* === H E A D E R S ======================================================= */
+
+#ifdef USING_PCH
+#      include "pch.h"
+#else
+#ifdef HAVE_CONFIG_H
+#      include <config.h>
+#endif
+
+#include <gtkmm/dialog.h>
+#include <gtkmm/entry.h>
+
+#include <synfig/valuenode_dynamiclist.h>
+#include <synfigapp/action_system.h>
+#include <synfig/valuenode_bline.h>
+
+#include "state_star.h"
+#include "canvasview.h"
+#include "workarea.h"
+#include "app.h"
+
+#include <synfigapp/action.h>
+#include "event_mouse.h"
+#include "event_layerclick.h"
+#include "toolbox.h"
+#include "dialog_tooloptions.h"
+#include <gtkmm/optionmenu.h>
+#include "duck.h"
+#include "widget_enum.h"
+#include <synfigapp/main.h>
+
+#include "general.h"
+
+#endif
+
+/* === U S I N G =========================================================== */
+
+using namespace std;
+using namespace etl;
+using namespace synfig;
+using namespace studio;
+
+/* === M A C R O S ========================================================= */
+
+/* === G L O B A L S ======================================================= */
+
+StateStar studio::state_star;
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+class studio::StateStar_Context : public sigc::trackable
+{
+       etl::handle<CanvasView> canvas_view_;
+       CanvasView::IsWorking is_working;
+
+       Duckmatic::Push duckmatic_push;
+
+       Point point_holder;
+
+       etl::handle<Duck> point2_duck;
+
+       void refresh_ducks();
+
+       bool prev_workarea_layer_status_;
+
+       //Toolbox settings
+       synfigapp::Settings& settings;
+
+       //Toolbox display
+       Gtk::Table options_table;
+
+       Gtk::Entry              entry_id; //what to name the layer
+
+       Gtk::Adjustment adj_feather;
+       Gtk::Adjustment adj_number_of_points;
+       Gtk::Adjustment adj_angle_offset;
+       Gtk::SpinButton spin_feather;
+       Gtk::SpinButton spin_number_of_points;
+       Gtk::SpinButton spin_angle_offset;
+
+       Gtk::CheckButton checkbutton_invert;
+       Gtk::CheckButton checkbutton_regular_polygon;
+       Gtk::CheckButton checkbutton_layer_star;
+       Gtk::CheckButton checkbutton_layer_region;
+       Gtk::CheckButton checkbutton_layer_outline;
+       Gtk::CheckButton checkbutton_layer_curve_gradient;
+       Gtk::CheckButton checkbutton_layer_plant;
+       Gtk::CheckButton checkbutton_layer_link_offsets;
+
+public:
+
+       // this only counts the layers which use blines - they're the only
+       // ones we link the offsets for
+       int layers_to_create()const
+       {
+               return
+                       get_layer_region_flag() +
+                       get_layer_outline_flag() +
+                       get_layer_curve_gradient_flag() +
+                       get_layer_plant_flag();
+       }
+
+       synfig::String get_id()const { return entry_id.get_text(); }
+       void set_id(const synfig::String& x) { return entry_id.set_text(x); }
+
+       Real get_feather()const { return adj_feather.get_value(); }
+       void set_feather(Real f) { adj_feather.set_value(f); }
+
+       Real get_number_of_points()const { return adj_number_of_points.get_value(); }
+       void set_number_of_points(Real f) { adj_number_of_points.set_value(f); }
+
+       Real get_angle_offset()const { return adj_angle_offset.get_value(); }
+       void set_angle_offset(Real f) { adj_angle_offset.set_value(f); }
+
+       bool get_invert()const { return checkbutton_invert.get_active(); }
+       void set_invert(bool i) { checkbutton_invert.set_active(i); }
+
+       bool get_regular_polygon()const { return checkbutton_regular_polygon.get_active(); }
+       void set_regular_polygon(bool i) { checkbutton_regular_polygon.set_active(i); }
+
+       bool get_layer_star_flag()const { return checkbutton_layer_star.get_active(); }
+       void set_layer_star_flag(bool x) { return checkbutton_layer_star.set_active(x); }
+
+       bool get_layer_region_flag()const { return checkbutton_layer_region.get_active(); }
+       void set_layer_region_flag(bool x) { return checkbutton_layer_region.set_active(x); }
+
+       bool get_layer_outline_flag()const { return checkbutton_layer_outline.get_active(); }
+       void set_layer_outline_flag(bool x) { return checkbutton_layer_outline.set_active(x); }
+
+       bool get_layer_curve_gradient_flag()const { return checkbutton_layer_curve_gradient.get_active(); }
+       void set_layer_curve_gradient_flag(bool x) { return checkbutton_layer_curve_gradient.set_active(x); }
+
+       bool get_layer_plant_flag()const { return checkbutton_layer_plant.get_active(); }
+       void set_layer_plant_flag(bool x) { return checkbutton_layer_plant.set_active(x); }
+
+       bool get_layer_link_offsets_flag()const { return checkbutton_layer_link_offsets.get_active(); }
+       void set_layer_link_offsets_flag(bool x) { return checkbutton_layer_link_offsets.set_active(x); }
+
+       void refresh_tool_options(); //to refresh the toolbox
+
+       //events
+       Smach::event_result event_stop_handler(const Smach::event& x);
+       Smach::event_result event_refresh_handler(const Smach::event& x);
+       Smach::event_result event_mouse_click_handler(const Smach::event& x);
+       Smach::event_result event_refresh_tool_options(const Smach::event& x);
+
+       //constructor destructor
+       StateStar_Context(CanvasView* canvas_view);
+       ~StateStar_Context();
+
+       //Canvas interaction
+       const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
+       etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
+       synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
+       WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
+
+       //Modifying settings etc.
+       void load_settings();
+       void save_settings();
+       void reset();
+       void increment_id();
+       bool egress_on_selection_change;
+       Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
+       {
+               if(egress_on_selection_change)
+                       throw Smach::egress_exception();
+               return Smach::RESULT_OK;
+       }
+
+       void make_star(const Point& p1, const Point& p2);
+
+};     // END of class StateStar_Context
+
+/* === M E T H O D S ======================================================= */
+
+StateStar::StateStar():
+       Smach::state<StateStar_Context>("star")
+{
+       insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateStar_Context::event_layer_selection_changed_handler));
+       insert(event_def(EVENT_STOP,&StateStar_Context::event_stop_handler));
+       insert(event_def(EVENT_REFRESH,&StateStar_Context::event_refresh_handler));
+       insert(event_def(EVENT_REFRESH_DUCKS,&StateStar_Context::event_refresh_handler));
+       insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateStar_Context::event_mouse_click_handler));
+       insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateStar_Context::event_mouse_click_handler));
+       insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateStar_Context::event_mouse_click_handler));
+       insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateStar_Context::event_refresh_tool_options));
+}
+
+StateStar::~StateStar()
+{
+}
+
+void
+StateStar_Context::load_settings()
+{
+       String value;
+
+       //parse the arguments yargh!
+       if(settings.get_value("star.id",value))
+               set_id(value);
+       else
+               set_id("Star");
+
+       if(settings.get_value("star.feather",value))
+               set_feather(atof(value.c_str()));
+       else
+               set_feather(0);
+
+       if(settings.get_value("star.number_of_points",value))
+               set_number_of_points(atof(value.c_str()));
+       else
+               set_number_of_points(5);
+
+       if(settings.get_value("star.angle_offset",value))
+               set_angle_offset(atof(value.c_str()));
+       else
+               set_angle_offset(0);
+
+       if(settings.get_value("star.invert",value) && value != "0")
+               set_invert(true);
+       else
+               set_invert(false);
+
+       if(settings.get_value("star.regular_polygon",value) && value != "0")
+               set_regular_polygon(true);
+       else
+               set_regular_polygon(false);
+
+       if(settings.get_value("star.layer_star",value) && value=="0")
+               set_layer_star_flag(false);
+       else
+               set_layer_star_flag(true);
+
+       if(settings.get_value("star.layer_region",value) && value=="1")
+               set_layer_region_flag(true);
+       else
+               set_layer_region_flag(false);
+
+       if(settings.get_value("star.layer_outline",value) && value=="1")
+               set_layer_outline_flag(true);
+       else
+               set_layer_outline_flag(false);
+
+       if(settings.get_value("star.layer_curve_gradient",value) && value=="1")
+               set_layer_curve_gradient_flag(true);
+       else
+               set_layer_curve_gradient_flag(false);
+
+       if(settings.get_value("star.layer_plant",value) && value=="1")
+               set_layer_plant_flag(true);
+       else
+               set_layer_plant_flag(false);
+
+       if(settings.get_value("star.layer_link_offsets",value) && value=="0")
+               set_layer_link_offsets_flag(false);
+       else
+               set_layer_link_offsets_flag(true);
+}
+
+void
+StateStar_Context::save_settings()
+{
+       settings.set_value("star.id",get_id());
+       settings.set_value("star.feather",strprintf("%f",(float)get_feather()));
+       settings.set_value("star.number_of_points",strprintf("%d",(int)(get_number_of_points() + 0.5)));
+       settings.set_value("star.angle_offset",strprintf("%f",(float)get_angle_offset()));
+       settings.set_value("star.invert",get_invert()?"1":"0");
+       settings.set_value("star.regular_polygon",get_regular_polygon()?"1":"0");
+       settings.set_value("star.layer_star",get_layer_star_flag()?"1":"0");
+       settings.set_value("star.layer_outline",get_layer_outline_flag()?"1":"0");
+       settings.set_value("star.layer_region",get_layer_region_flag()?"1":"0");
+       settings.set_value("star.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0");
+       settings.set_value("star.layer_plant",get_layer_plant_flag()?"1":"0");
+       settings.set_value("star.layer_link_offsets",get_layer_link_offsets_flag()?"1":"0");
+}
+
+void
+StateStar_Context::reset()
+{
+       refresh_ducks();
+}
+
+void
+StateStar_Context::increment_id()
+{
+       String id(get_id());
+       int number=1;
+       int digits=0;
+
+       if(id.empty())
+               id="Star";
+
+       // If there is a number
+       // already at the end of the
+       // id, then remove it.
+       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++)
+                       ;
+
+               String str_number;
+               str_number=String(id,id.size()-digits,id.size());
+               id=String(id,0,id.size()-digits);
+
+               number=atoi(str_number.c_str());
+       }
+       else
+       {
+               number=1;
+               digits=3;
+       }
+
+       number++;
+
+       // Add the number back onto the id
+       {
+               const String format(strprintf("%%0%dd",digits));
+               id+=strprintf(format.c_str(),number);
+       }
+
+       // Set the ID
+       set_id(id);
+}
+
+StateStar_Context::StateStar_Context(CanvasView* canvas_view):
+       canvas_view_(canvas_view),
+       is_working(*canvas_view),
+       duckmatic_push(get_work_area()),
+       prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
+       settings(synfigapp::Main::get_selected_input_device()->settings()),
+       entry_id(),
+       adj_feather(0,0,1,0.01,0.1),
+       adj_number_of_points(4,2,120,1,1,1), // value, lower, upper, step_increment, page_increment, page_size
+       adj_angle_offset(0,-360,360,.1,1,1), // value, lower, upper, step_increment, page_increment, page_size
+       spin_feather(adj_feather,0.1,3),
+       spin_number_of_points(adj_number_of_points,1,0),
+       spin_angle_offset(adj_angle_offset,1,1),
+       checkbutton_invert(_("Invert")),
+       checkbutton_regular_polygon(_("Regular Polygon")),
+       checkbutton_layer_star(_("Create Star Layer")),
+       checkbutton_layer_region(_("Create Region BLine")),
+       checkbutton_layer_outline(_("Create Outline BLine")),
+       checkbutton_layer_curve_gradient(_("Create Curve Gradient BLine")),
+       checkbutton_layer_plant(_("Create Plant BLine")),
+       checkbutton_layer_link_offsets(_("Link BLine Offsets"))
+{
+       egress_on_selection_change=true;
+       // Set up the tool options dialog
+       //options_table.attach(*manage(new Gtk::Label(_("Star 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);
+
+       load_settings();
+
+       //feather stuff
+       options_table.attach(*manage(new Gtk::Label(_("Feather:"))),                    0, 1,  2,  3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(spin_feather,                                                                              1, 2,  2,  3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(checkbutton_invert,                                                                0, 2,  5,  6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(checkbutton_regular_polygon,                                               0, 2,  6,  7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(checkbutton_layer_star,                                                    0, 2,  7,  8, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+//     options_table.attach(checkbutton_layer_outline,                                                 0, 2,  8,  9, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+//     options_table.attach(checkbutton_layer_region,                                                  0, 2,  9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+//     options_table.attach(checkbutton_layer_plant,                                                   0, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+//     options_table.attach(checkbutton_layer_curve_gradient,                                  0, 2, 11, 12, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+//     options_table.attach(checkbutton_layer_link_offsets,                                    0, 2, 12, 13, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(*manage(new Gtk::Label(_("Number of Points:"))),   0, 1, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(spin_number_of_points,                                                             1, 2, 13, 14, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(*manage(new Gtk::Label(_("Angle Offset:"))),               0, 1, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(spin_angle_offset,                                                                 1, 2, 14, 15, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+
+       options_table.show_all();
+
+       refresh_tool_options();
+       App::dialog_tool_options->present();
+
+       // Turn off layer clicking
+       get_work_area()->set_allow_layer_clicks(false);
+
+       // clear out the ducks
+       get_work_area()->clear_ducks();
+
+       // Refresh the work area
+       get_work_area()->queue_draw();
+
+       // Hide the tables if they are showing
+       //prev_table_status=get_canvas_view()->tables_are_visible();
+       //if(prev_table_status)get_canvas_view()->hide_tables();
+
+       // Disable the time bar
+       //get_canvas_view()->set_sensitive_timebar(false);
+
+       // Connect a signal
+       //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateStar_Context::on_user_click));
+       get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
+
+       App::toolbox->refresh();
+}
+
+void
+StateStar_Context::refresh_tool_options()
+{
+       App::dialog_tool_options->clear();
+       App::dialog_tool_options->set_widget(options_table);
+       App::dialog_tool_options->set_local_name(_("Star Tool"));
+       App::dialog_tool_options->set_name("star");
+}
+
+Smach::event_result
+StateStar_Context::event_refresh_tool_options(const Smach::event& /*x*/)
+{
+       refresh_tool_options();
+       return Smach::RESULT_ACCEPT;
+}
+
+StateStar_Context::~StateStar_Context()
+{
+       save_settings();
+
+       // Restore layer clicking
+       get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
+       get_canvas_view()->work_area->reset_cursor();
+
+       App::dialog_tool_options->clear();
+
+       // Enable the time bar
+       //get_canvas_view()->set_sensitive_timebar(true);
+
+       // Bring back the tables if they were out before
+       //if(prev_table_status)get_canvas_view()->show_tables();
+
+       // Refresh the work area
+       get_work_area()->queue_draw();
+
+       get_canvas_view()->queue_rebuild_ducks();
+
+       App::toolbox->refresh();
+}
+
+Smach::event_result
+StateStar_Context::event_stop_handler(const Smach::event& /*x*/)
+{
+       throw Smach::egress_exception();
+}
+
+Smach::event_result
+StateStar_Context::event_refresh_handler(const Smach::event& /*x*/)
+{
+       refresh_ducks();
+       return Smach::RESULT_ACCEPT;
+}
+
+void
+StateStar_Context::make_star(const Point& _p1, const Point& _p2)
+{
+       synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Star"));
+       synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
+
+       Layer::Handle layer;
+
+       Canvas::Handle canvas;
+       int depth(0);
+
+       // we are temporarily using the layer to hold something
+       layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
+       if(layer)
+       {
+               depth=layer->get_depth();
+               canvas=layer->get_canvas();
+       }
+
+       synfigapp::SelectionManager::LayerList layer_selection;
+       if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
+               layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
+
+       const synfig::TransformStack& transform(get_canvas_view()->get_curr_transform_stack());
+       const Point p1(transform.unperform(_p1));
+       const Point p2(transform.unperform(_p2));
+
+       Real radius((p2-p1).mag());
+       int points = get_number_of_points();
+       Angle::deg offset(get_angle_offset());
+       bool regular(get_regular_polygon());
+       Angle::deg angle(360.0/points);
+       Real x(p1[0]), y(p1[1]);
+       Real tangent(0);
+
+       std::vector<BLinePoint> new_list;
+       for (int i = 0; i < points; i++)
+       {
+               new_list.push_back(*(new BLinePoint));
+               new_list[i].set_width(1);
+               new_list[i].set_vertex(Point(radius*Angle::cos(angle*i + offset).get() + x,
+                                                                        radius*Angle::sin(angle*i + offset).get() + y));
+               new_list[i].set_tangent(Point(-radius*tangent*Angle::sin(angle*i + offset).get(),
+                                                                          radius*tangent*Angle::cos(angle*i + offset).get()));
+       }
+
+       ValueNode_BLine::Handle value_node_bline(ValueNode_BLine::create(new_list));
+       assert(value_node_bline);
+
+       ValueNode_Const::Handle value_node_offset(ValueNode_Const::create(Vector()));
+       assert(value_node_offset);
+
+       // Set the looping flag
+       value_node_bline->set_loop(true);
+
+       if(!canvas)
+               canvas=get_canvas_view()->get_canvas();
+
+       value_node_bline->set_member_canvas(canvas);
+
+       // count how many layers we're going to be creating
+       int layers_to_create = this->layers_to_create();
+
+       ///////////////////////////////////////////////////////////////////////////
+       //   S T A R
+       ///////////////////////////////////////////////////////////////////////////
+
+       if (get_layer_star_flag())
+       {
+               layer=get_canvas_interface()->add_layer_to("star",canvas,depth);
+               layer_selection.push_back(layer);
+
+               layer->set_param("offset",p1);
+               get_canvas_interface()->signal_layer_param_changed()(layer,"offset");
+
+               layer->set_param("radius1",(p2-p1).mag());
+               get_canvas_interface()->signal_layer_param_changed()(layer,"radius1");
+
+               layer->set_param("radius2",(p2-p1).mag()/2);
+               get_canvas_interface()->signal_layer_param_changed()(layer,"radius2");
+
+               layer->set_param("angle",offset);
+               get_canvas_interface()->signal_layer_param_changed()(layer,"angle");
+
+               layer->set_param("points",points);
+               get_canvas_interface()->signal_layer_param_changed()(layer,"points");
+
+               layer->set_param("regular_polygon",regular);
+               get_canvas_interface()->signal_layer_param_changed()(layer,"regular_polygon");
+
+               layer->set_param("feather",get_feather());
+               get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
+
+               layer->set_param("invert",get_invert());
+               get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
+
+               layer->set_description(get_id());
+               get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
+       }
+
+       ///////////////////////////////////////////////////////////////////////////
+       //   C U R V E   G R A D I E N T
+       ///////////////////////////////////////////////////////////////////////////
+
+       if(get_layer_curve_gradient_flag())
+       {
+               synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
+
+               Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth));
+               assert(layer);
+               layer_selection.push_back(layer);
+               layer->set_description(get_id()+_(" Gradient"));
+               get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
+
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("bline")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Gradient layer"));
+                               return;
+                       }
+               }
+
+               // only link the curve gradient's offset parameter if the option is selected and we're creating more than one layer
+               if (get_layer_link_offsets_flag() && layers_to_create > 1)
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("offset")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_offset)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Gradient layer"));
+                               return;
+                       }
+               }
+       }
+
+       ///////////////////////////////////////////////////////////////////////////
+       //   P L A N T
+       ///////////////////////////////////////////////////////////////////////////
+
+       if(get_layer_plant_flag())
+       {
+               synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
+
+               Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth));
+               assert(layer);
+               layer_selection.push_back(layer);
+               layer->set_description(get_id()+_(" Plant"));
+               get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
+
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("bline")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Plant layer"));
+                               return;
+                       }
+               }
+
+               // only link the plant's offset parameter if the option is selected and we're creating more than one layer
+               if (get_layer_link_offsets_flag() && layers_to_create > 1)
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("offset")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_offset)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Plant layer"));
+                               return;
+                       }
+               }
+       }
+
+       ///////////////////////////////////////////////////////////////////////////
+       //   R E G I O N
+       ///////////////////////////////////////////////////////////////////////////
+
+       if(get_layer_region_flag())
+       {
+               synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
+
+               Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth));
+               assert(layer);
+               layer_selection.push_back(layer);
+               layer->set_description(get_id()+_(" Region"));
+               get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
+
+               layer->set_param("feather",get_feather());
+               get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
+
+               layer->set_param("invert",get_invert());
+               get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
+
+               if(get_layer_outline_flag())
+                       layer->set_param("color",synfigapp::Main::get_background_color());
+
+               // I don't know if it's safe to reuse the same layer_param_connect action, so I'm
+               // using 2 separate ones.
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("bline")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Region layer"));
+                               return;
+                       }
+               }
+
+               // only link the region's offset parameter if the option is selected and we're creating more than one layer
+               if (get_layer_link_offsets_flag() && layers_to_create > 1)
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("offset")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_offset)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Region layer"));
+                               return;
+                       }
+               }
+       }
+
+       ///////////////////////////////////////////////////////////////////////////
+       //   O U T L I N E
+       ///////////////////////////////////////////////////////////////////////////
+
+       if (get_layer_outline_flag())
+       {
+               Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth));
+               assert(layer);
+               layer_selection.push_back(layer);
+               layer->set_description(get_id()+_(" Outline"));
+               get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
+
+               layer->set_param("feather",get_feather());
+               get_canvas_interface()->signal_layer_param_changed()(layer,"feather");
+
+               layer->set_param("invert",get_invert());
+               get_canvas_interface()->signal_layer_param_changed()(layer,"invert");
+
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("bline")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_bline)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Outline layer"));
+                               return;
+                       }
+               }
+
+               // only link the outline's offset parameter if the option is selected and we're creating more than one layer
+               if (get_layer_link_offsets_flag() && layers_to_create > 1)
+               {
+                       synfigapp::Action::Handle action(synfigapp::Action::create("layer_param_connect"));
+                       assert(action);
+
+                       action->set_param("canvas",get_canvas());
+                       action->set_param("canvas_interface",get_canvas_interface());
+                       action->set_param("layer",layer);
+                       if(!action->set_param("param",String("offset")))
+                               synfig::error("LayerParamConnect didn't like \"param\"");
+                       if(!action->set_param("value_node",ValueNode::Handle(value_node_offset)))
+                               synfig::error("LayerParamConnect didn't like \"value_node\"");
+
+                       if(!get_canvas_interface()->get_instance()->perform_action(action))
+                       {
+                               //get_canvas_view()->get_ui_interface()->error(_("Unable to create BLine layer"));
+                               group.cancel();
+                               throw String(_("Unable to create Outline layer"));
+                               return;
+                       }
+               }
+       }
+
+       egress_on_selection_change=false;
+       get_canvas_interface()->get_selection_manager()->clear_selected_layers();
+       get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
+       egress_on_selection_change=true;
+
+       reset();
+       increment_id();
+}
+
+Smach::event_result
+StateStar_Context::event_mouse_click_handler(const Smach::event& x)
+{
+       const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
+
+       if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DOWN && event.button==BUTTON_LEFT)
+       {
+               point_holder=get_work_area()->snap_point_to_grid(event.pos);
+               etl::handle<Duck> duck=new Duck();
+               duck->set_point(point_holder);
+               duck->set_name("p1");
+               duck->set_type(Duck::TYPE_POSITION);
+               duck->set_editable(false);
+               get_work_area()->add_duck(duck);
+
+               point2_duck=new Duck();
+               point2_duck->set_point(Vector(0,0));
+               point2_duck->set_name("radius");
+               point2_duck->set_origin(duck);
+               point2_duck->set_radius(true);
+               point2_duck->set_scalar(-1);
+               point2_duck->set_type(Duck::TYPE_RADIUS);
+               point2_duck->set_hover(true);
+               get_work_area()->add_duck(point2_duck);
+
+               return Smach::RESULT_ACCEPT;
+       }
+
+       if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT)
+       {
+               point2_duck->set_point(point_holder-get_work_area()->snap_point_to_grid(event.pos));
+               get_work_area()->queue_draw();
+               return Smach::RESULT_ACCEPT;
+       }
+
+       if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_UP && event.button==BUTTON_LEFT)
+       {
+               Point point(get_work_area()->snap_point_to_grid(event.pos));
+
+               if (App::restrict_radius_ducks)
+               {
+                       if ((point[0] - point_holder[0]) < 0) point[0] = point_holder[0];
+                       if ((point[1] - point_holder[1]) < 0) point[1] = point_holder[1];
+               }
+
+               make_star(point_holder, point);
+               get_work_area()->clear_ducks();
+               return Smach::RESULT_ACCEPT;
+       }
+
+       return Smach::RESULT_OK;
+}
+
+
+void
+StateStar_Context::refresh_ducks()
+{
+       get_work_area()->clear_ducks();
+       get_work_area()->queue_draw();
+}
diff --git a/synfig-studio/trunk/src/gtkmm/state_star.h b/synfig-studio/trunk/src/gtkmm/state_star.h
new file mode 100644 (file)
index 0000000..1095679
--- /dev/null
@@ -0,0 +1,56 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file state_star.h
+**     \brief Star creation state
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
+**
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
+**     \endlegal
+*/
+/* ========================================================================= */
+
+/* === S T A R T =========================================================== */
+
+#ifndef __SYNFIG_STUDIO_STATE_STAR_H
+#define __SYNFIG_STUDIO_STATE_STAR_H
+
+/* === H E A D E R S ======================================================= */
+
+#include "smach.h"
+
+
+/* === M A C R O S ========================================================= */
+
+/* === T Y P E D E F S ===================================================== */
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+namespace studio {
+
+class StateStar_Context;
+
+class StateStar : public Smach::state<StateStar_Context>
+{
+public:
+       StateStar();
+       ~StateStar();
+}; // END of class StateStar
+
+extern StateStar state_star;
+
+}; // END of namespace studio
+
+/* === E N D =============================================================== */
+
+#endif