raylib_impl 0.1.0
Vendor raylib 5.5 : IGraphic2Module / IGraphic3Module / IAudioModule
Loading...
Searching...
No Matches
RaySprite.hpp
Go to the documentation of this file.
1
11#ifndef RAYSPRITE_HPP_
12#define RAYSPRITE_HPP_
13
14//Raylib (without conflict)
15#include "RaylibAliases.hpp"
16
17//Interface
18#include "ISprite.hpp"
19
20//encapsulation
21#include "RayTexture.hpp"
22
27class RaySprite : public graphic::ISprite {
28
29 public:
30 RaySprite(RayTexture &texture) : _texture(texture) {
31 _position = {0, 0};
32 _scale = {1, 1};
33 raylib::Texture2D t = _texture.handle();
34 _crop = {0, 0, float(t.width), float(t.height)};
35 _rotation = 0;
36 }
37
38 ~RaySprite() = default;
39
40 bool isReady() const override {
41 return _texture.isReady();
42 }
43
44 Rect<float> getBounds() const override {
45 return {_position.x, _position.y, _crop.width, _crop.height};
46 }
47
48 void setCrop(Rect<float> rect) override {
49 _crop = {float(rect.x), float(rect.y), float(rect.w), float(rect.h)};
50 }
51
52 Vector2f getPosition() const override {
53 return {_position.x, _position.y};
54 }
55 void setPosition(Vector2f position) override {
56 _position = {float(position.x), float(position.y)};
57 }
58
59 float getRotation() const override {
60 return _rotation;
61 }
62
63 void setRotation(float angle, bool isRad = false) override {
64 _rotation = isRad ? angle * RAD2DEG : angle;
65 }
66
67 Vector2f getSize() const override {
68 raylib::Texture2D t = _texture.handle();
69 return {
70 static_cast<float>(t.width) * _scale.x,
71 static_cast<float>(t.height) * _scale.y
72 };
73 }
74
75 void setSize(Vector2f size) override {
76 raylib::Texture2D t = _texture.handle();
77 if (t.width == 0 || t.height == 0) return;
78
79 _scale.x = size.x / static_cast<float>(t.width);
80 _scale.y = size.y / static_cast<float>(t.height);
81 }
82
83 friend class RayWindow;
84
85 private:
86 RayTexture &_texture;
87 raylib::Vector2 _position;
88 raylib::Vector2 _scale;
89 raylib::Rectangle _crop;
90 float _rotation;
91};
92
95#endif /* !RAYSPRITE_HPP_ */
Raylib Sprite class - references a RayTexture, does not own it. Deleting the sprite never touches the...
Definition RaySprite.hpp:27
void setRotation(float angle, bool isRad=false) override
Definition RaySprite.hpp:63
RaySprite(RayTexture &texture)
Definition RaySprite.hpp:30
float getRotation() const override
Definition RaySprite.hpp:59
void setPosition(Vector2f position) override
Definition RaySprite.hpp:55
Vector2f getSize() const override
Definition RaySprite.hpp:67
void setCrop(Rect< float > rect) override
Definition RaySprite.hpp:48
void setSize(Vector2f size) override
Definition RaySprite.hpp:75
Vector2f getPosition() const override
Definition RaySprite.hpp:52
~RaySprite()=default
Rect< float > getBounds() const override
Definition RaySprite.hpp:44
bool isReady() const override
Definition RaySprite.hpp:40
Raylib Texture class - owns the GPU texture. RaySprite/RayModel only reference it,...
Definition RayTexture.hpp:26
raylib::Texture2D handle() const
Definition RayTexture.hpp:45
bool isReady() const override
Definition RayTexture.hpp:37
Raylib Window class - a single concrete class implementing IWindow3 fully (which already IS-A IWindow...
Definition RayWindow.hpp:37