From 8887a3137cb23bcfdfe798d11d98698aed364f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 3 Dec 2021 19:46:31 +0100 Subject: [PATCH] move DoClearableEditBox to CUIEx --- src/game/client/components/menus.cpp | 21 +--------------- src/game/client/ui_ex.cpp | 36 +++++++++++++++++++++------- src/game/client/ui_ex.h | 6 +++-- src/game/editor/editor.cpp | 33 +++++++------------------ src/game/editor/editor.h | 4 ++-- 5 files changed, 44 insertions(+), 56 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index f4d093791..3616a9fac 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -603,26 +603,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS int CMenus::DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners, const char *pEmptyText) { - bool ReturnValue = false; - CUIRect EditBox; - CUIRect ClearButton; - pRect->VSplitRight(15.0f, &EditBox, &ClearButton); - if(DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, Offset, Hidden, Corners & ~CUI::CORNER_R, pEmptyText)) - { - ReturnValue = true; - } - - TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT); - RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~CUI::CORNER_L, 3.0f); - UI()->DoLabel(&ClearButton, "×", ClearButton.h * ms_FontmodHeight, 0, -1, 0); - TextRender()->SetRenderFlags(0); - if(UI()->DoButtonLogic(pClearID, "×", 0, &ClearButton)) - { - pStr[0] = 0; - UI()->SetActiveItem(pID); - ReturnValue = true; - } - return ReturnValue; + return m_UIEx.DoClearableEditBox(pID, pClearID, pRect, pStr, StrSize, FontSize, Offset, Hidden, Corners, pEmptyText); } int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key, int Modifier, int *NewModifier) diff --git a/src/game/client/ui_ex.cpp b/src/game/client/ui_ex.cpp index b52feb712..6e6c1d336 100644 --- a/src/game/client/ui_ex.cpp +++ b/src/game/client/ui_ex.cpp @@ -206,7 +206,7 @@ float CUIEx::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, return ReturnValue; } -int CUIEx::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners, const char *pEmptyText) +bool CUIEx::DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners, const char *pEmptyText) { int Inside = UI()->MouseInside(pRect); bool ReturnValue = false; @@ -518,26 +518,26 @@ int CUIEx::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSi if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || *m_pInputEventCount)) { float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits::max()); - if(w - *Offset > Textbox.w) + if(w - *pOffset > Textbox.w) { // move to the left float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, std::numeric_limits::max()); do { - *Offset += minimum(wt - *Offset - Textbox.w, Textbox.w / 3); - } while(w - *Offset > Textbox.w + 0.0001f); + *pOffset += minimum(wt - *pOffset - Textbox.w, Textbox.w / 3); + } while(w - *pOffset > Textbox.w + 0.0001f); } - else if(w - *Offset < 0.0f) + else if(w - *pOffset < 0.0f) { // move to the right do { - *Offset = maximum(0.0f, *Offset - Textbox.w / 3); - } while(w - *Offset < -0.0001f); + *pOffset = maximum(0.0f, *pOffset - Textbox.w / 3); + } while(w - *pOffset < -0.0001f); } } UI()->ClipEnable(pRect); - Textbox.x -= *Offset; + Textbox.x -= *pOffset; CTextCursor SelCursor; TextRender()->SetCursor(&SelCursor, 0, 0, 16, 0); @@ -611,3 +611,23 @@ int CUIEx::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSi return ReturnValue; } + +bool CUIEx::DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners, const char *pEmptyText) +{ + CUIRect EditBox; + CUIRect ClearButton; + pRect->VSplitRight(15.0f, &EditBox, &ClearButton); + bool ReturnValue = DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, pOffset, Hidden, Corners & ~CUI::CORNER_R, pEmptyText); + + TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT); + RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~CUI::CORNER_L, 3.0f); + UI()->DoLabel(&ClearButton, "×", ClearButton.h * /*ms_FontmodHeight*/ 0.8f, 0, -1, 0); + TextRender()->SetRenderFlags(0); + if(UI()->DoButtonLogic(pClearID, "×", 0, &ClearButton)) + { + pStr[0] = 0; + UI()->SetActiveItem(pID); + ReturnValue = true; + } + return ReturnValue; +} diff --git a/src/game/client/ui_ex.h b/src/game/client/ui_ex.h index 1a0ace56d..882fe7711 100644 --- a/src/game/client/ui_ex.h +++ b/src/game/client/ui_ex.h @@ -35,7 +35,7 @@ class CUIEx bool m_MouseSlow; int m_CurSelStart = 0; int m_CurSelEnd = 0; - void *m_pSelItem = nullptr; + const void *m_pSelItem = NULL; int m_CurCursor = 0; @@ -57,7 +57,9 @@ public: float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current); float DoScrollbarH(const void *pID, const CUIRect *pRect, float Current, const ColorRGBA *pColorInner = NULL); - int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden = false, int Corners = CUI::CORNER_ALL, const char *pEmptyText = ""); + + bool DoEditBox(const void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = CUI::CORNER_ALL, const char *pEmptyText = ""); + bool DoClearableEditBox(const void *pID, const void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = CUI::CORNER_ALL, const char *pEmptyText = ""); }; #endif diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 1cd005af5..a72c60cf8 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -304,33 +304,18 @@ void CEditor::EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, void OTHER *********************************************************/ -int CEditor::DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners) -{ - bool ReturnValue = false; - CUIRect EditBox; - CUIRect ClearButton; - pRect->VSplitRight(15.0f, &EditBox, &ClearButton); - if(DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, Offset, Hidden, Corners & ~CUI::CORNER_R)) - { - ReturnValue = true; - } - - RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * UI()->ButtonColorMul(pClearID)), Corners & ~CUI::CORNER_L, 3.0f); - UI()->DoLabel(&ClearButton, "×", ClearButton.h * 0.8f, 0); - if(UI()->DoButtonLogic(pClearID, "×", 0, &ClearButton)) - { - pStr[0] = 0; - UI()->SetActiveItem(pID); - ReturnValue = true; - } - return ReturnValue; -} - -int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners) +bool CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners) { if(UI()->LastActiveItem() == pID) m_EditBoxActive = 2; - return m_UIEx.DoEditBox(pID, pRect, pStr, StrSize, FontSize, Offset, Hidden, Corners); + return m_UIEx.DoEditBox(pID, pRect, pStr, StrSize, FontSize, pOffset, Hidden, Corners); +} + +bool CEditor::DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners) +{ + if(UI()->LastActiveItem() == pID) + m_EditBoxActive = 2; + return m_UIEx.DoClearableEditBox(pID, pClearID, pRect, pStr, StrSize, FontSize, pOffset, Hidden, Corners); } ColorRGBA CEditor::GetButtonColor(const void *pID, int Checked) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 00ee2530c..1c2ba0941 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -970,8 +970,8 @@ public: int DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip = 0); - int DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners); - int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden = false, int Corners = CUI::CORNER_ALL); + bool DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden = false, int Corners = CUI::CORNER_ALL); + bool DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden, int Corners); void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness);