22 #ifndef TWP_SCENEGRAPH_H 23 #define TWP_SCENEGRAPH_H 25 #include "common/array.h" 26 #include "common/str.h" 27 #include "math/vector2d.h" 28 #include "math/matrix4.h" 30 #include "twp/rectf.h" 32 #include "twp/spritesheet.h" 49 virtual void setVisible(
bool visible) { _visible = visible; }
50 bool isVisible()
const {
return _visible; }
56 void addChild(
Node *child);
57 void removeChild(
Node *node);
63 Node *getParent()
const {
return _parent; }
64 const Node *getRoot()
const;
66 int find(
Node *other);
69 void setPos(
const Math::Vector2d &pos) { _pos = pos; }
70 Math::Vector2d getPos()
const {
return _pos; }
72 void setOffset(
const Math::Vector2d &offset) { _offset = offset; }
73 Math::Vector2d getOffset()
const {
return _offset; }
75 void setShakeOffset(
const Math::Vector2d &offset) { _shakeOffset = offset; }
76 Math::Vector2d getShakeOffset()
const {
return _shakeOffset; }
78 void setRenderOffset(
const Math::Vector2d &offset) { _renderOffset = offset; }
79 Math::Vector2d getRenderOffset()
const {
return _renderOffset; }
81 void setScale(
const Math::Vector2d &
scale) { _scale =
scale; }
82 virtual Math::Vector2d getScale()
const {
return _scale; }
85 Math::Vector2d getAbsPos()
const;
88 virtual Math::Matrix4 getTrsf(
const Math::Matrix4 &parentTrsf);
90 void setColor(
const Color &color);
91 Color getColor()
const {
return _color; }
92 Color getComputedColor()
const {
return _computedColor; }
94 void setAlpha(
float alpha);
95 float getAlpha()
const {
return _color.rgba.a; }
97 void setZSort(
int zsort) { _zOrder = zsort; }
98 virtual int getZSort()
const {
return _zOrder; }
100 void setRotation(
float rotation) { _rotation = rotation; }
101 float getRotation()
const {
return _rotation; }
103 void setRotationOffset(
float rotationOffset) { _rotationOffset = rotationOffset; }
104 float getRotationOffset()
const {
return _rotationOffset; }
106 void setAnchor(
const Math::Vector2d &anchor);
107 void setAnchorNorm(
const Math::Vector2d &anchorNorm);
108 void setSize(
const Math::Vector2d &size);
109 Math::Vector2d getSize()
const {
return _size; }
110 virtual Rectf getRect()
const;
112 void draw(
const Math::Matrix4 &parent = Math::Matrix4());
115 virtual void onDrawChildren(
const Math::Matrix4 &trsf);
116 virtual void onColorUpdated(
const Color &c) {}
117 virtual void drawCore(
const Math::Matrix4 &trsf) {}
121 Math::Matrix4 getLocalTrsf();
123 void updateColor(
const Color &parentColor);
125 void updateAlpha(
float parentAlpha);
131 Node *_parent =
nullptr;
133 Math::Vector2d _offset, _shakeOffset, _renderOffset, _anchor, _anchorNorm, _scale, _size;
134 Color _color, _computedColor;
135 bool _visible =
true;
136 float _rotation = 0.f;
137 float _rotationOffset = 0.f;
145 Math::Matrix4 getTrsf(
const Math::Matrix4 &parentTrsf)
override final;
148 void onDrawChildren(
const Math::Matrix4 &trsf)
override;
149 void drawCore(
const Math::Matrix4 &trsf)
override final;
152 Math::Vector2d _parallax;
165 void setAnim(
const ObjectAnimation *anim,
float fps = 0.f,
bool loop =
false,
bool instant =
false);
166 void update(
float elapsed);
167 void disable() { _disabled =
true; }
171 virtual void drawCore(
const Math::Matrix4 &trsf)
override final;
175 bool _disabled =
false;
180 size_t _frameIndex = 0;
181 float _elapsed = 0.f;
182 float _frameDuration = 0.f;
184 bool _instant =
false;
193 int getZSort()
const override final;
194 Math::Vector2d getScale()
const override final;
205 void setText(
const Text &text);
207 virtual Rectf getRect()
const override final;
210 virtual void onColorUpdated(
const Color &color)
override final;
211 virtual void drawCore(
const Math::Matrix4 &trsf)
override final;
220 virtual ~
Scene()
final;
223 enum class CursorShape {
232 enum InputStateFlag {
233 II_FLAGS_UI_INPUT_ON = 1,
234 II_FLAGS_UI_INPUT_OFF = 2,
235 II_FLAGS_UI_VERBS_ON = 4,
236 II_FLAGS_UI_VERBS_OFF = 8,
237 II_FLAGS_UI_HUDOBJECTS_ON = 0x10,
238 II_FLAGS_UI_HUDOBJECTS_OFF = 0x20,
239 II_FLAGS_UI_CURSOR_ON = 0x40,
240 II_FLAGS_UI_CURSOR_OFF = 0x80
248 InputStateFlag getState()
const;
249 void setState(InputStateFlag state);
251 void setInputHUD(
bool value) { _inputHUD = value; }
252 bool getInputHUD()
const {
return _inputHUD; }
254 void setInputActive(
bool value) { _inputActive = value; }
255 bool getInputActive()
const {
return _inputActive; }
257 void setShowCursor(
bool value) { _showCursor = value; }
258 bool getShowCursor()
const {
return _showCursor; }
260 void setInputVerbsActive(
bool value) { _inputVerbsActive = value; }
261 bool getInputVerbsActive()
const {
return _inputVerbsActive; }
263 void setHotspot(
bool value) { _hotspot = value; }
264 bool getHotspot()
const {
return _hotspot; }
266 void setCursorShape(CursorShape shape);
269 virtual void drawCore(
const Math::Matrix4 &trsf)
override final;
273 bool _inputHUD =
false;
274 bool _inputActive =
false;
275 bool _showCursor =
false;
276 bool _inputVerbsActive =
false;
277 CursorShape _cursorShape = CursorShape::Normal;
278 bool _hotspot =
false;
285 void setOverlayColor(
const Color &color) { _ovlColor = color; }
286 Color getOverlayColor()
const {
return _ovlColor; }
289 virtual void drawCore(
const Math::Matrix4 &trsf)
override final;
300 bool isOver()
const {
return _over; }
303 Math::Vector2d getPos(
int index)
const;
304 int getOverIndex()
const;
306 void setVisible(
bool visible)
override;
309 virtual void drawCore(
const Math::Matrix4 &trsf)
override final;
310 void drawArrows(
const Math::Matrix4 &trsf);
311 void drawBack(
const Math::Matrix4 &trsf);
312 void drawItems(
const Math::Matrix4 &trsf);
316 bool _active =
false;
320 Color _backColor, _verbNormal;
325 bool _inventoryOver[NUMOBJECTS];
326 Math::Vector2d _shakeOffset[NUMOBJECTS];
327 float _shakeTime[NUMOBJECTS];
330 float _jiggleTime = 0.f;
331 float _fadeTime = 0.f;
332 bool _fadeIn =
false;
344 void drawCore(
const Math::Matrix4 &trsf)
override final;
358 void drawCore(
const Math::Matrix4 &trsf)
override final;
371 bool update(
float elapsed);
375 float _elapsed = 0.f;
385 void drawCore(
const Math::Matrix4 &trsf)
override final;
Definition: scenegraph.h:281
Definition: objectanimation.h:31
Definition: scenegraph.h:350
Definition: scenegraph.h:336
Definition: scenegraph.h:160
Definition: scenegraph.h:200
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: scenegraph.h:217
Definition: scenegraph.h:295
Definition: scenegraph.h:189
Definition: scenegraph.h:41
Definition: scenegraph.h:140
Definition: scenegraph.h:365
Definition: scenegraph.h:378
Definition: achievements_tables.h:27
Definition: spritesheet.h:37