diff options
author | Robert Müller <robytemueller@gmail.com> | 2022-04-22 23:07:43 +0200 |
---|---|---|
committer | Robert Müller <robytemueller@gmail.com> | 2023-06-16 20:49:40 +0200 |
commit | b9e544dbcf0d33a71e4cad87a23e0b9c5ef48089 (patch) | |
tree | fba427d3d874adcb5a4283c44b5d17aa41b3cebd | |
parent | 257de7e2e4a0a6fde3564ce60c73e42ebb8b9265 (diff) |
Don't blink caret shortly after moving, refactor using LocalTime
-rw-r--r-- | src/game/client/components/chat.cpp | 2 | ||||
-rw-r--r-- | src/game/client/components/console.cpp | 2 | ||||
-rw-r--r-- | src/game/client/lineinput.cpp | 15 | ||||
-rw-r--r-- | src/game/client/lineinput.h | 12 | ||||
-rw-r--r-- | src/game/client/ui.cpp | 6 |
5 files changed, 27 insertions, 10 deletions
diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index d6fcac9b8..b6ff10a6a 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -974,7 +974,7 @@ void CChat::OnRender() const float XScale = Graphics()->ScreenWidth()/Width; const float YScale = Graphics()->ScreenHeight()/Height; Graphics()->ClipEnable((int)(ClippingRect.x*XScale), (int)(ClippingRect.y*YScale), (int)(ClippingRect.w*XScale), (int)(ClippingRect.h*YScale)); - m_Input.Render(); + m_Input.Render(m_Input.WasChanged()); Graphics()->ClipDisable(); // scroll to keep the caret inside the clipping rect diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 5abc8af20..4aae61daa 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -560,7 +560,7 @@ void CGameConsole::OnRender() pInputCursor->MoveTo(x, y + FontSize * 1.35f); pConsole->m_Input.Activate(CONSOLE); // ensure the input is active - pConsole->m_Input.Render(); + pConsole->m_Input.Render(pConsole->m_Input.WasChanged()); y -= (pInputCursor->LineCount() - 1) * FontSize; diff --git a/src/game/client/lineinput.cpp b/src/game/client/lineinput.cpp index 6b2ec0ab4..ff6752f36 100644 --- a/src/game/client/lineinput.cpp +++ b/src/game/client/lineinput.cpp @@ -12,6 +12,7 @@ IInput *CLineInput::s_pInput = 0; ITextRender *CLineInput::s_pTextRender = 0; IGraphics *CLineInput::s_pGraphics = 0; +IClient *CLineInput::s_pClient = 0; CLineInput *CLineInput::s_pActiveInput = 0; EInputPriority CLineInput::s_ActiveInputPriority = NONE; @@ -352,7 +353,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event) return m_WasChanged; } -void CLineInput::Render() +void CLineInput::Render(bool Changed) { m_TextCursor.Reset(); @@ -399,9 +400,15 @@ void CLineInput::Render() s_pTextRender->TextDeferred(&s_MarkerCursor, "|", -1); s_MarkerCursor.MoveTo(s_pTextRender->CaretPosition(&m_TextCursor, HasComposition ? DisplayCompositionStart : DisplayCursorOffset)); - // render blinking caret - if((2*time_get()/time_freq())%2) - s_pTextRender->DrawTextOutlined(&s_MarkerCursor); + // render blinking caret, don't blink shortly after caret has been moved + { + const float LocalTime = s_pClient->LocalTime(); + static float s_LastChanged = 0.0f; + if(Changed) + s_LastChanged = LocalTime; + if(fmod(LocalTime - s_LastChanged, 1.0f) < 0.5f) + s_pTextRender->DrawTextOutlined(&s_MarkerCursor); + } m_CaretPosition = s_pTextRender->CaretPosition(&m_TextCursor, DisplayCursorOffset); s_MarkerCursor.MoveTo(m_CaretPosition); diff --git a/src/game/client/lineinput.h b/src/game/client/lineinput.h index e4895081b..6ab4d5d46 100644 --- a/src/game/client/lineinput.h +++ b/src/game/client/lineinput.h @@ -5,6 +5,7 @@ #include <base/vmath.h> +#include <engine/client.h> #include <engine/graphics.h> #include <engine/input.h> #include <engine/textrender.h> @@ -23,6 +24,7 @@ class CLineInput static IInput *s_pInput; static ITextRender *s_pTextRender; static IGraphics *s_pGraphics; + static IClient *s_pClient; static CLineInput *s_pActiveInput; static EInputPriority s_ActiveInputPriority; @@ -64,7 +66,13 @@ class CLineInput void OnDeactivate(); public: - static void Init(IInput *pInput, ITextRender *pTextRender, IGraphics *pGraphics) { s_pInput = pInput; s_pTextRender = pTextRender; s_pGraphics = pGraphics; } + static void Init(IInput *pInput, ITextRender *pTextRender, IGraphics *pGraphics, IClient *pClient) + { + s_pInput = pInput; + s_pTextRender = pTextRender; + s_pGraphics = pGraphics; + s_pClient = pClient; + } static void RenderCandidates(); static CLineInput *GetActiveInput() { return s_pActiveInput; } @@ -114,7 +122,7 @@ public: bool ProcessInput(const IInput::CEvent &Event); bool WasChanged() { bool Changed = m_WasChanged; m_WasChanged = false; return Changed; } - void Render(); + void Render(bool Changed); bool IsActive() const { return GetActiveInput() == this; } void Activate(EInputPriority Priority); diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index d62a24c27..6b5815311 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -84,7 +84,7 @@ void CUI::Init(class IKernel *pKernel) m_pInput = pKernel->RequestInterface<IInput>(); m_pTextRender = pKernel->RequestInterface<ITextRender>(); CUIRect::Init(m_pGraphics); - CLineInput::Init(m_pInput, m_pTextRender, m_pGraphics); + CLineInput::Init(m_pInput, m_pTextRender, m_pGraphics, m_pClient); CUIElementBase::Init(this); } @@ -447,6 +447,7 @@ bool CUI::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize CursorOffset = PrevOffset; if(s_SelectionStartOffset < 0) s_SelectionStartOffset = CursorOffset; + UpdateOffset = true; break; } TotalTextWidth += AddedTextWidth; @@ -456,6 +457,7 @@ bool CUI::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize CursorOffset = pLineInput->GetLength(); if(s_SelectionStartOffset < 0) s_SelectionStartOffset = CursorOffset; + UpdateOffset = true; } } } @@ -543,7 +545,7 @@ bool CUI::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize ClipEnable(pRect); Textbox.x -= ScrollOffset; ApplyCursorAlign(pCursor, &Textbox, TEXTALIGN_ML); - pLineInput->Render(); + pLineInput->Render(UpdateOffset || Changed); ClipDisable(); // check if the text has to be moved |