11static int currentSize = 0;
12static int presetSize = 0;
13static int presetMaxWidth = 0;
14static ALIGN_H presetAlignmentHor = ALIGN_H::LEFT;
15static ALIGN_V presetAlignmentVert = ALIGN_V::TOP;
16static uint16_t presetStyle = 0;
18#define TEXT_SCROLL_DELAY 8
19#define TEXT_SCROLL_INITIAL_DELAY 6
31 style = GUI_TEXT_JUSTIFY_CENTER | GUI_TEXT_ALIGN_MIDDLE;
35 textScroll = SCROLL::NONE;
37 textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
38 textScrollDelay = TEXT_SCROLL_DELAY;
49 for(
int i=0; i < 20; i++)
62 alpha = presetColor.a;
64 maxWidth = presetMaxWidth;
67 textScroll = SCROLL::NONE;
69 textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
70 textScrollDelay = TEXT_SCROLL_DELAY;
81 for(
int i=0; i < 20; i++)
97 for(
int i=0; i < textDynNum; i++)
103wchar_t* GuiText::getText(
const char *t)
const {
116 for(
int i=0; i < textDynNum; i++)
125 textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
129 origText = strdup(t);
143 for(
int i=0; i < textDynNum; i++)
152 textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
172 presetAlignmentHor = h;
173 presetAlignmentVert = v;
185 for(
int i=0; i < textDynNum; i++)
190 textDyn[i] =
nullptr;
202 fontSystem->setPixelSize(size);
203 return fontSystem->getWidth(text);
211 for(
int i=0; i < textDynNum; i++)
216 textDyn[i] =
nullptr;
228 for(
int i=0; i < textDynNum; i++)
233 textDyn[i] =
nullptr;
241 textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
242 textScrollDelay = TEXT_SCROLL_DELAY;
263 style |= GUI_TEXT_JUSTIFY_LEFT;
266 style |= GUI_TEXT_JUSTIFY_RIGHT;
269 style |= GUI_TEXT_JUSTIFY_CENTER;
275 style |= GUI_TEXT_ALIGN_TOP;
277 case ALIGN_V::BOTTOM:
278 style |= GUI_TEXT_ALIGN_BOTTOM;
281 style |= GUI_TEXT_ALIGN_MIDDLE;
296 text = getText(origText);
298 for(
int i=0; i < textDynNum; i++)
303 textDyn[i] =
nullptr;
314bool GuiText::scrollStepDue()
316 const uint32_t now = platform->getVideo()->getFrameTimer();
319 if(now < textScrollLastTick)
320 textScrollLastTick = now;
322 if(now - textScrollLastTick < (uint32_t)textScrollDelay)
325 textScrollLastTick = now;
343 int newSize = size*this->
getScale();
345 fontSystem->setPixelSize(newSize);
349 fontSystem->drawText(this->
getLeft(), this->
getTop(), text, c, style);
354 uint32_t textlen = wcslen(text);
364 int lastSpaceIndex = -1;
366 while(ch < textlen && linenum < 20)
369 textDyn[linenum] =
new wchar_t[textlen + 1];
371 textDyn[linenum][n] = text[ch];
372 textDyn[linenum][n+1] = 0;
374 if(text[ch] ==
' ' || ch == textlen-1)
376 if(fontSystem->getWidth(textDyn[linenum]) > maxWidth)
380 textDyn[linenum][lastSpaceIndex] = 0;
388 else if(ch == textlen-1)
393 if(text[ch] ==
' ' && n >= 0)
401 textDynNum = linenum;
404 int lineheight = newSize + 6;
408 voffset = (lineheight >> 1) * (1-textDynNum);
411 int top = this->
getTop() + voffset;
413 for(
int i=0; i < textDynNum; ++i)
414 fontSystem->drawText(left, top+i*lineheight, textDyn[i], c, style);
421 textDyn[0] = wcsdup(text);
422 int len = wcslen(textDyn[0]);
424 while(fontSystem->getWidth(textDyn[0]) > maxWidth)
425 textDyn[0][--len] = 0;
428 if(textScroll == SCROLL::HORIZONTAL)
430 if(fontSystem->getWidth(text) > maxWidth && scrollStepDue())
432 if(textScrollInitialDelay)
434 --textScrollInitialDelay;
439 if((uint32_t)textScrollPos > textlen-1)
442 textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
445 wcscpy(textDyn[0], &text[textScrollPos]);
446 uint32_t dynlen = wcslen(textDyn[0]);
448 if(dynlen+2 < textlen)
450 textDyn[0][dynlen] =
' ';
451 textDyn[0][dynlen+1] =
' ';
452 textDyn[0][dynlen+2] = 0;
456 if(fontSystem->getWidth(textDyn[0]) > maxWidth)
458 while(fontSystem->getWidth(textDyn[0]) > maxWidth)
459 textDyn[0][--dynlen] = 0;
465 while(fontSystem->getWidth(textDyn[0]) < maxWidth && dynlen+1 < textlen)
467 textDyn[0][dynlen] = text[i++];
468 textDyn[0][++dynlen] = 0;
471 if(fontSystem->getWidth(textDyn[0]) > maxWidth)
472 textDyn[0][dynlen-2] = 0;
474 textDyn[0][dynlen-1] = 0;
479 fontSystem->drawText(this->
getLeft(), this->
getTop(), textDyn[0], c, style);
493 fontSystem->setPixelSize(size);
494 w = fontSystem->getWidth(text);
495 h = fontSystem->getHeight(text);
496 if(maxWidth > 0 && w > maxWidth)
Umbrella header for the platform-agnostic libgui core.
bool isVisible()
Checks whether or not the element is visible.
int getTop()
Gets the current topmost coordinate of the element Considers vertical alignment, y offset,...
int alpha
Element alpha value (0-255)
ALIGN_H alignmentHor
Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE)
void updateEffects()
Updates the element's effects (dynamic values) Called by Draw(), used for animation purposes.
int getLeft()
Gets the current leftmost coordinate of the element Considers horizontal alignment,...
ALIGN_V alignmentVert
Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE)
float getScale()
Gets the element's current scale Considers scale, scaleDyn, and the parent element's GetScale() value...
int getAlpha()
Gets the element's alpha value Considers alpha, alphaDyn, and the parent element's GetAlpha() value.
static wchar_t * charToWideChar(const char *p)
Hashed msgid -> UTF-8 string table loaded from a single binary .lang blob (see loadLanguage()).
void setWrap(bool w, int width=0)
Enables/disables text wrapping.
void setColor(PixelColor c)
Sets the font color.
void resetText()
Updates the text to the selected language.
GuiText(const char *t, int s, PixelColor c)
Constructor.
void setScroll(SCROLL s)
Enables/disables text scrolling.
static void setPresets(int sz, PixelColor c, int w, uint16_t s, ALIGN_H h, ALIGN_V v)
Sets up preset values to be used by GuiText(t) Useful when printing multiple text elements,...
void getNaturalSize(int &w, int &h) override
Gets the text's size for layout: its rendered width and height on one line (at most the maximum width...
void setFontSize(int s)
Sets the font size.
void setText(const char *t)
Sets the text of the GuiText element.
int getTextWidth()
Gets the width of the text when rendered.
void draw() override
Constantly called to draw the text.
void setWText(wchar_t *t)
Sets the text of the GuiText element.
void setMaxWidth(int w)
Sets the maximum width of the drawn texture image.
int getLength()
Gets the translated text length of the GuiText element.
void setStyle(uint16_t s)
Sets the GuiTextRenderer style attributes.
void setAlignment(ALIGN_H hor, ALIGN_V vert)
Sets the text alignment.
SCROLL
Scrolling mode of a GuiText (none or horizontal).
ALIGN_V
Vertical alignment of a GuiElement relative to its parent.
ALIGN_H
Horizontal alignment of a GuiElement relative to its parent.
8-bit-per-channel RGBA color used by the video interfaces.
uint8_t a
Alpha component.