KolibriLib
Loading...
Searching...
No Matches
window.hpp
1#pragma once
2
3#ifndef __WINDOW_H__
4#define __WINDOW_H__
5
6
7#include <string>
8#include <vector>
9
10
11#include <sys/ksys.h>
12
13#include "base.hpp"
14#include "mouse.hpp"
15#include "windowBase.hpp"
16#include "UI.hpp"
17
18namespace KolibriLib
19{ //=============================================================================================================================================================
20
21
22
24 namespace window
25 {
26
28 {
30 bool use;
31 };
32
34 {
36 bool use;
37 };
38
40 {
41 UI::Form frm;
42 bool use;
43 };
44
46 class Window
47 {
48 private:
50 std::string _title;
51
53 point _size;
54
56 ksys_colors_table_t _colors;
57
59 unsigned _MARGIN;
60
62 bool _Redraw = false;
63
65 int _style;
66
68 std::vector<ButtonListElement> _Buttons;
70 std::vector<TextListElement> _Texts;
71
72 std::vector<FormListElement> _Forms;
73
77 unsigned AddNewButton(UI::buttons::Button btn);
78
82 unsigned AddNewTextLabel(UI::text::TextLabel text);
83
87 unsigned AddNewForm(UI::Form form);
88
89 public:
96 Window(std::string Title = "Window", point size = DefaultWindowSize, int style = 0x14, ksys_colors_table_t colors = Color::DefaultColorTable, unsigned Margin = 0);
97 ~Window();
98
100 void Render();
101
104 unsigned GetMargin();
105
108 point GetSize();
109
112 void SetWindowColors(ksys_colors_table_t colorTable);
113
117 void StartRedraw();
118
121 void EndRedraw();
122
130
134 void ChangeWindow(point coord, point size);
135
138 void ChangeTilte(std::string newTitle);
139
144
154 unsigned CreateButton(point coord = {0, 0}, point size = {16, 16}, std::string Text = " ", unsigned margin = UI::DefaultMargin, bool UseWindowColors = true, ksys_color_t color = OS::sys_color_table.work_button, ksys_color_t TextColor = OS::sys_color_table.work_button_text);
155
159 unsigned CreateButton(UI::buttons::Button btn);
160
163 void DeleteButton(unsigned id);
164
173 unsigned CreateText(point coord = {0,0}, point size = {16, 16}, std::string text = "Text", unsigned FontSize = 9, bool UseWindowColors = true, ksys_color_t color = OS::sys_color_table.work_text);
174
178 unsigned CreateText(UI::text::TextLabel text);
179
182 void DeleteText(unsigned id);
183
187 unsigned CreateForm(UI::Form form);
188
191 void DeleteForm(unsigned id);
192 };
193
194 unsigned Window::AddNewButton(UI::buttons::Button btn)
195 {
196 for(unsigned i = 0; i < _Buttons.size(); i++)
197 {
198 if(!_Buttons[i].use)
199 {
200 _Buttons[i].btn = btn;
201 _Buttons[i].use = true;
202 return i;
203 }
204 }
205 ButtonListElement a;
206 a.btn = btn;
207 a.use = true;
208 _Buttons.push_back(a);
209 return _Buttons.size();
210 }
211
212 unsigned Window::AddNewTextLabel(UI::text::TextLabel text)
213 {
214 for (unsigned i = 0; i < _Texts.size(); i++)
215 {
216 if (!_Texts[i].use)
217 {
218 _Texts[i].txt = text;
219 _Texts[i].use = true;
220 return i;
221 }
222 }
223 TextListElement a;
224 a.txt = text;
225 a.use = true;
226 _Texts.push_back(a);
227 }
228
229 inline unsigned Window::AddNewForm(UI::Form form)
230 {
231 for (unsigned i = 0; i < _Forms.size(); i++)
232 {
233 if (!_Forms[i].use)
234 {
235 _Forms[i].frm = form;
236 _Forms[i].use = true;
237 return i;
238 }
239 }
240 FormListElement a;
241 a.frm = form;
242 a.use = true;
243 _Forms.push_back(a);
244 return _Forms.size();
245 }
246
247 Window::Window(std::string Title, point size, int style, ksys_colors_table_t colors, unsigned Margin)
248 {
249 _title = Title;
250 _size = size;
251 _style = style;
253 {
254 _colors = OS::GetSystemColors();
255 }
256 else
257 {
258 _colors = colors;
259 }
260 _MARGIN = Margin;
262 }
263
264 Window::~Window()
265 {
266 }
267
268 void Window::SetWindowColors(ksys_colors_table_t colorTable)
269 {
270 _colors = colorTable;
271 }
272
274 {
275 _ksys_start_draw();
276 _Redraw = true;
277 }
278
280 {
281 if (_Redraw)
282 {
283 _ksys_end_draw();
284 _Redraw = false;
285 }
286 }
287
289 {
290 _ksys_create_window(coord.x, coord.y, _size.x, _size.y, _title.c_str(), _colors.work_area, _style);
291 }
292
294 {
295 _size = size;
296 _ksys_change_window(coord.x, coord.y, size.x, size.y);
297 }
298
299 void Window::ChangeTilte(std::string newTitle)
300 {
301 _ksys_set_window_title(newTitle.c_str());
302 }
303
305 {
306 return _size;
307 }
309 {
310 StartRedraw();
311 DrawWindow();
312
313 for(unsigned i = 0; i < _Buttons.size(); i++)
314 {
315 if(_Buttons[i].use)
316 {
317 _Buttons[i].btn.render();
318 }
319 }
320 for(unsigned i = 0; i < _Texts.size(); i++)
321 {
322 if(_Texts[i].use)
323 {
324 _Texts[i].txt.render();
325 }
326 }
327 for(unsigned i = 0; i < _Forms.size(); i++)
328 {
329 if(_Forms[i].use)
330 {
331 _Forms[i].frm.render();
332 }
333 }
334
335 EndRedraw();
336 }
337
339 {
340 return _MARGIN;
341 }
342
344 {
345 return _size;
346 }
347
348 unsigned KolibriLib::window::Window::CreateButton(point coord, point size, std::string Text, unsigned margin, bool UseWindowColors, ksys_color_t color, ksys_color_t TextColor)
349 {
350 if(UseWindowColors)
351 {
352 color = _colors.work_button;
353 TextColor = _colors.work_button_text;
354 }
355 UI::buttons::Button btn(coord, size, Text, margin, color, TextColor);
356 return AddNewButton(btn);
357 }
358
360 {
361 return AddNewButton(btn);
362 }
363
365 {
366 _Buttons[id].btn.Deactivate();
367 _Buttons[id].use = false;
368 }
369 unsigned Window::CreateText(point coord, point size, std::string text, unsigned FontSize, bool UseWindowColors, ksys_color_t color)
370 {
371 if(UseWindowColors)
372 {
373 color = _colors.work_text;
374 }
375
376 UI::text::TextLabel t(coord, size, text, FontSize);
377
378 return AddNewTextLabel(t);
379
380 }
382 {
383 return AddNewTextLabel(text);
384 }
385
386 void Window::DeleteText(unsigned id)
387 {
388 _Texts[id].use = false;
389 }
390
392 {
393 return AddNewForm(form);
394 }
395 void Window::DeleteForm(unsigned id)
396 {
397 _Forms[id].use = false;
398 }
399 }
400
401 //=============================================================================================================================================================
402
403
404
405}
406
407
408
409
410//=============================================================================================================================================================
411
412
413#endif
Форма для ввода текста
Definition UI.hpp:426
Класс для работы с кнопками
Definition UI.hpp:265
Класс для работы с текстом
Definition UI.hpp:104
Класс для работы с окном
Definition window.hpp:47
Window(std::string Title="Window", point size=DefaultWindowSize, int style=0x14, ksys_colors_table_t colors=Color::DefaultColorTable, unsigned Margin=0)
Конструктор
Definition window.hpp:247
void EndRedraw()
Закончить перересовку окна
Definition window.hpp:279
void DeleteText(unsigned id)
Удалить текст
Definition window.hpp:386
void DeleteForm(unsigned id)
Удалить форму
Definition window.hpp:395
void ChangeWindow(point coord, point size)
Изменить окно
Definition window.hpp:293
unsigned CreateText(point coord={0, 0}, point size={16, 16}, std::string text="Text", unsigned FontSize=9, bool UseWindowColors=true, ksys_color_t color=OS::sys_color_table.work_text)
Создать текст в окне
Definition window.hpp:369
void StartRedraw()
Начать перересовку окна
Definition window.hpp:273
void SetWindowColors(ksys_colors_table_t colorTable)
Задать стандартные цвета окна
Definition window.hpp:268
void ChangeTilte(std::string newTitle)
Изменить заголовок окна
Definition window.hpp:299
point GetSize()
Получить размер окна
Definition window.hpp:343
unsigned CreateButton(point coord={0, 0}, point size={16, 16}, std::string Text=" ", unsigned margin=UI::DefaultMargin, bool UseWindowColors=true, ksys_color_t color=OS::sys_color_table.work_button, ksys_color_t TextColor=OS::sys_color_table.work_button_text)
Создать кнопку
Definition window.hpp:348
unsigned GetMargin()
Получить рамер отступов в этом окне
Definition window.hpp:338
void DeleteButton(unsigned id)
Удалить кнопку
Definition window.hpp:364
void Render()
Отрисовать окно
Definition window.hpp:308
point GetWindowSize()
Получить размер окна
Definition window.hpp:304
unsigned CreateForm(UI::Form form)
Создать форму
Definition window.hpp:391
void DrawWindow(point coord=mouse::GetMousePositionOnSreen())
Отрисовать окно
Definition window.hpp:288
const ksys_colors_table_t DefaultColorTable
Таблица цветов по умолчанию
Definition windowBase.hpp:14
bool ComparisonColorsTables(ksys_colors_table_t a, ksys_colors_table_t b)
Сравнить две таблица цветов
Definition windowBase.hpp:20
ksys_colors_table_t sys_color_table
Таблица стандартных(системных) цветов
Definition base.hpp:37
point GetMousePositionOnSreen()
Получить позицияю курсора на экране
Definition mouse.hpp:17
const point DefaultWindowCoord
Соординаты окна по умолчанию
Definition windowBase.hpp:39
const point DefaultWindowSize
Размер окна поумолчанию
Definition windowBase.hpp:36
Основное пространство имён
Definition base.hpp:17
Просто точка
Definition base.hpp:22
Definition window.hpp:40
Definition window.hpp:34