TazGraph Project v0.1.0
Loading...
Searching...
No Matches
Rectangle_w_Color.h
1#pragma once
2
3#include "../../../Components.h"
4
6{
7public:
8 Color default_color = { 255, 255, 255, 255 };
9
10 Color color = { 255, 255, 255, 255 };
11
12 TransformComponent* transform = nullptr;
13
14 FlashAnimation flash_animation;
15
17 {
18
19 }
20
21
23
24 }
25
26 void init() override {
27 transform = &entity->GetComponent<TransformComponent>();
28 }
29
30 void update(float deltaTime) override {
31 }
32
33 //void draw(size_t v_index, PlaneModelRenderer& batch, TazGraphEngine::Window& window) {
34 // glm::vec3 pos((float)destRect.x, (float)destRect.y, transform->getPosition().z);
35 // glm::vec2 size = glm::vec2((float)destRect.w, (float)destRect.h);
36 // batch.draw(v_index, pos, size, transform->rotation, glm::vec4(-1.0f, -1.0f, 2.0f, 2.0f), 0, transform->bodyCenter, color); // 0 is for texture
37 //}
38
39 void draw(size_t v_index, PlaneColorRenderer& batch, TazGraphEngine::Window& window) {
40 glm::vec2 size((float)transform->size.x, (float)transform->size.y);
41 batch.draw(v_index, size, transform->bodyCenter, transform->rotation, color);
42 }
43
44 void setColor(Color clr) {
45 default_color = clr;
46 color = clr;
47 }
48
49 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)
50 {
51 flash_animation = FlashAnimation(idX, idY, fr, sp, type, flashTimes, flashC, reps);
52 }
53
54 void setFlashFrame() {
55 float t = this->flash_animation.interpolation_a;
56 this->color = Color::fromVec4(glm::mix(default_color.toVec4(), this->flash_animation.flashColor.toVec4(), t));
57
58
59 }
60
61
62 std::string GetComponentName() override {
63 return "Rectangle_w_Color";
64 }
65
66 void showGUI() override {
67 ImGui::Separator();
68
69 ImVec4 a_color = ImVec4(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
70 if(ImGui::ColorPicker4("Color", (float*)&a_color)) {
71 Color newColor = {
72 (GLubyte)(a_color.x * 255),
73 (GLubyte)(a_color.y * 255),
74 (GLubyte)(a_color.z * 255),
75 (GLubyte)(a_color.w * 255)
76 };
77
78 color = newColor;
79 }
80
81 }
82};
Definition GECS.h:123
Definition PlaneColorRenderer.h:19
void draw(size_t v_index, const glm::vec2 &rectSize, const glm::vec3 &bodyCenter, const glm::vec3 &mRotation, const Color &color)
draws are needed to convert the pos and size to vertices
Definition PlaneColorRenderer.cpp:72
Definition Rectangle_w_Color.h:6
Definition Window.h:18
Definition TransformComponent.h:6
Definition Vertex.h:47
Definition FlashAnimation.h:10