TazGraph Project v0.1.0
Loading...
Searching...
No Matches
UILabel.h
1#pragma once
2
3#include "../../../../PNG_Letters.h"
4#include "../../../Components.h"
5#include "../../../UtilComponents.h"
6
7class Manager;
8
9class UILabel : public Component
10{
11private:
12 Manager* _manager;
13 std::vector<Entity*> letters;
14 std::string label;
15 std::string fontFamily;
16public:
17 TransformComponent* transform = nullptr;
18
19 UILabel() = default;
20 UILabel(Manager* manager, std::string lab, std::string fontFam)
21 {
22 _manager = manager;
23 fontFamily = fontFam;
24 label = lab;
25 }
26
27 ~UILabel() {
28
29 }
30
31 void init() override {
32 //create entities for each letter
33 if (!entity->hasComponent<TransformComponent>())
34 {
36 }
37 transform = &entity->GetComponent<TransformComponent>();
38 setLetters(label);
39 }
40
41 void update(float deltaTime) override {
42 //if string changes then for all the labels that have been created,
43 //find the ones that are for that string and delete them?
44
45 float previousCharX = 0;
46
47 for (auto& l : letters) {
48 l->GetComponent<TransformComponent>().setPosition_X(transform->getPosition().x + previousCharX) ;
49 l->GetComponent<TransformComponent>().setPosition_Y(transform->getPosition().y);
50 previousCharX += l->GetComponent<TransformComponent>().size.x;
51 }
52
53 if (previousCharX > transform->size.x) {
54 transform->size.x = previousCharX;
55 }
56 }
57
58 void draw(size_t e_index, PlaneModelRenderer& batch, TazGraphEngine::Window& window) override {
59 //draw each letter
60 for (auto& l : letters) {
61 l->draw(e_index, batch, window);
62 }
63 }
64
65 void setLetters(std::string lab) {
66 letters.clear();
67 label = lab;
68 for (char c : label) {
69 // todo make this as an entity
70 //auto& label(_manager->addEntity());
71 //SDL_Rect charRect = getLetterRect(c);
72 //label.addComponent<TransformComponent>(transform->getPosition(), Manager::actionLayer,
73 // glm::ivec2(charRect.w, charRect.h),//!set the dest.w/h from the table and then also set src.x/y/w/h. dest.x/y is based on previous letter and original label position
74 // 1);
75 //label.addComponent<SpriteComponent>(fontFamily);
76 //label.GetComponent<SpriteComponent>().srcRect.x = charRect.x;
77 //label.GetComponent<SpriteComponent>().srcRect.y = charRect.y;
78
79 //letters.push_back(&label);
80
81 }
82 }
83
84 std::string GetComponentName() override {
85 return "UILabel";
86 }
87};
88
Definition GECS.h:123
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition GECS.h:239
Definition GECSManager.h:14
Definition PlaneModelRenderer.h:21
Definition Window.h:18
Definition TransformComponent.h:6
Definition UILabel.h:10