From b054a4463e94169b6d119191000b8485cf7fa853 Mon Sep 17 00:00:00 2001 From: dooglus Date: Thu, 6 Mar 2008 01:03:07 +0000 Subject: [PATCH] Added 3 new parameters to the "BLine Tangent" ValueNode, and incremented the canvas version number to allow checking for their presence in .sif files created from now on. git-svn-id: http://svn.voria.com/code@1863 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/synfig/canvas.h | 7 ++- synfig-core/trunk/src/synfig/loadcanvas.cpp | 18 ++++++-- .../src/synfig/valuenode_blinecalctangent.cpp | 52 +++++++++++++++++----- .../trunk/src/synfig/valuenode_blinecalctangent.h | 3 ++ 4 files changed, 65 insertions(+), 15 deletions(-) diff --git a/synfig-core/trunk/src/synfig/canvas.h b/synfig-core/trunk/src/synfig/canvas.h index d9e00d7..cbed17d 100644 --- a/synfig-core/trunk/src/synfig/canvas.h +++ b/synfig-core/trunk/src/synfig/canvas.h @@ -86,9 +86,14 @@ * 0.4: svn r1856 * * Stop scaling tangents by 0.5. + * + * 0.5: svn r1863 + * + * Added "offset", "scale", and "fixed_length" links to the + * "BLine Tangent" ValueNode. */ -#define CURRENT_CANVAS_VERSION "0.4" +#define CURRENT_CANVAS_VERSION "0.5" /* === T Y P E D E F S ===================================================== */ diff --git a/synfig-core/trunk/src/synfig/loadcanvas.cpp b/synfig-core/trunk/src/synfig/loadcanvas.cpp index 5b4fe86..8cf5cba 100644 --- a/synfig-core/trunk/src/synfig/loadcanvas.cpp +++ b/synfig-core/trunk/src/synfig/loadcanvas.cpp @@ -1275,12 +1275,23 @@ CanvasParser::parse_linkable_value_node(xmlpp::Element *element,Canvas::Handle c } } + String version(canvas->get_version()); for (int i = 0; i < value_node->link_count(); i++) { - if (!c[i] && - // the 'width' parameter of wasn't always present, so it won't be in old .sif files - !(element->get_name() == "stripes" && value_node->link_name(i) == "width")) + if (!c[i]) { + // the 'width' parameter of wasn't always present in version 0.1 canvases + if (version == "0.1" && element->get_name() == "stripes" && value_node->link_name(i) == "width") + continue; + + // these 3 blinecalctangent parameters didn't appear until canvas version 0.5 + if ((version == "0.1" || version == "0.2" || version == "0.3" || version == "0.4") && + element->get_name() == "blinecalctangent" && + (value_node->link_name(i) == "offset" || + value_node->link_name(i) == "scale" || + value_node->link_name(i) == "fixed_length")) + continue; + error(element, strprintf(_("<%s> is missing link %d (%s)"), element->get_name().c_str(), i, @@ -1292,7 +1303,6 @@ CanvasParser::parse_linkable_value_node(xmlpp::Element *element,Canvas::Handle c // pre 0.4 canvases had *calctangent outputs scaled down by 0.5 for some reason if (element->get_name() == "blinecalctangent" || element->get_name() == "segcalctangent") { - String version(canvas->get_version()); if (version == "0.1" || version == "0.2" || version == "0.3") { handle scale_value_node=LinkableValueNode::create("scale",type); diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp index 9dfc067..8fa0212 100644 --- a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp @@ -65,6 +65,9 @@ ValueNode_BLineCalcTangent::ValueNode_BLineCalcTangent(const ValueBase::Type &x) set_link("bline",value_node); set_link("loop",ValueNode_Const::create(bool(false))); set_link("amount",ValueNode_Const::create(Real(0.5))); + set_link("offset",ValueNode_Const::create(Angle::deg(0))); + set_link("scale",ValueNode_Const::create(Real(1.0))); + set_link("fixed_length",ValueNode_Const::create(bool(false))); } LinkableValueNode* @@ -93,6 +96,9 @@ ValueNode_BLineCalcTangent::operator()(Time t)const int size = bline.size(), from_vertex; bool loop((*loop_)(t).get(bool())); Real amount((*amount_)(t).get(Real())); + Angle offset((*offset_)(t).get(Angle())); + Real scale((*scale_)(t).get(Real())); + bool fixed_length((*fixed_length_)(t).get(bool())); BLinePoint blinepoint0, blinepoint1; if (!looped) size--; @@ -130,9 +136,20 @@ ValueNode_BLineCalcTangent::operator()(Time t)const switch (get_type()) { - case ValueBase::TYPE_ANGLE: return deriv(amount-from_vertex).angle(); - case ValueBase::TYPE_REAL: return deriv(amount-from_vertex).mag(); - case ValueBase::TYPE_VECTOR: return deriv(amount-from_vertex); + case ValueBase::TYPE_ANGLE: return deriv(amount-from_vertex).angle() + offset; + case ValueBase::TYPE_REAL: + { + if (fixed_length) return scale; + return deriv(amount-from_vertex).mag() * scale; + } + case ValueBase::TYPE_VECTOR: + { + Vector tangent(deriv(amount-from_vertex)); + Angle angle(tangent.angle() + offset); + Real mag = fixed_length ? scale : (tangent.mag() * scale); + return Vector(Angle::cos(angle).get()*mag, + Angle::sin(angle).get()*mag); + } default: assert(0); return ValueBase(); } } @@ -156,9 +173,12 @@ ValueNode_BLineCalcTangent::set_link_vfunc(int i,ValueNode::Handle value) switch(i) { - case 0: CHECK_TYPE_AND_SET_VALUE(bline_, ValueBase::TYPE_LIST); - case 1: CHECK_TYPE_AND_SET_VALUE(loop_, ValueBase::TYPE_BOOL); - case 2: CHECK_TYPE_AND_SET_VALUE(amount_, ValueBase::TYPE_REAL); + case 0: CHECK_TYPE_AND_SET_VALUE(bline_, ValueBase::TYPE_LIST); + case 1: CHECK_TYPE_AND_SET_VALUE(loop_, ValueBase::TYPE_BOOL); + case 2: CHECK_TYPE_AND_SET_VALUE(amount_, ValueBase::TYPE_REAL); + case 3: CHECK_TYPE_AND_SET_VALUE(offset_, ValueBase::TYPE_ANGLE); + case 4: CHECK_TYPE_AND_SET_VALUE(scale_, ValueBase::TYPE_REAL); + case 5: CHECK_TYPE_AND_SET_VALUE(fixed_length_, ValueBase::TYPE_BOOL); } return false; } @@ -173,6 +193,9 @@ ValueNode_BLineCalcTangent::get_link_vfunc(int i)const case 0: return bline_; case 1: return loop_; case 2: return amount_; + case 3: return offset_; + case 4: return scale_; + case 5: return fixed_length_; } return 0; @@ -181,7 +204,7 @@ ValueNode_BLineCalcTangent::get_link_vfunc(int i)const int ValueNode_BLineCalcTangent::link_count()const { - return 3; + return 6; } String @@ -194,6 +217,9 @@ ValueNode_BLineCalcTangent::link_name(int i)const case 0: return "bline"; case 1: return "loop"; case 2: return "amount"; + case 3: return "offset"; + case 4: return "scale"; + case 5: return "fixed_length"; } return String(); } @@ -208,6 +234,9 @@ ValueNode_BLineCalcTangent::link_local_name(int i)const case 0: return _("BLine"); case 1: return _("Loop"); case 2: return _("Amount"); + case 3: return _("Offset"); + case 4: return _("Scale"); + case 5: return _("Fixed Length"); } return String(); } @@ -215,9 +244,12 @@ ValueNode_BLineCalcTangent::link_local_name(int i)const int ValueNode_BLineCalcTangent::get_link_index_from_name(const String &name)const { - if(name=="bline") return 0; - if(name=="loop") return 1; - if(name=="amount") return 2; + if (name=="bline") return 0; + if (name=="loop") return 1; + if (name=="amount") return 2; + if (name=="offset") return 3; + if (name=="scale") return 4; + if (name=="fixed_length") return 5; throw Exception::BadLinkName(name); } diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.h b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.h index 92e219a..ffe3747 100644 --- a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.h +++ b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.h @@ -40,6 +40,9 @@ class ValueNode_BLineCalcTangent : public LinkableValueNode ValueNode::RHandle bline_; ValueNode::RHandle loop_; ValueNode::RHandle amount_; + ValueNode::RHandle offset_; + ValueNode::RHandle scale_; + ValueNode::RHandle fixed_length_; ValueNode_BLineCalcTangent(const ValueBase::Type &x=ValueBase::TYPE_VECTOR); -- 2.7.4