mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-13 03:28:19 +00:00
Refactor CUIElements
This commit is contained in:
parent
7f5ca0ffe1
commit
1e07a00c3b
|
@ -1188,8 +1188,8 @@ void CMenus::OnInit()
|
||||||
|
|
||||||
m_UIEx.Init(UI(), Kernel(), RenderTools(), m_aInputEvents, &m_NumInputEvents);
|
m_UIEx.Init(UI(), Kernel(), RenderTools(), m_aInputEvents, &m_NumInputEvents);
|
||||||
|
|
||||||
m_RefreshButton.Init(UI());
|
m_RefreshButton.Init(UI(), -1);
|
||||||
m_ConnectButton.Init(UI());
|
m_ConnectButton.Init(UI(), -1);
|
||||||
|
|
||||||
Console()->Chain("add_favorite", ConchainServerbrowserUpdate, this);
|
Console()->Chain("add_favorite", ConchainServerbrowserUpdate, this);
|
||||||
Console()->Chain("remove_favorite", ConchainServerbrowserUpdate, this);
|
Console()->Chain("remove_favorite", ConchainServerbrowserUpdate, this);
|
||||||
|
|
|
@ -130,12 +130,12 @@ class CMenus : public CComponent
|
||||||
Text.HMargin(pRect->h >= 20.0f ? 2.0f : 1.0f, &Text);
|
Text.HMargin(pRect->h >= 20.0f ? 2.0f : 1.0f, &Text);
|
||||||
Text.HMargin((Text.h * FontFactor) / 2.0f, &Text);
|
Text.HMargin((Text.h * FontFactor) / 2.0f, &Text);
|
||||||
|
|
||||||
if(UIElement.Size() != 3 || HintRequiresStringCheck || HintCanChangePositionOrSize)
|
if(!UIElement.AreRectsInit() || HintRequiresStringCheck || HintCanChangePositionOrSize || UIElement.Get(0)->m_UITextContainer == -1)
|
||||||
{
|
{
|
||||||
bool NeedsRecalc = UIElement.Size() != 3;
|
bool NeedsRecalc = !UIElement.AreRectsInit() || UIElement.Get(0)->m_UITextContainer == -1;
|
||||||
if(HintCanChangePositionOrSize)
|
if(HintCanChangePositionOrSize)
|
||||||
{
|
{
|
||||||
if(UIElement.Size() == 3)
|
if(UIElement.AreRectsInit())
|
||||||
{
|
{
|
||||||
if(UIElement.Get(0)->m_X != pRect->x || UIElement.Get(0)->m_Y != pRect->y || UIElement.Get(0)->m_Width != pRect->w || UIElement.Get(0)->m_Y != pRect->h)
|
if(UIElement.Get(0)->m_X != pRect->x || UIElement.Get(0)->m_Y != pRect->y || UIElement.Get(0)->m_Width != pRect->w || UIElement.Get(0)->m_Y != pRect->h)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +146,7 @@ class CMenus : public CComponent
|
||||||
const char *pText = NULL;
|
const char *pText = NULL;
|
||||||
if(HintRequiresStringCheck)
|
if(HintRequiresStringCheck)
|
||||||
{
|
{
|
||||||
if(UIElement.Size() == 3)
|
if(UIElement.AreRectsInit())
|
||||||
{
|
{
|
||||||
pText = GetTextLambda();
|
pText = GetTextLambda();
|
||||||
if(str_comp(UIElement.Get(0)->m_Text.c_str(), pText) != 0)
|
if(str_comp(UIElement.Get(0)->m_Text.c_str(), pText) != 0)
|
||||||
|
@ -157,10 +157,11 @@ class CMenus : public CComponent
|
||||||
}
|
}
|
||||||
if(NeedsRecalc)
|
if(NeedsRecalc)
|
||||||
{
|
{
|
||||||
if(UIElement.Size() > 0)
|
if(!UIElement.AreRectsInit())
|
||||||
{
|
{
|
||||||
UI()->ResetUIElement(UIElement);
|
UIElement.InitRects(3);
|
||||||
}
|
}
|
||||||
|
UI()->ResetUIElement(UIElement);
|
||||||
|
|
||||||
vec4 RealColor = Color;
|
vec4 RealColor = Color;
|
||||||
for(int i = 0; i < 3; ++i)
|
for(int i = 0; i < 3; ++i)
|
||||||
|
@ -174,14 +175,13 @@ class CMenus : public CComponent
|
||||||
Color.a *= ButtonColorMulDefault();
|
Color.a *= ButtonColorMulDefault();
|
||||||
Graphics()->SetColor(Color);
|
Graphics()->SetColor(Color);
|
||||||
|
|
||||||
CUIElement::SUIElementRect NewRect;
|
CUIElement::SUIElementRect &NewRect = *UIElement.Get(i);
|
||||||
NewRect.m_UIRectQuadContainer = RenderTools()->CreateRoundRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, r, Corners);
|
NewRect.m_UIRectQuadContainer = RenderTools()->CreateRoundRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, r, Corners);
|
||||||
|
|
||||||
NewRect.m_X = pRect->x;
|
NewRect.m_X = pRect->x;
|
||||||
NewRect.m_Y = pRect->y;
|
NewRect.m_Y = pRect->y;
|
||||||
NewRect.m_Width = pRect->w;
|
NewRect.m_Width = pRect->w;
|
||||||
NewRect.m_Height = pRect->h;
|
NewRect.m_Height = pRect->h;
|
||||||
|
|
||||||
if(i == 0)
|
if(i == 0)
|
||||||
{
|
{
|
||||||
if(pText == NULL)
|
if(pText == NULL)
|
||||||
|
@ -189,12 +189,10 @@ class CMenus : public CComponent
|
||||||
NewRect.m_Text = pText;
|
NewRect.m_Text = pText;
|
||||||
UI()->DoLabel(NewRect, &Text, pText, Text.h * ms_FontmodHeight, 0, -1, AlignVertically);
|
UI()->DoLabel(NewRect, &Text, pText, Text.h * ms_FontmodHeight, 0, -1, AlignVertically);
|
||||||
}
|
}
|
||||||
UIElement.Add(NewRect);
|
|
||||||
}
|
}
|
||||||
Graphics()->SetColor(1, 1, 1, 1);
|
Graphics()->SetColor(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// render
|
// render
|
||||||
size_t Index = 2;
|
size_t Index = 2;
|
||||||
if(UI()->ActiveItem() == pID)
|
if(UI()->ActiveItem() == pID)
|
||||||
|
@ -207,7 +205,6 @@ class CMenus : public CComponent
|
||||||
STextRenderColor ColorTextOutline(TextRender()->DefaultTextOutlineColor());
|
STextRenderColor ColorTextOutline(TextRender()->DefaultTextOutlineColor());
|
||||||
if(UIElement.Get(0)->m_UITextContainer != -1)
|
if(UIElement.Get(0)->m_UITextContainer != -1)
|
||||||
TextRender()->RenderTextContainer(UIElement.Get(0)->m_UITextContainer, &ColorText, &ColorTextOutline);
|
TextRender()->RenderTextContainer(UIElement.Get(0)->m_UITextContainer, &ColorText, &ColorTextOutline);
|
||||||
|
|
||||||
return UI()->DoButtonLogic(pID, Checked, pRect);
|
return UI()->DoButtonLogic(pID, Checked, pRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -233,23 +233,11 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
|
||||||
CUIRect Row;
|
CUIRect Row;
|
||||||
CUIRect SelectHitBox;
|
CUIRect SelectHitBox;
|
||||||
|
|
||||||
|
const int UIRectCount = 2 + (COL_VERSION + 1) * 3;
|
||||||
//initialize
|
//initialize
|
||||||
if(pItem->m_pUIElement == NULL)
|
if(pItem->m_pUIElement == NULL)
|
||||||
{
|
{
|
||||||
pItem->m_pUIElement = UI()->GetNewUIElement();
|
pItem->m_pUIElement = UI()->GetNewUIElement(UIRectCount);
|
||||||
}
|
|
||||||
|
|
||||||
const int UIRectCount = 2 + (COL_VERSION + 1) * 3;
|
|
||||||
|
|
||||||
if(pItem->m_pUIElement->Size() != UIRectCount)
|
|
||||||
{
|
|
||||||
UI()->ResetUIElement(*pItem->m_pUIElement);
|
|
||||||
|
|
||||||
for(int UIElIndex = 0; UIElIndex < UIRectCount; ++UIElIndex)
|
|
||||||
{
|
|
||||||
CUIElement::SUIElementRect AddRect;
|
|
||||||
pItem->m_pUIElement->Add(AddRect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Selected = str_comp(pItem->m_aAddress, g_Config.m_UiServerAddress) == 0; //selected_index==ItemIndex;
|
int Selected = str_comp(pItem->m_aAddress, g_Config.m_UiServerAddress) == 0; //selected_index==ItemIndex;
|
||||||
|
|
|
@ -448,7 +448,7 @@ int CRenderTools::CreateRoundRectQuadContainer(float x, float y, float w, float
|
||||||
void CRenderTools::DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding)
|
void CRenderTools::DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding)
|
||||||
{
|
{
|
||||||
bool NeedsRecreate = false;
|
bool NeedsRecreate = false;
|
||||||
if(ElUIRect.m_UIRectQuadContainer == -1 || ElUIRect.m_X != pRect->x || ElUIRect.m_Y != pRect->y || ElUIRect.m_Width != pRect->w || ElUIRect.m_Height != pRect->h)
|
if(ElUIRect.m_UIRectQuadContainer == -1 || ElUIRect.m_X != pRect->x || ElUIRect.m_Y != pRect->y || ElUIRect.m_Width != pRect->w || ElUIRect.m_Height != pRect->h || mem_comp(&ElUIRect.m_QuadColor, &Color, sizeof(Color)) != 0)
|
||||||
{
|
{
|
||||||
if(ElUIRect.m_UIRectQuadContainer != -1)
|
if(ElUIRect.m_UIRectQuadContainer != -1)
|
||||||
Graphics()->DeleteQuadContainer(ElUIRect.m_UIRectQuadContainer);
|
Graphics()->DeleteQuadContainer(ElUIRect.m_UIRectQuadContainer);
|
||||||
|
@ -460,6 +460,7 @@ void CRenderTools::DrawUIElRect(CUIElement::SUIElementRect &ElUIRect, const CUIR
|
||||||
ElUIRect.m_Y = pRect->y;
|
ElUIRect.m_Y = pRect->y;
|
||||||
ElUIRect.m_Width = pRect->w;
|
ElUIRect.m_Width = pRect->w;
|
||||||
ElUIRect.m_Height = pRect->h;
|
ElUIRect.m_Height = pRect->h;
|
||||||
|
ElUIRect.m_QuadColor = Color;
|
||||||
|
|
||||||
Graphics()->SetColor(Color);
|
Graphics()->SetColor(Color);
|
||||||
ElUIRect.m_UIRectQuadContainer = CreateRoundRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, Rounding, Corners);
|
ElUIRect.m_UIRectQuadContainer = CreateRoundRectQuadContainer(pRect->x, pRect->y, pRect->w, pRect->h, Rounding, Corners);
|
||||||
|
|
|
@ -8,17 +8,34 @@
|
||||||
#include <engine/shared/config.h>
|
#include <engine/shared/config.h>
|
||||||
#include <engine/textrender.h>
|
#include <engine/textrender.h>
|
||||||
|
|
||||||
void CUIElement::Init(CUI *pUI)
|
void CUIElement::Init(CUI *pUI, int RequestedRectCount)
|
||||||
{
|
{
|
||||||
pUI->AddUIElement(this);
|
pUI->AddUIElement(this);
|
||||||
|
if(RequestedRectCount > 0)
|
||||||
|
m_UIRects.resize(RequestedRectCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUIElement::SUIElementRect::SUIElementRect() :
|
void CUIElement::InitRects(int RequestedRectCount)
|
||||||
m_UIRectQuadContainer(-1), m_UITextContainer(-1), m_X(-1), m_Y(-1), m_Width(-1), m_Height(-1)
|
|
||||||
{
|
{
|
||||||
|
dbg_assert(m_UIRects.size() == 0, "UI rects can only be initialized once, create another ui element instead.");
|
||||||
|
m_UIRects.resize(RequestedRectCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
CUIElement::SUIElementRect::SUIElementRect() { Reset(); }
|
||||||
|
|
||||||
|
void CUIElement::SUIElementRect::Reset()
|
||||||
|
{
|
||||||
|
m_UIRectQuadContainer = -1;
|
||||||
|
m_UITextContainer = -1;
|
||||||
|
m_X = -1;
|
||||||
|
m_Y = -1;
|
||||||
|
m_Width = -1;
|
||||||
|
m_Height = -1;
|
||||||
|
m_Text.clear();
|
||||||
mem_zero(&m_Cursor, sizeof(m_Cursor));
|
mem_zero(&m_Cursor, sizeof(m_Cursor));
|
||||||
mem_zero(&m_TextColor, sizeof(m_TextColor));
|
m_TextColor.Set(-1, -1, -1, -1);
|
||||||
mem_zero(&m_TextOutlineColor, sizeof(m_TextOutlineColor));
|
m_TextOutlineColor.Set(-1, -1, -1, -1);
|
||||||
|
m_QuadColor = ColorRGBA(-1, -1, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
|
@ -54,9 +71,9 @@ CUI::~CUI()
|
||||||
m_OwnUIElements.clear();
|
m_OwnUIElements.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CUIElement *CUI::GetNewUIElement()
|
CUIElement *CUI::GetNewUIElement(int RequestedRectCount)
|
||||||
{
|
{
|
||||||
CUIElement *pNewEl = new CUIElement(this);
|
CUIElement *pNewEl = new CUIElement(this, RequestedRectCount);
|
||||||
|
|
||||||
m_OwnUIElements.push_back(pNewEl);
|
m_OwnUIElements.push_back(pNewEl);
|
||||||
|
|
||||||
|
@ -78,9 +95,9 @@ void CUI::ResetUIElement(CUIElement &UIElement)
|
||||||
if(Rect.m_UITextContainer != -1)
|
if(Rect.m_UITextContainer != -1)
|
||||||
TextRender()->DeleteTextContainer(Rect.m_UITextContainer);
|
TextRender()->DeleteTextContainer(Rect.m_UITextContainer);
|
||||||
Rect.m_UITextContainer = -1;
|
Rect.m_UITextContainer = -1;
|
||||||
}
|
|
||||||
|
|
||||||
UIElement.Clear();
|
Rect.Reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUI::OnElementsReset()
|
void CUI::OnElementsReset()
|
||||||
|
@ -407,68 +424,45 @@ int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
float CUI::DoTextLabel(float x, float y, float w, float h, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically, bool StopAtEnd)
|
||||||
int CUI::DoButton(const void *id, const char *text, int checked, const CUIRect *r, ui_draw_button_func draw_func, const void *extra)
|
|
||||||
{
|
|
||||||
// logic
|
|
||||||
int ret = 0;
|
|
||||||
int inside = ui_MouseInside(r);
|
|
||||||
static int button_used = 0;
|
|
||||||
|
|
||||||
if(ui_ActiveItem() == id)
|
|
||||||
{
|
|
||||||
if(!ui_MouseButton(button_used))
|
|
||||||
{
|
|
||||||
if(inside && checked >= 0)
|
|
||||||
ret = 1+button_used;
|
|
||||||
ui_SetActiveItem(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(ui_HotItem() == id)
|
|
||||||
{
|
|
||||||
if(ui_MouseButton(0))
|
|
||||||
{
|
|
||||||
ui_SetActiveItem(id);
|
|
||||||
button_used = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ui_MouseButton(1))
|
|
||||||
{
|
|
||||||
ui_SetActiveItem(id);
|
|
||||||
button_used = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(inside)
|
|
||||||
ui_SetHotItem(id);
|
|
||||||
|
|
||||||
if(draw_func)
|
|
||||||
draw_func(id, text, checked, r, extra);
|
|
||||||
return ret;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically)
|
|
||||||
{
|
{
|
||||||
float AlignedSize = 0;
|
float AlignedSize = 0;
|
||||||
float MaxCharacterHeightInLine = 0;
|
float MaxCharacterHeightInLine = 0;
|
||||||
float tw = TextRender()->TextWidth(0, Size, pText, -1, MaxWidth, &AlignedSize, &MaxCharacterHeightInLine);
|
float tw = TextRender()->TextWidth(0, Size, pText, -1, MaxWidth, &AlignedSize, &MaxCharacterHeightInLine);
|
||||||
float AlignmentVert = r->y + (r->h - AlignedSize) / 2.f;
|
|
||||||
|
int Flags = TEXTFLAG_RENDER | (StopAtEnd ? TEXTFLAG_STOP_AT_END : 0);
|
||||||
|
|
||||||
|
float AlignmentVert = y + (h - AlignedSize) / 2.f;
|
||||||
|
float AlignmentHori = 0;
|
||||||
if(AlignVertically == 0)
|
if(AlignVertically == 0)
|
||||||
{
|
{
|
||||||
AlignmentVert = r->y + (r->h - AlignedSize) / 2.f - (AlignedSize - MaxCharacterHeightInLine) / 2.f;
|
AlignmentVert = y + (h - AlignedSize) / 2.f - (AlignedSize - MaxCharacterHeightInLine) / 2.f;
|
||||||
}
|
}
|
||||||
if(Align == 0)
|
if(Align == 0)
|
||||||
{
|
{
|
||||||
TextRender()->Text(0, r->x + (r->w - tw) / 2.f, AlignmentVert, Size, pText, MaxWidth);
|
AlignmentHori = x + (w - tw) / 2.f;
|
||||||
}
|
}
|
||||||
else if(Align < 0)
|
else if(Align < 0)
|
||||||
{
|
{
|
||||||
TextRender()->Text(0, r->x, AlignmentVert, Size, pText, MaxWidth);
|
AlignmentHori = x;
|
||||||
}
|
}
|
||||||
else if(Align > 0)
|
else if(Align > 0)
|
||||||
{
|
{
|
||||||
TextRender()->Text(0, r->x + r->w - tw, AlignmentVert, Size, pText, MaxWidth);
|
AlignmentHori = x + w - tw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CTextCursor Cursor;
|
||||||
|
TextRender()->SetCursor(&Cursor, AlignmentHori, AlignmentVert, Size, Flags);
|
||||||
|
Cursor.m_LineWidth = (float)MaxWidth;
|
||||||
|
|
||||||
|
TextRender()->TextEx(&Cursor, pText, -1);
|
||||||
|
|
||||||
|
return tw;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically)
|
||||||
|
{
|
||||||
|
DoTextLabel(r->x, r->y, r->w, r->h, pText, Size, Align, MaxWidth, AlignVertically);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically)
|
void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically)
|
||||||
|
@ -515,17 +509,21 @@ void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, cons
|
||||||
}
|
}
|
||||||
Cursor.m_LineWidth = MaxWidth;
|
Cursor.m_LineWidth = MaxWidth;
|
||||||
|
|
||||||
RectEl.m_UITextContainer = TextRender()->CreateTextContainer(&Cursor, pText, StrLen);
|
|
||||||
RectEl.m_Cursor = Cursor;
|
|
||||||
RectEl.m_TextColor = TextRender()->GetTextColor();
|
RectEl.m_TextColor = TextRender()->GetTextColor();
|
||||||
RectEl.m_TextOutlineColor = TextRender()->GetTextOutlineColor();
|
RectEl.m_TextOutlineColor = TextRender()->GetTextOutlineColor();
|
||||||
|
TextRender()->TextColor(TextRender()->DefaultTextColor());
|
||||||
|
TextRender()->TextOutlineColor(TextRender()->DefaultTextOutlineColor());
|
||||||
|
RectEl.m_UITextContainer = TextRender()->CreateTextContainer(&Cursor, pText, StrLen);
|
||||||
|
TextRender()->TextColor(RectEl.m_TextColor);
|
||||||
|
TextRender()->TextOutlineColor(RectEl.m_TextOutlineColor);
|
||||||
|
RectEl.m_Cursor = Cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor)
|
void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, float x, float y, float w, float h, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor)
|
||||||
{
|
{
|
||||||
bool NeedsRecreate = false;
|
bool NeedsRecreate = false;
|
||||||
bool ColorChanged = RectEl.m_TextColor != TextRender()->GetTextColor() || RectEl.m_TextOutlineColor != TextRender()->GetTextOutlineColor();
|
bool ColorChanged = RectEl.m_TextColor != TextRender()->GetTextColor() || RectEl.m_TextOutlineColor != TextRender()->GetTextOutlineColor();
|
||||||
if(RectEl.m_UITextContainer == -1 || RectEl.m_X != pRect->x || RectEl.m_Y != pRect->y || RectEl.m_Width != pRect->w || RectEl.m_Height != pRect->h || ColorChanged)
|
if(RectEl.m_UITextContainer == -1 || RectEl.m_X != x || RectEl.m_Y != y || RectEl.m_Width != w || RectEl.m_Height != h || ColorChanged)
|
||||||
{
|
{
|
||||||
NeedsRecreate = true;
|
NeedsRecreate = true;
|
||||||
}
|
}
|
||||||
|
@ -542,17 +540,16 @@ void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRe
|
||||||
NeedsRecreate = true;
|
NeedsRecreate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NeedsRecreate)
|
if(NeedsRecreate)
|
||||||
{
|
{
|
||||||
if(RectEl.m_UITextContainer != -1)
|
if(RectEl.m_UITextContainer != -1)
|
||||||
TextRender()->DeleteTextContainer(RectEl.m_UITextContainer);
|
TextRender()->DeleteTextContainer(RectEl.m_UITextContainer);
|
||||||
RectEl.m_UITextContainer = -1;
|
RectEl.m_UITextContainer = -1;
|
||||||
|
|
||||||
RectEl.m_X = pRect->x;
|
RectEl.m_X = x;
|
||||||
RectEl.m_Y = pRect->y;
|
RectEl.m_Y = y;
|
||||||
RectEl.m_Width = pRect->w;
|
RectEl.m_Width = w;
|
||||||
RectEl.m_Height = pRect->h;
|
RectEl.m_Height = h;
|
||||||
|
|
||||||
if(StrLen > 0)
|
if(StrLen > 0)
|
||||||
RectEl.m_Text = std::string(pText, StrLen);
|
RectEl.m_Text = std::string(pText, StrLen);
|
||||||
|
@ -561,11 +558,21 @@ void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRe
|
||||||
else
|
else
|
||||||
RectEl.m_Text.clear();
|
RectEl.m_Text.clear();
|
||||||
|
|
||||||
DoLabel(RectEl, pRect, pText, Size, Align, MaxWidth, AlignVertically, StopAtEnd, StrLen, pReadCursor);
|
CUIRect TmpRect;
|
||||||
|
TmpRect.x = x;
|
||||||
|
TmpRect.y = y;
|
||||||
|
TmpRect.w = w;
|
||||||
|
TmpRect.h = h;
|
||||||
|
DoLabel(RectEl, &TmpRect, pText, Size, Align, MaxWidth, AlignVertically, StopAtEnd, StrLen, pReadCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
STextRenderColor ColorText(TextRender()->DefaultTextColor());
|
STextRenderColor ColorText(RectEl.m_TextColor);
|
||||||
STextRenderColor ColorTextOutline(TextRender()->DefaultTextOutlineColor());
|
STextRenderColor ColorTextOutline(RectEl.m_TextOutlineColor);
|
||||||
if(RectEl.m_UITextContainer != -1)
|
if(RectEl.m_UITextContainer != -1)
|
||||||
TextRender()->RenderTextContainer(RectEl.m_UITextContainer, &ColorText, &ColorTextOutline);
|
TextRender()->RenderTextContainer(RectEl.m_UITextContainer, &ColorText, &ColorTextOutline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor)
|
||||||
|
{
|
||||||
|
DoLabelStreamed(RectEl, pRect->x, pRect->y, pRect->w, pRect->h, pText, Size, Align, MaxWidth, AlignVertically, StopAtEnd, StrLen, pReadCursor);
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits 2 CUIRect inside *this* CUIRect horizontally. You can pass null pointers.
|
* Splits 2 CUIRect inside *this* CUIRect horizontally. You can pass null pointers.
|
||||||
*
|
*
|
||||||
* @param pTop This rect will end up taking the top half of this CUIRect
|
* @param pTop This rect will end up taking the top half of this CUIRect
|
||||||
* @param pBottom This rect will end up taking the bottom half of this CUIRect
|
* @param pBottom This rect will end up taking the bottom half of this CUIRect
|
||||||
*/
|
*/
|
||||||
|
@ -123,7 +123,7 @@ class CUIElement
|
||||||
{
|
{
|
||||||
friend class CUI;
|
friend class CUI;
|
||||||
|
|
||||||
CUIElement(CUI *pUI) { Init(pUI); }
|
CUIElement(CUI *pUI, int RequestedRectCount) { Init(pUI, RequestedRectCount); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct SUIElementRect
|
struct SUIElementRect
|
||||||
|
@ -145,6 +145,10 @@ public:
|
||||||
STextRenderColor m_TextOutlineColor;
|
STextRenderColor m_TextOutlineColor;
|
||||||
|
|
||||||
SUIElementRect();
|
SUIElementRect();
|
||||||
|
|
||||||
|
ColorRGBA m_QuadColor;
|
||||||
|
|
||||||
|
void Reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -156,24 +160,19 @@ protected:
|
||||||
public:
|
public:
|
||||||
CUIElement() = default;
|
CUIElement() = default;
|
||||||
|
|
||||||
void Init(CUI *pUI);
|
void Init(CUI *pUI, int RequestedRectCount);
|
||||||
|
|
||||||
SUIElementRect *Get(size_t Index)
|
SUIElementRect *Get(size_t Index)
|
||||||
{
|
{
|
||||||
return &m_UIRects[Index];
|
return &m_UIRects[Index];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Size()
|
bool AreRectsInit()
|
||||||
{
|
{
|
||||||
return m_UIRects.size();
|
return m_UIRects.size() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear() { m_UIRects.clear(); }
|
void InitRects(int RequestedRectCount);
|
||||||
|
|
||||||
void Add(SUIElementRect &ElRect)
|
|
||||||
{
|
|
||||||
m_UIRects.push_back(ElRect);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CUI
|
class CUI
|
||||||
|
@ -210,7 +209,7 @@ public:
|
||||||
|
|
||||||
void ResetUIElement(CUIElement &UIElement);
|
void ResetUIElement(CUIElement &UIElement);
|
||||||
|
|
||||||
CUIElement *GetNewUIElement();
|
CUIElement *GetNewUIElement(int RequestedRectCount);
|
||||||
|
|
||||||
void AddUIElement(CUIElement *pElement);
|
void AddUIElement(CUIElement *pElement);
|
||||||
void OnElementsReset();
|
void OnElementsReset();
|
||||||
|
@ -273,11 +272,12 @@ public:
|
||||||
int DoButtonLogic(const void *pID, const char *pText /* TODO: Refactor: Remove */, int Checked, const CUIRect *pRect);
|
int DoButtonLogic(const void *pID, const char *pText /* TODO: Refactor: Remove */, int Checked, const CUIRect *pRect);
|
||||||
int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY);
|
int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY);
|
||||||
|
|
||||||
// TODO: Refactor: Remove this?
|
float DoTextLabel(float x, float y, float w, float h, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false);
|
||||||
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1);
|
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1);
|
||||||
void DoLabelScaled(const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1);
|
void DoLabelScaled(const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1);
|
||||||
|
|
||||||
void DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
|
void DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
|
||||||
|
void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, float x, float y, float w, float h, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
|
||||||
void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
|
void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, int AlignVertically = 1, bool StopAtEnd = false, int StrLen = -1, class CTextCursor *pReadCursor = NULL);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue