KolibriLib
Loading...
Searching...
No Matches
text.hpp
1#ifndef __TEXT_H__
2#define __TEXT_H__
3
4
5#include <sys/ksys.h>
6
7#include <string>
8
9#include "UI.hpp"
10#include "color.hpp"
11
12namespace KolibriLib
13{
14 namespace UI
15 {
17 namespace text
18 {
21 inline unsigned int GetTextSize()
22 {
23 unsigned Size;
24 asm_inline(
25 "int $0x40"
26 : "=c"(Size)
27 : "a"(48), "b"(11));
28 return Size;
29 }
30
33 inline void SetTextSize(unsigned int newSize)
34 {
35 asm_inline(
36 "int $0x40"
37 :
38 :"a"(48), "b"(12), "c"(newSize)
39 );
40 }
41
46 inline void DrawText(const std::string &text, const Coord &coord, const unsigned &size = 9, Color::Color color = OS::sys_color_table.work_text)
47 {
48 SetTextSize(size);
49 _ksys_draw_text(text.c_str(), coord.x, coord.y, text.length(), color);
50 }
51
56 inline void DrawText(const char *text, const Coord &coord, const unsigned &size = 9, Color::Color color = OS::sys_color_table.work_text)
57 {
58 SetTextSize(size);
59 _ksys_draw_text(text, coord.x, coord.y, strlen(text), color);
60 }
61
62 //=============================================================================================================================================================
63
65 class TextLabel : public UI::UIElement
66 {
67 private:
69 std::string _text;
70
71 /*
73 std::string FontFamily;
74 */
75
77 unsigned _FontSize;
78
80 bool _TextScale;
81
82 public:
90 TextLabel(const Coord& coord = {0, 0}, const Size& size = {16, 16}, const std::string& text = "Text", const unsigned& FontSize = 9, bool TextScale = true, const Color::Color& TextColor = OS::sys_color_table.work_text, const unsigned& Margin = 0);
91
92 ~TextLabel();
93
95 void Render();
96
99 std::string GetText();
100
103 unsigned GetFontSize();
104
108
111 void SetText(const std::string &NewText);
112
115 void SetFontSize(const unsigned &NewTextSize);
116
117
120 void SetScale(bool scale);
121
122 void init(Coord coord, Size size, std::string text, unsigned FontSize, Color::Color TextColor);
123
124 };
125
126 TextLabel::TextLabel(const Coord& coord, const Size& size, const std::string& text, const unsigned& FontSize, bool TextScale, const Color::Color& TextColor, const unsigned& Margin) : UIElement(coord, size, TextColor, Margin)
127 {
128 _ksys_debug_puts("text:");
129 _text = text;
130 _FontSize = FontSize;
131 _TextScale = TextScale;
132 }
133
134 TextLabel::~TextLabel()
135 {
136
137 }
138
140 {
141 if (_TextScale) // Если текст нужно подстраивать размер, то
142 { // Постраиваем
143 _FontSize = _size.x / _text.length();
144 }
145
146 unsigned a = _Margin;
147
148 if ((_text.length() * _FontSize) > _size.x) // Центрирование текста
149 {
150 a = (_size.x / 2) - (_text.length() * _FontSize);
151 }
152
153 SetTextSize(_FontSize);
154 DrawText(_text, {_coord.x + (int)a, _coord.y + ((int)_size.y / 2)}, _FontSize, _MainColor);
155 }
156
157 std::string TextLabel::GetText()
158 {
159 return _text;
160 }
162 {
163 return _FontSize;
164 }
165
166 void TextLabel::SetText(const std::string &NewText)
167 {
168 _text = NewText;
169 }
170 void TextLabel::SetFontSize(const unsigned &NewTextSize)
171 {
172 _FontSize = NewTextSize;
173 }
174
175 void TextLabel::SetScale(bool scale)
176 {
177 _TextScale = scale;
178 }
179
180 void TextLabel::init(Coord coord, Size size, std::string text, unsigned FontSize, Color::Color TextColor)
181 {
182 SetCoord(coord);
183 SetSize(size);
184 SetText(text);
185 SetColor(TextColor);
186 SetFontSize(FontSize);
187 }
188 }
189 } // namespace UI
190
191} // namespace KolibriLib
192
193
194#endif // __TEXT_H__
Элемент интерфейса
Definition UI.hpp:29
unsigned _Margin
Отступы
Definition UI.hpp:41
Size _size
Размер
Definition UI.hpp:36
Coord _coord
Координаты
Definition UI.hpp:33
Текстовая метка
Definition text.hpp:66
Color::Color GetTextColor()
Получить цвет текста
void SetScale(bool scale)
Изменить значение переменной _TextScale.
Definition text.hpp:175
void SetFontSize(const unsigned &NewTextSize)
Изменить рамер текста
Definition text.hpp:170
TextLabel(const Coord &coord={0, 0}, const Size &size={16, 16}, const std::string &text="Text", const unsigned &FontSize=9, bool TextScale=true, const Color::Color &TextColor=OS::sys_color_table.work_text, const unsigned &Margin=0)
Конструктор
Definition text.hpp:126
unsigned GetFontSize()
Получить Размер шрифта
Definition text.hpp:161
void Render()
Отрисовать текстовую метку
Definition text.hpp:139
void SetText(const std::string &NewText)
Изменить текст
Definition text.hpp:166
std::string GetText()
Получить текст
Definition text.hpp:157
ksys_color_t Color
Цвет
Definition color.hpp:13
Color::ColorsTable sys_color_table
Таблица стандартных(системных) цветов
Definition os.hpp:15
void DrawText(const std::string &text, const Coord &coord, const unsigned &size=9, Color::Color color=OS::sys_color_table.work_text)
Вывести текст
Definition text.hpp:46
void SetTextSize(unsigned int newSize)
Изменить размер текста
Definition text.hpp:33
unsigned int GetTextSize()
Получить размер текста
Definition text.hpp:21
Основное пространство имён
Definition base.hpp:18
void init()
инициализация
Definition base.hpp:21