diff --git a/include/eepp/ui/uiaction.hpp b/include/eepp/scene/action.hpp similarity index 78% rename from include/eepp/ui/uiaction.hpp rename to include/eepp/scene/action.hpp index 0efc68e8f..84c56e330 100644 --- a/include/eepp/ui/uiaction.hpp +++ b/include/eepp/scene/action.hpp @@ -1,5 +1,5 @@ -#ifndef EE_UIACTION_HPP -#define EE_UIACTION_HPP +#ifndef EE_SCENEACTION_HPP +#define EE_SCENEACTION_HPP #include #include @@ -7,10 +7,13 @@ using namespace EE::System; namespace EE { namespace UI { - class UINode; +}} +using namespace EE::UI; -class EE_API UIAction { +namespace EE { namespace Scene { + +class EE_API Action { public: enum ActionType { @@ -20,11 +23,11 @@ class EE_API UIAction { OnStep }; - typedef cb::Callback2 ActionCallback; + typedef cb::Callback2 ActionCallback; - UIAction(); + Action(); - virtual ~UIAction(); + virtual ~Action(); virtual void start() = 0; @@ -34,9 +37,9 @@ class EE_API UIAction { virtual bool isDone() = 0; - virtual UIAction * clone() const; + virtual Action * clone() const; - virtual UIAction * reverse() const; + virtual Action * reverse() const; Uint32 getFlags() const; diff --git a/include/eepp/scene/actionmanager.hpp b/include/eepp/scene/actionmanager.hpp new file mode 100644 index 000000000..e1152f32b --- /dev/null +++ b/include/eepp/scene/actionmanager.hpp @@ -0,0 +1,39 @@ +#ifndef EE_SCENEACTIONMANAGER_HPP +#define EE_SCENEACTIONMANAGER_HPP + +#include +#include +#include +using namespace EE::System; + +namespace EE { namespace Scene { + +class Action; + +class EE_API ActionManager { + public: + ActionManager(); + + ~ActionManager(); + + void addAction( Action * action ); + + Action * getActionByTag( const Uint32& tag ); + + void removeActionByTag( const Uint32& tag ); + + void removeAction( Action * action ); + + void update( const Time& time ); + + std::size_t count() const; + + bool isEmpty() const; + protected: + std::list mActions; +}; + +}} + +#endif + diff --git a/include/eepp/ui/actions/actioninterpolation1d.hpp b/include/eepp/scene/actions/actioninterpolation1d.hpp similarity index 64% rename from include/eepp/ui/actions/actioninterpolation1d.hpp rename to include/eepp/scene/actions/actioninterpolation1d.hpp index 1e1526fe7..f60ff711f 100644 --- a/include/eepp/ui/actions/actioninterpolation1d.hpp +++ b/include/eepp/scene/actions/actioninterpolation1d.hpp @@ -1,13 +1,13 @@ -#ifndef EE_UI_ACTIONINTERPOLATION1D_HPP -#define EE_UI_ACTIONINTERPOLATION1D_HPP +#ifndef EE_SCENE_ACTIONINTERPOLATION1D_HPP +#define EE_SCENE_ACTIONINTERPOLATION1D_HPP -#include +#include #include using namespace EE::Math; -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { -class EE_API ActionInterpolation1d : public UIAction { +class EE_API ActionInterpolation1d : public Action { public: void start() override; diff --git a/include/eepp/ui/actions/actioninterpolation2d.hpp b/include/eepp/scene/actions/actioninterpolation2d.hpp similarity index 64% rename from include/eepp/ui/actions/actioninterpolation2d.hpp rename to include/eepp/scene/actions/actioninterpolation2d.hpp index 1b968b493..58f71c8dd 100644 --- a/include/eepp/ui/actions/actioninterpolation2d.hpp +++ b/include/eepp/scene/actions/actioninterpolation2d.hpp @@ -1,13 +1,13 @@ -#ifndef EE_UI_ACTIONINTERPOLATION2D_HPP -#define EE_UI_ACTIONINTERPOLATION2D_HPP +#ifndef EE_SCENE_ACTIONINTERPOLATION2D_HPP +#define EE_SCENE_ACTIONINTERPOLATION2D_HPP -#include +#include #include using namespace EE::Math; -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { -class EE_API ActionInterpolation2d : public UIAction { +class EE_API ActionInterpolation2d : public Action { public: void start() override; diff --git a/include/eepp/ui/actions/delay.hpp b/include/eepp/scene/actions/delay.hpp similarity index 56% rename from include/eepp/ui/actions/delay.hpp rename to include/eepp/scene/actions/delay.hpp index 4b3b8d12f..703a9cf61 100644 --- a/include/eepp/ui/actions/delay.hpp +++ b/include/eepp/scene/actions/delay.hpp @@ -1,13 +1,13 @@ -#ifndef EE_UI_ACTION_DELAY_HPP -#define EE_UI_ACTION_DELAY_HPP +#ifndef EE_SCENE_ACTION_DELAY_HPP +#define EE_SCENE_ACTION_DELAY_HPP -#include +#include #include using namespace EE::System; -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { -class EE_API Delay : public UIAction { +class EE_API Delay : public Action { public: static Delay * New( const Time& time ); @@ -19,9 +19,9 @@ class EE_API Delay : public UIAction { bool isDone() override; - UIAction * clone() const override; + Action * clone() const override; - UIAction * reverse() const override; + Action * reverse() const override; protected: Clock mClock; diff --git a/include/eepp/ui/actions/fade.hpp b/include/eepp/scene/actions/fade.hpp similarity index 64% rename from include/eepp/ui/actions/fade.hpp rename to include/eepp/scene/actions/fade.hpp index a634ccdf2..2cf016e27 100644 --- a/include/eepp/ui/actions/fade.hpp +++ b/include/eepp/scene/actions/fade.hpp @@ -1,18 +1,18 @@ -#ifndef EE_UI_ACTION_FADE_HPP -#define EE_UI_ACTION_FADE_HPP +#ifndef EE_SCENE_ACTION_FADE_HPP +#define EE_SCENE_ACTION_FADE_HPP -#include -#include +#include +#include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { class EE_API Fade : public ActionInterpolation1d { public: static Fade * New( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear, const bool& alphaChilds = true ); - UIAction * clone() const override; + Action * clone() const override; - UIAction * reverse() const override; + Action * reverse() const override; protected: Fade( const Float & start, const Float & end, const Time & duration, const Ease::Interpolation & type, const bool& alphaChilds ); diff --git a/include/eepp/ui/actions/marginmove.hpp b/include/eepp/scene/actions/marginmove.hpp similarity index 82% rename from include/eepp/ui/actions/marginmove.hpp rename to include/eepp/scene/actions/marginmove.hpp index 1b5648f43..624e4264c 100644 --- a/include/eepp/ui/actions/marginmove.hpp +++ b/include/eepp/scene/actions/marginmove.hpp @@ -1,15 +1,15 @@ -#ifndef EE_UI_ACTION_MARGINMOVE_HPP -#define EE_UI_ACTION_MARGINMOVE_HPP +#ifndef EE_SCENE_ACTION_MARGINMOVE_HPP +#define EE_SCENE_ACTION_MARGINMOVE_HPP -#include +#include #include #include using namespace EE::Math; -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { -class EE_API MarginMove : public UIAction { +class EE_API MarginMove : public Action { public: static MarginMove * New( const Rect& start, const Rect& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); @@ -21,9 +21,9 @@ class EE_API MarginMove : public UIAction { bool isDone() override; - UIAction * clone() const override; + Action * clone() const override; - UIAction * reverse() const override; + Action * reverse() const override; Interpolation1d getInterpolationLeft() const; diff --git a/include/eepp/ui/actions/move.hpp b/include/eepp/scene/actions/move.hpp similarity index 60% rename from include/eepp/ui/actions/move.hpp rename to include/eepp/scene/actions/move.hpp index cc580f13c..ed3547cd9 100644 --- a/include/eepp/ui/actions/move.hpp +++ b/include/eepp/scene/actions/move.hpp @@ -1,18 +1,18 @@ -#ifndef EE_UI_ACTION_MOVE_HPP -#define EE_UI_ACTION_MOVE_HPP +#ifndef EE_SCENE_ACTION_MOVE_HPP +#define EE_SCENE_ACTION_MOVE_HPP -#include -#include +#include +#include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { class EE_API Move : public ActionInterpolation2d { public: static Move * New( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); - UIAction * clone() const override; + Action * clone() const override; - UIAction * reverse() const override; + Action * reverse() const override; protected: Move( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type ); diff --git a/include/eepp/ui/actions/rotate.hpp b/include/eepp/scene/actions/rotate.hpp similarity index 60% rename from include/eepp/ui/actions/rotate.hpp rename to include/eepp/scene/actions/rotate.hpp index 617d9be6d..33071783b 100644 --- a/include/eepp/ui/actions/rotate.hpp +++ b/include/eepp/scene/actions/rotate.hpp @@ -1,18 +1,18 @@ -#ifndef EE_UI_ACTION_ROTATE_HPP -#define EE_UI_ACTION_ROTATE_HPP +#ifndef EE_SCENE_ACTION_ROTATE_HPP +#define EE_SCENE_ACTION_ROTATE_HPP -#include -#include +#include +#include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { class EE_API Rotate : public ActionInterpolation1d { public: static Rotate * New( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); - UIAction * clone() const override; + Action * clone() const override; - UIAction * reverse() const override; + Action * reverse() const override; protected: Rotate( const Float & start, const Float & end, const Time & duration, const Ease::Interpolation & type ); diff --git a/include/eepp/ui/actions/scale.hpp b/include/eepp/scene/actions/scale.hpp similarity index 60% rename from include/eepp/ui/actions/scale.hpp rename to include/eepp/scene/actions/scale.hpp index fe917863d..6a6568a21 100644 --- a/include/eepp/ui/actions/scale.hpp +++ b/include/eepp/scene/actions/scale.hpp @@ -1,18 +1,18 @@ -#ifndef EE_UI_ACTION_SCALE_HPP -#define EE_UI_ACTION_SCALE_HPP +#ifndef EE_SCENE_ACTION_SCALE_HPP +#define EE_SCENE_ACTION_SCALE_HPP -#include -#include +#include +#include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { class EE_API Scale : public ActionInterpolation2d { public: static Scale * New( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); - UIAction * clone() const override; + Action * clone() const override; - UIAction * reverse() const override; + Action * reverse() const override; protected: Scale( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type ); diff --git a/include/eepp/scene/actions/sequence.hpp b/include/eepp/scene/actions/sequence.hpp new file mode 100644 index 000000000..f256e9687 --- /dev/null +++ b/include/eepp/scene/actions/sequence.hpp @@ -0,0 +1,44 @@ +#ifndef EE_SCENE_ACTION_SEQUENCE_HPP +#define EE_SCENE_ACTION_SEQUENCE_HPP + +#include + +namespace EE { namespace Scene { namespace Actions { + +class EE_API Sequence : public Action { + public: + static Sequence * New( const std::vector sequence ); + static Sequence * New( Action * action, Action * action2 ); + static Sequence * New( Action * action, Action * action2, Action * action3 ); + static Sequence * New( Action * action, Action * action2, Action * action3, Action * action4 ); + static Sequence * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5 ); + static Sequence * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6 ); + static Sequence * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7 ); + static Sequence * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8 ); + static Sequence * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8, Action * action9 ); + + void start() override; + + void stop() override; + + void update( const Time& time ) override; + + bool isDone() override; + + Action * clone() const override; + + Action * reverse() const override; + + virtual ~Sequence(); + + protected: + std::vector mSequence; + Uint32 mCurPos; + + Sequence( const std::vector sequence ); + +}; + +}}} + +#endif diff --git a/include/eepp/scene/actions/spawn.hpp b/include/eepp/scene/actions/spawn.hpp new file mode 100644 index 000000000..382a8c18a --- /dev/null +++ b/include/eepp/scene/actions/spawn.hpp @@ -0,0 +1,43 @@ +#ifndef EE_SCENE_ACTION_SPAWN_HPP +#define EE_SCENE_ACTION_SPAWN_HPP + +#include + +namespace EE { namespace Scene { namespace Actions { + +class EE_API Spawn : public Action { + public: + static Spawn * New( const std::vector spawn ); + static Spawn * New( Action * action, Action * action2 ); + static Spawn * New( Action * action, Action * action2, Action * action3 ); + static Spawn * New( Action * action, Action * action2, Action * action3, Action * action4 ); + static Spawn * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5 ); + static Spawn * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6 ); + static Spawn * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7 ); + static Spawn * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8 ); + static Spawn * New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8, Action * action9 ); + + void start() override; + + void stop() override; + + void update( const Time& time ) override; + + bool isDone() override; + + Action * clone() const override; + + Action * reverse() const override; + + virtual ~Spawn(); + protected: + std::vector mSpawn; + bool mAllDone; + + Spawn( const std::vector spawn ); + +}; + +}}} + +#endif diff --git a/include/eepp/scene/node.hpp b/include/eepp/scene/node.hpp new file mode 100644 index 000000000..476b91a42 --- /dev/null +++ b/include/eepp/scene/node.hpp @@ -0,0 +1,396 @@ +#ifndef EE_SCENE_NODE_HPP +#define EE_SCENE_NODE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace EE::UI; + +namespace EE { namespace Scene { +class Action; +class ActionManager; +}} +using namespace EE::Scene; + +namespace EE { namespace UI { +class UIWindow; +class UIManager; +}} + +namespace EE { namespace Scene { + +class EE_API Node : public Transformable { + public: + static Node * New(); + + typedef cb::Callback1 UIEventCallback; + + Node(); + + virtual ~Node(); + + void worldToNodeTranslation( Vector2f& position ) const; + + void nodeToWorldTranslation( Vector2f& position ) const; + + void worldToNode( Vector2i& pos ); + + void nodeToWorld( Vector2i& pos ); + + void worldToNode( Vector2f& pos ); + + void nodeToWorld( Vector2f& pos ); + + virtual Uint32 getType() const; + + virtual bool isType( const Uint32& type ) const; + + void messagePost( const UIMessage * Msg ); + + void setPosition( const Vector2f& Pos ); + + Node * setPosition( const Float& x, const Float& y ); + + virtual Node * setSize( const Sizef& size ); + + const Sizef& getSize(); + + Node * setVisible( const bool& visible ); + + bool isVisible() const; + + bool isHided() const; + + Node * setEnabled( const bool& enabled ); + + bool isEnabled() const; + + bool isDisabled() const; + + Node * getParent() const; + + Node * setParent( Node * parent ); + + void centerHorizontal(); + + void centerVertical(); + + void center(); + + virtual void close(); + + virtual void draw(); + + virtual void update( const Time& time ); + + Node * getNextNode() const; + + Node * getPrevNode() const; + + Node * getNextNodeLoop() const; + + Node * setData( const UintPtr& data ); + + const UintPtr& getData() const; + + Node * setBlendMode( const BlendMode& blend ); + + BlendMode getBlendMode(); + + void toFront(); + + void toBack(); + + void toPosition( const Uint32& position ); + + const Uint32& getNodeFlags() const; + + /** Use it at your own risk */ + void setNodeFlags( const Uint32& flags ); + + Uint32 isWidget(); + + Uint32 isWindow(); + + Uint32 isClipped(); + + Uint32 isRotated(); + + Uint32 isScaled(); + + Uint32 isFrameBuffer(); + + bool isMouseOver(); + + bool isMouseOverMeOrChilds(); + + bool isMeOrParentTreeRotated(); + + bool isMeOrParentTreeScaled(); + + bool isMeOrParentTreeScaledOrRotated(); + + bool isMeOrParentTreeScaledOrRotatedOrFrameBuffer(); + + Uint32 addEventListener( const Uint32& EventType, const UIEventCallback& Callback ); + + void removeEventListener( const Uint32& CallbackId ); + + Node * getFirstChild() const; + + Node * getLastChild() const; + + const Polygon2f& getWorldPolygon(); + + const Rectf& getWorldBounds(); + + bool isParentOf( Node * Ctrl ); + + void sendEvent( const UIEvent * Event ); + + void sendMouseEvent( const Uint32& Event, const Vector2i& position, const Uint32& flags ); + + void sendCommonEvent( const Uint32& Event ); + + void childsCloseAll(); + + std::string getId() const; + + Node * setId( const std::string & id ); + + Uint32 getIdHash() const; + + Node * find( const std::string& id ); + + template + T * find( const std::string& id ) + { + return reinterpret_cast( find( id ) ); + } + + template + T * bind( const std::string& id, T*& ctrl ) + { + ctrl = find( id ); + return ctrl; + } + + bool isReverseDraw() const; + + void setReverseDraw( bool reverseDraw ); + + void invalidateDraw(); + + void setClipEnabled(); + + void setClipDisabled(); + + void setRotation( float angle ); + + void setRotation( const Float& angle, const OriginPoint& center ); + + const OriginPoint& getRotationOriginPoint() const; + + void setRotationOriginPoint( const OriginPoint& center ); + + Vector2f getRotationCenter(); + + void setScale( const Vector2f& scale ); + + void setScale( const Vector2f& scale, const OriginPoint& center ); + + void setScale( const Float& scale , const OriginPoint & center = OriginPoint::OriginCenter ); + + const OriginPoint& getScaleOriginPoint() const; + + void setScaleOriginPoint( const OriginPoint& center ); + + Vector2f getScaleCenter(); + + virtual void setScale(float factorX, float factorY); + + virtual void setScaleOrigin(float x, float y); + + virtual void setRotationOrigin(float x, float y); + + const Float& getAlpha() const; + + virtual void setAlpha( const Float& alpha ); + + virtual void setChildsAlpha( const Float& alpha ); + + ActionManager * getActionManager(); + + void runAction( Action * action ); + + Transform getLocalTransform(); + + Transform getGlobalTransform(); + + Transform getNodeToWorldTransform(); + + Transform getWorldToNodeTransform(); + + Vector2f convertToNodeSpace(const Vector2f& worldPoint); + + Vector2f convertToWorldSpace(const Vector2f& nodePoint); + + Rectf getLocalBounds(); + + UIWindow * getOwnerWindow(); + protected: + typedef std::map< Uint32, std::map > UIEventsMap; + friend class UIManager; + friend class UIWindow; + + std::string mId; + Uint32 mIdHash; + Vector2f mScreenPos; + Vector2i mScreenPosi; + Sizef mSize; + UintPtr mData; + Node * mParentCtrl; + UIWindow * mParentWindowCtrl; + Node * mChild; //! Pointer to the first child of the node + Node * mChildLast; //! Pointer to the last child added + Node * mNext; //! Pointer to the next child of the father + Node * mPrev; //! Pointer to the prev child of the father + Uint32 mNodeFlags; + BlendMode mBlend; + Uint16 mNumCallBacks; + + mutable Polygon2f mPoly; + mutable Rectf mWorldBounds; + Vector2f mCenter; + + UIEventsMap mEvents; + + bool mVisible; + bool mEnabled; + + OriginPoint mRotationOriginPoint; + OriginPoint mScaleOriginPoint; + Float mAlpha; + + ActionManager * mActionManager; + + virtual Uint32 onMessage( const UIMessage * Msg ); + + virtual Uint32 onKeyDown( const UIEventKey& Event ); + + virtual Uint32 onKeyUp( const UIEventKey& Event ); + + virtual Uint32 onMouseMove( const Vector2i& position, const Uint32 flags ); + + virtual Uint32 onMouseDown( const Vector2i& position, const Uint32 flags ); + + virtual Uint32 onMouseClick( const Vector2i& position, const Uint32 flags ); + + virtual Uint32 onMouseDoubleClick( const Vector2i& position, const Uint32 flags ); + + virtual Uint32 onMouseUp( const Vector2i& position, const Uint32 flags ); + + virtual Uint32 onMouseEnter( const Vector2i& position, const Uint32 flags ); + + virtual Uint32 onMouseExit( const Vector2i& position, const Uint32 flags ); + + virtual void onClose(); + + virtual void onVisibilityChange(); + + virtual void onEnabledChange(); + + virtual void onPositionChange(); + + virtual void onSizeChange(); + + virtual void onParentSizeChange( const Vector2f& SizeChange ); + + virtual void onParentChange(); + + virtual void updateWorldPolygon(); + + virtual void updateCenter(); + + virtual void matrixSet(); + + virtual void matrixUnset(); + + virtual void drawChilds(); + + virtual void onChildCountChange(); + + virtual void onAngleChange(); + + virtual void onScaleChange(); + + virtual void onAlphaChange(); + + virtual Node * overFind( const Vector2f& Point ); + + virtual void onParentWindowChange(); + + virtual void clipMe(); + + void checkClose(); + + virtual void internalDraw(); + + void childDeleteAll(); + + void childAdd( Node * ChildCtrl ); + + void childAddAt( Node * ChildCtrl, Uint32 position ); + + void childRemove( Node * ChildCtrl ); + + bool isChild( Node * ChildCtrl ) const; + + bool inParentTreeOf( Node * Child ) const; + + Uint32 childCount() const; + + Node * childAt( Uint32 Index ) const; + + Node * childPrev( Node * Ctrl, bool Loop = false ) const; + + Node * childNext( Node * Ctrl, bool Loop = false ) const; + + virtual void clipDisable(); + + virtual void updateScreenPos(); + + void writeCtrlFlag( const Uint32& Flag, const Uint32& Val ); + + Rectf getScreenBounds(); + + void setInternalPosition( const Vector2f& Pos ); + + void setInternalSize(const Sizef& size ); + + void setInternalWidth(const Float& width ); + + void setInternalHeight( const Float& height ); + + Color getColor( const Color& Col ); + + Node * findIdHash( const Uint32& idHash ); + + UIWindow * getParentWindow(); + + void updateOriginPoint(); + + void setDirty(); + + void setChildsDirty(); +}; + +}} + +#endif diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index fc793999b..5de834aa1 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -58,15 +58,18 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace EE::Scene; #endif diff --git a/include/eepp/ui/actions/sequence.hpp b/include/eepp/ui/actions/sequence.hpp deleted file mode 100644 index c7980c703..000000000 --- a/include/eepp/ui/actions/sequence.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef EE_UI_ACTION_SEQUENCE_HPP -#define EE_UI_ACTION_SEQUENCE_HPP - -#include - -namespace EE { namespace UI { namespace Action { - -class EE_API Sequence : public UIAction { - public: - static Sequence * New( const std::vector sequence ); - static Sequence * New( UIAction * action, UIAction * action2 ); - static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3 ); - static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ); - static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ); - static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ); - static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ); - static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ); - static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ); - - void start() override; - - void stop() override; - - void update( const Time& time ) override; - - bool isDone() override; - - UIAction * clone() const override; - - UIAction * reverse() const override; - - virtual ~Sequence(); - - protected: - std::vector mSequence; - Uint32 mCurPos; - - Sequence( const std::vector sequence ); - -}; - -}}} - -#endif diff --git a/include/eepp/ui/actions/spawn.hpp b/include/eepp/ui/actions/spawn.hpp deleted file mode 100644 index ae1f733be..000000000 --- a/include/eepp/ui/actions/spawn.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef EE_UI_ACTION_SPAWN_HPP -#define EE_UI_ACTION_SPAWN_HPP - -#include - -namespace EE { namespace UI { namespace Action { - -class EE_API Spawn : public UIAction { - public: - static Spawn * New( const std::vector spawn ); - static Spawn * New( UIAction * action, UIAction * action2 ); - static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3 ); - static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ); - static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ); - static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ); - static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ); - static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ); - static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ); - - void start() override; - - void stop() override; - - void update( const Time& time ) override; - - bool isDone() override; - - UIAction * clone() const override; - - UIAction * reverse() const override; - - virtual ~Spawn(); - protected: - std::vector mSpawn; - bool mAllDone; - - Spawn( const std::vector spawn ); - -}; - -}}} - -#endif diff --git a/include/eepp/ui/uiactionmanager.hpp b/include/eepp/ui/uiactionmanager.hpp deleted file mode 100644 index bfe1b902e..000000000 --- a/include/eepp/ui/uiactionmanager.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EE_UIActionManager_HPP -#define EE_UIActionManager_HPP - -#include -#include -#include -using namespace EE::System; - -namespace EE { namespace UI { - -class UIAction; - -class EE_API UIActionManager { - public: - UIActionManager(); - - ~UIActionManager(); - - void addAction( UIAction * action ); - - UIAction * getActionByTag( const Uint32& tag ); - - void removeActionByTag( const Uint32& tag ); - - void removeAction( UIAction * action ); - - void update( const Time& time ); - - std::size_t count() const; - - bool isEmpty() const; - protected: - std::list mActions; -}; - -}} - -#endif - diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index b89f30ea3..c2f579127 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -16,13 +16,17 @@ #include #include +namespace EE { namespace Scene { +class Action; +class ActionManager; +}} +using namespace EE::Scene; + namespace EE { namespace UI { class UITheme; class UIWindow; class UIManager; -class UIAction; -class UIActionManager; class EE_API UINode : public Transformable { public: @@ -350,9 +354,9 @@ class EE_API UINode : public Transformable { bool isFadingOut(); - UIActionManager * getActionManager(); + ActionManager * getActionManager(); - void runAction( UIAction * action ); + void runAction( Action * action ); Transform getLocalTransform(); @@ -414,7 +418,7 @@ class EE_API UINode : public Transformable { OriginPoint mScaleOriginPoint; Float mAlpha; - UIActionManager * mActionManager; + ActionManager * mActionManager; virtual Uint32 onMessage( const UIMessage * Msg ); diff --git a/premake4.lua b/premake4.lua index 7b2a508f3..fbe46ea2f 100644 --- a/premake4.lua +++ b/premake4.lua @@ -712,6 +712,8 @@ function build_eepp( build_name ) "src/eepp/window/platform/null/*.cpp", "src/eepp/network/*.cpp", "src/eepp/network/ssl/*.cpp", + "src/eepp/scene/*.cpp", + "src/eepp/scene/actions/*.cpp", "src/eepp/ui/*.cpp", "src/eepp/ui/actions/*.cpp", "src/eepp/ui/tools/*.cpp", diff --git a/projects/linux/ee.files b/projects/linux/ee.files index a5c9c4594..f17696c89 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -51,19 +51,21 @@ ../../include/eepp/system/iostreamzip.hpp ../../include/eepp/system/translator.hpp ../../include/eepp/system/virtualfilesystem.hpp -../../include/eepp/ui/actions/actioninterpolation1d.hpp -../../include/eepp/ui/actions/actioninterpolation2d.hpp -../../include/eepp/ui/actions/delay.hpp -../../include/eepp/ui/actions/fade.hpp -../../include/eepp/ui/actions/marginmove.hpp -../../include/eepp/ui/actions/move.hpp -../../include/eepp/ui/actions/rotate.hpp -../../include/eepp/ui/actions/scale.hpp -../../include/eepp/ui/actions/sequence.hpp -../../include/eepp/ui/actions/spawn.hpp +../../include/eepp/scene/node.hpp +../../src/eepp/scene/node.cpp +../../include/eepp/scene/actions/actioninterpolation1d.hpp +../../include/eepp/scene/actions/actioninterpolation2d.hpp +../../include/eepp/scene/actions/delay.hpp +../../include/eepp/scene/actions/fade.hpp +../../include/eepp/scene/actions/marginmove.hpp +../../include/eepp/scene/actions/move.hpp +../../include/eepp/scene/actions/rotate.hpp +../../include/eepp/scene/actions/scale.hpp +../../include/eepp/scene/actions/sequence.hpp +../../include/eepp/scene/actions/spawn.hpp ../../include/eepp/ui/marginmove/scale.hpp -../../include/eepp/ui/uiaction.hpp -../../include/eepp/ui/uiactionmanager.hpp +../../include/eepp/scene/action.hpp +../../include/eepp/scene/actionmanager.hpp ../../include/eepp/ui/uieventmouse.hpp ../../include/eepp/ui/uigridlayout.hpp ../../include/eepp/ui/uiimage.hpp @@ -134,18 +136,18 @@ ../../src/eepp/system/iostreamzip.cpp ../../src/eepp/system/translator.cpp ../../src/eepp/system/virtualfilesystem.cpp -../../src/eepp/ui/actions/actioninterpolation1d.cpp -../../src/eepp/ui/actions/actioninterpolation2d.cpp -../../src/eepp/ui/actions/delay.cpp -../../src/eepp/ui/actions/fade.cpp -../../src/eepp/ui/actions/move.cpp -../../src/eepp/ui/actions/rotate.cpp -../../src/eepp/ui/actions/scale.cpp -../../src/eepp/ui/actions/marginmove.cpp -../../src/eepp/ui/actions/sequence.cpp -../../src/eepp/ui/actions/spawn.cpp -../../src/eepp/ui/uiaction.cpp -../../src/eepp/ui/uiactionmanager.cpp +../../src/eepp/scene/actions/actioninterpolation1d.cpp +../../src/eepp/scene/actions/actioninterpolation2d.cpp +../../src/eepp/scene/actions/delay.cpp +../../src/eepp/scene/actions/fade.cpp +../../src/eepp/scene/actions/move.cpp +../../src/eepp/scene/actions/rotate.cpp +../../src/eepp/scene/actions/scale.cpp +../../src/eepp/scene/actions/marginmove.cpp +../../src/eepp/scene/actions/sequence.cpp +../../src/eepp/scene/actions/spawn.cpp +../../src/eepp/scene/action.cpp +../../src/eepp/scene/actionmanager.cpp ../../src/eepp/ui/uigridlayout.cpp ../../src/eepp/ui/uiimage.cpp ../../src/eepp/ui/uilayout.cpp diff --git a/src/eepp/scene/action.cpp b/src/eepp/scene/action.cpp new file mode 100644 index 000000000..f432149dc --- /dev/null +++ b/src/eepp/scene/action.cpp @@ -0,0 +1,83 @@ +#include +#include + +namespace EE { namespace Scene { + +Action::Action() : + mNode( NULL ), + mFlags( 0 ), + mTag( 0 ), + mNumCallBacks( 0 ) +{ +} + +Action::~Action() +{} + +Uint32 Action::getFlags() const { + return mFlags; +} + +void Action::setFlags( const Uint32 & flags ) { + mFlags = flags; +} + +Uint32 Action::getTag() const { + return mTag; +} + +void Action::setTag( const Uint32 & tag ) { + mTag = tag; +} + +void Action::setTarget( UINode * target ) { + mNode = target; +} + +UINode * Action::getTarget() const { + return mNode; +} + +Action * Action::clone() const { + return NULL; +} + +Action * Action::reverse() const { + return NULL; +} + +Uint32 Action::addEventListener( const ActionType& actionType, const ActionCallback& callback ) { + mNumCallBacks++; + + mCallbacks[ actionType ][ mNumCallBacks ] = callback; + + return mNumCallBacks; +} + +void Action::removeEventListener( const Uint32& callbackId ) { + for ( auto it = mCallbacks.begin(); it != mCallbacks.end(); ++it ) { + std::map event = it->second; + + if ( event.erase( callbackId ) ) + break; + } +} + +void Action::sendEvent( const ActionType& actionType ) { + if ( 0 != mCallbacks.count( actionType ) ) { + auto event = mCallbacks[ actionType ]; + + if ( !event.empty() ) { + for ( auto it = event.begin(); it != event.end(); ++it ) + it->second( this, actionType ); + } + } +} + +void Action::onStart() {} + +void Action::onStop() {} + +void Action::onUpdate( const Time& time ) {} + +}} diff --git a/src/eepp/ui/uiactionmanager.cpp b/src/eepp/scene/actionmanager.cpp similarity index 55% rename from src/eepp/ui/uiactionmanager.cpp rename to src/eepp/scene/actionmanager.cpp index 14752b54b..60f6c10a9 100644 --- a/src/eepp/ui/uiactionmanager.cpp +++ b/src/eepp/scene/actionmanager.cpp @@ -1,22 +1,22 @@ -#include -#include +#include +#include #include #include -namespace EE { namespace UI { +namespace EE { namespace Scene { -UIActionManager::UIActionManager() { +ActionManager::ActionManager() { } -UIActionManager::~UIActionManager() { +ActionManager::~ActionManager() { for ( auto it = mActions.begin(); it != mActions.end(); ++it ) { - UIAction * action = (*it); + Action * action = (*it); eeSAFE_DELETE( action ); } } -void UIActionManager::addAction( UIAction * action ) { +void ActionManager::addAction( Action * action ) { bool found = (std::find(mActions.begin(), mActions.end(), action) != mActions.end()); if ( !found ) { @@ -24,9 +24,9 @@ void UIActionManager::addAction( UIAction * action ) { } } -UIAction * UIActionManager::getActionByTag( const Uint32& tag ) { +Action * ActionManager::getActionByTag( const Uint32& tag ) { for ( auto it = mActions.begin(); it != mActions.end(); ++it ) { - UIAction * action = (*it); + Action * action = (*it); if ( action->getTag() == tag ) return action; @@ -35,23 +35,23 @@ UIAction * UIActionManager::getActionByTag( const Uint32& tag ) { return NULL; } -void UIActionManager::removeActionByTag( const Uint32& tag ) { +void ActionManager::removeActionByTag( const Uint32& tag ) { removeAction( getActionByTag( tag ) ); } -void UIActionManager::update( const Time& time ) { +void ActionManager::update( const Time& time ) { if ( isEmpty() ) return; - std::list removeList; + std::list removeList; for ( auto it = mActions.begin(); it != mActions.end(); ++it ) { - UIAction * action = (*it); + Action * action = (*it); action->update( time ); if ( action->isDone() ) { - action->sendEvent( UIAction::ActionType::OnDone ); + action->sendEvent( Action::ActionType::OnDone ); removeList.push_back( action ); } @@ -61,15 +61,15 @@ void UIActionManager::update( const Time& time ) { removeAction( (*it) ); } -std::size_t UIActionManager::count() const { +std::size_t ActionManager::count() const { return mActions.size(); } -bool UIActionManager::isEmpty() const { +bool ActionManager::isEmpty() const { return mActions.empty(); } -void UIActionManager::removeAction( UIAction * action ) { +void ActionManager::removeAction( Action * action ) { if ( NULL != action ) { mActions.remove( action ); diff --git a/src/eepp/ui/actions/actioninterpolation1d.cpp b/src/eepp/scene/actions/actioninterpolation1d.cpp similarity index 86% rename from src/eepp/ui/actions/actioninterpolation1d.cpp rename to src/eepp/scene/actions/actioninterpolation1d.cpp index d5c3b91d8..ab73314b1 100644 --- a/src/eepp/ui/actions/actioninterpolation1d.cpp +++ b/src/eepp/scene/actions/actioninterpolation1d.cpp @@ -1,7 +1,7 @@ -#include +#include #include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { ActionInterpolation1d::ActionInterpolation1d() {} diff --git a/src/eepp/ui/actions/actioninterpolation2d.cpp b/src/eepp/scene/actions/actioninterpolation2d.cpp similarity index 86% rename from src/eepp/ui/actions/actioninterpolation2d.cpp rename to src/eepp/scene/actions/actioninterpolation2d.cpp index ff1a62fb6..92f7b0251 100644 --- a/src/eepp/ui/actions/actioninterpolation2d.cpp +++ b/src/eepp/scene/actions/actioninterpolation2d.cpp @@ -1,7 +1,7 @@ -#include +#include #include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { ActionInterpolation2d::ActionInterpolation2d() {} diff --git a/src/eepp/ui/actions/delay.cpp b/src/eepp/scene/actions/delay.cpp similarity index 75% rename from src/eepp/ui/actions/delay.cpp rename to src/eepp/scene/actions/delay.cpp index b0f7b23cb..24fa86d60 100644 --- a/src/eepp/ui/actions/delay.cpp +++ b/src/eepp/scene/actions/delay.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { Delay * Delay::New(const Time & time) { return eeNew( Delay, ( time ) ); @@ -24,11 +24,11 @@ bool Delay::isDone() { return mClock.getElapsedTime() >= mTime; } -UIAction *Delay::clone() const { +Action *Delay::clone() const { return New( mTime ); } -UIAction *Delay::reverse() const { +Action *Delay::reverse() const { return NULL; // or a time machine } diff --git a/src/eepp/ui/actions/fade.cpp b/src/eepp/scene/actions/fade.cpp similarity index 89% rename from src/eepp/ui/actions/fade.cpp rename to src/eepp/scene/actions/fade.cpp index 06832b164..ebb99d1eb 100644 --- a/src/eepp/ui/actions/fade.cpp +++ b/src/eepp/scene/actions/fade.cpp @@ -1,7 +1,7 @@ -#include +#include #include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { Fade * Fade::New( const Float & start, const Float & end, const Time& duration, const Ease::Interpolation& type, const bool& alphaChilds ) { return eeNew( Fade, ( start, end, duration, type, alphaChilds ) ); @@ -38,14 +38,14 @@ void Fade::onUpdate( const Time& time ) { } } -UIAction * Fade::clone() const { +Action * Fade::clone() const { Fade * action = eeNew( Fade, () ); action->mAffectChilds = mAffectChilds; action->setInterpolation( mInterpolation ); return action; } -UIAction * Fade::reverse() const { +Action * Fade::reverse() const { Fade * action = eeNew( Fade, () ); action->mAffectChilds = mAffectChilds; action->setInterpolation( Interpolation1d( mInterpolation.getReversePoints() ) ); diff --git a/src/eepp/ui/actions/marginmove.cpp b/src/eepp/scene/actions/marginmove.cpp similarity index 94% rename from src/eepp/ui/actions/marginmove.cpp rename to src/eepp/scene/actions/marginmove.cpp index ef7d51c20..ef0eb7507 100644 --- a/src/eepp/ui/actions/marginmove.cpp +++ b/src/eepp/scene/actions/marginmove.cpp @@ -1,8 +1,8 @@ -#include +#include #include #include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { MarginMove * MarginMove::New( const Rect & start, const Rect & end, const Time& duration, const Ease::Interpolation& type ) { return eeNew( MarginMove, ( start, end, duration, type ) ); @@ -106,7 +106,7 @@ void MarginMove::onUpdate( const Time& time ) { } } -UIAction * MarginMove::clone() const { +Action * MarginMove::clone() const { MarginMove * action = eeNew( MarginMove, () ); action->setInterpolationLeft( mInterpolationLeft ); action->setInterpolationRight( mInterpolationRight ); @@ -115,7 +115,7 @@ UIAction * MarginMove::clone() const { return action; } -UIAction * MarginMove::reverse() const { +Action * MarginMove::reverse() const { return NULL; } diff --git a/src/eepp/ui/actions/move.cpp b/src/eepp/scene/actions/move.cpp similarity index 85% rename from src/eepp/ui/actions/move.cpp rename to src/eepp/scene/actions/move.cpp index 82e538619..58c661def 100644 --- a/src/eepp/ui/actions/move.cpp +++ b/src/eepp/scene/actions/move.cpp @@ -1,7 +1,7 @@ -#include +#include #include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { Move * Move::New( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type ) { return eeNew( Move, ( start, end, duration, type ) ); @@ -26,13 +26,13 @@ void Move::onUpdate( const Time& time ) { } } -UIAction * Move::clone() const { +Action * Move::clone() const { Move * action = eeNew( Move, () ); action->setInterpolation( mInterpolation ); return action; } -UIAction * Move::reverse() const { +Action * Move::reverse() const { Move * action = eeNew( Move, () ); action->setInterpolation( Interpolation2d( mInterpolation.getReversePoints() ) ); return action; diff --git a/src/eepp/ui/actions/rotate.cpp b/src/eepp/scene/actions/rotate.cpp similarity index 84% rename from src/eepp/ui/actions/rotate.cpp rename to src/eepp/scene/actions/rotate.cpp index e3e380dde..43fc3ef12 100644 --- a/src/eepp/ui/actions/rotate.cpp +++ b/src/eepp/scene/actions/rotate.cpp @@ -1,7 +1,7 @@ -#include +#include #include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { Rotate * Rotate::New( const Float & start, const Float & end, const Time& duration, const Ease::Interpolation& type ) { return eeNew( Rotate, ( start, end, duration, type ) ); @@ -26,13 +26,13 @@ void Rotate::onUpdate( const Time& time ) { } } -UIAction * Rotate::clone() const { +Action * Rotate::clone() const { Rotate * action = eeNew( Rotate, () ); action->setInterpolation( mInterpolation ); return action; } -UIAction * Rotate::reverse() const { +Action * Rotate::reverse() const { Rotate * action = eeNew( Rotate, () ); action->setInterpolation( Interpolation1d( mInterpolation.getReversePoints() ) ); return action; diff --git a/src/eepp/ui/actions/scale.cpp b/src/eepp/scene/actions/scale.cpp similarity index 84% rename from src/eepp/ui/actions/scale.cpp rename to src/eepp/scene/actions/scale.cpp index 8189c333d..fc4f9555b 100644 --- a/src/eepp/ui/actions/scale.cpp +++ b/src/eepp/scene/actions/scale.cpp @@ -1,7 +1,7 @@ -#include +#include #include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { Scale * Scale::New( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type ) { return eeNew( Scale, ( start, end, duration, type ) ); @@ -26,13 +26,13 @@ void Scale::onUpdate( const Time& time ) { } } -UIAction * Scale::clone() const { +Action * Scale::clone() const { Scale * action = eeNew( Scale, () ); action->setInterpolation( mInterpolation ); return action; } -UIAction * Scale::reverse() const { +Action * Scale::reverse() const { Scale * action = eeNew( Scale, () ); action->setInterpolation( mInterpolation.getReversePoints() ); return action; diff --git a/src/eepp/ui/actions/sequence.cpp b/src/eepp/scene/actions/sequence.cpp similarity index 52% rename from src/eepp/ui/actions/sequence.cpp rename to src/eepp/scene/actions/sequence.cpp index 7516feb3f..eb42e487b 100644 --- a/src/eepp/ui/actions/sequence.cpp +++ b/src/eepp/scene/actions/sequence.cpp @@ -1,40 +1,40 @@ -#include +#include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { -Sequence * Sequence::New( const std::vector sequence ) { +Sequence * Sequence::New( const std::vector sequence ) { return eeNew( Sequence, ( sequence ) ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2 ) { +Sequence * Sequence::New( Action * action, Action * action2 ) { return New( { action, action2 } ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3 ) { +Sequence * Sequence::New( Action * action, Action * action2, Action * action3 ) { return New( { action, action2, action3 } ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ) { +Sequence * Sequence::New( Action * action, Action * action2, Action * action3, Action * action4 ) { return New( { action, action2, action3, action4 } ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ) { +Sequence * Sequence::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5 ) { return New( { action, action2, action3, action4, action5 } ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ) { +Sequence * Sequence::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6 ) { return New( { action, action2, action3, action4, action5, action6 } ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ) { +Sequence * Sequence::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7 ) { return New( { action, action2, action3, action4, action5, action6, action7 } ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ) { +Sequence * Sequence::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8 ) { return New( { action, action2, action3, action4, action5, action6, action7, action8 } ); } -Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ) { +Sequence * Sequence::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8, Action * action9 ) { return New( { action, action2, action3, action4, action5, action6, action7, action8, action9 } ); } @@ -70,12 +70,12 @@ bool Sequence::isDone() { return mCurPos == mSequence.size() - 1 && mSequence[ mCurPos ]->isDone(); } -UIAction * Sequence::clone() const { +Action * Sequence::clone() const { return Sequence::New( mSequence ); } -UIAction * Sequence::reverse() const { - std::vector reversed; +Action * Sequence::reverse() const { + std::vector reversed; for ( auto it = mSequence.rbegin(); it != mSequence.rend(); ++it ) { reversed.push_back( *it ); @@ -86,12 +86,12 @@ UIAction * Sequence::reverse() const { Sequence::~Sequence() { for ( size_t i = 0; i < mSequence.size(); i++ ) { - UIAction * action = mSequence[ i ]; + Action * action = mSequence[ i ]; eeSAFE_DELETE( action ); } } -Sequence::Sequence( const std::vector sequence ) : +Sequence::Sequence( const std::vector sequence ) : mSequence( sequence ), mCurPos( 0 ) {} diff --git a/src/eepp/ui/actions/spawn.cpp b/src/eepp/scene/actions/spawn.cpp similarity index 51% rename from src/eepp/ui/actions/spawn.cpp rename to src/eepp/scene/actions/spawn.cpp index f3ff41b87..bf4aa2185 100644 --- a/src/eepp/ui/actions/spawn.cpp +++ b/src/eepp/scene/actions/spawn.cpp @@ -1,40 +1,40 @@ -#include +#include -namespace EE { namespace UI { namespace Action { +namespace EE { namespace Scene { namespace Actions { -Spawn * Spawn::New( const std::vector spawn ) { +Spawn * Spawn::New( const std::vector spawn ) { return eeNew( Spawn, ( spawn ) ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2 ) { +Spawn * Spawn::New( Action * action, Action * action2 ) { return New( { action, action2 } ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3 ) { +Spawn * Spawn::New( Action * action, Action * action2, Action * action3 ) { return New( { action, action2, action3 } ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ) { +Spawn * Spawn::New( Action * action, Action * action2, Action * action3, Action * action4 ) { return New( { action, action2, action3, action4 } ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ) { +Spawn * Spawn::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5 ) { return New( { action, action2, action3, action4, action5 } ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ) { +Spawn * Spawn::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6 ) { return New( { action, action2, action3, action4, action5, action6 } ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ) { +Spawn * Spawn::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7 ) { return New( { action, action2, action3, action4, action5, action6, action7 } ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ) { +Spawn * Spawn::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8 ) { return New( { action, action2, action3, action4, action5, action6, action7, action8 } ); } -Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ) { +Spawn * Spawn::New( Action * action, Action * action2, Action * action3, Action * action4, Action * action5, Action * action6, Action * action7, Action * action8, Action * action9 ) { return New( { action, action2, action3, action4, action5, action6, action7, action8, action9 } ); } @@ -75,12 +75,12 @@ bool Spawn::isDone() { return mAllDone; } -UIAction * Spawn::clone() const { +Action * Spawn::clone() const { return Spawn::New( mSpawn ); } -UIAction * Spawn::reverse() const { - std::vector reversed; +Action * Spawn::reverse() const { + std::vector reversed; for ( auto it = mSpawn.rbegin(); it != mSpawn.rend(); ++it ) { reversed.push_back( *it ); @@ -91,12 +91,12 @@ UIAction * Spawn::reverse() const { Spawn::~Spawn() { for ( size_t i = 0; i < mSpawn.size(); i++ ) { - UIAction * action = mSpawn[ i ]; + Action * action = mSpawn[ i ]; eeSAFE_DELETE( action ); } } -Spawn::Spawn( const std::vector spawn ) : +Spawn::Spawn( const std::vector spawn ) : mSpawn( spawn ) {} diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp new file mode 100644 index 000000000..cb12c5adb --- /dev/null +++ b/src/eepp/scene/node.cpp @@ -0,0 +1,1238 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace EE { namespace Scene { + +Node * Node::New() { + return eeNew( Node, () ); +} + +Node::Node() : + mIdHash( 0 ), + mSize( 0, 0 ), + mData( 0 ), + mParentCtrl( NULL ), + mParentWindowCtrl( NULL ), + mChild( NULL ), + mChildLast( NULL ), + mNext( NULL ), + mPrev( NULL ), + mNodeFlags( NODE_FLAG_POSITION_DIRTY | NODE_FLAG_POLYGON_DIRTY ), + mBlend( BlendAlpha ), + mNumCallBacks( 0 ), + mVisible( true ), + mEnabled( true ), + mAlpha(255.f), + mActionManager(NULL) +{ + if ( NULL == mParentCtrl && NULL != UIManager::instance()->getMainControl() ) { + //mParentCtrl = UIManager::instance()->getMainControl(); + mParentWindowCtrl = getParentWindow(); + } + + if ( NULL != mParentCtrl ) + mParentCtrl->childAdd( this ); +} + +Node::~Node() { + eeSAFE_DELETE( mActionManager ); + + childDeleteAll(); + + if ( NULL != mParentCtrl ) + mParentCtrl->childRemove( this ); +} + +void Node::worldToNodeTranslation( Vector2f& Pos ) const { + Node * ParentLoop = mParentCtrl; + + Pos -= mPosition; + + while ( NULL != ParentLoop ) { + const Vector2f& ParentPos = ParentLoop->getPosition(); + + Pos -= ParentPos; + + ParentLoop = ParentLoop->getParent(); + } +} + +void Node::nodeToWorldTranslation( Vector2f& Pos ) const { + Node * ParentLoop = mParentCtrl; + + while ( NULL != ParentLoop ) { + const Vector2f& ParentPos = ParentLoop->getPosition(); + + Pos += ParentPos; + + ParentLoop = ParentLoop->getParent(); + } +} + +Uint32 Node::getType() const { + return UI_TYPE_NODE; +} + +bool Node::isType( const Uint32& type ) const { + return Node::getType() == type; +} + +void Node::messagePost( const UIMessage * Msg ) { + Node * Ctrl = this; + + while( NULL != Ctrl ) { + if ( Ctrl->onMessage( Msg ) ) + break; + + Ctrl = Ctrl->getParent(); + } +} + +Uint32 Node::onMessage( const UIMessage * Msg ) { + return 0; +} + +void Node::setInternalPosition( const Vector2f& Pos ) { + Transformable::setPosition( Pos.x * PixelDensity::getPixelDensity(), Pos.y * PixelDensity::getPixelDensity() ); + setDirty(); +} + +void Node::setPosition( const Vector2f& Pos ) { + if ( Pos != getPosition()) { + setInternalPosition( Pos ); + onPositionChange(); + } +} + +Node * Node::setPosition( const Float& x, const Float& y ) { + setPosition( Vector2f( x, y ) ); + return this; +} + +void Node::setInternalSize( const Sizef& size ) { + mSize = size; + updateCenter(); + sendCommonEvent( UIEvent::OnSizeChange ); + invalidateDraw(); +} + +Node * Node::setSize( const Sizef & Size ) { + if ( Size != mSize ) { + Vector2f sizeChange( Size.x - mSize.x, Size.y - mSize.y ); + + setInternalSize( Size ); + + onSizeChange(); + } + + return this; +} + +void Node::setInternalWidth( const Float& width ) { + setInternalSize( Sizef( width, mSize.getHeight() ) ); +} + +void Node::setInternalHeight( const Float& height ) { + setInternalSize( Sizef( mSize.getWidth(), height ) ); +} + +const Sizef& Node::getSize() { + return mSize; +} + +Node * Node::setVisible( const bool& visible ) { + if ( mVisible != visible ) { + mVisible = visible; + onVisibilityChange(); + } + return this; +} + +bool Node::isVisible() const { + return mVisible; +} + +bool Node::isHided() const { + return !mVisible; +} + +Node * Node::setEnabled( const bool& enabled ) { + if ( mEnabled != enabled ) { + mEnabled = enabled; + onEnabledChange(); + } + return this; +} + +bool Node::isEnabled() const { + return mEnabled; +} + +bool Node::isDisabled() const { + return !mEnabled; +} + +Node * Node::getParent() const { + return mParentCtrl; +} + +Node * Node::setParent( Node * parent ) { + if ( parent == mParentCtrl ) + return this; + + if ( NULL != mParentCtrl ) + mParentCtrl->childRemove( this ); + + mParentCtrl = parent; + + if ( NULL != mParentCtrl ) + mParentCtrl->childAdd( this ); + + setDirty(); + + onParentChange(); + + if ( mParentWindowCtrl != getParentWindow() ) + onParentWindowChange(); + + return this; +} + +bool Node::isParentOf( Node * Ctrl ) { + eeASSERT( NULL != Ctrl ); + + Node * tParent = Ctrl->getParent(); + + while ( NULL != tParent ) { + if ( this == tParent ) + return true; + + tParent = tParent->getParent(); + } + + return false; +} + +void Node::centerHorizontal() { + Node * Ctrl = getParent(); + + if ( NULL != Ctrl ) + setPosition( eefloor( ( Ctrl->getSize().getWidth() - mSize.getWidth() ) * 0.5f ), getPosition().y ); +} + +void Node::centerVertical(){ + Node * Ctrl = getParent(); + + if ( NULL != Ctrl ) + setPosition( getPosition().x, eefloor( Ctrl->getSize().getHeight() - mSize.getHeight() ) * 0.5f ); +} + +void Node::center() { + Node * Ctrl = getParent(); + + if ( NULL != Ctrl ) + setPosition( eefloor( ( Ctrl->getSize().getWidth() - mSize.getWidth() ) * 0.5f ), eefloor( Ctrl->getSize().getHeight() - mSize.getHeight() ) * 0.5f ); +} + +void Node::close() { + mNodeFlags |= NODE_FLAG_CLOSE; + + //UIManager::instance()->addToCloseQueue( this ); +} + +void Node::draw() { +} + +void Node::update( const Time& time ) { + if ( NULL != mActionManager ) { + mActionManager->update( time ); + + if ( mActionManager->isEmpty() ) + eeSAFE_DELETE( mActionManager ); + } + + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + ChildLoop->update( time ); + ChildLoop = ChildLoop->mNext; + } + + writeCtrlFlag( NODE_FLAG_MOUSEOVER_ME_OR_CHILD, 0 ); +} + +void Node::sendMouseEvent( const Uint32& Event, const Vector2i& Pos, const Uint32& Flags ) { + //UIEventMouse MouseEvent( this, Event, Pos, Flags ); + //sendEvent( &MouseEvent ); +} + +void Node::sendCommonEvent( const Uint32& Event ) { + //UIEvent CommonEvent( this, Event ); + //sendEvent( &CommonEvent ); +} + +Uint32 Node::onKeyDown( const UIEventKey& Event ) { + sendEvent( &Event ); + return 0; +} + +Uint32 Node::onKeyUp( const UIEventKey& Event ) { + sendEvent( &Event ); + return 0; +} + +Uint32 Node::onMouseMove( const Vector2i& Pos, const Uint32 Flags ) { + sendMouseEvent( UIEvent::MouseMove, Pos, Flags ); + return 1; +} + +Uint32 Node::onMouseDown( const Vector2i& Pos, const Uint32 Flags ) { + sendMouseEvent( UIEvent::MouseDown, Pos, Flags ); + return 1; +} + +Uint32 Node::onMouseUp( const Vector2i& Pos, const Uint32 Flags ) { + sendMouseEvent( UIEvent::MouseUp, Pos, Flags ); + return 1; +} + +Uint32 Node::onMouseClick( const Vector2i& Pos, const Uint32 Flags ) { + sendMouseEvent( UIEvent::MouseClick, Pos, Flags ); + return 1; +} + +bool Node::isMouseOver() { + return 0 != ( mNodeFlags & NODE_FLAG_MOUSEOVER ); +} + +bool Node::isMouseOverMeOrChilds() { + return 0 != ( mNodeFlags & NODE_FLAG_MOUSEOVER_ME_OR_CHILD ); +} + +Uint32 Node::onMouseDoubleClick( const Vector2i& Pos, const Uint32 Flags ) { + sendMouseEvent( UIEvent::MouseDoubleClick, Pos, Flags ); + return 1; +} + +Uint32 Node::onMouseEnter( const Vector2i& Pos, const Uint32 Flags ) { + writeCtrlFlag( NODE_FLAG_MOUSEOVER, 1 ); + + sendMouseEvent( UIEvent::MouseEnter, Pos, Flags ); + + return 1; +} + +Uint32 Node::onMouseExit( const Vector2i& Pos, const Uint32 Flags ) { + writeCtrlFlag( NODE_FLAG_MOUSEOVER, 0 ); + + sendMouseEvent( UIEvent::MouseExit, Pos, Flags ); + + return 1; +} + +void Node::onClose() { + sendCommonEvent( UIEvent::OnClose ); + invalidateDraw(); +} + +Node * Node::getNextNode() const { + return mNext; +} + +Node * Node::getPrevNode() const { + return mPrev; +} + +Node * Node::getNextNodeLoop() const { + if ( NULL == mNext ) + return getParent()->getFirstChild(); + else + return mNext; +} + +Node * Node::setData(const UintPtr& data ) { + mData = data; + return this; +} + +const UintPtr& Node::getData() const { + return mData; +} + +Node * Node::setBlendMode( const BlendMode& blend ) { + mBlend = blend; + invalidateDraw(); + return this; +} + +BlendMode Node::getBlendMode() { + return mBlend; +} + +void Node::toFront() { + if ( NULL != mParentCtrl && mParentCtrl->mChildLast != this ) { + mParentCtrl->childRemove( this ); + mParentCtrl->childAdd( this ); + } +} + +void Node::toBack() { + if ( NULL != mParentCtrl ) { + mParentCtrl->childAddAt( this, 0 ); + } +} + +void Node::toPosition( const Uint32& Pos ) { + if ( NULL != mParentCtrl ) { + mParentCtrl->childAddAt( this, Pos ); + } +} + +void Node::onVisibilityChange() { + sendCommonEvent( UIEvent::OnVisibleChange ); + invalidateDraw(); +} + +void Node::onEnabledChange() { + sendCommonEvent( UIEvent::OnEnabledChange ); + invalidateDraw(); +} + +void Node::onPositionChange() { + sendCommonEvent( UIEvent::OnPositionChange ); + invalidateDraw(); +} + +void Node::onSizeChange() { + updateOriginPoint(); + + invalidateDraw(); +} + +Rectf Node::getScreenBounds() { + return Rectf( Vector2f( mScreenPosi.x, mScreenPosi.y ), Sizef( (Float)(int)mSize.getWidth(), (Float)(int)mSize.getHeight() ) ); +} + +Rectf Node::getLocalBounds() { + return Rectf( 0, 0, mSize.getWidth(), mSize.getHeight() ); +} + +const Uint32& Node::getNodeFlags() const { + return mNodeFlags; +} + +void Node::setNodeFlags( const Uint32& Flags ) { + mNodeFlags = Flags; +} + +void Node::drawChilds() { + if ( isReverseDraw() ) { + Node * ChildLoop = mChildLast; + + while ( NULL != ChildLoop ) { + if ( ChildLoop->mVisible ) { + ChildLoop->internalDraw(); + } + + ChildLoop = ChildLoop->mPrev; + } + } else { + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + if ( ChildLoop->mVisible ) { + ChildLoop->internalDraw(); + } + + ChildLoop = ChildLoop->mNext; + } + } +} + +void Node::internalDraw() { + if ( mVisible ) { + if ( mNodeFlags & NODE_FLAG_POSITION_DIRTY ) + updateScreenPos(); + + matrixSet(); + + clipMe(); + + draw(); + + drawChilds(); + + clipDisable(); + + matrixUnset(); + } +} + +void Node::clipMe() { + //if ( mVisible && ( mFlags & UI_CLIP_ENABLE ) ) { + if ( false ) { + // UIManager::instance()->clipSmartEnable( this, mScreenPos.x, mScreenPos.y, mSize.getWidth(), mSize.getHeight() ); + } +} + +void Node::clipDisable() { + //if ( mVisible && ( mFlags & UI_CLIP_ENABLE ) ) { + if ( false ) { + // UIManager::instance()->clipSmartDisable( this ); + } +} + +void Node::matrixSet() { + if ( getScale() != 1.f || getRotation() != 0.f ) { + GlobalBatchRenderer::instance()->draw(); + + GLi->pushMatrix(); + + Vector2f scaleCenter = getScaleCenter(); + GLi->translatef( scaleCenter.x , scaleCenter.y, 0.f ); + GLi->scalef( getScale().x, getScale().y, 1.0f ); + GLi->translatef( -scaleCenter.x, -scaleCenter.y, 0.f ); + + Vector2f rotationCenter = getRotationCenter(); + GLi->translatef( rotationCenter.x , rotationCenter.y, 0.f ); + GLi->rotatef( getRotation(), 0.0f, 0.0f, 1.0f ); + GLi->translatef( -rotationCenter.x, -rotationCenter.y, 0.f ); + } +} + +void Node::matrixUnset() { + if ( getScale() != 1.f || getRotation() != 0.f ) { + GlobalBatchRenderer::instance()->draw(); + + GLi->popMatrix(); + } +} + +void Node::childDeleteAll() { + while( NULL != mChild ) { + eeDelete( mChild ); + } +} + +void Node::childAdd( Node * ChildCtrl ) { + if ( NULL == mChild ) { + mChild = ChildCtrl; + mChildLast = ChildCtrl; + } else { + mChildLast->mNext = ChildCtrl; + ChildCtrl->mPrev = mChildLast; + ChildCtrl->mNext = NULL; + mChildLast = ChildCtrl; + } + + onChildCountChange(); +} + +void Node::childAddAt( Node * ChildCtrl, Uint32 Pos ) { + eeASSERT( NULL != ChildCtrl ); + + Node * ChildLoop = mChild; + + ChildCtrl->setParent( this ); + + childRemove( ChildCtrl ); + + ChildCtrl->mParentCtrl = this; + ChildCtrl->mParentWindowCtrl = ChildCtrl->getParentWindow(); + + if ( ChildLoop == NULL ) { + mChild = ChildCtrl; + mChildLast = ChildCtrl; + ChildCtrl->mNext = NULL; + ChildCtrl->mPrev = NULL; + } else { + if( Pos == 0 ) { + if ( NULL != mChild ) { + mChild->mPrev = ChildCtrl; + } + + ChildCtrl->mNext = mChild; + ChildCtrl->mPrev = NULL; + mChild = ChildCtrl; + } else { + Uint32 i = 0; + + while ( NULL != ChildLoop->mNext && i < Pos ) { + ChildLoop = ChildLoop->mNext; + i++; + } + + Node * ChildTmp = ChildLoop->mNext; + ChildLoop->mNext = ChildCtrl; + ChildCtrl->mPrev = ChildLoop; + ChildCtrl->mNext = ChildTmp; + + if ( NULL != ChildTmp ) { + ChildTmp->mPrev = ChildCtrl; + } else { + mChildLast = ChildCtrl; + } + } + } + + onChildCountChange(); +} + +void Node::childRemove( Node * ChildCtrl ) { + if ( ChildCtrl == mChild ) { + mChild = mChild->mNext; + + if ( NULL != mChild ) { + mChild->mPrev = NULL; + + if ( ChildCtrl == mChildLast ) + mChildLast = mChild; + } else { + mChildLast = NULL; + } + } else { + if ( mChildLast == ChildCtrl ) + mChildLast = mChildLast->mPrev; + + ChildCtrl->mPrev->mNext = ChildCtrl->mNext; + + if ( NULL != ChildCtrl->mNext ) { + ChildCtrl->mNext->mPrev = ChildCtrl->mPrev; + ChildCtrl->mNext = NULL; + } + + ChildCtrl->mPrev = NULL; + } + + onChildCountChange(); +} + +void Node::childsCloseAll() { + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + ChildLoop->close(); + ChildLoop = ChildLoop->mNext; + } +} + +std::string Node::getId() const { + return mId; +} + +Node * Node::setId(const std::string & id) { + mId = id; + mIdHash = String::hash( id ); + return this; +} + +Uint32 Node::getIdHash() const { + return mIdHash; +} + +Node * Node::findIdHash( const Uint32& idHash ) { + if ( mIdHash == idHash ) { + return this; + } else { + Node * child = mChild; + + while ( NULL != child ) { + Node * foundCtrl = child->findIdHash( idHash ); + + if ( NULL != foundCtrl ) + return foundCtrl; + + child = child->mNext; + } + } + + return NULL; +} + +Node * Node::find( const std::string& id ) { + return findIdHash( String::hash( id ) ); +} + +bool Node::isChild( Node * ChildCtrl ) const { + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + if ( ChildCtrl == ChildLoop ) + return true; + + ChildLoop = ChildLoop->mNext; + } + + return false; +} + +bool Node::inParentTreeOf( Node * Child ) const { + Node * ParentLoop = Child->mParentCtrl; + + while ( NULL != ParentLoop ) { + if ( ParentLoop == this ) + return true; + + ParentLoop = ParentLoop->mParentCtrl; + } + + return false; +} + +Uint32 Node::childCount() const { + Node * ChildLoop = mChild; + Uint32 Count = 0; + + while( NULL != ChildLoop ) { + ChildLoop = ChildLoop->mNext; + Count++; + } + + return Count; +} + +Node * Node::childAt( Uint32 Index ) const { + Node * ChildLoop = mChild; + + while( NULL != ChildLoop && Index ) { + ChildLoop = ChildLoop->mNext; + Index--; + } + + return ChildLoop; +} + +Node * Node::childPrev( Node * Ctrl, bool Loop ) const { + if ( Loop && Ctrl == mChild && NULL != mChild->mNext ) + return mChildLast; + + return Ctrl->mPrev; +} + +Node * Node::childNext( Node * Ctrl, bool Loop ) const { + if ( NULL == Ctrl->mNext && Loop ) + return mChild; + + return Ctrl->mNext; +} + +Node * Node::getFirstChild() const { + return mChild; +} + +Node * Node::getLastChild() const { + return mChildLast; +} + +Node * Node::overFind( const Vector2f& Point ) { + Node * pOver = NULL; + + if ( mEnabled && mVisible ) { + updateWorldPolygon(); + + if ( mWorldBounds.contains( Point ) && mPoly.pointInside( Point ) ) { + writeCtrlFlag( NODE_FLAG_MOUSEOVER_ME_OR_CHILD, 1 ); + + Node * ChildLoop = mChildLast; + + while ( NULL != ChildLoop ) { + Node * ChildOver = ChildLoop->overFind( Point ); + + if ( NULL != ChildOver ) { + pOver = ChildOver; + + break; // Search from top to bottom, so the first over will be the topmost + } + + ChildLoop = ChildLoop->mPrev; + } + + + if ( NULL == pOver ) + pOver = this; + } + } + + return pOver; +} + +void Node::onParentWindowChange() { + mParentWindowCtrl = getParentWindow(); + + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + ChildLoop->onParentWindowChange(); + ChildLoop = ChildLoop->mNext; + } +} + +Uint32 Node::isWidget() { + return mNodeFlags & NODE_FLAG_WIDGET; +} + +Uint32 Node::isWindow() { + return mNodeFlags & NODE_FLAG_WINDOW; +} + +Uint32 Node::isClipped() { + return 0; //mFlags & UI_CLIP_ENABLE; +} + +Uint32 Node::isRotated() { + return mNodeFlags & NODE_FLAG_ROTATED; +} + +Uint32 Node::isScaled() { + return mNodeFlags & NODE_FLAG_SCALED; +} + +Uint32 Node::isFrameBuffer() { + return mNodeFlags & NODE_FLAG_FRAME_BUFFER; +} + +bool Node::isMeOrParentTreeRotated() { + Node * Ctrl = this; + + while( NULL != Ctrl ) { + if ( Ctrl->isRotated() ) + return true; + + Ctrl = Ctrl->getParent(); + } + + return false; +} + +bool Node::isMeOrParentTreeScaled() { + Node * Ctrl = this; + + while( NULL != Ctrl ) { + if ( Ctrl->isScaled() ) + return true; + + Ctrl = Ctrl->getParent(); + } + + return false; +} + +bool Node::isMeOrParentTreeScaledOrRotated() { + Node * Ctrl = this; + + while( NULL != Ctrl ) { + if ( Ctrl->isScaled() || Ctrl->isRotated() ) + return true; + + Ctrl = Ctrl->getParent(); + } + + return false; +} + +bool Node::isMeOrParentTreeScaledOrRotatedOrFrameBuffer() { + Node * Ctrl = this; + + while( NULL != Ctrl ) { + if ( Ctrl->isScaled() || Ctrl->isRotated() || Ctrl->isFrameBuffer() ) + return true; + + Ctrl = Ctrl->getParent(); + } + + return false; +} + +const Polygon2f & Node::getWorldPolygon() { + if ( mNodeFlags & NODE_FLAG_POLYGON_DIRTY ) + updateWorldPolygon(); + + return mPoly; +} + +const Rectf& Node::getWorldBounds() { + if ( mNodeFlags & NODE_FLAG_POLYGON_DIRTY ) + updateWorldPolygon(); + + return mWorldBounds; +} + +void Node::updateWorldPolygon() { + if ( !( mNodeFlags & NODE_FLAG_POLYGON_DIRTY ) ) + return; + + if ( mNodeFlags & NODE_FLAG_POSITION_DIRTY ) + updateScreenPos(); + + mPoly = Polygon2f( Rectf( mScreenPos.x, mScreenPos.y, mScreenPos.x + mSize.getWidth(), mScreenPos.y + mSize.getHeight() ) ); + + mPoly.rotate( getRotation(), getRotationCenter() ); + mPoly.scale( getScale(), getScaleCenter() ); + + Node * tParent = getParent(); + + while ( tParent ) { + mPoly.rotate( tParent->getRotation(), tParent->getRotationCenter() ); + mPoly.scale( tParent->getScale(), tParent->getScaleCenter() ); + + tParent = tParent->getParent(); + }; + + mWorldBounds = mPoly.getBounds(); + + mNodeFlags &= ~NODE_FLAG_POLYGON_DIRTY; +} + +void Node::updateCenter() { + mCenter = Vector2f( mScreenPos.x + (Float)mSize.getWidth() * 0.5f, mScreenPos.y + (Float)mSize.getHeight() * 0.5f ); +} + +Uint32 Node::addEventListener( const Uint32& EventType, const UIEventCallback& Callback ) { + mNumCallBacks++; + + mEvents[ EventType ][ mNumCallBacks ] = Callback; + + return mNumCallBacks; +} + +void Node::removeEventListener( const Uint32& CallbackId ) { + UIEventsMap::iterator it; + + for ( it = mEvents.begin(); it != mEvents.end(); ++it ) { + std::map event = it->second; + + if ( event.erase( CallbackId ) ) + break; + } +} + +void Node::sendEvent( const UIEvent * Event ) { + if ( 0 != mEvents.count( Event->getEventType() ) ) { + std::map event = mEvents[ Event->getEventType() ]; + std::map::iterator it; + + if ( event.begin() != event.end() ) { + for ( it = event.begin(); it != event.end(); ++it ) + it->second( Event ); + } + } +} + +void Node::onParentChange() { + invalidateDraw(); +} + +void Node::updateScreenPos() { + if ( !(mNodeFlags & NODE_FLAG_POSITION_DIRTY) ) + return; + + Vector2f Pos( mPosition ); + + nodeToWorldTranslation( Pos ); + + mScreenPos = Pos; + mScreenPosi = Vector2i( Pos.x, Pos.y ); + + updateCenter(); + + mNodeFlags &= ~NODE_FLAG_POSITION_DIRTY; +} + +void Node::writeCtrlFlag( const Uint32& Flag, const Uint32& Val ) { + BitOp::setBitFlagValue( &mNodeFlags, Flag, Val ); +} + +void Node::onParentSizeChange( const Vector2f& SizeChange ) { + sendCommonEvent( UIEvent::OnParentSizeChange ); + invalidateDraw(); +} + +void Node::onChildCountChange() { + invalidateDraw(); +} + +void Node::worldToNode( Vector2i& pos ) { + Vector2f toPos( convertToNodeSpace( Vector2f( pos.x, pos.y ) ) ); + pos = Vector2i( toPos.x / PixelDensity::getPixelDensity(), toPos.y / PixelDensity::getPixelDensity() ); +} + +void Node::nodeToWorld( Vector2i& pos ) { + Vector2f toPos( convertToWorldSpace( Vector2f( pos.x * PixelDensity::getPixelDensity(), pos.y * PixelDensity::getPixelDensity() ) ) ); + pos = Vector2i( toPos.x, toPos.y ); +} + +void Node::worldToNode( Vector2f& pos ) { + Vector2f toPos( convertToNodeSpace( pos ) ); + pos = Vector2f( toPos.x / PixelDensity::getPixelDensity(), toPos.y / PixelDensity::getPixelDensity() ); +} + +void Node::nodeToWorld( Vector2f& pos ) { + Vector2f toPos( convertToWorldSpace( Vector2f( pos.x * PixelDensity::getPixelDensity(), pos.y * PixelDensity::getPixelDensity() ) ) ); + pos = Vector2f( toPos.x, toPos.y ); +} + +bool Node::isReverseDraw() const { + return 0 != ( mNodeFlags & NODE_FLAG_REVERSE_DRAW ); +} + +void Node::setReverseDraw( bool reverseDraw ) { + writeCtrlFlag( NODE_FLAG_REVERSE_DRAW, reverseDraw ? 1 : 0 ); + invalidateDraw(); +} + +void Node::invalidateDraw() { + if ( NULL != mParentWindowCtrl ) { + mParentWindowCtrl->invalidate(); + } else if ( NULL == mParentCtrl && isWindow() ) { + // static_cast( this )->invalidate(); + } +} + +void Node::setClipEnabled() { + //writeFlag( UI_CLIP_ENABLE, 1 ); +} + +void Node::setClipDisabled() { + //writeFlag( UI_CLIP_ENABLE, 0 ); +} + +UIWindow * Node::getOwnerWindow() { + return mParentWindowCtrl; +} + +UIWindow *Node::getParentWindow() { + return mParentWindowCtrl; +} + +void Node::updateOriginPoint() { + switch ( mRotationOriginPoint.OriginType ) { + case OriginPoint::OriginCenter: + mRotationOriginPoint.x = mSize.x * 0.5f; + mRotationOriginPoint.y = mSize.y * 0.5f; + break; + case OriginPoint::OriginTopLeft: + mRotationOriginPoint.x = mRotationOriginPoint.y = 0; + break; + default: {} + } + + switch ( mScaleOriginPoint.OriginType ) { + case OriginPoint::OriginCenter: + mScaleOriginPoint.x = mSize.x * 0.5f; + mScaleOriginPoint.y = mSize.y * 0.5f; + break; + case OriginPoint::OriginTopLeft: + mScaleOriginPoint.x = mScaleOriginPoint.y = 0; + break; + default: {} + } + + setDirty(); +} + +void Node::setDirty() { + if ( ( mNodeFlags & NODE_FLAG_POSITION_DIRTY ) && + ( mNodeFlags & NODE_FLAG_POLYGON_DIRTY ) ) + return; + + mNodeFlags |= NODE_FLAG_POSITION_DIRTY | NODE_FLAG_POLYGON_DIRTY; + + setChildsDirty(); +} + +void Node::setChildsDirty() { + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + ChildLoop->setDirty(); + + ChildLoop = ChildLoop->mNext; + } +} + +void Node::onAngleChange() { + sendCommonEvent( UIEvent::OnAngleChange ); + invalidateDraw(); +} + +void Node::onScaleChange() { + sendCommonEvent( UIEvent::OnScaleChange ); + invalidateDraw(); +} + +void Node::onAlphaChange() { + sendCommonEvent( UIEvent::OnAlphaChange ); + invalidateDraw(); +} + +Color Node::getColor( const Color& Col ) { + return Color( Col.r, Col.g, Col.b, static_cast( (Float)Col.a * ( mAlpha / 255.f ) ) ); +} + +const OriginPoint& Node::getRotationOriginPoint() const { + return mRotationOriginPoint; +} + +void Node::setRotationOriginPoint( const OriginPoint & center ) { + mRotationOriginPoint = PixelDensity::dpToPx( center ); + updateOriginPoint(); + Transformable::setRotationOrigin( getRotationOriginPoint().x, getRotationOriginPoint().y ); +} + +Vector2f Node::getRotationCenter() { + switch ( mRotationOriginPoint.OriginType ) { + case OriginPoint::OriginCenter: return mCenter; + case OriginPoint::OriginTopLeft: return mScreenPos; + case OriginPoint::OriginCustom: default: return mScreenPos + mRotationOriginPoint; + } +} + +void Node::setRotation( float angle ) { + Transformable::setRotation( angle ); + + updateOriginPoint(); + Transformable::setRotationOrigin( getRotationOriginPoint().x, getRotationOriginPoint().y ); + + if ( getRotation() != 0.f ) { + mNodeFlags |= NODE_FLAG_ROTATED; + } else { + if ( mNodeFlags & NODE_FLAG_ROTATED ) + mNodeFlags &= ~NODE_FLAG_ROTATED; + } + + setDirty(); + + onAngleChange(); +} + +void Node::setRotation( const Float& angle , const OriginPoint & center ) { + mRotationOriginPoint = PixelDensity::dpToPx( center ); + updateOriginPoint(); + setRotation( angle ); +} + +void Node::setScale( const Vector2f & scale ) { + Transformable::setScale( scale.x, scale.y ); + + updateOriginPoint(); + Transformable::setScaleOrigin( getScaleOriginPoint().x, getScaleOriginPoint().y ); + + if ( getScale() != 1.f ) { + mNodeFlags |= NODE_FLAG_SCALED; + } else { + if ( mNodeFlags & NODE_FLAG_SCALED ) + mNodeFlags &= ~NODE_FLAG_SCALED; + } + + setDirty(); + + onScaleChange(); +} + +const OriginPoint& Node::getScaleOriginPoint() const { + return mScaleOriginPoint; +} + +void Node::setScaleOriginPoint( const OriginPoint & center ) { + mScaleOriginPoint = PixelDensity::dpToPx( center ); + updateOriginPoint(); + Transformable::setScaleOrigin( getScaleCenter().x, getScaleCenter().y ); +} + +Vector2f Node::getScaleCenter() { + switch ( mScaleOriginPoint.OriginType ) { + case OriginPoint::OriginCenter: return mCenter; + case OriginPoint::OriginTopLeft: return mScreenPos; + case OriginPoint::OriginCustom: default: return mScreenPos + mScaleOriginPoint; + } +} + +void Node::setScale( const Vector2f& scale, const OriginPoint& center ) { + mScaleOriginPoint = PixelDensity::dpToPx( center ); + updateOriginPoint(); + Transformable::setScale( scale.x, scale.y ); + Transformable::setScaleOrigin( getScaleOriginPoint().x, getScaleOriginPoint().y ); +} + +void Node::setScale( const Float& scale, const OriginPoint& center ) { + setScale( Vector2f( scale, scale ), center ); +} + +const Float& Node::getAlpha() const { + return mAlpha; +} + +void Node::setAlpha( const Float& alpha ) { + mAlpha = alpha; + onAlphaChange(); +} + +void Node::setChildsAlpha( const Float &alpha ) { + Node * CurChild = mChild; + + while ( NULL != CurChild ) { + CurChild->setAlpha( alpha ); + CurChild->setChildsAlpha( alpha ); + CurChild = CurChild->getNextNode(); + } +} + +ActionManager * Node::getActionManager() { + if ( NULL == mActionManager ) + mActionManager = eeNew( ActionManager, () ); + + return mActionManager; +} + +void Node::runAction( Action * action ) { + /*if ( NULL != action ) { + action->setTarget( this ); + + action->start(); + + getActionManager()->addAction( action ); + }*/ +} + +Transform Node::getLocalTransform() { + return getTransform(); +} + +Transform Node::getGlobalTransform() { + return NULL != mParentCtrl ? mParentCtrl->getGlobalTransform() * getTransform() : getTransform(); +} + +Transform Node::getNodeToWorldTransform() { + return getGlobalTransform(); +} + +Transform Node::getWorldToNodeTransform() { + return getNodeToWorldTransform().getInverse(); +} + +Vector2f Node::convertToNodeSpace(const Vector2f& worldPoint) { + return getWorldToNodeTransform().transformPoint(worldPoint.x, worldPoint.y); +} + +Vector2f Node::convertToWorldSpace(const Vector2f& nodePoint) { + return getNodeToWorldTransform().transformPoint(nodePoint.x, nodePoint.y); +} + +void Node::setScale(float factorX, float factorY) { + setScale( Vector2f( factorX, factorY ) ); +} + +void Node::setScaleOrigin(float x, float y) { + setScaleOriginPoint( OriginPoint( x, y ) ); +} + +void Node::setRotationOrigin(float x, float y) { + setRotationOriginPoint( OriginPoint( x, y ) ); +} + +}} diff --git a/src/eepp/ui/uiaction.cpp b/src/eepp/ui/uiaction.cpp deleted file mode 100644 index bbf49218a..000000000 --- a/src/eepp/ui/uiaction.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include - -namespace EE { namespace UI { - -UIAction::UIAction() : - mNode( NULL ), - mFlags( 0 ), - mTag( 0 ), - mNumCallBacks( 0 ) -{ -} - -UIAction::~UIAction() -{} - -Uint32 UIAction::getFlags() const { - return mFlags; -} - -void UIAction::setFlags( const Uint32 & flags ) { - mFlags = flags; -} - -Uint32 UIAction::getTag() const { - return mTag; -} - -void UIAction::setTag( const Uint32 & tag ) { - mTag = tag; -} - -void UIAction::setTarget( UINode * target ) { - mNode = target; -} - -UINode * UIAction::getTarget() const { - return mNode; -} - -UIAction * UIAction::clone() const { - return NULL; -} - -UIAction * UIAction::reverse() const { - return NULL; -} - -Uint32 UIAction::addEventListener( const ActionType& actionType, const ActionCallback& callback ) { - mNumCallBacks++; - - mCallbacks[ actionType ][ mNumCallBacks ] = callback; - - return mNumCallBacks; -} - -void UIAction::removeEventListener( const Uint32& callbackId ) { - for ( auto it = mCallbacks.begin(); it != mCallbacks.end(); ++it ) { - std::map event = it->second; - - if ( event.erase( callbackId ) ) - break; - } -} - -void UIAction::sendEvent( const ActionType& actionType ) { - if ( 0 != mCallbacks.count( actionType ) ) { - auto event = mCallbacks[ actionType ]; - - if ( !event.empty() ) { - for ( auto it = event.begin(); it != event.end(); ++it ) - it->second( this, actionType ); - } - } -} - -void UIAction::onStart() {} - -void UIAction::onStop() {} - -void UIAction::onUpdate( const Time& time ) {} - -}} diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 88a5317f3..e9511f010 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -11,10 +11,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include namespace EE { namespace UI { @@ -1803,7 +1803,7 @@ bool UINode::isAnimating() { return NULL != mActionManager && !mActionManager->isEmpty(); } -static void UINode_onFadeDone( UIAction * action, const UIAction::ActionType& actionType ) { +static void UINode_onFadeDone( Action * action, const Action::ActionType& actionType ) { UINode * node = action->getTarget(); if ( NULL != node ) { @@ -1819,11 +1819,11 @@ static void UINode_onFadeDone( UIAction * action, const UIAction::ActionType& ac } Interpolation1d * UINode::startAlphaAnim( const Float& From, const Float& To, const Time& TotalTime, const bool& AlphaChilds, const Ease::Interpolation& Type, Interpolation1d::OnPathEndCallback PathEndCallback ) { - Action::Fade * action = Action::Fade::New( From, To, TotalTime, Type ); + Actions::Fade * action = Actions::Fade::New( From, To, TotalTime, Type ); action->getInterpolation()->setPathEndCallback( PathEndCallback ); - action->addEventListener( UIAction::ActionType::OnDone, cb::Make2( &UINode_onFadeDone ) ); + action->addEventListener( Action::ActionType::OnDone, cb::Make2( &UINode_onFadeDone ) ); runAction( action ); @@ -1831,7 +1831,7 @@ Interpolation1d * UINode::startAlphaAnim( const Float& From, const Float& To, co } Interpolation2d * UINode::startScaleAnim( const Vector2f& From, const Vector2f& To, const Time& TotalTime, const Ease::Interpolation& Type, Interpolation2d::OnPathEndCallback PathEndCallback ) { - Action::Scale * action = Action::Scale::New( From, To, TotalTime, Type ); + Actions::Scale * action = Actions::Scale::New( From, To, TotalTime, Type ); action->getInterpolation()->setPathEndCallback( PathEndCallback ); @@ -1845,7 +1845,7 @@ Interpolation2d * UINode::startScaleAnim( const Float& From, const Float& To, co } Interpolation2d * UINode::startTranslation( const Vector2f& From, const Vector2f& To, const Time& TotalTime, const Ease::Interpolation& Type, Interpolation2d::OnPathEndCallback PathEndCallback ) { - Action::Move * action = Action::Move::New( From, To, TotalTime, Type ); + Actions::Move * action = Actions::Move::New( From, To, TotalTime, Type ); action->getInterpolation()->setPathEndCallback( PathEndCallback ); @@ -1855,7 +1855,7 @@ Interpolation2d * UINode::startTranslation( const Vector2f& From, const Vector2f } Interpolation1d * UINode::startRotation( const Float& From, const Float& To, const Time& TotalTime, const Ease::Interpolation& Type, Interpolation1d::OnPathEndCallback PathEndCallback ) { - Action::Rotate * action = Action::Rotate::New( From, To, TotalTime, Type ); + Actions::Rotate * action = Actions::Rotate::New( From, To, TotalTime, Type ); action->getInterpolation()->setPathEndCallback( PathEndCallback ); @@ -2014,14 +2014,14 @@ void UINode::setChildsAlpha( const Float &alpha ) { } } -UIActionManager * UINode::getActionManager() { +ActionManager * UINode::getActionManager() { if ( NULL == mActionManager ) - mActionManager = eeNew( UIActionManager, () ); + mActionManager = eeNew( ActionManager, () ); return mActionManager; } -void UINode::runAction( UIAction * action ) { +void UINode::runAction( Action * action ) { if ( NULL != action ) { action->setTarget( this ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 72b3784cc..07eef51ee 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1123,7 +1123,7 @@ void EETest::onMainClick( const UIEvent * Event ) { } } -using namespace EE::UI::Action; +using namespace EE::Scene::Actions; void EETest::onButtonClick( const UIEvent * Event ) { const UIEventMouse * MouseEvent = reinterpret_cast ( Event );