Sfoglia il codice sorgente

Add definition to default property value

Michael Ragazzon 6 anni fa
parent
commit
24e369e69c

+ 2 - 0
Include/Rocket/Core/PropertyDefinition.h

@@ -45,6 +45,8 @@ class ROCKETCORE_API PropertyDefinition
 {
 public:
 	PropertyDefinition(const String& default_value, bool inherited, bool forces_layout);
+	PropertyDefinition(const PropertyDefinition &) = delete; 
+	PropertyDefinition& operator=(const PropertyDefinition &) = delete;
 	virtual ~PropertyDefinition();
 
 	/// Registers a parser to parse values for this definition.

+ 7 - 2
Source/Core/ElementAnimation.cpp

@@ -84,9 +84,10 @@ static Property InterpolateProperties(const Property & p0, const Property& p1, f
 {
 	if ((p0.unit & Property::NUMBER_LENGTH_PERCENT) && (p1.unit & Property::NUMBER_LENGTH_PERCENT))
 	{
-		if (p0.unit == p1.unit)
+		if (p0.unit == p1.unit || !definition)
 		{
 			// If we have the same units, we can just interpolate regardless of what the value represents.
+			// Or if we have distinct units but no definition, all bets are off. This shouldn't occur, just interpolate values.
 			float f0 = p0.value.Get<float>();
 			float f1 = p1.value.Get<float>();
 			float f = (1.0f - alpha) * f0 + alpha * f1;
@@ -368,7 +369,10 @@ ElementAnimation::ElementAnimation(const String& property_name, const Property&
 	: property_name(property_name), duration(duration), num_iterations(num_iterations), alternate_direction(alternate_direction),
 	last_update_world_time(start_world_time), time_since_iteration_start(0.0f), current_iteration(0), reverse_direction(false), animation_complete(false), is_transition(is_transition)
 {
-	ROCKET_ASSERT(current_value.definition);
+	if (!current_value.definition)
+	{
+		Log::Message(Log::LT_WARNING, "Property in animation key did not have a definition (while adding key '%s').", current_value.ToString().CString());
+	}
 	InternalAddKey(AnimationKey{ 0.0f, current_value, Tween{} });
 }
 
@@ -490,6 +494,7 @@ float ElementAnimation::GetInterpolationFactorAndKeys(int* out_key0, int* out_ke
 
 Property ElementAnimation::UpdateAndGetProperty(double world_time, Element& element)
 {
+	ROCKET_ASSERT(keys.size() >= 2);
 	float dt = float(world_time - last_update_world_time);
 	if (animation_complete || dt <= 0.0f)
 		return Property{};

+ 1 - 0
Source/Core/PropertyDefinition.cpp

@@ -37,6 +37,7 @@ PropertyDefinition::PropertyDefinition(const String& _default_value, bool _inher
 {
 	inherited = _inherited;
 	forces_layout = _forces_layout;
+	default_value.definition = this;
 }
 
 PropertyDefinition::~PropertyDefinition()