R-Type
R-Type project
UiImage.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** gameEngine2
4 ** File description:
5 ** UiImage
6 */
7 
8 #ifndef UIIMAGE_HPP_
9 #define UIIMAGE_HPP_
10 
11 #include "Vectors.hpp"
12 #include "Colors.hpp"
13 #include "Rectangle.hpp"
14 
15 #include "Component.hpp"
16 #include <filesystem>
17 
18 #include "KapEngineSettings.hpp"
19 
20 
21 namespace KapEngine {
22 
23  class Component;
24 
25  namespace Tools {
26  class Color;
27  class Vector2;
28  }
29 }
30 
31 namespace KapEngine {
32 
33  namespace UI {
34 
35  class Image : public Component {
36  public:
37  Image(std::shared_ptr<GameObject> &go);
38  ~Image();
39 
40  void onAwake() override;
41  void onDisplay() override;
42  bool checkComponentValidity() override;
43 
44  bool isUsingSprite() const {
45  PROFILER_FUNC_START();
46  if (_pathSprite == "") {
47  PROFILER_FUNC_END();
48  return false;
49  }
50  return true;
51  }
52 
53  std::string getPathSprite() const {
54  PROFILER_FUNC_START();
55  PROFILER_FUNC_END();
56  return _pathSprite;
57  }
58 
59  Tools::Color getColorSprite() const {
60  PROFILER_FUNC_START();
61  PROFILER_FUNC_END();
62  return _color;
63  }
64 
65  void setPathSprite(std::string const& pathSprite) {
66  PROFILER_FUNC_START();
67  _pathSprite = pathSprite;
68  PROFILER_FUNC_END();
69  }
70 
71  void setPathSpriteRoot(std::string const& pathSprite) {
72  PROFILER_FUNC_START();
73  _pathSprite = std::filesystem::current_path().generic_string() + "/" + pathSprite;
74  PROFILER_FUNC_END();
75  }
76 
77  void setColor(Tools::Color const& color) {
78  PROFILER_FUNC_START();
79  _color = color;
80  PROFILER_FUNC_END();
81  }
82 
83  void setRectangle(Tools::Rectangle rect) {
84  PROFILER_FUNC_START();
85  _rect = rect;
86  PROFILER_FUNC_END();
87  }
88 
89  Tools::Vector2 getCalculatedPosition();
90 
91  Tools::Vector2 getCalculatedScale();
92 
93  Tools::Rectangle getRectangle() const {
94  PROFILER_FUNC_START();
95  PROFILER_FUNC_END();
96  return _rect;
97  }
98 
99  protected:
100  private:
101  std::string _pathSprite = "";
102  Tools::Color _color;
103  Tools::Rectangle _rect;
104  Tools::Vector2 _lastScale;
105  Tools::Vector2 _lastCompare;
106  Tools::Vector2 _lastPos;
107  Tools::Vector2 _lastScaleWant;
108  Tools::Vector2 _lastPosWant;
109  };
110 
111  }
112 
113 }
114 
115 #endif /* !UIIMAGE_HPP_ */
KapEngine::UI::Image::onAwake
void onAwake() override
call component awake
Definition: UiImage.cpp:22
KapEngine::UI::Image::checkComponentValidity
bool checkComponentValidity() override
Check you component is runnable With this function you can add some conditions to make your component...
Definition: UiImage.cpp:134
KapEngine::UI::Image
Definition: UiImage.hpp:35
KapEngine::Component
Definition: Component.hpp:38
KapEngine::Tools::Vector2
Definition: Vectors.hpp:25
KapEngine::UI::Image::onDisplay
void onDisplay() override
use to display some things this function is call after all updates fucntion
Definition: UiImage.cpp:35
KapEngine::Tools::Color
Definition: Colors.hpp:22
KapEngine
main namespace
Definition: Component.hpp:17
KapEngine::Tools::Rectangle
Definition: Rectangle.hpp:23