Project Alice
Loading...
Searching...
No Matches
gui_deserialize.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include <string>
4#include <string_view>
5#include "stools.hpp"
7#include "text/text.hpp"
8#include "unordered_dense.h"
9#include "simple_fs.hpp"
10
13};
14enum class aui_text_type : uint8_t {
15 body,
16 header
17};
19 none,
20 list,
21 grid
22};
23
24enum class aui_property : uint8_t {
25 texture = 1,
27 text_key = 3,
29 text_color = 5,
30 background = 6,
31 no_grid = 7,
32 text_align = 8,
34 dynamic_tooltip = 10,
35 can_disable = 11,
36 can_hide = 12,
40 dynamic_text = 16,
41 border_size = 17,
42 text_scale = 18,
43 text_type = 19,
44 container_type = 20,
45 child_window = 21,
46 list_content = 22,
47 data_member = 23,
49 alternate_bg = 25,
50 ignore_rtl = 25,
51 draggable = 26,
57 row_height = 32,
58 table_insert = 33,
63 animation_type = 38,
64 datapoints = 39,
65 other_color = 40,
66};
67
68inline void bytes_to_windows(char const* bytes, size_t size, std::string const& project_name, ankerl::unordered_dense::map<std::string, sys::aui_pending_bytes>& map) {
69 serialization::in_buffer buffer(bytes, size);
70 auto header_section = buffer.read_section();
71
72 while(buffer) {
73 auto window_section = buffer.read_section(); // essential section
74 auto window_offset = window_section.view_read_position();
75 auto window_size = window_section.view_size() - window_offset;
76
77 auto essential_window_section = window_section.read_section(); // essential section
78
79 std::string name;
80 essential_window_section.read(name);
81
82 map.insert_or_assign(project_name + "::" + name, sys::aui_pending_bytes{ bytes + window_offset, window_size });
83 }
84}
85
87 std::string_view texture;
88 std::string_view alt_texture;
89 int16_t x_pos;
90 int16_t y_pos;
91 int16_t x_size;
92 int16_t y_size;
93 int16_t border_size;
95};
96
97namespace ogl {
98struct color4f {
99 float r = 0.0f;
100 float g = 0.0f;
101 float b = 0.0f;
102 float a = 1.0f;
103
104 bool operator==(color4f const& o) const noexcept {
105 return r == o.r && g == o.g && b == o.b && a == o.a;
106 }
107 bool operator!=(color4f const& o) const noexcept {
108 return !(*this == o);
109 }
110 color4f operator*(float v) const noexcept {
111 return color4f{ r * v, b * v, g * v, a };
112 }
113};
114}
115
117 std::string_view header_key;
118 std::string_view header_tooltip_key;
119 std::string_view header_texture;
120 std::string_view cell_tooltip_key;
121 int16_t width = 0;
125};
126
128 std::vector<table_display_column> table_columns;
129 std::string_view name;
130 std::string_view texture;
131 std::string_view alt_texture;
132 std::string_view tooltip_text_key;
133 std::string_view text_key;
134 std::string_view ascending_sort_icon;
135 std::string_view descending_sort_icon;
136 std::string_view row_background_a;
137 std::string_view row_background_b;
138 ogl::color4f table_highlight_color{ 0.0f, 0.0f, 0.0f, 0.0f };
140 float text_scale = 1.0f;
141 float row_height = 2.0f;
142 int16_t x_pos = 0;
143 int16_t y_pos = 0;
144 int16_t x_size = 0;
145 int16_t y_size = 0;
146 int16_t border_size = 0;
148 aui_text_type text_type = aui_text_type::body;
150};
151
152inline aui_window_data read_window_bytes(char const* bytes, size_t size, std::vector<sys::aui_pending_bytes>& children_out) {
153 aui_window_data result;
154
155 serialization::in_buffer window_section(bytes, size);
156
157 auto essential_window_section = window_section.read_section(); // essential section
158
159 essential_window_section.read<std::string_view>(); // toss name
160 essential_window_section.read(result.x_pos);
161 essential_window_section.read(result.y_pos);
162 essential_window_section.read(result.x_size);
163 essential_window_section.read(result.y_size);
164 essential_window_section.read(result.orientation);
165 while(essential_window_section) {
166 auto ptype = essential_window_section.read<aui_property>();
167 if(ptype == aui_property::border_size) {
168 essential_window_section.read(result.border_size);
169 } else if(ptype == aui_property::texture) {
170 result.texture = essential_window_section.read<std::string_view>();
171 } else if(ptype == aui_property::alternate_bg) {
172 result.alt_texture = essential_window_section.read<std::string_view>();
173 } else {
174 abort();
175 }
176 }
177
178 auto optional_section = window_section.read_section(); // toss section
179
180 while(window_section) {
181 auto child_start = window_section.view_read_position();
182
183 auto essential_child_section = window_section.read_section(); // toss
184 auto optional_child_section = window_section.read_section(); // toss
185
186 auto child_size = window_section.view_read_position() - child_start;
187 children_out.push_back(sys::aui_pending_bytes{ bytes + child_start, child_size});
188 }
189 return result;
190}
191
192inline aui_element_data read_child_bytes(char const* bytes, size_t size) {
193 aui_element_data result;
194 serialization::in_buffer window_section(bytes, size);
195 auto essential_child_section = window_section.read_section();
196
197 result.name = essential_child_section.read<std::string_view>();
198 essential_child_section.read(result.x_pos);
199 essential_child_section.read(result.y_pos);
200 essential_child_section.read(result.x_size);
201 essential_child_section.read(result.y_size);
202
203 while(essential_child_section) {
204 auto ptype = essential_child_section.read< aui_property>();
205 if(ptype == aui_property::text_color) {
206 essential_child_section.read(result.text_color);
207 } else if(ptype == aui_property::text_align) {
208 essential_child_section.read(result.text_alignment);
209 } else if(ptype == aui_property::tooltip_text_key) {
210 result.tooltip_text_key = essential_child_section.read<std::string_view>();
211 } else if(ptype == aui_property::text_key) {
212 result.text_key = essential_child_section.read<std::string_view>();
213 } else if(ptype == aui_property::text_type) {
214 essential_child_section.read(result.text_type);
215 } else if(ptype == aui_property::text_scale) {
216 essential_child_section.read(result.text_scale);
217 } else if(ptype == aui_property::border_size) {
218 essential_child_section.read(result.border_size);
219 } else if(ptype == aui_property::texture) {
220 result.texture = essential_child_section.read<std::string_view>();
221 } else if(ptype == aui_property::alternate_bg) {
222 result.alt_texture = essential_child_section.read<std::string_view>();
223 } else if(ptype == aui_property::table_highlight_color) {
224 essential_child_section.read(result.table_highlight_color);
225 } else if(ptype == aui_property::other_color) {
226 essential_child_section.read(result.table_highlight_color);
227 } else if(ptype == aui_property::ascending_sort_icon) {
228 result.ascending_sort_icon =essential_child_section.read<std::string_view>();
229 } else if(ptype == aui_property::descending_sort_icon) {
230 result.descending_sort_icon = essential_child_section.read<std::string_view>();
231 } else if(ptype == aui_property::row_background_a) {
232 result.row_background_a = essential_child_section.read<std::string_view>();
233 } else if(ptype == aui_property::row_background_b) {
234 result.row_background_b = essential_child_section.read<std::string_view>();
235 } else if(ptype == aui_property::row_height) {
236 essential_child_section.read(result.row_height);
237 } else if(ptype == aui_property::table_divider_color) {
238 essential_child_section.read(result.table_divider_color);
239 } else if(ptype == aui_property::table_display_column_data) {
241 tc.header_key = essential_child_section.read<std::string_view>();
242 tc.header_tooltip_key = essential_child_section.read<std::string_view>();
243 tc.header_texture = essential_child_section.read<std::string_view>();
244 tc.cell_tooltip_key = essential_child_section.read<std::string_view>();
245 essential_child_section.read(tc.width);
246 essential_child_section.read(tc.cell_text_color);
247 essential_child_section.read(tc.header_text_color);
248 essential_child_section.read(tc.text_alignment);
249 result.table_columns.emplace_back(tc);
250 } else {
251 abort();
252 }
253 }
254
255 return result;
256}
in_buffer read_section()
Definition: stools.hpp:162
size_t view_read_position() const
Definition: stools.hpp:125
aui_text_type
aui_container_type
aui_background_type
void bytes_to_windows(char const *bytes, size_t size, std::string const &project_name, ankerl::unordered_dense::map< std::string, sys::aui_pending_bytes > &map)
aui_element_data read_child_bytes(char const *bytes, size_t size)
aui_property
@ table_internal_column_data
@ table_has_per_section_headers
@ table_display_column_data
aui_window_data read_window_bytes(char const *bytes, size_t size, std::vector< sys::aui_pending_bytes > &children_out)
alignment
Definition: text.hpp:36
text_color
Definition: text.hpp:18
uchar uint8_t
std::vector< table_display_column > table_columns
std::string_view descending_sort_icon
text::alignment text_alignment
std::string_view name
std::string_view row_background_b
ogl::color4f table_highlight_color
std::string_view row_background_a
text::text_color text_color
ogl::color3f table_divider_color
std::string_view ascending_sort_icon
std::string_view texture
aui_text_type text_type
std::string_view alt_texture
std::string_view tooltip_text_key
std::string_view text_key
ui::orientation orientation
std::string_view texture
std::string_view alt_texture
bool operator==(color4f const &o) const noexcept
color4f operator*(float v) const noexcept
bool operator!=(color4f const &o) const noexcept
std::string_view header_texture
text::text_color header_text_color
std::string_view header_tooltip_key
std::string_view header_key
std::string_view cell_tooltip_key
text::text_color cell_text_color
text::alignment text_alignment