summaryrefslogtreecommitdiff
path: root/ui.hpp
blob: a181afe3b0631f1c23937623b6f719360b1d2b98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef ui_hpp
#define ui_hpp

#include "video.hpp"

struct Arena;
struct UI {
	struct Rect {
		int x, y, w, h;
	};

	struct Element : Rect {
		enum class Type {
			label
		} type;
		Element* next;
		static int size(Type t);
	};

	struct Label : Element {
		char* text;
		int len;
		int x, y;
	};

	struct Vertex {
		float x, y, u, v, r, g, b, a;
	};

	Arena* arena;
	Device* device;
	Element* tree;
	Texture_Id atlas;
	Shader_Id shader;
	Vertex_Format_Id vertex_format;
	Buffer_Id mesh;
	Sampler_Id sampler;
	struct {
		int vert_binding;
		int atlas_binding;
	} shader_info;
	float ndc[2];

	static int text_width(const char* t);
	static int text_height(const char* t);

	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 destroy();
	void update(Arena* s);
	void render(Arena* s, Texture_Id target);

	int render_label(const Label* l, int off);
};

#endif