return ValueBase();
}
+synfig::ValueBase
+synfig::ValueNode_Range::get_inverse(Time t, const synfig::Vector &target_value) const
+{
+ switch (get_type())
+ {
+ case ValueBase::TYPE_INTEGER:
+ {
+ int max_value((*max_)(t).get(int()));
+ int min_value((*min_)(t).get(int()));
+ return std::max(min_value, std::min(max_value, int(target_value.mag())));
+ }
+ case ValueBase::TYPE_REAL:
+ {
+ Real max_value((*max_)(t).get(Real()));
+ Real min_value((*min_)(t).get(Real()));
+ return std::max(min_value, std::min(max_value, target_value.mag()));
+ }
+ case ValueBase::TYPE_ANGLE:
+ {
+ Angle max_value((*max_)(t).get(Angle()));
+ Angle min_value((*min_)(t).get(Angle()));
+ Angle target_angle(Angle::tan(target_value[1],target_value[0]));
+ return target_angle>max_value?max_value:target_angle<min_value?min_value:target_angle;
+ }
+ case ValueBase::TYPE_TIME:
+ {
+ Real max_value((*max_)(t).get(Time()));
+ Real min_value((*min_)(t).get(Time()));
+ return std::max(min_value, std::min(max_value, target_value.mag()));
+ }
+ default:
+ return target_value;
+ }
+ return ValueBase();
+}
+
+synfig::ValueBase
+synfig::ValueNode_Range::get_inverse(Time t, const synfig::Angle &target_value) const
+{
+ Angle minimum = (* min_)(t).get(Angle());
+ Angle maximum = (* max_)(t).get(Angle());
+ Angle link = (*link_)(t).get(Angle());
+ switch (get_type())
+ {
+ default:
+ // Notice that target_value is the rotation between the current
+ // 'link' value and the target angle in the canvas, so we need
+ // to add it to 'link'
+ if(Angle::rad(maximum).get()>=Angle::rad(link+target_value).get() && Angle::rad(link+target_value).get()>=Angle::rad(minimum).get())
+ return link + target_value;
+ else if (Angle::rad(minimum).get()>Angle::rad(target_value).get())
+ return minimum;
+ else
+ return maximum;
+ }
+ return ValueBase();
+}
+
+
bool
ValueNode_Range::set_link_vfunc(int i,ValueNode::Handle value)
{
virtual String get_name()const;
virtual String get_local_name()const;
+ //! Returns the modified Link to match the target value at time t
+ ValueBase get_inverse(Time t, const synfig::Vector &target_value) const;
+ ValueBase get_inverse(Time t, const synfig::Angle &target_value) const;
+
virtual ValueNode::LooseHandle get_link_vfunc(int i)const;
virtual int link_count()const;
virtual String link_name(int i)const;
#include <synfig/valuenode_linear.h>
#include <synfig/valuenode_timedswap.h>
#include <synfig/valuenode_scale.h>
+#include <synfig/valuenode_range.h>
#include <synfig/valuenode_dynamiclist.h>
#include <synfig/valuenode_twotone.h>
#include <synfig/valuenode_stripes.h>
return false;
}
+ if (ValueNode_Range::Handle range_value_node = ValueNode_Range::Handle::cast_dynamic(value_desc.get_value_node()))
+ {
+ int link_index(range_value_node->get_link_index_from_name("link"));
+ return canvas_interface()->change_value(
+ synfigapp::ValueDesc(range_value_node,link_index),
+ range_value_node->get_inverse(get_time(), value)
+ );
+ }
+
switch(value_desc.get_value_type())
{
case ValueBase::TYPE_REAL:
return false;
}
+ if (ValueNode_Range::Handle range_value_node = ValueNode_Range::Handle::cast_dynamic(value_desc.get_value_node()))
+ {
+ int link_index(range_value_node->get_link_index_from_name("link"));
+ return canvas_interface()->change_value(
+ synfigapp::ValueDesc(range_value_node,link_index),
+ range_value_node->get_inverse(get_time(), rotation)
+ );
+ }
// \todo will this really always be the case?
assert(value_desc.get_value_type() == ValueBase::TYPE_ANGLE);
return canvas_interface()->change_value(value_desc, value_desc.get_value(get_time()).get(Angle()) + rotation);
#include <synfig/valuenode_blinecalcvertex.h>
#include <synfig/valuenode_blinecalcwidth.h>
#include <synfig/valuenode_scale.h>
+#include <synfig/valuenode_range.h>
#include <map>
#include "general.h"
|| ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_node)
|| ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_node)
|| ValueNode_Scale::Handle::cast_dynamic(value_node)
+ || ValueNode_Range::Handle::cast_dynamic(value_node)
)
return true;
return false;