2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** v_text.cpp
|
|
|
|
** Draws text to a canvas. Also has a text line-breaker thingy.
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2006 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <ctype.h>
|
2018-02-27 10:10:47 +00:00
|
|
|
#include <wctype.h>
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
#include "v_text.h"
|
|
|
|
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "hu_stuff.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "templates.h"
|
2017-02-10 12:20:19 +00:00
|
|
|
#include "gstrings.h"
|
2017-04-12 23:12:04 +00:00
|
|
|
#include "vm.h"
|
2018-11-01 08:02:20 +00:00
|
|
|
#include "serializer.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-02-05 15:47:33 +00:00
|
|
|
int ListGetInt(VMVa_List &tags);
|
|
|
|
|
2017-02-05 15:18:41 +00:00
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// DrawChar
|
|
|
|
//
|
|
|
|
// Write a single character using the given font
|
|
|
|
//
|
2017-02-05 15:18:41 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
2017-02-04 22:26:28 +00:00
|
|
|
void DCanvas::DrawChar (FFont *font, int normalcolor, double x, double y, int character, int tag_first, ...)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (font == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (normalcolor >= NumTextColors)
|
|
|
|
normalcolor = CR_UNTRANSLATED;
|
|
|
|
|
|
|
|
FTexture *pic;
|
|
|
|
int dummy;
|
|
|
|
|
|
|
|
if (NULL != (pic = font->GetChar (character, &dummy)))
|
|
|
|
{
|
2016-04-09 18:47:54 +00:00
|
|
|
DrawParms parms;
|
2017-02-05 20:54:09 +00:00
|
|
|
Va_List tags;
|
|
|
|
va_start(tags.list, tag_first);
|
2016-04-09 18:47:54 +00:00
|
|
|
bool res = ParseDrawTextureTags(pic, x, y, tag_first, tags, &parms, false);
|
2017-02-05 20:54:09 +00:00
|
|
|
va_end(tags.list);
|
2016-04-09 18:47:54 +00:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-03-29 19:54:11 +00:00
|
|
|
PalEntry color = 0xffffffff;
|
2017-03-29 19:22:05 +00:00
|
|
|
parms.remap = font->GetColorTranslation((EColorRange)normalcolor, &color);
|
|
|
|
parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255);
|
2016-04-09 18:47:54 +00:00
|
|
|
DrawTextureParms(pic, parms);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-05 15:47:33 +00:00
|
|
|
void DCanvas::DrawChar(FFont *font, int normalcolor, double x, double y, int character, VMVa_List &args)
|
|
|
|
{
|
|
|
|
if (font == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (normalcolor >= NumTextColors)
|
|
|
|
normalcolor = CR_UNTRANSLATED;
|
|
|
|
|
|
|
|
FTexture *pic;
|
|
|
|
int dummy;
|
|
|
|
|
|
|
|
if (NULL != (pic = font->GetChar(character, &dummy)))
|
|
|
|
{
|
|
|
|
DrawParms parms;
|
|
|
|
uint32_t tag = ListGetInt(args);
|
|
|
|
bool res = ParseDrawTextureTags(pic, x, y, tag, args, &parms, false);
|
|
|
|
if (!res) return;
|
2017-03-29 19:54:11 +00:00
|
|
|
PalEntry color = 0xffffffff;
|
2017-03-29 19:22:05 +00:00
|
|
|
parms.remap = font->GetColorTranslation((EColorRange)normalcolor, &color);
|
|
|
|
parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255);
|
2017-02-05 15:47:33 +00:00
|
|
|
DrawTextureParms(pic, parms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(_Screen, DrawChar)
|
|
|
|
{
|
|
|
|
PARAM_PROLOGUE;
|
|
|
|
PARAM_POINTER(font, FFont);
|
|
|
|
PARAM_INT(cr);
|
|
|
|
PARAM_FLOAT(x);
|
|
|
|
PARAM_FLOAT(y);
|
|
|
|
PARAM_INT(chr);
|
|
|
|
|
2018-11-18 18:31:13 +00:00
|
|
|
PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array
|
|
|
|
|
2017-03-28 22:45:53 +00:00
|
|
|
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
|
2018-11-18 20:18:15 +00:00
|
|
|
VMVa_List args = { param + 5, 0, numparam - 6, va_reginfo + 5 };
|
2017-02-05 15:47:33 +00:00
|
|
|
screen->DrawChar(font, cr, x, y, chr, args);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-05 15:18:41 +00:00
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// DrawText
|
|
|
|
//
|
|
|
|
// Write a string using the given font
|
|
|
|
//
|
2017-02-05 15:18:41 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
2017-02-05 15:47:33 +00:00
|
|
|
void DCanvas::DrawTextCommon(FFont *font, int normalcolor, double x, double y, const char *string, DrawParms &parms)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-04-09 18:47:54 +00:00
|
|
|
int w;
|
2017-03-08 17:47:52 +00:00
|
|
|
const uint8_t *ch;
|
2016-03-01 15:47:10 +00:00
|
|
|
int c;
|
2017-02-05 15:47:33 +00:00
|
|
|
double cx;
|
|
|
|
double cy;
|
2016-03-01 15:47:10 +00:00
|
|
|
int boldcolor;
|
2016-04-09 18:47:54 +00:00
|
|
|
FRemapTable *range;
|
2016-03-01 15:47:10 +00:00
|
|
|
int kerning;
|
|
|
|
FTexture *pic;
|
2016-04-09 18:47:54 +00:00
|
|
|
|
|
|
|
if (parms.celly == 0) parms.celly = font->GetHeight() + 1;
|
|
|
|
parms.celly *= parms.scaley;
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
if (normalcolor >= NumTextColors)
|
|
|
|
normalcolor = CR_UNTRANSLATED;
|
|
|
|
boldcolor = normalcolor ? normalcolor - 1 : NumTextColors - 1;
|
|
|
|
|
2017-03-29 19:22:05 +00:00
|
|
|
PalEntry colorparm = parms.color;
|
2017-03-29 19:54:11 +00:00
|
|
|
PalEntry color = 0xffffffff;
|
2017-03-29 19:22:05 +00:00
|
|
|
range = font->GetColorTranslation((EColorRange)normalcolor, &color);
|
2017-03-29 19:54:11 +00:00
|
|
|
parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255);
|
2016-04-09 18:47:54 +00:00
|
|
|
|
2017-02-05 15:47:33 +00:00
|
|
|
kerning = font->GetDefaultKerning();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-03-08 17:47:52 +00:00
|
|
|
ch = (const uint8_t *)string;
|
2016-03-01 15:47:10 +00:00
|
|
|
cx = x;
|
|
|
|
cy = y;
|
|
|
|
|
2019-04-13 10:17:38 +00:00
|
|
|
if (parms.monospace == EMonospacing::CellCenter)
|
|
|
|
cx += parms.spacing / 2;
|
|
|
|
else if (parms.monospace == EMonospacing::CellRight)
|
|
|
|
cx += parms.spacing;
|
2017-02-05 15:47:33 +00:00
|
|
|
|
2016-04-09 18:47:54 +00:00
|
|
|
while ((const char *)ch - string < parms.maxstrlen)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-12-02 20:21:57 +00:00
|
|
|
c = GetCharFromString(ch);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (!c)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (c == TEXTCOLOR_ESCAPE)
|
|
|
|
{
|
2017-02-05 15:47:33 +00:00
|
|
|
EColorRange newcolor = V_ParseFontColor(ch, normalcolor, boldcolor);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (newcolor != CR_UNDEFINED)
|
|
|
|
{
|
2017-03-29 19:22:05 +00:00
|
|
|
range = font->GetColorTranslation(newcolor, &color);
|
2017-03-29 19:54:11 +00:00
|
|
|
parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2017-02-05 15:47:33 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
cx = x;
|
2016-04-09 18:47:54 +00:00
|
|
|
cy += parms.celly;
|
2016-03-01 15:47:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-02-05 15:47:33 +00:00
|
|
|
if (NULL != (pic = font->GetChar(c, &w)))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-04-09 18:47:54 +00:00
|
|
|
parms.remap = range;
|
|
|
|
SetTextureParms(&parms, pic, cx, cy);
|
|
|
|
if (parms.cellx)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-04-09 18:47:54 +00:00
|
|
|
w = parms.cellx;
|
|
|
|
parms.destwidth = parms.cellx;
|
|
|
|
parms.destheight = parms.celly;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2019-04-13 10:17:38 +00:00
|
|
|
if (parms.monospace == EMonospacing::CellLeft)
|
|
|
|
parms.left = 0;
|
|
|
|
else if (parms.monospace == EMonospacing::CellCenter)
|
|
|
|
parms.left = w / 2.;
|
|
|
|
else if (parms.monospace == EMonospacing::CellRight)
|
|
|
|
parms.left = w;
|
|
|
|
|
2016-04-09 18:47:54 +00:00
|
|
|
DrawTextureParms(pic, parms);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2019-04-13 10:17:38 +00:00
|
|
|
if (parms.monospace == EMonospacing::MOff)
|
|
|
|
{
|
|
|
|
cx += (w + kerning + parms.spacing) * parms.scalex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cx += (parms.spacing) * parms.scalex;
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-05 15:47:33 +00:00
|
|
|
void DCanvas::DrawText(FFont *font, int normalcolor, double x, double y, const char *string, int tag_first, ...)
|
|
|
|
{
|
2017-02-05 20:54:09 +00:00
|
|
|
Va_List tags;
|
2017-02-05 15:47:33 +00:00
|
|
|
DrawParms parms;
|
|
|
|
|
|
|
|
if (font == NULL || string == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-02-05 20:54:09 +00:00
|
|
|
va_start(tags.list, tag_first);
|
2017-02-05 15:47:33 +00:00
|
|
|
bool res = ParseDrawTextureTags(nullptr, 0, 0, tag_first, tags, &parms, true);
|
2017-02-05 20:54:09 +00:00
|
|
|
va_end(tags.list);
|
2017-02-05 15:47:33 +00:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DrawTextCommon(font, normalcolor, x, y, string, parms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DCanvas::DrawText(FFont *font, int normalcolor, double x, double y, const char *string, VMVa_List &args)
|
|
|
|
{
|
|
|
|
DrawParms parms;
|
|
|
|
|
|
|
|
if (font == NULL || string == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t tag = ListGetInt(args);
|
|
|
|
bool res = ParseDrawTextureTags(nullptr, 0, 0, tag, args, &parms, true);
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DrawTextCommon(font, normalcolor, x, y, string, parms);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(_Screen, DrawText)
|
|
|
|
{
|
|
|
|
PARAM_PROLOGUE;
|
|
|
|
PARAM_POINTER(font, FFont);
|
|
|
|
PARAM_INT(cr);
|
|
|
|
PARAM_FLOAT(x);
|
|
|
|
PARAM_FLOAT(y);
|
|
|
|
PARAM_STRING(chr);
|
|
|
|
|
2018-11-18 18:31:13 +00:00
|
|
|
PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array
|
|
|
|
|
2017-03-28 22:45:53 +00:00
|
|
|
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
|
2018-11-18 20:18:15 +00:00
|
|
|
VMVa_List args = { param + 5, 0, numparam - 6, va_reginfo + 5 };
|
2017-02-12 13:28:38 +00:00
|
|
|
const char *txt = chr[0] == '$' ? GStrings(&chr[1]) : chr.GetChars();
|
2017-02-10 12:20:19 +00:00
|
|
|
screen->DrawText(font, cr, x, y, txt, args);
|
2017-02-05 15:47:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-02-05 15:18:41 +00:00
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// Break long lines of text into multiple lines no longer than maxwidth pixels
|
|
|
|
//
|
2017-02-05 15:18:41 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
2017-03-08 17:47:52 +00:00
|
|
|
static void breakit (FBrokenLines *line, FFont *font, const uint8_t *start, const uint8_t *stop, FString &linecolor)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (!linecolor.IsEmpty())
|
|
|
|
{
|
|
|
|
line->Text = TEXTCOLOR_ESCAPE;
|
|
|
|
line->Text += linecolor;
|
|
|
|
}
|
|
|
|
line->Text.AppendCStrPart ((const char *)start, stop - start);
|
|
|
|
line->Width = font->StringWidth (line->Text);
|
|
|
|
}
|
|
|
|
|
2018-11-01 08:02:20 +00:00
|
|
|
TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *string, bool preservecolor)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-02-05 15:18:41 +00:00
|
|
|
TArray<FBrokenLines> Lines(128);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-03-08 17:47:52 +00:00
|
|
|
const uint8_t *space = NULL, *start = string;
|
2016-03-01 15:47:10 +00:00
|
|
|
int c, w, nw;
|
|
|
|
FString lastcolor, linecolor;
|
|
|
|
bool lastWasSpace = false;
|
|
|
|
int kerning = font->GetDefaultKerning ();
|
|
|
|
|
2019-04-10 15:53:57 +00:00
|
|
|
// The real isspace is a bit too badly defined, so use our own one
|
|
|
|
auto myisspace = [](int ch) { return ch == '\t' || ch == '\r' || ch == '\n' || ch == ' '; };
|
|
|
|
|
2017-02-05 15:18:41 +00:00
|
|
|
w = 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-12-02 20:21:57 +00:00
|
|
|
while ( (c = GetCharFromString(string)) )
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (c == TEXTCOLOR_ESCAPE)
|
|
|
|
{
|
|
|
|
if (*string)
|
|
|
|
{
|
|
|
|
if (*string == '[')
|
|
|
|
{
|
2017-03-08 17:47:52 +00:00
|
|
|
const uint8_t *start = string;
|
2016-03-01 15:47:10 +00:00
|
|
|
while (*string != ']' && *string != '\0')
|
|
|
|
{
|
|
|
|
string++;
|
|
|
|
}
|
|
|
|
if (*string != '\0')
|
|
|
|
{
|
|
|
|
string++;
|
|
|
|
}
|
|
|
|
lastcolor = FString((const char *)start, string - start);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastcolor = *string++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-04-10 15:53:57 +00:00
|
|
|
if (myisspace(c))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (!lastWasSpace)
|
|
|
|
{
|
|
|
|
space = string - 1;
|
|
|
|
lastWasSpace = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastWasSpace = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nw = font->GetCharWidth (c);
|
|
|
|
|
|
|
|
if ((w > 0 && w + nw > maxwidth) || c == '\n')
|
|
|
|
{ // Time to break the line
|
|
|
|
if (!space)
|
|
|
|
space = string - 1;
|
|
|
|
|
2017-02-05 15:18:41 +00:00
|
|
|
auto index = Lines.Reserve(1);
|
|
|
|
breakit (&Lines[index], font, start, space, linecolor);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (c == '\n' && !preservecolor)
|
|
|
|
{
|
|
|
|
lastcolor = ""; // Why, oh why, did I do it like this?
|
|
|
|
}
|
|
|
|
linecolor = lastcolor;
|
|
|
|
|
|
|
|
w = 0;
|
|
|
|
lastWasSpace = false;
|
|
|
|
start = space;
|
|
|
|
space = NULL;
|
|
|
|
|
2019-04-10 15:53:57 +00:00
|
|
|
while (*start && myisspace (*start) && *start != '\n')
|
2016-03-01 15:47:10 +00:00
|
|
|
start++;
|
|
|
|
if (*start == '\n')
|
|
|
|
start++;
|
|
|
|
else
|
2019-04-10 15:53:57 +00:00
|
|
|
while (*start && myisspace (*start))
|
2016-03-01 15:47:10 +00:00
|
|
|
start++;
|
|
|
|
string = start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w += nw + kerning;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// String here is pointing one character after the '\0'
|
2017-02-05 15:18:41 +00:00
|
|
|
if (--string - start >= 1)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-03-08 17:47:52 +00:00
|
|
|
const uint8_t *s = start;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
while (s < string)
|
|
|
|
{
|
|
|
|
// If there is any non-white space in the remainder of the string, add it.
|
2019-04-10 15:53:57 +00:00
|
|
|
if (!myisspace (*s++))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-02-05 15:18:41 +00:00
|
|
|
auto i = Lines.Reserve(1);
|
|
|
|
breakit (&Lines[i], font, start, string, linecolor);
|
2016-03-01 15:47:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 18:13:54 +00:00
|
|
|
return Lines;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 08:02:20 +00:00
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, FBrokenLines& g, FBrokenLines *def)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2018-11-01 08:02:20 +00:00
|
|
|
if (arc.BeginObject(key))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2018-11-01 08:02:20 +00:00
|
|
|
arc("text", g.Text)
|
|
|
|
("width", g.Width)
|
|
|
|
.EndObject();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2018-11-01 08:02:20 +00:00
|
|
|
return arc;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2017-02-05 15:18:41 +00:00
|
|
|
|
2018-11-01 08:02:20 +00:00
|
|
|
|
|
|
|
|
2017-02-05 15:18:41 +00:00
|
|
|
class DBrokenLines : public DObject
|
|
|
|
{
|
2018-11-01 08:02:20 +00:00
|
|
|
DECLARE_CLASS(DBrokenLines, DObject)
|
2017-02-05 15:18:41 +00:00
|
|
|
|
|
|
|
public:
|
2018-10-31 18:13:54 +00:00
|
|
|
TArray<FBrokenLines> mBroken;
|
2017-02-05 15:18:41 +00:00
|
|
|
|
2018-11-01 08:02:20 +00:00
|
|
|
DBrokenLines() = default;
|
|
|
|
|
2018-10-31 18:13:54 +00:00
|
|
|
DBrokenLines(TArray<FBrokenLines> &broken)
|
2017-02-05 15:18:41 +00:00
|
|
|
{
|
2018-10-31 18:13:54 +00:00
|
|
|
mBroken = std::move(broken);
|
2017-02-05 15:18:41 +00:00
|
|
|
}
|
2018-11-01 08:02:20 +00:00
|
|
|
|
|
|
|
void Serialize(FSerializer &arc) override
|
|
|
|
{
|
|
|
|
arc("lines", mBroken);
|
|
|
|
}
|
2017-02-05 15:18:41 +00:00
|
|
|
};
|
|
|
|
|
2018-11-01 08:02:20 +00:00
|
|
|
IMPLEMENT_CLASS(DBrokenLines, false, false);
|
2017-02-05 15:18:41 +00:00
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(DBrokenLines, Count)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(DBrokenLines);
|
2018-10-31 18:13:54 +00:00
|
|
|
ACTION_RETURN_INT(self->mBroken.Size());
|
2017-02-05 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(DBrokenLines, StringWidth)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(DBrokenLines);
|
|
|
|
PARAM_INT(index);
|
2018-10-31 18:13:54 +00:00
|
|
|
ACTION_RETURN_INT((unsigned)index >= self->mBroken.Size()? -1 : self->mBroken[index].Width);
|
2017-02-05 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(DBrokenLines, StringAt)
|
|
|
|
{
|
2018-12-01 13:26:15 +00:00
|
|
|
|
2017-02-05 15:18:41 +00:00
|
|
|
PARAM_SELF_PROLOGUE(DBrokenLines);
|
|
|
|
PARAM_INT(index);
|
2018-10-31 18:13:54 +00:00
|
|
|
ACTION_RETURN_STRING((unsigned)index >= self->mBroken.Size() ? -1 : self->mBroken[index].Text);
|
2017-02-05 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(FFont, BreakLines)
|
|
|
|
{
|
|
|
|
PARAM_SELF_STRUCT_PROLOGUE(FFont);
|
|
|
|
PARAM_STRING(text);
|
|
|
|
PARAM_INT(maxwidth);
|
|
|
|
|
2018-11-01 08:02:20 +00:00
|
|
|
auto broken = V_BreakLines(self, maxwidth, text, true);
|
2018-10-31 18:13:54 +00:00
|
|
|
ACTION_RETURN_OBJECT(Create<DBrokenLines>(broken));
|
2017-02-05 15:18:41 +00:00
|
|
|
}
|