Loading...
Searching...
No Matches
Positionable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4//
5// Created by Dave Smith on 11/13/22.
6//
7
8#ifndef MALENA_PORTFOLIO_POSITIONABLE_H
9#define MALENA_PORTFOLIO_POSITIONABLE_H
10
11#pragma once
12
14#include <SFML/Graphics.hpp>
15#include <float.h>
16#include <queue>
19
20namespace ml
21{
68 {
69 private:
70 float velocityX{}, velocityY{}, framerate = 60.f;
71 sf::Vector2f initialPosition = {FLT_MIN, FLT_MAX};
72 sf::Clock clock;
73 std::queue<sf::Vector2f> points;
74 bool scrolling = false;
75
76 bool error(sf::Vector2f a, sf::Vector2f b, float err = 0.1f);
77 void generatePoints(sf::Vector2f position, float duration, Tween tween);
78 void generateExponential(sf::Vector2f position, float duration);
79 void calcVelocity(sf::Vector2f velocity, float seconds);
80
81 public:
91 void setFramerate(float framerate);
92
103 void moveTo(sf::Vector2f position, float seconds = 1.f);
104
114 void moveTo(sf::FloatRect position, float seconds = 1.f);
115
124 void moveDistance(sf::Vector2f distance, float seconds = 1.f);
125
133
141 virtual void setPosition(const sf::Vector2f& position) = 0;
142
150 virtual sf::Vector2f getPosition() const = 0;
151
161 virtual sf::FloatRect getGlobalBounds() const = 0;
162
163 // ── Relative layout helpers ──────────────────────────────────────────
164
171 template<class T>
172 void setRightOf(T& obj, float spacing = 0);
173
180 template<class T>
181 void setLeftOf(T& obj, float spacing = 0);
182
189 template<class T>
190 void setBelow(T& obj, float spacing = 0);
191
198 template<class T>
199 void setAbove(T& obj, float spacing = 0);
200
206 template<class T>
207 void center(T& obj);
208
214 template<class T>
215 void centerHorizonally(T& obj);
216
222 template<class T>
223 void centerVertically(T& obj);
224
234 };
235
236} // namespace ml
237
238#include "../../../../src/Traits/Spatial/Positionable.tpp"
239#endif // MALENA_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:35
Tween
Easing curve selection for animated movement.
Definition Tween.h:45
#define MALENA_API
Definition Component.h:22
Rect< float > FloatRect
Vector2< float > Vector2f