TazGraph Project v0.1.0
Loading...
Searching...
No Matches
PortComponent.h
1#pragma once
2
3#include "../../../Components.h"
4
6// todo this can be generally a flexbox
7class PortComponent : public Component
8{
9private:
10 bool tempIsVertical = false;
11public:
12 TazColor color = { 255, 255, 255, 255 };
13
14
15 TransformComponent* transform = nullptr;
16
18 {
19
20 }
21
22 PortComponent(bool m_isVertical)
23 {
24 tempIsVertical = m_isVertical;
25 }
26
28
29 }
30
31 void init() override {
32 transform = &entity->GetComponent<TransformComponent>();
33 entity->isVertical = tempIsVertical;
34 }
35
36 void update(float deltaTime) override {
37 transform->size.x = entity->getParentEntity()->GetComponent<TransformComponent>().size.x;
38 transform->size.y = entity->getParentEntity()->GetComponent<TransformComponent>().size.y;
39 size_t childrenSize = entity->children.size();
40 if (!entity->isVertical) {
41 if (childrenSize > 1)
42 entity->slotSpacing = transform->size.x / childrenSize;
43 else
44 entity->slotSpacing = transform->size.x;
45 }
46 else { // Vertical
47 if (childrenSize > 1)
48 entity->slotSpacing = transform->size.y / childrenSize;
49 else
50 entity->slotSpacing = transform->size.y;
51 }
52
53 }
54
55 void draw(size_t v_index, PlaneColorRenderer& batch, TazGraphEngine::Window& window) {
56 glm::vec2 size(1, 1);
57 batch.draw(v_index, size, transform->getPosition(), transform->rotation, color);
58 }
59
60 std::string GetComponentName() override {
61 return "PortComponent";
62 }
63
64 void showGUI(std::vector<BaseComponent*> otherComponents = {}) override {
65 showGUI(otherComponents, { entity });
66 }
67
68 void showGUI(std::vector<BaseComponent*> otherComponents, std::vector<Entity*> otherEntities) override {
69 ImGui::Separator();
70
71 ImVec4 a_color = ImVec4(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
72 if (ImGui::ColorPicker4("TazColor", (float*)&a_color)) {
73 TazColor newColor = {
74 (GLubyte)(a_color.x * 255),
75 (GLubyte)(a_color.y * 255),
76 (GLubyte)(a_color.z * 255),
77 (GLubyte)(a_color.w * 255)
78 };
79 for (auto& ent : otherEntities) {
80 ent->GetComponent<PortComponent>().color = newColor;
81 }
82 }
83
84 }
85
86
87
88};
Definition GECS.h:131
std::map< EntityID, EntityID > children
child_index(id) -> real_entity_id
Definition GECS.h:248
Definition PlaneColorRenderer.h:14
void draw(size_t v_index, const glm::vec2 &rectSize, const glm::vec3 &position, const glm::vec3 &mRotation, const TazColor &color)
draws are needed to convert the pos and size to vertices
Definition PlaneColorRenderer.cpp:87
Definition PortComponent.h:8
Definition PortSlotComponent.h:7
Definition Window.h:12
Definition TransformComponent.h:7
Definition Vertex.h:44