diff --git a/include/eepp/ui/css/stylesheetlength.hpp b/include/eepp/ui/css/stylesheetlength.hpp index db0a420a0..eb108fef9 100644 --- a/include/eepp/ui/css/stylesheetlength.hpp +++ b/include/eepp/ui/css/stylesheetlength.hpp @@ -50,6 +50,8 @@ class StyleSheetLength { Float asDp( const Float& parentSize, const Sizef& viewSize, const Float& displayDpi, const Float& elFontSize = 12, const Float& globalFontSize = 12 ) const; + bool operator==( const StyleSheetLength& val ); + StyleSheetLength& operator=( const StyleSheetLength& val ); StyleSheetLength& operator=( const Float& val ); diff --git a/include/eepp/ui/css/stylesheetlengthtransition.hpp b/include/eepp/ui/css/stylesheetlengthtransition.hpp new file mode 100644 index 000000000..a42b207dc --- /dev/null +++ b/include/eepp/ui/css/stylesheetlengthtransition.hpp @@ -0,0 +1,69 @@ +#ifndef EE_UI_CSS_STYLESHEETLENGTHTRANSITION_HPP +#define EE_UI_CSS_STYLESHEETLENGTHTRANSITION_HPP + +#include +#include +#include + +using namespace EE::Math; +using namespace EE::Scene; + +namespace EE { namespace UI { namespace CSS { + +class EE_API StyleSheetLengthTransition : public Action { + public: + typedef std::function ContainerLengthProvider; + + static StyleSheetLengthTransition * New( const std::string& propertyName, const std::string& startValue, const std::string& endValue, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); + + void start() override; + + void stop() override; + + void update( const Time& time ) override; + + bool isDone() override; + + Float getCurrentProgress(); + + Action * clone() const override; + + Action * reverse() const override; + + const std::string& getPropertyName() const; + + const std::string& getStartValue() const; + + const std::string& getEndValue() const; + + const Time& getDuration() const; + + const Ease::Interpolation& getType() const; + + const Time& getElapsed() const; + + const Float& getContainerLength() const; + + StyleSheetLengthTransition& setContainerLength(const Float& containerLength); + + StyleSheetLengthTransition& setContainerLengthFunction(const ContainerLengthProvider& containerLengthProvider); + protected: + StyleSheetLengthTransition( const std::string& propertyName, const std::string& startValue, const std::string& endValue, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); + + void onStart() override; + + void onUpdate( const Time& time ) override; + + std::string mPropertyName; + std::string mStartValue; + std::string mEndValue; + Time mDuration; + Time mElapsed; + Ease::Interpolation mType; + Float mContainerLength; + ContainerLengthProvider mContainerLengthFunction; +}; + +}}} + +#endif diff --git a/include/eepp/ui/css/stylesheetproperty.hpp b/include/eepp/ui/css/stylesheetproperty.hpp index c090e958a..ffe2addfe 100644 --- a/include/eepp/ui/css/stylesheetproperty.hpp +++ b/include/eepp/ui/css/stylesheetproperty.hpp @@ -17,6 +17,8 @@ class EE_API StyleSheetProperty { const std::string& getName() const; + const Uint32& getNameHash() const; + const std::string& getValue() const; const Uint32& getSpecificity() const; @@ -32,8 +34,11 @@ class EE_API StyleSheetProperty { const bool& isVolatile() const; void setVolatile( const bool& isVolatile ); + + bool operator==( const StyleSheetProperty& property ); protected: std::string mName; + Uint32 mNameHash; std::string mValue; Uint32 mSpecificity; bool mVolatile; diff --git a/include/eepp/ui/css/transitiondefinition.hpp b/include/eepp/ui/css/transitiondefinition.hpp new file mode 100644 index 000000000..dfd0a09b6 --- /dev/null +++ b/include/eepp/ui/css/transitiondefinition.hpp @@ -0,0 +1,42 @@ +#ifndef EE_UI_CSS_TRANSITIONDEFINITION_HPP +#define EE_UI_CSS_TRANSITIONDEFINITION_HPP + +#include +#include +#include +#include +#include + +using namespace EE::Math; +using namespace EE::System; + +namespace EE { namespace UI { namespace CSS { + +class EE_API TransitionDefinition { + public: + static std::map parseTransitionProperties( const std::vector& styleSheetProperties ); + + TransitionDefinition() : + timingFunction( Ease::Linear ) + {} + + const std::string& getProperty() const { return property; } + + Ease::Interpolation getTimingFunction() const { return timingFunction; } + + const Time& getDelay() const { return delay; } + + const Time& getDuration() const { return duration; } + + std::string property; + Ease::Interpolation timingFunction; + Time delay; + Time duration; +}; + + +typedef std::map TransitionsMap; + +}}} + +#endif diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index e28cecd87..78cabf72f 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -197,9 +197,9 @@ class EE_API UINode : public Node { virtual void setFocus(); - virtual Float convertLength( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth = true ); + virtual Float convertLength( const CSS::StyleSheetLength& length, const Float& containerLength ); - Float lengthAsDp( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth = true ); + Float convertLengthAsDp( const CSS::StyleSheetLength& length, const Float& containerLength ); protected: Vector2f mDpPos; Sizef mDpSize; diff --git a/include/eepp/ui/uinodedrawable.hpp b/include/eepp/ui/uinodedrawable.hpp index 5f8f63bd1..751917554 100644 --- a/include/eepp/ui/uinodedrawable.hpp +++ b/include/eepp/ui/uinodedrawable.hpp @@ -26,40 +26,6 @@ class EE_API UINodeDrawable : public Drawable { static Repeat repeatFromText( const std::string& text ); - class EE_API MoveAction : public Action { - public: - static MoveAction * New( const std::string& posEqStart, const std::string& posEqEnd, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); - - void start() override; - - void stop() override; - - void update( const Time& time ) override; - - bool isDone() override; - - Float getCurrentProgress(); - - Action * clone() const override; - - Action * reverse() const override; - - const Vector2f& getOffset() const { return mOffset; } - protected: - MoveAction( const std::string& posEqStart, const std::string& posEqEnd, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); - - void onStart() override; - - void onUpdate( const Time& time ) override; - - std::string mStart; - std::string mEnd; - Time mDuration; - Ease::Interpolation mType; - Time mElapsed; - Vector2f mOffset; - }; - class EE_API LayerDrawable : public Drawable { public: static LayerDrawable * New( UINodeDrawable * container ); @@ -111,10 +77,6 @@ class EE_API UINodeDrawable : public Drawable { Sizef calcDrawableSize( const std::string& drawableSizeEq ); Vector2f calcPosition( const std::string& positionEq ); - - MoveAction * getMoveAction() const; - - void setMoveAction(MoveAction * moveAction); protected: UINodeDrawable * mContainer; Sizef mSize; @@ -127,8 +89,6 @@ class EE_API UINodeDrawable : public Drawable { Drawable * mDrawable; Uint32 mResourceChangeCbId; Repeat mRepeat; - MoveAction * mMoveAction; - Uint32 mMoveActionCbId; virtual void onPositionChange(); diff --git a/include/eepp/ui/uistyle.hpp b/include/eepp/ui/uistyle.hpp index 8bfa51fae..1ddd3819b 100644 --- a/include/eepp/ui/uistyle.hpp +++ b/include/eepp/ui/uistyle.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -22,27 +23,6 @@ class UIWidget; class EE_API UIStyle : public UIState { public: - class TransitionInfo - { - public: - TransitionInfo() : - timingFunction( Ease::Linear ) - {} - - const std::string& getProperty() const { return property; } - - Ease::Interpolation getTimingFunction() const { return timingFunction; } - - const Time& getDelay() const { return delay; } - - const Time& getDuration() const { return duration; } - - std::string property; - Ease::Interpolation timingFunction; - Time delay; - Time duration; - }; - static UIStyle * New( UIWidget * widget ); explicit UIStyle( UIWidget * widget ); @@ -67,19 +47,17 @@ class EE_API UIStyle : public UIState { bool hasTransition( const std::string& propertyName ); - TransitionInfo getTransition( const std::string& propertyName ); + CSS::TransitionDefinition getTransition( const std::string& propertyName ); const bool& isChangingState() const; protected: - typedef std::map TransitionsMap; - UIWidget * mWidget; CSS::StyleSheetStyleVector mCacheableStyles; CSS::StyleSheetStyleVector mNoncacheableStyles; CSS::StyleSheetStyle mElementStyle; CSS::StyleSheetProperties mProperties; std::vector mTransitionAttributes; - TransitionsMap mTransitions; + CSS::TransitionsMap mTransitions; std::set mRelatedWidgets; std::set mSubscribedWidgets; bool mChangingState; @@ -88,8 +66,6 @@ class EE_API UIStyle : public UIState { void updateState(); - void parseTransitions(); - void subscribeNonCacheableStyles(); void unsubscribeNonCacheableStyles(); diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 2682a617d..310aa2793 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -292,6 +292,7 @@ ../../include/eepp/ui/css/stylesheet.hpp ../../include/eepp/ui/css/stylesheetelement.hpp ../../include/eepp/ui/css/stylesheetlength.hpp +../../include/eepp/ui/css/stylesheetlengthtransition.hpp ../../include/eepp/ui/css/stylesheetparser.hpp ../../include/eepp/ui/css/stylesheetpropertiesparser.hpp ../../include/eepp/ui/css/stylesheetproperty.hpp @@ -299,6 +300,7 @@ ../../include/eepp/ui/css/stylesheetselectorparser.hpp ../../include/eepp/ui/css/stylesheetselectorrule.hpp ../../include/eepp/ui/css/stylesheetstyle.hpp +../../include/eepp/ui/css/transitiondefinition.hpp ../../include/eepp/ui/marginmove/scale.hpp ../../include/eepp/ui/tools/textureatlaseditor.hpp ../../include/eepp/ui/tools/uicolorpicker.hpp @@ -712,6 +714,7 @@ ../../src/eepp/system/zip.cpp ../../src/eepp/ui/css/stylesheet.cpp ../../src/eepp/ui/css/stylesheetlength.cpp +../../src/eepp/ui/css/stylesheetlengthtransition.cpp ../../src/eepp/ui/css/stylesheetparser.cpp ../../src/eepp/ui/css/stylesheetpropertiesparser.cpp ../../src/eepp/ui/css/stylesheetproperty.cpp @@ -719,6 +722,7 @@ ../../src/eepp/ui/css/stylesheetselectorparser.cpp ../../src/eepp/ui/css/stylesheetselectorrule.cpp ../../src/eepp/ui/css/stylesheetstyle.cpp +../../src/eepp/ui/css/transitiondefinition.cpp ../../src/eepp/ui/tools/textureatlaseditor.cpp ../../src/eepp/ui/tools/textureatlasnew.cpp ../../src/eepp/ui/tools/textureatlasnew.hpp diff --git a/src/eepp/ui/css/stylesheetlength.cpp b/src/eepp/ui/css/stylesheetlength.cpp index 8b4a68733..bf2074d2c 100644 --- a/src/eepp/ui/css/stylesheetlength.cpp +++ b/src/eepp/ui/css/stylesheetlength.cpp @@ -110,6 +110,10 @@ Float StyleSheetLength::asDp( const Float& parentSize, const Sizef& viewSize, co return PixelDensity::pxToDp( asPixels( parentSize, viewSize, displayDpi, elFontSize, globalFontSize ) ); } +bool StyleSheetLength::operator==( const StyleSheetLength& length ) { + return mValue == length.mValue && mUnit == length.mUnit; +} + StyleSheetLength& StyleSheetLength::operator=( const Float& val ) { mValue = val; mUnit = Unit::Px; diff --git a/src/eepp/ui/css/stylesheetlengthtransition.cpp b/src/eepp/ui/css/stylesheetlengthtransition.cpp new file mode 100644 index 000000000..ad0c1639f --- /dev/null +++ b/src/eepp/ui/css/stylesheetlengthtransition.cpp @@ -0,0 +1,112 @@ +#include +#include +#include + +using namespace EE::Math::easing; + +namespace EE { namespace UI { namespace CSS { + +StyleSheetLengthTransition * StyleSheetLengthTransition::New( const std::string& propertyName, const std::string& startValue, const std::string& endValue, const Time& duration, const Ease::Interpolation& type ) { + return eeNew( StyleSheetLengthTransition, ( propertyName, startValue, endValue, duration, type ) ); +} + +StyleSheetLengthTransition::StyleSheetLengthTransition( const std::string& propertyName, const std::string& startValue, const std::string& endValue, const Time& duration, const Ease::Interpolation& type ) : + mPropertyName( propertyName ), + mStartValue( startValue ), + mEndValue( endValue ), + mDuration( duration ), + mType( type ) +{} + +Action * StyleSheetLengthTransition::clone() const { + return &StyleSheetLengthTransition::New( mPropertyName, mStartValue, mEndValue, mDuration, mType ) + ->setContainerLength( mContainerLength ) + .setContainerLengthFunction( mContainerLengthFunction ); +} + +Action * StyleSheetLengthTransition::reverse() const { + return &StyleSheetLengthTransition::New( mPropertyName, mEndValue, mStartValue, mDuration, mType ) + ->setContainerLength( mContainerLength ) + .setContainerLengthFunction( mContainerLengthFunction ); +} + +void StyleSheetLengthTransition::start() { + onStart(); + + sendEvent( ActionType::OnStart ); +} + +void StyleSheetLengthTransition::stop() { + onStop(); + + sendEvent( ActionType::OnStop ); +} + +void StyleSheetLengthTransition::update( const Time& time ) { + mElapsed += time; + + onUpdate( time ); +} + +bool StyleSheetLengthTransition::isDone() { + return mElapsed.asMicroseconds() >= mDuration.asMicroseconds(); +} + +Float StyleSheetLengthTransition::getCurrentProgress() { + return mElapsed.asMilliseconds() / mDuration.asMilliseconds(); +} + +void StyleSheetLengthTransition::onStart() { + onUpdate( Time::Zero ); +} + +void StyleSheetLengthTransition::onUpdate( const Time& ) { + if ( NULL != mNode && mNode->isWidget() ) { + UIWidget * node = mNode->asType(); + Float start = node->convertLength( mStartValue, mContainerLengthFunction ? mContainerLengthFunction() : mContainerLength ); + Float end = node->convertLength( mEndValue, mContainerLengthFunction ? mContainerLengthFunction() : mContainerLength ); + Time time = mElapsed.asMicroseconds() > mDuration.asMicroseconds() ? mDuration : mElapsed; + Float value = easingCb[ mType ]( time.asMilliseconds(), start, end - start, mDuration.asMilliseconds() ); + node->setStyleSheetProperty( mPropertyName, String::format( "%.f", value ) ); + } +} + +const Float& StyleSheetLengthTransition::getContainerLength() const { + return mContainerLength; +} + +StyleSheetLengthTransition& StyleSheetLengthTransition::setContainerLength( const Float& containerLength ) { + mContainerLength = containerLength; + return *this; +} + +StyleSheetLengthTransition& StyleSheetLengthTransition::setContainerLengthFunction( const StyleSheetLengthTransition::ContainerLengthProvider& containerLengthProvider ) { + mContainerLengthFunction = containerLengthProvider; + return *this; +} + +const Time& StyleSheetLengthTransition::getElapsed() const { + return mElapsed; +} + +const Ease::Interpolation& StyleSheetLengthTransition::getType() const { + return mType; +} + +const Time& StyleSheetLengthTransition::getDuration() const { + return mDuration; +} + +const std::string& StyleSheetLengthTransition::getEndValue() const { + return mEndValue; +} + +const std::string& StyleSheetLengthTransition::getStartValue() const { + return mStartValue; +} + +const std::string& StyleSheetLengthTransition::getPropertyName() const { + return mPropertyName; +} + +}}} diff --git a/src/eepp/ui/css/stylesheetproperty.cpp b/src/eepp/ui/css/stylesheetproperty.cpp index 067560285..b3948c09e 100644 --- a/src/eepp/ui/css/stylesheetproperty.cpp +++ b/src/eepp/ui/css/stylesheetproperty.cpp @@ -12,6 +12,7 @@ StyleSheetProperty::StyleSheetProperty() : StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::string& value ) : mName( String::toLower( String::trim( name ) ) ), + mNameHash( String::hash( mName ) ), mValue( String::trim( value ) ), mSpecificity( 0 ), mVolatile( false ), @@ -22,6 +23,7 @@ StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::stri StyleSheetProperty::StyleSheetProperty( const std::string & name, const std::string& value, const Uint32 & specificity, const bool& isVolatile ) : mName( String::toLower( String::trim( name ) ) ), + mNameHash( String::hash( mName ) ), mValue( String::trim( value ) ), mSpecificity( specificity ), mVolatile( isVolatile ), @@ -56,6 +58,7 @@ bool StyleSheetProperty::isEmpty() const { void StyleSheetProperty::setName( const std::string& name ) { mName = name; + mNameHash = String::hash( mName ); } void StyleSheetProperty::setValue( const std::string& value ) { @@ -70,6 +73,14 @@ void StyleSheetProperty::setVolatile( const bool & isVolatile ) { mVolatile = isVolatile; } +bool StyleSheetProperty::operator==( const StyleSheetProperty& property ) { + return mNameHash == property.mNameHash && mValue == property.mValue; +} + +const Uint32& StyleSheetProperty::getNameHash() const { + return mNameHash; +} + void StyleSheetProperty::checkImportant() { if ( String::endsWith( mValue, "!important" ) ) { mImportant = true; diff --git a/src/eepp/ui/css/transitiondefinition.cpp b/src/eepp/ui/css/transitiondefinition.cpp new file mode 100644 index 000000000..db30af4c9 --- /dev/null +++ b/src/eepp/ui/css/transitiondefinition.cpp @@ -0,0 +1,115 @@ +#include +#include +#include + +using namespace EE::Scene; + +namespace EE { namespace UI { namespace CSS { + +std::map TransitionDefinition::parseTransitionProperties( const std::vector& styleSheetProperties ) { + std::vector properties; + std::vector