Loading...
Searching...
No Matches
Positionable.h
Go to the documentation of this file.
1//
2// Created by Dave Smith on 11/13/22.
3//
4
5#ifndef PORTFOLIO_POSITIONABLE_H
6#define PORTFOLIO_POSITIONABLE_H
7
8#pragma once
9
10#include <SFML/Graphics.hpp>
11#include <cmath>
12#include <float.h>
13#include <queue>
18
19namespace ml
20{
66 class Positionable : public Trait
67 {
68 private:
69 float velocityX{}, velocityY{}, framerate = 60.f;
70 sf::Vector2f initialPosition = {FLT_MIN, FLT_MAX};
71 sf::Clock clock;
72 std::queue<sf::Vector2f> points;
73 bool scrolling = false;
74
75 bool error(sf::Vector2f a, sf::Vector2f b, float err = 0.1f);
76 void generatePoints(sf::Vector2f position, float duration, Tween tween);
77 void generateExponential(sf::Vector2f position, float duration);
78 void calcVelocity(sf::Vector2f velocity, float seconds);
79
80 public:
90 void setFramerate(float framerate);
91
102 void moveTo(sf::Vector2f position, float seconds = 1.f);
103
113 void moveTo(sf::FloatRect position, float seconds = 1.f);
114
123 void moveDistance(sf::Vector2f distance, float seconds = 1.f);
124
132
140 virtual void setPosition(const sf::Vector2f& position) = 0;
141
149 virtual sf::Vector2f getPosition() const = 0;
150
160 virtual sf::FloatRect getGlobalBounds() const = 0;
161
162 // ── Relative layout helpers ──────────────────────────────────────────
163
170 template<class T>
171 void setRightOf(T& obj, float spacing = 0);
172
179 template<class T>
180 void setLeftOf(T& obj, float spacing = 0);
181
188 template<class T>
189 void setBelow(T& obj, float spacing = 0);
190
197 template<class T>
198 void setAbove(T& obj, float spacing = 0);
199
205 template<class T>
206 void center(T& obj);
207
213 template<class T>
214 void centerHorizonally(T& obj);
215
221 template<class T>
222 void centerVertically(T& obj);
223
233 };
234
235} // namespace ml
236
237#include "../../../src/Traits/Positionable.tpp"
238#endif // PORTFOLIO_POSITIONABLE_H
Trait that provides position, bounds, and animated movement.
bool isScrolling()
Return true while a moveTo or moveDistance animation is in progress.
void setBelow(T &obj, float spacing=0)
Position this object immediately below obj.
void center(T &obj)
Center this object within obj (both axes).
void setAbove(T &obj, float spacing=0)
Position this object immediately above obj.
void centerVertically(T &obj)
Center this object vertically within obj.
void moveDistance(sf::Vector2f distance, float seconds=1.f)
Animate by a relative offset from the current position.
virtual sf::FloatRect getGlobalBounds() const =0
Return the axis-aligned bounding box in world space.
void centerHorizonally(T &obj)
Center this object horizontally within obj.
void setRightOf(T &obj, float spacing=0)
Position this object immediately to the right of obj.
void moveTo(sf::Vector2f position, float seconds=1.f)
Animate to an absolute world-space position.
virtual void setPosition(const sf::Vector2f &position)=0
Set the world-space position immediately (no animation).
void setFramerate(float framerate)
Set the assumed framerate for movement interpolation.
void setLeftOf(T &obj, float spacing=0)
Position this object immediately to the left of obj.
void moveTo(sf::FloatRect position, float seconds=1.f)
Animate to a position defined by a FloatRect origin.
void centerText(sf::Text &obj)
Center an sf::Text object within this object's bounds.
virtual sf::Vector2f getPosition() const =0
Return the current world-space position.
Empty marker base class for all Malena traits.
Definition Trait.h:31
Tween
Easing curve selection for animated movement.
Definition Tween.h:40
Definition Component.h:18
Rect< float > FloatRect
Vector2< float > Vector2f