Project Alice
Loading...
Searching...
No Matches
immediate_mode.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace sys {
4struct state;
5};
6
7namespace ui {
9 sys::state& state,
11 float x,
12 float baseline_y,
13 uint16_t font_id,
16);
18};
19
20
21namespace iui {
22
25};
28};
29
30struct rect {
31 float x, y, w, h;
32};
33
35 float w;
36 float h;
38};
39
40void shrink(rect& rectangle, float value);
41void move_to(rect& rectangle, float x, float y);
42rect subrect(rect& rectangle, float w, float h, alignment_horizontal align_hor, alignment_vertical align_vert);
43
44enum iui_tab {
46};
47
48struct iui_state {
49 // immediate mode UI state storage
50 uint16_t current_font = 0;
51 int32_t active_element = 0;
52 int32_t hovered_element = 0;
53
55
56 bool over_ui = false;
57 bool mouse_pressed = false;
58
60
61 std::vector<float> per_market_data;
62 std::vector<dcon::nation_id> input_efficiency_leaders;
63 std::vector<text::text_chunk> input_efficiency_leaders_string;
64
65 bool loaded_descriptions = false;
77
78 ankerl::unordered_dense::map<int32_t, std::vector<text::text_chunk>> gui_text_chunks_map;
79 ankerl::unordered_dense::map<int32_t, std::string> gui_text_map;
80 ankerl::unordered_dense::map<int32_t, float> gui_float_map;
81 ankerl::unordered_dense::map<int32_t, int32_t> gui_int_map;
82
83 void panel(
84 sys::state& state,
85 rect& r
86 );
87
88 void panel_subsprite(
89 sys::state& state,
90 rect& r,
91 int frame, int total_frames,
92 GLuint texture_handle
93 );
94
95 void panel_textured(
96 sys::state& state,
97 rect& r,
98 GLuint texture_handle
99 );
100
101 void panel_colored(
102 sys::state& state,
103 rect& r,
104 float red, float green, float blue
105 );
106
107 bool button(
108 sys::state& state, int32_t identifier,
109 rect& r,
110 bool active
111 );
112
113 bool button_textured(
114 sys::state& state, int32_t identifier,
115 rect& r,
116 int total_frames,
117 GLuint texture_handle,
118 bool active
119 );
120
122 sys::state& state,
123 text::layout& layout,
124 uint16_t font_handle,
125 text::alignment align, float w, float h
126 );
127 void float_2(
128 sys::state& state, int32_t identifier,
129 rect& r, float value
130 );
131 void int_whole(
132 sys::state& state, int32_t identifier,
133 rect& r,
134 int32_t value
135 );
136 void price(
137 sys::state& state, int32_t identifier,
138 rect& r,
139 float value
140 );
141 void render_text(
142 sys::state& state,
143 std::vector<text::text_chunk>& content,
144 rect& r, ogl::color3f color
145 );
146 void localized_string(
147 sys::state& state, int32_t identifier,
148 rect& r, std::string_view key, ogl::color3f color = { 0.f, 0.f, 0.f }
149 );
151 sys::state& state, int32_t identifier,
152 rect r, std::string_view key, ogl::color3f color = { 0.f, 0.f, 0.f }
153 );
154
155 void frame_start() {
156 over_ui = false;
157 }
158
159 void frame_end() {
160 if(mouse_pressed && (active_element == 0)) {
161 mouse_pressed = false;
162 }
163 if(!mouse_pressed) {
164 active_element = 0;
165 }
166 }
167
168 void load_description(sys::state& state, std::string_view name, element_description& local_desc);
169};
170
171}
void shrink(rect &rectangle, float value)
alignment_vertical
alignment_horizontal
rect subrect(rect &rectangle, float w, float h, alignment_horizontal align_hor, alignment_vertical align_vert)
void move_to(rect &rectangle, float x, float y)
@ commodities_nations
@ factory_types
@ commodities_markets
color_modification
Definition: constants.hpp:4
alignment
Definition: text.hpp:36
text_color
Definition: text.hpp:18
void render_text_chunk(sys::state &state, text::text_chunk t, float x, float baseline_y, uint16_t font_id, ogl::color3f text_color, ogl::color_modification cmod)
ogl::color3f get_text_color(sys::state &state, text::text_color text_color)
uchar uint8_t
void load_description(sys::state &state, std::string_view name, element_description &local_desc)
ankerl::unordered_dense::map< int32_t, std::vector< text::text_chunk > > gui_text_chunks_map
void localized_string(sys::state &state, int32_t identifier, rect &r, std::string_view key, ogl::color3f color={ 0.f, 0.f, 0.f })
element_description priority_button
void render_text(sys::state &state, std::vector< text::text_chunk > &content, rect &r, ogl::color3f color)
element_description page_selector_bg
element_description top_bar_button
std::vector< text::text_chunk > input_efficiency_leaders_string
void int_whole(sys::state &state, int32_t identifier, rect &r, int32_t value)
text::endless_layout init_layout(sys::state &state, text::layout &layout, uint16_t font_handle, text::alignment align, float w, float h)
element_description factory_type_bg
element_description close_button
ankerl::unordered_dense::map< int32_t, int32_t > gui_int_map
std::vector< dcon::nation_id > input_efficiency_leaders
element_description item_selector_bg
ankerl::unordered_dense::map< int32_t, float > gui_float_map
bool button(sys::state &state, int32_t identifier, rect &r, bool active)
element_description map_label
void panel(sys::state &state, rect &r)
void float_2(sys::state &state, int32_t identifier, rect &r, float value)
void localized_string_r(sys::state &state, int32_t identifier, rect r, std::string_view key, ogl::color3f color={ 0.f, 0.f, 0.f })
void panel_textured(sys::state &state, rect &r, GLuint texture_handle)
ankerl::unordered_dense::map< int32_t, std::string > gui_text_map
element_description commodity_bg
bool button_textured(sys::state &state, int32_t identifier, rect &r, int total_frames, GLuint texture_handle, bool active)
std::vector< float > per_market_data
element_description factory_type_name_bg
element_description page_button
void panel_colored(sys::state &state, rect &r, float red, float green, float blue)
void price(sys::state &state, int32_t identifier, rect &r, float value)
int32_t hovered_element
void panel_subsprite(sys::state &state, rect &r, int frame, int total_frames, GLuint texture_handle)
element_description factory_type_priority_bg
uint16_t current_font
int32_t active_element
Holds important data about the game world, state, and other data regarding windowing,...