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;
69
71 std::vector<TextListElement> _Texts;
72
74 std::vector<FormListElement> _Forms;
77 unsigned ActiveForm = 0;
78
82 unsigned AddNewButton(UI::buttons::Button btn);
83
87 unsigned AddNewTextLabel(UI::text::TextLabel text);
88
92 unsigned AddNewForm(UI::Form form);
93
94 public:
101 Window(std::string Title = "Window", point size = DefaultWindowSize, int style = 0x14, ksys_colors_table_t colors = Color::DefaultColorTable, unsigned Margin = 0);
102 ~Window();
103
105 void Render();
106
109 unsigned GetMargin();
110
113 point GetSize();
114
117 void SetWindowColors(ksys_colors_table_t colorTable);
118
122 void StartRedraw();
123
126 void EndRedraw();
127
135
139 void ChangeWindow(point coord, point size);
140
143 void ChangeTilte(std::string newTitle);
144
149
159 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);
160
164 unsigned CreateButton(UI::buttons::Button btn);
165
168 void DeleteButton(unsigned id);
169
178 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);
179
183 unsigned CreateText(UI::text::TextLabel text);
184
187 void DeleteText(unsigned id);
188
193 unsigned CreateForm(point coord = {0, 0}, KolibriLib::point size = {32, 16}, std::string BackgroundText = " ", ksys_color_t FormColor = OS::sys_color_table.work_text, ksys_color_t BackgroundTextColor = OS::sys_color_table.work_button_text);
194
198 unsigned CreateForm(UI::Form form);
199
203 std::string GetTextFromForm(unsigned form);
204
207 void DeleteForm(unsigned id);
208
210 void Handler();
211
214 unsigned GetPressedButton();
215 };
216
217 unsigned Window::AddNewButton(UI::buttons::Button btn)
218 {
219 for(unsigned i = 0; i < _Buttons.size(); i++)
220 {
221 if(!_Buttons[i].use)
222 {
223 _Buttons[i].btn = btn;
224 _Buttons[i].btn.Activate();
225 _Buttons[i].use = true;
226 return i;
227 }
228 }
229 ButtonListElement a;
230 a.btn = btn;
231 a.use = true;
232 _Buttons.push_back(a);
233 return _Buttons.size();
234 }
235
236 unsigned Window::AddNewTextLabel(UI::text::TextLabel text)
237 {
238 for (unsigned i = 0; i < _Texts.size(); i++)
239 {
240 if (!_Texts[i].use)
241 {
242 _Texts[i].txt = text;
243 _Texts[i].use = true;
244 return i;
245 }
246 }
247 TextListElement a;
248 a.txt = text;
249 a.use = true;
250 _Texts.push_back(a);
251 }
252
253 inline unsigned Window::AddNewForm(UI::Form form)
254 {
255 for (unsigned i = 0; i < _Forms.size(); i++)
256 {
257 if (!_Forms[i].use)
258 {
259 _Forms[i].frm = form;
260 _Forms[i].use = true;
261 return i;
262 }
263 }
264 FormListElement a;
265 a.frm = form;
266 a.use = true;
267 _Forms.push_back(a);
268 return _Forms.size();
269 }
270
271 Window::Window(std::string Title, point size, int style, ksys_colors_table_t colors, unsigned Margin)
272 {
273 _title = Title;
274 _size = size;
275 _style = style;
277 {
278 _colors = OS::GetSystemColors();
279 }
280 else
281 {
282 _colors = colors;
283 }
284 _MARGIN = Margin;
286 Render();
287 }
288
289 Window::~Window()
290 {
291 }
292
293 void Window::SetWindowColors(ksys_colors_table_t colorTable)
294 {
295 _colors = colorTable;
296 }
297
299 {
300 _ksys_start_draw();
301 _Redraw = true;
302 }
303
305 {
306 if (_Redraw)
307 {
308 _ksys_end_draw();
309 _Redraw = false;
310 }
311 }
312
314 {
315 _ksys_create_window(coord.x, coord.y, _size.x, _size.y, _title.c_str(), _colors.work_area, _style);
316 }
317
319 {
320 _size = size;
321 _ksys_change_window(coord.x, coord.y, size.x, size.y);
322 }
323
324 void Window::ChangeTilte(std::string newTitle)
325 {
326 _ksys_set_window_title(newTitle.c_str());
327 }
328
330 {
331 return _size;
332 }
334 {
335 StartRedraw();
336 DrawWindow();
337
338 for(unsigned i = 0; i < _Buttons.size(); i++)
339 {
340 if(_Buttons[i].use)
341 {
342 _Buttons[i].btn.render();
343 }
344 }
345 for(unsigned i = 0; i < _Texts.size(); i++)
346 {
347 if(_Texts[i].use)
348 {
349 _Texts[i].txt.render();
350 }
351 }
352 for(unsigned i = 0; i < _Forms.size(); i++)
353 {
354 if(_Forms[i].use)
355 {
356 _Forms[i].frm.render();
357 }
358 }
359
360 EndRedraw();
361 }
362
364 {
365 return _MARGIN;
366 }
367
369 {
370 return _size;
371 }
372
373 unsigned KolibriLib::window::Window::CreateButton(point coord, point size, std::string Text, unsigned margin, bool UseWindowColors, ksys_color_t color, ksys_color_t TextColor)
374 {
375 if(UseWindowColors)
376 {
377 color = _colors.work_button;
378 TextColor = _colors.work_button_text;
379 }
380 UI::buttons::Button btn(coord, size, Text, margin, color, TextColor);
381 unsigned a = AddNewButton(btn);
382 btn.Deactivate();
383 return a;
384 }
385
387 {
388 return AddNewButton(btn);
389 }
390
392 {
393 _Buttons[id].btn.Deactivate();
394 _Buttons[id].use = false;
395 }
396 unsigned Window::CreateText(point coord, point size, std::string text, unsigned FontSize, bool UseWindowColors, ksys_color_t color)
397 {
398 if(UseWindowColors)
399 {
400 color = _colors.work_text;
401 }
402
403 UI::text::TextLabel t(coord, size, text, FontSize);
404
405 return AddNewTextLabel(t);
406
407 }
409 {
410 return AddNewTextLabel(text);
411 }
412
413 void Window::DeleteText(unsigned id)
414 {
415 _Texts[id].use = false;
416 }
417
418 unsigned Window::CreateForm (point coord, KolibriLib::point size, std::string BackgroundText, ksys_color_t FormColor, ksys_color_t BackgroundTextColor)
419 {
420 UI::Form form (coord, size, BackgroundText, FormColor, BackgroundTextColor, _MARGIN);
421 return AddNewForm (form);
422 }
423
425 {
426 return AddNewForm(form);
427 }
428
429 std::string Window::GetTextFromForm(unsigned form)
430 {
431 return _Forms[form].frm.GetInput();
432 }
433
434 void Window::DeleteForm(unsigned id)
435 {
436 _Forms[id].use = false;
437 }
438
440 {
441 for (unsigned i = 0; i < _Buttons.size(); i++)
442 {
443 if (_Buttons[i].use) // Если кнопка используется
444 {
445 _Buttons[i].btn.Handler();
446 }
447 }
448
449 for (unsigned i = 0; i < _Forms.size(); i++)
450 {
451 if (_Forms[i].use) // Если форма используется
452 {
453 if (_Forms[i].frm.ButtonHandler())
454 {
455 ActiveForm = i;
456 }
457 }
458 }
459 _Forms[ActiveForm].frm.Handler();
460 }
461
463 {
464 for(unsigned i = 0; i < _Buttons.size(); i++)
465 {
466 if(_Buttons[i].btn.GetStatus())
467 {
468 return i;
469 }
470 }
471 return _Buttons.size();
472 }
473 }
474
475 //=============================================================================================================================================================
476
477
478
479}
480
481
482
483
484//=============================================================================================================================================================
485
486
487#endif
Форма для ввода текста
Definition UI.hpp:483
Класс для работы с кнопками
Definition UI.hpp:324
void Deactivate()
Деактивировать кнопку
Definition UI.hpp:393
bool GetStatus()
Получить сосояние кнопки на момент последней обработки
Definition UI.hpp:444
Текстовая метка
Definition UI.hpp:106
Класс для работы с окном
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:271
void EndRedraw()
Закончить перересовку окна
Definition window.hpp:304
void DeleteText(unsigned id)
Удалить текст
Definition window.hpp:413
void DeleteForm(unsigned id)
Удалить форму
Definition window.hpp:434
void Handler()
Обработчик элементов
Definition window.hpp:439
unsigned CreateForm(point coord={0, 0}, KolibriLib::point size={32, 16}, std::string BackgroundText=" ", ksys_color_t FormColor=OS::sys_color_table.work_text, ksys_color_t BackgroundTextColor=OS::sys_color_table.work_button_text)
Создать форму
Definition window.hpp:418
void ChangeWindow(point coord, point size)
Изменить окно
Definition window.hpp:318
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:396
void StartRedraw()
Начать перересовку окна
Definition window.hpp:298
void SetWindowColors(ksys_colors_table_t colorTable)
Задать стандартные цвета окна
Definition window.hpp:293
std::string GetTextFromForm(unsigned form)
Получить текст из формы
Definition window.hpp:429
void ChangeTilte(std::string newTitle)
Изменить заголовок окна
Definition window.hpp:324
point GetSize()
Получить размер окна
Definition window.hpp:368
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:373
unsigned GetMargin()
Получить рамер отступов в этом окне
Definition window.hpp:363
void DeleteButton(unsigned id)
Удалить кнопку
Definition window.hpp:391
void Render()
Отрисовать окно
Definition window.hpp:333
point GetWindowSize()
Получить размер окна
Definition window.hpp:329
unsigned GetPressedButton()
Получить нажатую кнопку
Definition window.hpp:462
void DrawWindow(point coord=mouse::GetMousePositionOnSreen())
Отрисовать окно
Definition window.hpp:313
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
const unsigned DefaultMargin
Отступы поумолчанию
Definition UI.hpp:20
point GetMousePositionOnSreen()
Получить позицияю курсора на экране
Definition mouse.hpp:15
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