synfig::ValueBase
synfig::ValueNode_Range::get_inverse(Time t, const synfig::Vector &target_value) const
{
	Type &type(get_type());
	if (type == 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())));
	}
	else
	if (type == 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()));
	}
	else
	if (type == 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;
	}
	else
	if (type == 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()));
	}

	return target_value;
}
예제 #2
0
synfig::ValueBase
synfig::ValueNode_Scale::get_inverse(Time t, const synfig::Vector &target_value) const
{
	Real scalar_value((*scalar)(t).get(Real()));
	if(scalar_value==0)
			throw runtime_error(strprintf("ValueNode_Scale: %s",_("Attempting to get the inverse of a non invertible Valuenode")));
	else
		{
			if (get_type() == type_real)
				return target_value.mag() / scalar_value;
			if (get_type() == type_angle)
				return Angle::tan(target_value[1] / scalar_value ,target_value[0] / scalar_value);
			return target_value / scalar_value;
		}
	return ValueBase();
}
예제 #3
0
synfig::ValueBase
synfig::ValueNode_Scale::get_inverse(Time t, const synfig::Vector &target_value) const
{
	Real scalar_value((*scalar)(t).get(Real()));
	if(scalar_value==0)
			throw runtime_error(strprintf("ValueNode_Scale: %s",_("Attempting to get the inverse of a non invertible Valuenode")));
	else
		{
			switch (get_type())
			{
				case ValueBase::TYPE_REAL:
					return target_value.mag() / scalar_value;
				case ValueBase::TYPE_ANGLE:
					return Angle::tan(target_value[1] / scalar_value ,target_value[0] / scalar_value);
				default:
					return target_value / scalar_value;
			}
		}
	return ValueBase();
}
예제 #4
0
bool
DuckDrag_SmoothMove::end_duck_drag(Duckmatic* duckmatic)
{
	//synfig::info("end_duck_drag(): Diff= %f",last_translate_.mag());
	if(last_translate_.mag()>0.0001)
	{
		const DuckList selected_ducks(duckmatic->get_selected_ducks());
		DuckList::const_iterator iter;

		int i;

		smart_ptr<OneMoment> wait;if(selected_ducks.size()>20)wait.spawn();

		for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
		{
			if(last_[i].mag()>0.0001)
				{
				if ((*iter)->get_type() == Duck::TYPE_ANGLE)
					{
						if(!(*iter)->signal_edited()(**iter))
						{
							throw String("Bad edit");
						}
					}
					else if (App::restrict_radius_ducks &&
							 (*iter)->is_radius())
					{
						Point point((*iter)->get_point());
						bool changed = false;

						if (point[0] < 0)
						{
							point[0] = 0;
							changed = true;
						}
						if (point[1] < 0)
						{
							point[1] = 0;
							changed = true;
						}

						if (changed) (*iter)->set_point(point);

						if(!(*iter)->signal_edited()(point))
						{
							throw String("Bad edit");
						}
					}
					else
					{
						if(!(*iter)->signal_edited()((*iter)->get_point()))
						{
							throw String("Bad edit");
						}
					}
				}
		}
		//duckmatic->get_selected_ducks()=new_set;
		//duckmatic->refresh_selected_ducks();
		return true;
	}
	else
	{
		duckmatic->signal_user_click_selected_ducks(0);
		return false;
	}
}