2 #include "oxygine-include.h" 3 #include "oxygine-forwards.h" 4 #include "core/Object.h" 5 #include "core/Renderer.h" 7 #include "math/AffineTransform.h" 8 #include "utils/intrusive_list.h" 9 #include "Serializable.h" 10 #include "EventDispatcher.h" 11 #include "TouchEvent.h" 19 explicit TweenOptions(timeMS duration = 500) : _duration(duration), _delay(0), _ease(Tween::ease_linear), _globalEase(Tween::ease_linear), _loops(1), _twoSides(
false), _detach(
false) {}
20 TweenOptions& duration(timeMS duration) { _duration = duration;
return *
this; }
21 TweenOptions& delay(timeMS delay) { _delay = delay;
return *
this; }
22 TweenOptions& loops(
int loops) { _loops = loops;
return *
this; }
23 TweenOptions& twoSides(
bool enabled =
true) { _twoSides = enabled;
return *
this; }
24 TweenOptions& ease(Tween::EASE ease) { _ease = ease;
return *
this; }
25 TweenOptions& detach(
bool detach_ =
true) { _detach = detach_;
return *
this; }
26 TweenOptions& globalEase(Tween::EASE ease) { _globalEase = ease;
return *
this; }
27 TweenOptions& doneCallback(
const EventCallback& cb) { _callback = cb;
return *
this; }
30 EventCallback _callback;
34 Tween::EASE _globalEase;
40 DECLARE_SMART(
Actor, spActor);
48 virtual Actor* clone(cloneOptions opt = 0)
const;
49 void copyFrom(
const Actor& src, cloneOptions opt = 0);
70 spActor
getChild(
const std::string& name, error_policy ep = ep_show_error)
const;
73 T*
getChildT(
const std::string& name, error_policy ep = ep_show_error)
const {
return safeCast<T*>(
getChild(name, ep).get()); }
76 spTween
getTween(
const std::string& name, error_policy ep = ep_show_error);
82 const Vector2& getAnchor()
const {
return _anchor;}
83 float getAnchorX()
const {
return _anchor.x;}
84 float getAnchorY()
const {
return _anchor.y;}
85 bool getIsAnchorInPixels() {
return (_flags & flag_anchorInPixels) != 0;}
86 const Vector2& getPosition()
const {
return _pos;}
87 float getX()
const {
return _pos.x;}
88 float getY()
const {
return _pos.y;}
89 const Vector2& getScale()
const {
return _scale;}
90 float getScaleX()
const {
return _scale.x;}
91 float getScaleY()
const {
return _scale.y;}
96 int getPriority()
const {
return _zOrder;}
97 bool getVisible()
const {
return (_flags & flag_visible) != 0;}
98 Actor* getParent() {
return _parent;}
99 const Actor* getParent()
const {
return _parent;}
100 Vector2 getSize()
const {
return _size;}
103 float getWidth()
const;
104 float getScaledWidth()
const {
return _size.x * _scale.x;}
105 float getHeight()
const;
106 float getScaledHeight()
const {
return _size.y * _scale.y;}
107 unsigned char getAlpha()
const;
108 const spClock& getClock()
const;
109 virtual RectF getDestRect()
const;
111 pointer_index
getPressed(MouseButton b = MouseButton_Touch)
const;
114 bool getTouchEnabled()
const {
return (_flags & flag_touchEnabled) != 0; }
115 bool getTouchChildrenEnabled()
const {
return (_flags & flag_touchChildrenEnabled) != 0; }
116 UpdateCallback getCallbackDoUpdate()
const {
return _cbDoUpdate;}
117 Material* getMaterial() {
return _material; }
122 const Transform& getTransformInvert()
const;
128 RectF
computeBounds(
const Transform& transform = Transform::getIdentity())
const;
135 void setAnchorInPixels(
const Vector2& anchor);
136 void setAnchorInPixels(
float x,
float y);
137 void setAnchorX(
float x);
138 void setAnchorY(
float y);
140 void setPosition(
const Vector2& pos);
141 void setPosition(
float x,
float y);
149 void setScale(
float scale);
150 void setScale(
const Vector2& scale);
151 void setScale(
float scaleX,
float scaleY);
152 void setScaleX(
float sx);
153 void setScaleY(
float sy);
161 void setSize(
float w,
float h);
162 void setWidth(
float w);
163 void setHeight(
float h);
167 void setClock(spClock clock);
171 void setVisible(
bool vis) {_flags &= ~flag_visible;
if (vis) _flags |= flag_visible;}
173 void setCull(
bool enable) {_flags &= ~flag_cull;
if (enable) _flags |= flag_cull;}
178 void setTouchEnabled(
bool enabled) { _flags &= ~flag_touchEnabled;
if (enabled) _flags |= flag_touchEnabled; }
180 void setTouchChildrenEnabled(
bool enabled) { _flags &= ~flag_touchChildrenEnabled;
if (enabled) _flags |= flag_touchChildrenEnabled; }
189 virtual bool isOn(
const Vector2& localPosition,
float localScale = 1.0f);
201 void addChild(spActor actor);
202 void addChild(
Actor* actor);
203 void attachTo(spActor parent);
204 void attachTo(
Actor* parent);
217 virtual void updateStateOvered() {}
218 virtual void updateStatePressed() {}
220 spTween addTween(spTween);
221 spTween addTween2(spTween,
const TweenOptions& opt);
224 spTween addTween(
const Prop& prop, timeMS duration,
int loops = 1,
bool twoSides =
false, timeMS delay = 0, Tween::EASE ease = Tween::ease_linear)
225 {
return addTween(createTween(prop, duration, loops, twoSides, delay, ease));}
228 spTween addTween(
const Prop& prop,
const TweenOptions& opt)
229 {
return addTween(createTween2(prop, opt));}
232 int addClickListener(
const EventCallback& cb) {
return addEventListener(TouchEvent::CLICK, cb); }
236 int addTouchUpListener(
const EventCallback& cb) {
return addEventListener(TouchEvent::TOUCH_UP, cb); }
238 void removeTween(spTween);
239 void removeTweensByName(
const std::string& name);
247 virtual void handleEvent(
Event* event);
251 Vector2 parent2local(
const Vector2& pos)
const;
253 Vector2 local2parent(
const Vector2& pos = Vector2(0, 0))
const;
256 Vector2 local2stage(
const Vector2& pos = Vector2(0, 0), Actor* stage = 0)
const;
258 Vector2 stage2local(
const Vector2& pos, Actor* stage = 0)
const;
260 typedef Property2Args<float, Vector2, const Vector2&, Actor, &Actor::getPosition, &Actor::setPosition> TweenPosition;
261 typedef Property<float, float, Actor, &Actor::getX, &Actor::setX> TweenX;
262 typedef Property<float, float, Actor, &Actor::getY, &Actor::setY> TweenY;
263 typedef Property<float, float, Actor, &Actor::getWidth, &Actor::setWidth> TweenWidth;
264 typedef Property<float, float, Actor, &Actor::getHeight, &Actor::setHeight> TweenHeight;
265 typedef Property2Args2<float, Vector2, Vector2, const Vector2&, Actor, &Actor::getSize, &Actor::setSize>TweenSize;
266 typedef Property<float, float, Actor, &Actor::getRotation, &Actor::setRotation> TweenRotation;
267 typedef Property<float, float, Actor, &Actor::getRotationDegrees, &Actor::setRotationDegrees> TweenRotationDegrees;
268 typedef Property2Args1Arg<float, Vector2, const Vector2&, Actor, &Actor::getScale, &Actor::setScale> TweenScale;
269 typedef Property2Args1Arg<float, Vector2, const Vector2&, Actor, &Actor::getAnchor, &Actor::setAnchor> TweenAnchor;
270 typedef Property<float, float, Actor, &Actor::getScaleX, &Actor::setScaleX> TweenScaleX;
271 typedef Property<float, float, Actor, &Actor::getScaleY, &Actor::setScaleY> TweenScaleY;
272 typedef Property<unsigned char, unsigned char, Actor, &Actor::getAlpha, &Actor::setAlpha> TweenAlpha;
275 void serialize(serializedata*)
override;
276 void deserialize(
const deserializedata*)
override;
279 virtual std::string
dump(
const dumpOptions& opt)
const;
284 void setNotPressed(MouseButton b);
286 bool internalRender(RenderState& rs,
const RenderState& parentRS);
291 virtual bool getBounds(RectF&)
const {
return false; }
298 void added2stage(Stage*);
299 void removedFromStage();
300 virtual void onAdded2Stage() {}
301 virtual void onRemovedFromStage() {}
302 virtual void transformUpdated() {}
304 virtual void calcBounds2(RectF& bounds,
const Transform& transform)
const;
307 typedef intrusive_list<spActor> children;
308 static void setParent(Actor* actor, Actor* parent);
309 static children& getChildren(spActor& actor) {
return actor->_children; }
310 static unsigned short& _getFlags(Actor* actor) {
return actor->_flags; }
312 void _onGlobalTouchUpEvent(Event*);
313 void _onGlobalTouchUpEvent1(Event*);
314 void _onGlobalTouchUpEvent2(Event*);
315 void _onGlobalTouchMoveEvent(Event*);
317 const Vector2& _getSize()
const {
return _size; }
318 void _setSize(
const Vector2&);
319 virtual void sizeChanged(
const Vector2& size);
320 Actor* _getDescendant(
const std::string& name);
321 spTween _addTween(spTween tween,
bool rel);
323 bool prepareRender(RenderState& rs,
const RenderState& parentRS);
324 void completeRender(
const RenderState& rs);
327 void updateTransform()
const;
328 void internalUpdate(
const UpdateState& us);
331 virtual void doUpdate(
const UpdateState& us);
332 UpdateCallback _cbDoUpdate;
334 mutable Transform _transform;
335 mutable Transform _transformInvert;
340 flag_anchorInPixels = 1,
341 flag_visible = 1 << 1,
342 flag_touchEnabled = 1 << 2,
343 flag_transformDirty = 1 << 3,
344 flag_transformInvertDirty = 1 << 4,
345 flag_touchChildrenEnabled = 1 << 5,
347 flag_fastTransform = 1 << 7,
348 flag_reserved = 1 << 8,
349 flag_last = flag_reserved
352 mutable unsigned short _flags;
353 unsigned char _alpha;
359 typedef intrusive_list<spTween> tweens;
369 pointer_index _overred;
370 pointer_index _pressedButton[MouseButton_Num];
372 int32_t _pressedOvered;
389 spTween setTimeout(timeMS dur,
const EventCallback& cb, spActor root = 0);
391 Vector2 convert_local2stage(spActor child,
const Vector2& pos, spActor root = 0);
392 Vector2 convert_local2stage(
const Actor* child,
const Vector2& pos,
const Actor* root = 0);
393 Vector2 convert_stage2local(spActor child,
const Vector2& pos, spActor root = 0);
394 Vector2 convert_stage2local(
const Actor* child,
const Vector2& pos,
const Actor* root = 0);
398 bool testIntersection(spActor obj1, spActor obj2, spActor commonParent = 0, Vector2* contact = 0);
401 RectF getActorTransformedDestRect(Actor* actor,
const Transform& tr);
404 void reattachActor(spActor actor, spActor newParent, spActor root = 0);
406 void decompose(
const Transform& t, Vector2& pos,
float& angle, Vector2& scale);
407 void setDecomposedTransform(spActor& a,
const Transform& t);
424 EDITOR_INCLUDE(Actor);
Transform computeGlobalTransform(Actor *parent=0) const
float getRotation() const
Definition: Actor.h:93
pointer_index getPressed(MouseButton b=MouseButton_Touch) const
void setTransform(const AffineTransform &tr)
void setCallbackDoUpdate(UpdateCallback cb)
Definition: Actor.h:185
Definition: intrusive_list.h:183
void setAlpha(unsigned char alpha)
void setTouchChildrenEnabled(bool enabled)
Definition: Actor.h:180
void removeChild(spActor actor)
spActor getFirstChild() const
Definition: Actor.h:55
virtual void doUpdate(const UpdateState &us)
spActor getChild(const std::string &name, error_policy ep=ep_show_error) const
void insertSiblingBefore(spActor)
void removeTweens(bool callComplete=false)
void setRotationDegrees(float angle)
int addTouchDownListener(const EventCallback &cb)
Definition: Actor.h:234
virtual void render(const RenderState &rs)
void reattachActor(spActor actor, spActor newParent, spActor root=0)
Definition: RenderState.h:27
void dispatchEvent(Event *event) override
RectF computeBounds(const Transform &transform=Transform::getIdentity()) const
void setExtendedClickArea(char add)
Definition: Actor.h:165
bool isDescendant(const spActor &actor) const
void setTouchEnabled(bool enabled, bool childrenEnabled)
Definition: Actor.h:182
Definition: UpdateState.h:6
int addClickListener(const EventCallback &cb)
Definition: Actor.h:232
void setPriority(short zorder)
–oxgl-end–!
Definition: Actor.h:14
void insertSiblingAfter(spActor)
void setAnchor(const Vector2 &anchor)
Definition: Serializable.h:6
void setCull(bool enable)
Definition: Actor.h:173
void prependChild(spActor actor)
void setVisible(bool vis)
Definition: Actor.h:171
spTween getTween(const std::string &name, error_policy ep=ep_show_error)
virtual void update(const UpdateState &us)
T * getChildT(const std::string &name, error_policy ep=ep_show_error) const
Definition: Actor.h:73
spActor getNextSibling() const
Definition: Actor.h:59
pointer_index getOvered() const
void setSize(const Vector2 &)
spTween getLastTween() const
Definition: Actor.h:80
void setTouchEnabled(bool enabled)
Definition: Actor.h:178
Actor * getDescendant(const std::string &name, error_policy ep=ep_show_error)
spActor getLastChild() const
Definition: Actor.h:57
spTween getFirstTween() const
Definition: Actor.h:78
T * getDescendantT(const std::string &name, error_policy ep=ep_show_error)
Definition: Actor.h:68
virtual bool isOn(const Vector2 &localPosition, float localScale=1.0f)
Vector2 getScaledSize() const
Definition: Actor.h:102
const Transform & getTransform() const
Definition: EventDispatcher.h:27
float getRotationDegrees() const
Definition: Actor.h:95
spActor getPrevSibling() const
Definition: Actor.h:61
int addTouchUpListener(const EventCallback &cb)
Definition: Actor.h:236
void setRotation(float angle)
virtual std::string dump(const dumpOptions &opt) const