Render selection in front of text instead of behind it

Makes the text selection easier to see, especially when the text selection height is lower than normal.

Change text selection color to light grey instead of blue.
This commit is contained in:
Robert Müller 2023-04-14 15:04:51 +02:00
parent ca90d83c10
commit 08b0a03ca4
2 changed files with 24 additions and 21 deletions

View file

@ -1590,14 +1590,6 @@ public:
const STextContainer &TextContainer = GetTextContainer(TextContainerIndex);
const CFont *pFont = TextContainer.m_pFont;
if(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex != -1 && TextContainer.m_HasSelection)
{
Graphics()->TextureClear();
Graphics()->SetColor(m_SelectionColor);
Graphics()->RenderQuadContainerEx(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, TextContainer.m_HasCursor ? 2 : 0, -1, 0, 0);
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
}
if(TextContainer.m_StringInfo.m_QuadNum > 0)
{
if(Graphics()->IsTextBufferingEnabled())
@ -1653,21 +1645,32 @@ public:
}
}
if(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex != -1 && TextContainer.m_HasCursor)
if(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex != -1)
{
const auto CurTime = time_get_nanoseconds();
Graphics()->TextureClear();
if((CurTime - m_CursorRenderTime) > 500ms)
if(TextContainer.m_HasSelection)
{
Graphics()->SetColor(TextOutlineColor);
Graphics()->RenderQuadContainerEx(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, 0, 1, 0, 0);
Graphics()->SetColor(TextColor);
Graphics()->RenderQuadContainerEx(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, 1, 1, 0, 0);
Graphics()->TextureClear();
Graphics()->SetColor(m_SelectionColor);
Graphics()->RenderQuadContainerEx(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, TextContainer.m_HasCursor ? 2 : 0, -1, 0, 0);
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
}
if(TextContainer.m_HasCursor)
{
const auto CurTime = time_get_nanoseconds();
Graphics()->TextureClear();
if((CurTime - m_CursorRenderTime) > 500ms)
{
Graphics()->SetColor(TextOutlineColor);
Graphics()->RenderQuadContainerEx(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, 0, 1, 0, 0);
Graphics()->SetColor(TextColor);
Graphics()->RenderQuadContainerEx(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, 1, 1, 0, 0);
}
if((CurTime - m_CursorRenderTime) > 1s)
m_CursorRenderTime = time_get_nanoseconds();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
}
if((CurTime - m_CursorRenderTime) > 1s)
m_CursorRenderTime = time_get_nanoseconds();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
}
}

View file

@ -233,7 +233,7 @@ public:
ColorRGBA DefaultTextColor() const { return ColorRGBA(1, 1, 1, 1); }
ColorRGBA DefaultTextOutlineColor() const { return ColorRGBA(0, 0, 0, 0.3f); }
ColorRGBA DefaultTextSelectionColor() const { return ColorRGBA(0, 0, 1.0f, 1.0f); }
ColorRGBA DefaultTextSelectionColor() const { return ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f); }
//
virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length = -1) = 0;