summaryrefslogtreecommitdiff
path: root/ui.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui.hpp')
-rw-r--r--ui.hpp89
1 files changed, 66 insertions, 23 deletions
diff --git a/ui.hpp b/ui.hpp
index c002fc9..4dc0dd9 100644
--- a/ui.hpp
+++ b/ui.hpp
@@ -6,36 +6,79 @@
struct Arena;
struct UI {
- struct Rect {
- int x, y, w, h;
+ struct Vertex {
+ float x, y, u, v, r, g, b, a;
};
- struct Element : Rect {
- enum class Type {
- label
- } type;
- Element* next;
- static int size(Type t);
+ struct Colour {
+ uint8_t r, g, b, a;
+ Colour(unsigned rgb, uint8_t a = 0xff);
+ float r_f() { return (float)r / 255.0f; };
+ float g_f() { return (float)g / 255.0f; };
+ float b_f() { return (float)b / 255.0f; };
+ float a_f() { return (float)a / 255.0f; };
};
- struct Label : Element {
- char* text;
- int len;
- int x, y;
+ struct Vertex_Buffer {
+ Staged_Buffer buf;
+ Buffer_Id indices;
+ int usage;
+
+ void init(Device* dev);
+ void init_indices(Device* dev);
+ void destroy(UI* ui);
+ void update_buffer(Context& ctx);
+
+ void add_quad(
+ UI* ui,
+ int x,
+ int y,
+ int w,
+ int h,
+ float u0,
+ float v0,
+ float u1,
+ float v1,
+ Colour col
+ );
+ void add_rect(
+ UI* ui,
+ int x,
+ int y,
+ int w,
+ int h,
+ Colour col
+ );
+ void add_char(UI* ui, int x, int y, char ch, Colour col);
+ void add_text(
+ UI* ui,
+ int x,
+ int y,
+ const char* txt,
+ Colour col
+ );
+ void draw(
+ UI* ui,
+ Context& ctx,
+ Pipeline& pip,
+ Render_Pass& rp
+ );
+ Vertex_Buffer* next;
};
- struct Vertex {
- float x, y, u, v, r, g, b, a;
+ struct Rect {
+ int x, y, w, h;
};
- Arena* arena;
+ Heap* heap;
Device* device;
- Element* tree;
Texture_Id atlas;
Shader_Id shader;
Vertex_Format_Id vertex_format;
- Buffer_Id mesh, config_buf;
Sampler_Id sampler;
+ Staged_Buffer cbuffer;
+ Vertex_Buffer mesh;
+
struct UI_CBuffer {
m4f projection;
};
@@ -50,15 +93,15 @@ struct UI {
static UI* create(Device* dev, Arena* a, Shader_Id sh);
- Element* create_element(Element::Type t);
- Label* create_label(const char* t, int x, int y);
-
- void init(Device* dev, Arena* a, Texture_Id atlas, Shader_Id sh);
+ void init(
+ Device* dev,
+ Heap* h,
+ Texture_Id atlas,
+ Shader_Id sh
+ );
void destroy();
void update(Arena* s);
void render(Arena* s, Texture_Id target);
-
- int render_label(const Label* l, int off);
};
#endif