TazGraph Project v0.1.0
Loading...
Searching...
No Matches
Line_w_Color.h
1#pragma once
2
3#include "../../../Components.h"
4
6{
7public:
8 Color default_src_color = { 255, 255, 255, 255 };
9 Color src_color = { 255, 255, 255, 255 };
10
11 Color default_dest_color = { 255, 255, 255, 255 };
12 Color dest_color = { 255, 255, 255, 255 };
13
14 FlashAnimation flash_animation;
15
17 {
18
19 }
20
22
23 }
24
25 void init() override {
26 }
27
28 void update(float deltaTime) override {
29 }
30
31 void draw(size_t v_index, LineRenderer& batch, TazGraphEngine::Window& window) {
32 //float tempScreenScale = window.getScale();
33
34 glm::vec3 fromNodeCenter = entity->getFromNode()->GetComponent<TransformComponent>().getCenterTransform();
35 glm::vec3 toNodeCenter = entity->getToNode()->GetComponent<TransformComponent>().getCenterTransform();
36
37 batch.drawLine(v_index, fromNodeCenter, toNodeCenter, src_color, dest_color);
38 }
39
40 void drawWithPorts(size_t v_index, LineRenderer& batch, TazGraphEngine::Window& window) {
41 //float tempScreenScale = window.getScale();
42
43 if (entity->fromPort < 0 || entity->toPort < 0) {
44 TazGraphEngine::ConsoleLogger::error("Ports are not assigned!");
45 return;
46 }
47
48 NodeEntity* fromNode = entity->getFromNode();
49 NodeEntity* toNode = entity->getToNode();
50
51 Entity* fromPortEntity = fromNode->children[entity->fromPort];
52 Entity* toPortEntity = toNode->children[entity->toPort];
53 PortComponent& fromPortComp = fromPortEntity->GetComponent<PortComponent>();
54 PortComponent& toPortComp = toPortEntity->GetComponent<PortComponent>();
55
56 if ((entity->fromSlotIndex >= fromPortComp.portSlots.size())
57 || (entity->toSlotIndex >= toPortComp.portSlots.size())) {
58 return;
59 }
60 glm::vec3 fromConnectionPoint = fromPortComp.portSlots[entity->fromSlotIndex]->GetComponent<TransformComponent>().getCenterTransform();
61 glm::vec3 toConnectionPoint = toPortComp.portSlots[entity->toSlotIndex]->GetComponent<TransformComponent>().getCenterTransform();
62
63 batch.drawLine(v_index, fromConnectionPoint, toConnectionPoint, src_color, dest_color);
64 }
65
66 void setSrcColor(Color clr) {
67 default_src_color = clr;
68 src_color = clr;
69 }
70
71 void setDestColor(Color clr) {
72 default_dest_color = clr;
73 dest_color = clr;
74 }
75
76 void SetFlashAnimation(int idX, int idY, size_t fr, float sp, const Animation::animType type, const std::vector<float>& flashTimes, Color flashC, int reps = 0)
77 {
78 flash_animation = FlashAnimation(idX, idY, fr, sp, type, flashTimes, flashC, reps);
79 }
80
81 void setFlashFrame() {
82 float t = this->flash_animation.interpolation_a;
83
84 if (t < 0.33f) {
85 this->src_color = Color::fromVec4(glm::mix(default_src_color.toVec4(), this->flash_animation.flashColor.toVec4(), 3 * t));
86 }
87 else if (t < 0.66f) {
88 this->src_color = Color::fromVec4(glm::mix(this->flash_animation.flashColor.toVec4(), default_src_color.toVec4(), std::min((3 * (t - 0.33f)), 1.0f)));
89 this->dest_color = Color::fromVec4(glm::mix(default_dest_color.toVec4(), this->flash_animation.flashColor.toVec4(), 3 * (t - 0.33f)));
90 }
91 else {
92 this->dest_color = Color::fromVec4(glm::mix(this->flash_animation.flashColor.toVec4(), default_dest_color.toVec4(), std::min((3 * (t - 0.66f)), 1.0f)));
93 }
94 // Smooth transition using lerp (linear interpolation)
95
96 }
97
98 std::string GetComponentName() override {
99 return "Line_w_Color";
100 }
101
102 void showGUI() override {
103 ImGui::Separator();
104
105 ImVec4 a_color = ImVec4(src_color.r / 255.0f, src_color.g / 255.0f, src_color.b / 255.0f, src_color.a / 255.0f);
106 if (ImGui::ColorPicker4("Color Line Src", (float*)&a_color)) {
107 Color newColor = {
108 (GLubyte)(a_color.x * 255),
109 (GLubyte)(a_color.y * 255),
110 (GLubyte)(a_color.z * 255),
111 (GLubyte)(a_color.w * 255)
112 };
113
114 setSrcColor(newColor);
115 }
116
117
118 ImVec4 b_color = ImVec4(dest_color.r / 255.0f, dest_color.g / 255.0f, dest_color.b / 255.0f, dest_color.a / 255.0f);
119 if (ImGui::ColorPicker4("Color Line Dest", (float*)&b_color)) {
120 Color newColor = {
121 (GLubyte)(b_color.x * 255),
122 (GLubyte)(b_color.y * 255),
123 (GLubyte)(b_color.z * 255),
124 (GLubyte)(b_color.w * 255)
125 };
126
127 setDestColor(newColor);
128 }
129 }
130};
Definition GECS.h:152
Definition LineRenderer.h:131
Definition Line_w_Color.h:6
Definition GECS.h:135
Definition GECSEntity.h:43
Definition PortComponent.h:7
Definition Window.h:18
Definition TransformComponent.h:6
Definition Vertex.h:47
Definition FlashAnimation.h:10