Widgets: Fix new line selection not being bound to scissor box

This commit is contained in:
SirLynix 2023-08-23 17:33:59 +02:00
parent 216686e7c1
commit 8f0890f719
4 changed files with 34 additions and 15 deletions

View File

@ -55,6 +55,7 @@ namespace Nz
inline const Color& GetBackgroundColor() const;
inline Canvas* GetCanvas();
inline const Canvas* GetCanvas() const;
inline SystemCursor GetCursor() const;
inline float GetHeight() const;
@ -123,6 +124,7 @@ namespace Nz
void InvalidateNode(Invalidation invalidation) override;
Recti GetScissorBox() const;
Rectf GetScissorRect() const;
virtual bool IsFocusable() const;

View File

@ -113,6 +113,11 @@ namespace Nz
return m_canvas;
}
inline const Canvas* BaseWidget::GetCanvas() const
{
return m_canvas;
}
inline SystemCursor BaseWidget::GetCursor() const
{
return m_cursor;
@ -359,4 +364,5 @@ namespace Nz
}
#include <Nazara/Widgets/DebugOff.hpp>
#include "BaseWidget.hpp"

View File

@ -563,6 +563,9 @@ namespace Nz
std::size_t oldSpriteCount = m_cursors.size();
if (m_cursors.size() < selectionLineCount)
{
Recti scissorBox = GetScissorBox();
bool isVisible = IsVisible() && HasFocus();
m_cursors.resize(selectionLineCount);
for (std::size_t i = oldSpriteCount; i < m_cursors.size(); ++i)
{
@ -570,8 +573,11 @@ namespace Nz
m_cursors[i].sprite->UpdateRenderLayer(GetBaseRenderLayer() + 1);
m_cursors[i].entity = CreateEntity();
registry.emplace<GraphicsComponent>(m_cursors[i].entity, IsVisible() && HasFocus()).AttachRenderable(m_cursors[i].sprite, GetCanvas()->GetRenderMask());
registry.emplace<NodeComponent>(m_cursors[i].entity).SetParent(textNode);
auto& cursorGfx = registry.emplace<GraphicsComponent>(m_cursors[i].entity, isVisible);
cursorGfx.AttachRenderable(m_cursors[i].sprite, GetCanvas()->GetRenderMask());
cursorGfx.UpdateScissorBox(scissorBox);
}
}
else if (m_cursors.size() > selectionLineCount)

View File

@ -253,6 +253,23 @@ namespace Nz
UpdatePositionAndSize();
}
Recti BaseWidget::GetScissorBox() const
{
Rectf scissorRect = GetScissorRect();
if (m_parentWidget)
{
Rectf parentScissorRect = m_parentWidget->GetScissorRect();
if (!scissorRect.Intersect(parentScissorRect, &scissorRect))
scissorRect = parentScissorRect;
}
scissorRect.y = GetCanvas()->GetSize().y - scissorRect.height - scissorRect.y; //< scissor rect is in screen coordinates
return Recti(scissorRect);
}
Rectf BaseWidget::GetScissorRect() const
{
Vector2f widgetPos = Vector2f(GetPosition(CoordSys::Global));
@ -419,25 +436,13 @@ namespace Nz
if (IsRegisteredToCanvas())
m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex);
Rectf scissorRect = GetScissorRect();
if (m_parentWidget)
{
Rectf parentScissorRect = m_parentWidget->GetScissorRect();
if (!scissorRect.Intersect(parentScissorRect, &scissorRect))
scissorRect = parentScissorRect;
}
scissorRect.y = GetCanvas()->GetSize().y - scissorRect.height - scissorRect.y; //< scissor rect is in screen coordinates
Recti fullBounds(scissorRect);
Recti scissorBox = GetScissorBox();
auto& registry = GetRegistry();
for (WidgetEntity& widgetEntity : m_entities)
{
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(widgetEntity.handle))
gfx->UpdateScissorBox(fullBounds);
gfx->UpdateScissorBox(scissorBox);
}
}
}