2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_TEXTRENDER_H
|
|
|
|
#define ENGINE_TEXTRENDER_H
|
|
|
|
#include "kernel.h"
|
|
|
|
|
2019-04-26 22:34:20 +00:00
|
|
|
#include <base/color.h>
|
2012-08-12 10:41:50 +00:00
|
|
|
#include <engine/graphics.h>
|
2020-08-29 10:10:38 +00:00
|
|
|
#include <stdint.h>
|
2019-04-26 22:34:20 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
TEXTFLAG_RENDER = 1,
|
|
|
|
TEXTFLAG_ALLOW_NEWLINE = 2,
|
|
|
|
TEXTFLAG_STOP_AT_END = 4
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2022-01-21 15:20:15 +00:00
|
|
|
enum ETextAlignment
|
|
|
|
{
|
|
|
|
TEXTALIGN_LEFT = 1 << 0,
|
|
|
|
TEXTALIGN_CENTER = 1 << 1,
|
|
|
|
TEXTALIGN_RIGHT = 1 << 2,
|
|
|
|
};
|
|
|
|
|
2018-03-13 20:49:07 +00:00
|
|
|
enum ETextRenderFlags
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
TEXT_RENDER_FLAG_NO_X_BEARING = 1 << 0,
|
|
|
|
TEXT_RENDER_FLAG_NO_Y_BEARING = 1 << 1,
|
|
|
|
TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH = 1 << 2,
|
|
|
|
TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT = 1 << 3,
|
|
|
|
TEXT_RENDER_FLAG_KERNING = 1 << 4,
|
|
|
|
TEXT_RENDER_FLAG_NO_OVERSIZE = 1 << 5,
|
|
|
|
TEXT_RENDER_FLAG_NO_FIRST_CHARACTER_X_BEARING = 1 << 6,
|
|
|
|
TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE = 1 << 7,
|
2020-10-22 20:21:19 +00:00
|
|
|
TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD = 1 << 8,
|
2018-03-13 20:49:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEXT_FONT_ICON_FONT = 0,
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CFont;
|
|
|
|
|
2021-09-12 17:40:23 +00:00
|
|
|
enum ETextCursorSelectionMode
|
|
|
|
{
|
|
|
|
// ignore any kind of selection
|
|
|
|
TEXT_CURSOR_SELECTION_MODE_NONE = 0,
|
|
|
|
// calculates the selection based on the mouse press and release cursor position
|
|
|
|
TEXT_CURSOR_SELECTION_MODE_CALCULATE,
|
|
|
|
// sets the selection based on the character start and end count(these values have to be decoded character offsets)
|
|
|
|
TEXT_CURSOR_SELECTION_MODE_SET,
|
|
|
|
};
|
|
|
|
|
2021-09-16 14:50:17 +00:00
|
|
|
enum ETextCursorCursorMode
|
|
|
|
{
|
|
|
|
// ignore any kind of cursor
|
|
|
|
TEXT_CURSOR_CURSOR_MODE_NONE = 0,
|
|
|
|
// calculates the cursor based on the mouse release cursor position
|
|
|
|
TEXT_CURSOR_CURSOR_MODE_CALCULATE,
|
|
|
|
// sets the cursor based on the current character (this value has to be decoded character offset)
|
|
|
|
TEXT_CURSOR_CURSOR_MODE_SET,
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CTextCursor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int m_Flags;
|
|
|
|
int m_LineCount;
|
2020-09-03 22:53:26 +00:00
|
|
|
int m_GlyphCount;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_CharCount;
|
2010-10-11 00:29:30 +00:00
|
|
|
int m_MaxLines;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float m_StartX;
|
|
|
|
float m_StartY;
|
|
|
|
float m_LineWidth;
|
|
|
|
float m_X, m_Y;
|
2020-10-06 10:25:10 +00:00
|
|
|
float m_MaxCharacterHeight;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-10-13 20:08:52 +00:00
|
|
|
float m_LongestLineWidth;
|
|
|
|
|
2010-07-05 18:57:07 +00:00
|
|
|
CFont *m_pFont;
|
2010-05-29 07:25:38 +00:00
|
|
|
float m_FontSize;
|
2018-03-21 14:43:56 +00:00
|
|
|
float m_AlignedFontSize;
|
2021-09-12 17:40:23 +00:00
|
|
|
|
|
|
|
ETextCursorSelectionMode m_CalculateSelectionMode;
|
|
|
|
|
|
|
|
// these coordinates are repsected if selection mode is set to calculate @see ETextCursorSelectionMode
|
|
|
|
int m_PressMouseX;
|
|
|
|
int m_PressMouseY;
|
2021-09-16 14:50:17 +00:00
|
|
|
// these coordinates are repsected if selection/cursor mode is set to calculate @see ETextCursorSelectionMode / @see ETextCursorCursorMode
|
2021-09-12 17:40:23 +00:00
|
|
|
int m_ReleaseMouseX;
|
|
|
|
int m_ReleaseMouseY;
|
|
|
|
|
|
|
|
// note m_SelectionStart can be bigger than m_SelectionEnd, depending on how the mouse cursor was dragged
|
|
|
|
// also note, that these are the character offsets decoded
|
|
|
|
int m_SelectionStart;
|
|
|
|
int m_SelectionEnd;
|
2021-09-16 14:50:17 +00:00
|
|
|
|
|
|
|
ETextCursorCursorMode m_CursorMode;
|
|
|
|
// note this is the decoded character offset
|
|
|
|
int m_CursorCharacter;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2018-03-13 20:49:07 +00:00
|
|
|
struct STextRenderColor
|
|
|
|
{
|
|
|
|
STextRenderColor() {}
|
|
|
|
STextRenderColor(float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
Set(r, g, b, a);
|
|
|
|
}
|
2020-10-12 10:29:47 +00:00
|
|
|
STextRenderColor(const ColorRGBA &TextColorRGBA)
|
|
|
|
{
|
|
|
|
Set(TextColorRGBA.r, TextColorRGBA.g, TextColorRGBA.b, TextColorRGBA.a);
|
|
|
|
}
|
2018-03-13 20:49:07 +00:00
|
|
|
|
|
|
|
void Set(float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
m_R = r;
|
|
|
|
m_G = g;
|
|
|
|
m_B = b;
|
|
|
|
m_A = a;
|
|
|
|
}
|
|
|
|
|
2020-11-08 18:41:16 +00:00
|
|
|
bool operator!=(const STextRenderColor &Other)
|
|
|
|
{
|
|
|
|
return m_R != Other.m_R || m_G != Other.m_G || m_B != Other.m_B || m_A != Other.m_A;
|
|
|
|
}
|
|
|
|
|
2021-09-13 21:14:04 +00:00
|
|
|
operator ColorRGBA()
|
|
|
|
{
|
|
|
|
return ColorRGBA(m_R, m_G, m_B, m_A);
|
|
|
|
}
|
|
|
|
|
2018-03-13 20:49:07 +00:00
|
|
|
float m_R, m_G, m_B, m_A;
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class ITextRender : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("textrender", 0)
|
|
|
|
public:
|
|
|
|
virtual void SetCursor(CTextCursor *pCursor, float x, float y, float FontSize, int Flags) = 0;
|
2020-10-13 20:08:52 +00:00
|
|
|
virtual void MoveCursor(CTextCursor *pCursor, float x, float y) = 0;
|
2020-10-29 00:55:01 +00:00
|
|
|
virtual void SetCursorPosition(CTextCursor *pCursor, float x, float y) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-13 21:02:01 +00:00
|
|
|
virtual CFont *LoadFont(const char *pFilename, const unsigned char *pBuf, size_t Size) = 0;
|
|
|
|
virtual bool LoadFallbackFont(CFont *pFont, const char *pFilename, const unsigned char *pBuf, size_t Size) = 0;
|
2018-03-13 20:49:07 +00:00
|
|
|
virtual CFont *GetFont(int FontIndex) = 0;
|
|
|
|
virtual CFont *GetFont(const char *pFilename) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-08-20 09:22:25 +00:00
|
|
|
virtual void SetDefaultFont(CFont *pFont) = 0;
|
2018-03-13 20:49:07 +00:00
|
|
|
virtual void SetCurFont(CFont *pFont) = 0;
|
|
|
|
|
|
|
|
virtual void SetRenderFlags(unsigned int Flags) = 0;
|
2020-10-22 20:21:19 +00:00
|
|
|
virtual unsigned int GetRenderFlags() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2020-10-12 10:29:47 +00:00
|
|
|
ColorRGBA DefaultTextColor() { return ColorRGBA(1, 1, 1, 1); }
|
|
|
|
ColorRGBA DefaultTextOutlineColor() { return ColorRGBA(0, 0, 0, 0.3f); }
|
2021-09-12 17:40:23 +00:00
|
|
|
ColorRGBA DefaultSelectionColor() { return ColorRGBA(0, 0, 1.0f, 1.0f); }
|
2020-10-12 10:29:47 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
//
|
|
|
|
virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length) = 0;
|
2020-10-12 10:29:47 +00:00
|
|
|
virtual int CreateTextContainer(CTextCursor *pCursor, const char *pText, int Length = -1) = 0;
|
|
|
|
virtual void AppendTextContainer(CTextCursor *pCursor, int TextContainerIndex, const char *pText, int Length = -1) = 0;
|
2018-03-13 20:49:07 +00:00
|
|
|
// just deletes and creates text container
|
2020-10-12 10:29:47 +00:00
|
|
|
virtual void RecreateTextContainer(CTextCursor *pCursor, int TextContainerIndex, const char *pText, int Length = -1) = 0;
|
|
|
|
virtual void RecreateTextContainerSoft(CTextCursor *pCursor, int TextContainerIndex, const char *pText, int Length = -1) = 0;
|
2018-03-13 20:49:07 +00:00
|
|
|
virtual void DeleteTextContainer(int TextContainerIndex) = 0;
|
|
|
|
|
2020-10-22 20:21:19 +00:00
|
|
|
virtual void UploadTextContainer(int TextContainerIndex) = 0;
|
|
|
|
|
2018-03-13 20:49:07 +00:00
|
|
|
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor) = 0;
|
|
|
|
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor, float X, float Y) = 0;
|
|
|
|
|
2020-09-14 14:39:05 +00:00
|
|
|
virtual void UploadEntityLayerText(void *pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontHeight) = 0;
|
2020-08-29 10:10:38 +00:00
|
|
|
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize, int MaxWidth) = 0;
|
2019-08-17 00:42:54 +00:00
|
|
|
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-09-12 17:40:23 +00:00
|
|
|
virtual bool SelectionToUTF8OffSets(const char *pText, int SelStart, int SelEnd, int &OffUTF8Start, int &OffUTF8End) = 0;
|
2021-09-16 14:50:17 +00:00
|
|
|
virtual bool UTF8OffToDecodedOff(const char *pText, int UTF8Off, int &DecodedOff) = 0;
|
|
|
|
virtual bool DecodedOffToUTF8Off(const char *pText, int DecodedOff, int &UTF8Off) = 0;
|
2021-09-12 17:40:23 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// old foolish interface
|
|
|
|
virtual void TextColor(float r, float g, float b, float a) = 0;
|
2019-04-26 22:34:20 +00:00
|
|
|
virtual void TextColor(ColorRGBA rgb) = 0;
|
2011-03-13 11:55:00 +00:00
|
|
|
virtual void TextOutlineColor(float r, float g, float b, float a) = 0;
|
2020-10-12 10:29:47 +00:00
|
|
|
virtual void TextOutlineColor(ColorRGBA rgb) = 0;
|
2021-09-12 17:40:23 +00:00
|
|
|
virtual void TextSelectionColor(float r, float g, float b, float a) = 0;
|
|
|
|
virtual void TextSelectionColor(ColorRGBA rgb) = 0;
|
2020-07-15 19:42:48 +00:00
|
|
|
virtual void Text(void *pFontSetV, float x, float y, float Size, const char *pText, float LineWidth) = 0;
|
2020-10-06 10:25:10 +00:00
|
|
|
virtual float TextWidth(void *pFontSetV, float Size, const char *pText, int StrLength, float LineWidth, float *pAlignedHeight = NULL, float *pMaxCharacterHeightInLine = NULL) = 0;
|
2010-08-16 00:21:18 +00:00
|
|
|
virtual int TextLineCount(void *pFontSetV, float Size, const char *pText, float LineWidth) = 0;
|
2018-03-21 14:43:56 +00:00
|
|
|
|
2020-11-08 18:41:16 +00:00
|
|
|
virtual ColorRGBA GetTextColor() = 0;
|
|
|
|
virtual ColorRGBA GetTextOutlineColor() = 0;
|
2021-09-12 17:40:23 +00:00
|
|
|
virtual ColorRGBA GetTextSelectionColor() = 0;
|
2020-11-08 18:41:16 +00:00
|
|
|
|
2018-03-21 14:43:56 +00:00
|
|
|
virtual void OnWindowResize() = 0;
|
2020-10-16 18:00:57 +00:00
|
|
|
|
|
|
|
virtual float GetGlyphOffsetX(int FontSize, char TextCharacter) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IEngineTextRender : public ITextRender
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("enginetextrender", 0)
|
|
|
|
public:
|
|
|
|
virtual void Init() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern IEngineTextRender *CreateEngineTextRender();
|
|
|
|
|
|
|
|
#endif
|