Skip to content

Commit

Permalink
Don't remove animated properties initiated through the Element API.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Feb 1, 2020
1 parent 5902905 commit 90c452b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Include/RmlUi/Core/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ class RMLUICORE_API Element : public ScriptInterface, public EnableObserverPtr<E
void UpdateTransformState();

/// Start an animation, replacing any existing animations of the same property name. If start_value is null, the element's current value is used.
ElementAnimationList::iterator StartAnimation(PropertyId property_id, const Property * start_value, int num_iterations, bool alternate_direction, float delay, bool origin_is_animation_property);
ElementAnimationList::iterator StartAnimation(PropertyId property_id, const Property * start_value, int num_iterations, bool alternate_direction, float delay, bool initiated_by_animation_property);

/// Add a key to an animation, extending its duration. If target_value is null, the element's current value is used.
bool AddAnimationKeyTime(PropertyId property_id, const Property * target_value, float time, Tween tween);
Expand All @@ -648,10 +648,10 @@ class RMLUICORE_API Element : public ScriptInterface, public EnableObserverPtr<E
bool StartTransition(const Transition& transition, const Property& start_value, const Property& target_value);

/// Removes all transitions that are no longer part of the element's 'transition' property.
void UpdateTransition();
void HandleTransitionProperty();

/// Starts new animations and removes animations no longer part of the element's 'animation' property.
void UpdateAnimation();
void HandleAnimationProperty();

/// Advances the animations (including transitions) forward in time.
void AdvanceAnimations();
Expand Down
2 changes: 1 addition & 1 deletion Samples/basic/demo/data/demo.rml
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ progressbar {

<h1>Sprite sheets</h1>
<p>Sprite sheets are defined by an image source and a collection of sprites, and can be declared in RCSS. Sprites are essentially rectangles into the given image. For example, the following image</p>
<img src="../../../assets/invader.tga" rect="0 0 500 300" style="margin-top: 10px; margin-bottom: 10px;"/>
<img src="../../../assets/invader.tga" rect="0 0 500 435" style="margin-top: 10px; margin-bottom: 10px;"/>
<p>is used to render most sprites in this demo. Sprites can be used in decorators and image elements as if they were separate images.</p>
</panel>
<tab>Font effects</tab>
Expand Down
25 changes: 14 additions & 11 deletions Source/Core/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ void Element::Update(float dp_ratio)

UpdateStructure();

UpdateTransition();
UpdateAnimation();
HandleTransitionProperty();
HandleAnimationProperty();
AdvanceAnimations();

scroll->Update();
Expand All @@ -191,7 +191,7 @@ void Element::Update(float dp_ratio)
// Do en extra pass over the animations and properties if the 'animation' property was just changed.
if (dirty_animation)
{
UpdateAnimation();
HandleAnimationProperty();
AdvanceAnimations();
UpdateProperties();
}
Expand Down Expand Up @@ -2149,7 +2149,7 @@ bool Element::AddAnimationKey(const String & property_name, const Property & tar
}


ElementAnimationList::iterator Element::StartAnimation(PropertyId property_id, const Property* start_value, int num_iterations, bool alternate_direction, float delay, bool origin_is_animation_property)
ElementAnimationList::iterator Element::StartAnimation(PropertyId property_id, const Property* start_value, int num_iterations, bool alternate_direction, float delay, bool initiated_by_animation_property)
{
auto it = std::find_if(animations.begin(), animations.end(), [&](const ElementAnimation& el) { return el.GetPropertyId() == property_id; });

Expand Down Expand Up @@ -2179,7 +2179,7 @@ ElementAnimationList::iterator Element::StartAnimation(PropertyId property_id, c

if (value.definition)
{
ElementAnimationOrigin origin = (origin_is_animation_property ? ElementAnimationOrigin::Animation : ElementAnimationOrigin::User);
ElementAnimationOrigin origin = (initiated_by_animation_property ? ElementAnimationOrigin::Animation : ElementAnimationOrigin::User);
double start_time = Clock::GetElapsedTime() + (double)delay;
*it = ElementAnimation{ property_id, origin, value, *this, start_time, 0.0f, num_iterations, alternate_direction };
}
Expand Down Expand Up @@ -2255,7 +2255,7 @@ bool Element::StartTransition(const Transition & transition, const Property& sta
return result;
}

void Element::UpdateTransition()
void Element::HandleTransitionProperty()
{
if(dirty_transition)
{
Expand Down Expand Up @@ -2295,15 +2295,15 @@ void Element::UpdateTransition()
);
}

// We can decide what to do with ended animations here, just removing them seems to be the CSS approach.
// We can decide what to do with cancelled transitions here.
for (auto it = it_remove; it != animations.end(); ++it)
RemoveProperty(it->GetPropertyId());

animations.erase(it_remove, animations.end());
}
}

void Element::UpdateAnimation()
void Element::HandleAnimationProperty()
{
// Note: We are effectively restarting all animations whenever 'dirty_animation' is set. Use the dirty flag with care,
// or find another approach which only updates actual "dirty" animations.
Expand All @@ -2324,7 +2324,7 @@ void Element::UpdateAnimation()
[](const ElementAnimation & animation) { return animation.GetOrigin() != ElementAnimationOrigin::Animation; }
);

// We can decide what to do with ended animations here, should be consistent with removal of transitions.
// We can decide what to do with cancelled animations here.
for (auto it = it_remove; it != animations.end(); ++it)
RemoveProperty(it->GetPropertyId());

Expand Down Expand Up @@ -2392,8 +2392,11 @@ void Element::AdvanceAnimations()
dictionary_list.emplace_back();
dictionary_list.back().emplace("property", StyleSheetSpecification::GetPropertyName(it->GetPropertyId()));
is_transition.push_back(it->IsTransition());
// Remove the property on ended animation (should do the same as in UpdateAnimation)
RemoveProperty(it->GetPropertyId());

// Remove completed transition- and animation-initiated properties.
// Should behave like in HandleTransitionProperty() and HandleAnimationProperty() respectively.
if (it->GetOrigin() != ElementAnimationOrigin::User)
RemoveProperty(it->GetPropertyId());
}

// Need to erase elements before submitting event, as iterators might be invalidated when calling external code.
Expand Down

0 comments on commit 90c452b

Please sign in to comment.