Untitled Game engine no.5
1.0
|
5 #ifndef ENGINE_PROJ_UI_HPP
6 #define ENGINE_PROJ_UI_HPP
10 #include "MeshRenderer.hpp"
11 #include "Components.hpp"
62 map = tex->getDefaultMapping();
74 setSize(lookup->width, lookup->height);
86 this->height = height;
115 case Allignment::TOP_LEFT:
116 pos = {.5f, .5f, .0f};
118 case Allignment::TOP:
119 pos = {.0f, .5f, .0f};
121 case Allignment::TOP_RIGHT:
122 pos = {-.5f, .5f, .0f};
125 case Allignment::LEFT:
126 pos = {.5f, .0f, .0f};
128 case Allignment::CENTER:
129 pos = {.0f, .0f, .0f};
131 case Allignment::RIGHT:
132 pos = {-.5f, .0f, .0f};
135 case Allignment::BOTTOM_LEFT:
136 pos = {.5f, -.5f, .0f};
138 case Allignment::BOTTOM:
139 pos = {.0f, -.5f, .0f};
141 case Allignment::BOTTOM_RIGHT:
142 pos = {.5f, -.5f, .0f};
146 mat *= glm::translate(pos);
147 mat *= glm::scale(glm::vec3{width, height, 0.f});
148 if (
mesh ==
nullptr) {
149 mesh = CreateRef<Mesh>();
152 mesh->verts = Mesh::quad(mat);
154 if (collider !=
nullptr) {
155 collider->verts = Mesh::quadVerts(mat);
158 visualUpdate =
false;
161 static void Update(
const Scene& scene) {
167 Ref<VertexCollider2D> collider =
nullptr;
170 float width = 0, height = 0;
172 bool visualUpdate =
false;
179 DEFAULT, HOVER, PRESS
204 void setText(
const std::string& newString) {
205 if (text != newString) {
207 font->renderText(newString,
this,
origin, 0.5f);
216 std::unordered_map<ButtonState, Ref<TextureLookup>>
stateLookup
217 = std::unordered_map<ButtonState, Ref<TextureLookup>>();
220 collider = CreateRef<VertexCollider2D>();
221 collider->hook = CreateRef<ButtonHook>(
this);
241 clickFunc = std::move(f);
256 this->nextState = next;
257 if (this->state == next) {
280 #endif //ENGINE_PROJ_UI_HPP
Scene Component for passing drawing data to the renderer. Stores vertex data and references to the te...
Definition: MeshRenderer.hpp:15
A container for entities currently in the Scene.
Definition: Scene.hpp:9
std::shared_ptr< T > Ref
Has stuff for making references a lot more easily shared smart pointer.
Definition: Base.hpp:21
void setSize(float width, float height)
Definition: UI.hpp:84
Ref< TextureMap > map
Definition: MeshRenderer.hpp:24
Ref< Texture > texture
Definition: MeshRenderer.hpp:29
std::vector< EntityID > GetEntitiesWith()
Definition: ECS.hpp:188
Wrapper for processing collisions between physics entities.
Definition: Components.hpp:23
ButtonState
Definition: UI.hpp:178
virtual void updateVisual()
Definition: UI.hpp:107
Allignment
enumeration representing alignment of text in a string of text.
Definition: Components.hpp:358
void setImage(const Ref< Texture > &tex)
Definition: UI.hpp:60
Allignment origin
collider reference (generated when setting a picture)
Definition: UI.hpp:168
virtual void update()
Definition: UI.hpp:93
Ref< C > GetComponent(const EntityID &id)
Definition: ECS.hpp:80
Definition: Animation.hpp:14
void queueVisualUpdate()
Definition: UI.hpp:100
Ref< Mesh > mesh
Definition: MeshRenderer.hpp:40
std::function< void(void)> func
Alias for any kind of function pointer.
Definition: Jobs.hpp:16
UIElement(const Ref< Texture > &tex)
Definition: UI.hpp:52
void setImage(const Ref< TextureLookup > &lookup)
Definition: UI.hpp:71
UIText(const Ref< Engine::Font > &font, const std::string &text, Allignment origin=CENTER)
Definition: UI.hpp:199