From: Nikita Kitaev Date: Sat, 12 Dec 2009 05:01:53 +0000 (-0800) Subject: Move live feedback code into duckmatic. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a0c4c834ff9eac521ea6e6efce297d4ece195bc2;p=synfig.git Move live feedback code into duckmatic. --- diff --git a/synfig-studio/src/gtkmm/duck.cpp b/synfig-studio/src/gtkmm/duck.cpp index da32897..14ea8d0 100644 --- a/synfig-studio/src/gtkmm/duck.cpp +++ b/synfig-studio/src/gtkmm/duck.cpp @@ -251,56 +251,6 @@ Duck::set_sub_trans_point(const synfig::Point &x, const synfig::Time &time) else set_point((x-get_sub_trans_origin())/get_scalar()); } -//! Updates width and tangent ducks that change when the origin moves -void -Duck::update(const synfig::Time &time) -{ - if((get_type() == Duck::TYPE_TANGENT || get_type() == Duck::TYPE_WIDTH || get_type() == Duck::TYPE_ANGLE) && origin_duck) - { - ValueNode_BLineCalcVertex::Handle bline_vertex; - ValueNode_Composite::Handle composite; - if ((bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(origin_duck->get_value_desc().get_value_node())) || - ((composite = ValueNode_Composite::Handle::cast_dynamic(origin_duck->get_value_desc().get_value_node())) && - composite->get_type() == ValueBase::TYPE_BLINEPOINT && - (bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point"))))) - { - synfig::Real radius = 0.0; - ValueNode_BLine::Handle bline(ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline")))); - Real amount = synfig::find_closest_point((*bline)(time), origin_duck->get_point(), radius, bline->get_loop()); - - int vertex_amount_index(bline_vertex->get_link_index_from_name("amount")); - ValueNode::Handle vertex_amount_value_node(bline_vertex->get_link(vertex_amount_index)); - - - if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(get_value_desc().get_value_node())) - { - switch (bline_tangent->get_type()) - { - case ValueBase::TYPE_ANGLE: - { - Angle angle((*bline_tangent)(time, amount).get(Angle())); - set_point(Point(Angle::cos(angle).get(), Angle::sin(angle).get())); - rotations=synfig::Angle::deg(0); //hack: rotations are a relative value - break; - } - case ValueBase::TYPE_REAL: - set_point(Point((*bline_tangent)(time, amount).get(Real()), 0)); - break; - case ValueBase::TYPE_VECTOR: - set_point((*bline_tangent)(time, amount).get(Vector())); - break; - default: - break; - } - } - else if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(get_value_desc().get_value_node())) - set_point(Point((*bline_width)(time, amount).get(Real()), 0)); - } - - } -} - - void Duck::set_sub_trans_point(const synfig::Point &x) { diff --git a/synfig-studio/src/gtkmm/duck.h b/synfig-studio/src/gtkmm/duck.h index 54b3412..9a054f3 100644 --- a/synfig-studio/src/gtkmm/duck.h +++ b/synfig-studio/src/gtkmm/duck.h @@ -218,6 +218,7 @@ public: synfig::Point get_point()const { return shared_point?*shared_point:point; } synfig::Angle get_rotations()const { return rotations; }; + void set_rotations(const synfig::Angle &x) { rotations=x; }; synfig::Point get_trans_point()const; @@ -229,8 +230,6 @@ public: void set_sub_trans_point(const synfig::Point &x, const synfig::Time &time); synfig::Point get_sub_trans_origin()const; - void update(const synfig::Time &time); - //! Sets the origin point. void set_origin(const synfig::Point &x); diff --git a/synfig-studio/src/gtkmm/duckmatic.cpp b/synfig-studio/src/gtkmm/duckmatic.cpp index c1813e7..786aa11 100644 --- a/synfig-studio/src/gtkmm/duckmatic.cpp +++ b/synfig-studio/src/gtkmm/duckmatic.cpp @@ -447,6 +447,75 @@ Duckmatic::start_duck_drag(const synfig::Vector& offset) drag_offset_=find_duck(offset)->get_trans_point(); } +void +Duckmatic::update_ducks() +{ + Time time(get_time()); + DuckList duck_list(get_duck_list()); + const DuckList selected_ducks(get_selected_ducks()); + DuckList::const_iterator iter; + for (iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter) + { + etl::handle duck(*iter); + if (duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION) + { + ValueNode_BLineCalcVertex::Handle bline_vertex; + ValueNode_Composite::Handle composite; + + if ((bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) || + ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) && + composite->get_type() == ValueBase::TYPE_BLINEPOINT && + (bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point"))))) + { + DuckList::iterator iter; + for (iter=duck_list.begin(); iter!=duck_list.end(); iter++) + if ( (*iter)->get_origin_duck()==duck /*&& !duck_is_selected(*iter)*/ ) + { + synfig::Real radius = 0.0; + ValueNode_BLine::Handle bline(ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline")))); + Real amount = synfig::find_closest_point((*bline)(time), duck->get_point(), radius, bline->get_loop()); + + int vertex_amount_index(bline_vertex->get_link_index_from_name("amount")); + ValueNode::Handle vertex_amount_value_node(bline_vertex->get_link(vertex_amount_index)); + + + ValueNode::Handle duck_value_node((*iter)->get_value_desc().get_value_node()); + if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(duck_value_node)) + { + if (bline_tangent->get_link(bline_tangent->get_link_index_from_name("amount")) == vertex_amount_value_node) + { + switch (bline_tangent->get_type()) + { + case ValueBase::TYPE_ANGLE: + { + Angle angle((*bline_tangent)(time, amount).get(Angle())); + (*iter)->set_point(Point(Angle::cos(angle).get(), Angle::sin(angle).get())); + (*iter)->set_rotations(Angle::deg(0)); //hack: rotations are a relative value + break; + } + case ValueBase::TYPE_REAL: + (*iter)->set_point(Point((*bline_tangent)(time, amount).get(Real()), 0)); + break; + case ValueBase::TYPE_VECTOR: + (*iter)->set_point((*bline_tangent)(time, amount).get(Vector())); + break; + default: + break; + } + } + } + else if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(duck_value_node)) + { + if (bline_width->get_link(bline_width->get_link_index_from_name("amount")) == vertex_amount_value_node) + (*iter)->set_point(Point((*bline_width)(time, amount).get(Real()), 0)); + } + } + } + } + } +} + + bool Duckmatic::end_duck_drag() { @@ -561,29 +630,7 @@ DuckDrag_Translate::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector (*iter)->set_trans_point(positions[i]+vect, time); // then patch up the tangents for the vertices we've moved - DuckList duck_list(duckmatic->get_duck_list()); - for (iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter) - { - etl::handle duck(*iter); - if (duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION) - { - ValueNode_Composite::Handle composite; - - if ((ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) || - ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) && - composite->get_type() == ValueBase::TYPE_BLINEPOINT && - (ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point"))))) - { - //! \todo update() will call dynamic cast again, see if we can avoid that - DuckList::iterator iter; - for (iter=duck_list.begin(); iter!=duck_list.end(); iter++) - if ((*iter)->get_origin_duck()==duck - && std::find(selected_ducks.begin(), - selected_ducks.end(), *iter) == selected_ducks.end() ) - (*iter)->update(time); - } - } - } + duckmatic->update_ducks(); last_translate_=vect; } diff --git a/synfig-studio/src/gtkmm/duckmatic.h b/synfig-studio/src/gtkmm/duckmatic.h index 42282e0..e10db0c 100644 --- a/synfig-studio/src/gtkmm/duckmatic.h +++ b/synfig-studio/src/gtkmm/duckmatic.h @@ -324,6 +324,7 @@ public: void start_duck_drag(const synfig::Vector& offset); void translate_selected_ducks(const synfig::Vector& vector); + void update_ducks(); bool end_duck_drag(); void signal_edited_selected_ducks(); diff --git a/synfig-studio/src/gtkmm/state_normal.cpp b/synfig-studio/src/gtkmm/state_normal.cpp index 6cca469..15a7b43 100644 --- a/synfig-studio/src/gtkmm/state_normal.cpp +++ b/synfig-studio/src/gtkmm/state_normal.cpp @@ -501,29 +501,7 @@ DuckDrag_Combo::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector) } // then patch up the tangents for the vertices we've moved - DuckList duck_list(duckmatic->get_duck_list()); - for (iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter) - { - etl::handle duck(*iter); - if (duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION) - { - ValueNode_Composite::Handle composite; - - if ((ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) || - ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) && - composite->get_type() == ValueBase::TYPE_BLINEPOINT && - (ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point"))))) - { - //! \todo update() will call dynamic cast again, see if we can avoid that - DuckList::iterator iter; - for (iter=duck_list.begin(); iter!=duck_list.end(); iter++) - if ((*iter)->get_origin_duck()==duck - && std::find(selected_ducks.begin(), - selected_ducks.end(), *iter) == selected_ducks.end()) - (*iter)->update(time); - } - } - } + duckmatic->update_ducks(); last_move=vect; } diff --git a/synfig-studio/src/gtkmm/state_smoothmove.cpp b/synfig-studio/src/gtkmm/state_smoothmove.cpp index 6f96f57..85442cf 100644 --- a/synfig-studio/src/gtkmm/state_smoothmove.cpp +++ b/synfig-studio/src/gtkmm/state_smoothmove.cpp @@ -302,29 +302,7 @@ DuckDrag_SmoothMove::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vecto } // then patch up the tangents for the vertices we've moved - DuckList duck_list(duckmatic->get_duck_list()); - for (iter=selected_ducks.begin(); iter!=selected_ducks.end(); ++iter) - { - etl::handle duck(*iter); - if (duck->get_type() == Duck::TYPE_VERTEX || duck->get_type() == Duck::TYPE_POSITION) - { - ValueNode_Composite::Handle composite; - - if ((ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) || - ((composite = ValueNode_Composite::Handle::cast_dynamic(duck->get_value_desc().get_value_node())) && - composite->get_type() == ValueBase::TYPE_BLINEPOINT && - (ValueNode_BLineCalcVertex::Handle::cast_dynamic(composite->get_link("point"))))) - { - //! \todo update() will call dynamic cast again, see if we can avoid that - DuckList::iterator iter; - for (iter=duck_list.begin(); iter!=duck_list.end(); iter++) - if ((*iter)->get_origin_duck()==duck - && std::find(selected_ducks.begin(), - selected_ducks.end(), *iter) == selected_ducks.end() ) - (*iter)->update(time); - } - } - } + duckmatic->update_ducks(); last_translate_=vect; //snap=Vector(0,0);