aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-15 20:40:37 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-15 20:40:37 -0500
commitbe993f55f5d93150b8b418b031d2e9c8d88978b2 (patch)
treeadbd8cdc4b5b6c55679219fde46e2a1231253d10 /src/ui.cpp
parent38b18b8bdaf0cd4f4f7b72ade4b3f27f7363eab3 (diff)
allow lua to create dialog box
Diffstat (limited to 'src/ui.cpp')
-rw-r--r--src/ui.cpp82
1 files changed, 47 insertions, 35 deletions
diff --git a/src/ui.cpp b/src/ui.cpp
index 71cb875..5d8b0cc 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1,56 +1,68 @@
#include "ui.hpp"
-#include "events/render.hpp"
#include "text.hpp"
#include <SDL2/SDL_opengl.h>
#include <iostream>
#include <string>
-static NewRenderEvent NRE (0, 0, 0, 0);
static const unsigned int NRE_TEX_DATA = 0xBBBBBBBB;
-static std::basic_string<TextMeshData> buffer;
void UISystem::configure(entityx::EntityManager&, entityx::EventManager&)
{
}
+void UISystem::createDialogBox(float x, float y, float w, float h)
+{
+ // Queue for generation in the main thread.
+ m_boxes.emplace_back(0, x, y, w, h);
+}
+
void UISystem::update(entityx::EntityManager&,
entityx::EventManager& events,
entityx::TimeDelta)
{
- static bool t = false;
-
- if (!t) {
- t = true;
-
- glGenBuffers(1, &NRE.vbo);
- glGenTextures(1, &NRE.tex);
-
- glBindTexture(GL_TEXTURE_2D, NRE.tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &NRE_TEX_DATA);
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
- buffer += { 30, -50, -5, 0, 0, 1 };
- buffer += { 160, -50, -5, 0, 0, 1 };
- buffer += { 160, -10, -5, 0, 0, 1 };
- buffer += { 160, -10, -5, 0, 0, 1 };
- buffer += { 30, -10, -5, 0, 0, 1 };
- buffer += { 30, -50, -5, 0, 0, 1 };
-
- glBindBuffer(GL_ARRAY_BUFFER, NRE.vbo);
- glBufferData(GL_ARRAY_BUFFER,
- buffer.size() * sizeof(TextMeshData), buffer.data(),
- GL_DYNAMIC_DRAW);
-
- NRE.normal = 0;
- NRE.vertex = buffer.size();
- events.emit<NewRenderEvent>(NRE);
+ for (auto& b : m_boxes) {
+ if (b.vbo == 0) {
+ auto nre = generateDialogBox(b);
+ events.emit<NewRenderEvent>(nre);
+ }
}
}
+NewRenderEvent UISystem::generateDialogBox(Box& box)
+{
+ NewRenderEvent nre;
+ std::basic_string<TextMeshData> buffer;
+
+ glGenBuffers(1, &nre.vbo);
+ glGenTextures(1, &nre.tex);
+ box.vbo = nre.vbo;
+
+ glBindTexture(GL_TEXTURE_2D, nre.tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, &NRE_TEX_DATA);
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
+ buffer += { box.x, box.y, -5, 0, 0, 1 };
+ buffer += { box.x + box.w, box.y, -5, 0, 0, 1 };
+ buffer += { box.x + box.w, box.y + box.h, -5, 0, 0, 1 };
+ buffer += { box.x + box.w, box.y + box.h, -5, 0, 0, 1 };
+ buffer += { box.x, box.y + box.h, -5, 0, 0, 1 };
+ buffer += { box.x, box.y, -5, 0, 0, 1 };
+
+ glBindBuffer(GL_ARRAY_BUFFER, nre.vbo);
+ glBufferData(GL_ARRAY_BUFFER,
+ buffer.size() * sizeof(TextMeshData), buffer.data(),
+ GL_DYNAMIC_DRAW);
+
+ nre.normal = 0;
+ nre.vertex = buffer.size();
+ return nre;
+}
+