Widgets: Fix new line selection not being bound to scissor box
This commit is contained in:
parent
216686e7c1
commit
8f0890f719
|
|
@ -55,6 +55,7 @@ namespace Nz
|
||||||
|
|
||||||
inline const Color& GetBackgroundColor() const;
|
inline const Color& GetBackgroundColor() const;
|
||||||
inline Canvas* GetCanvas();
|
inline Canvas* GetCanvas();
|
||||||
|
inline const Canvas* GetCanvas() const;
|
||||||
inline SystemCursor GetCursor() const;
|
inline SystemCursor GetCursor() const;
|
||||||
inline float GetHeight() const;
|
inline float GetHeight() const;
|
||||||
|
|
||||||
|
|
@ -123,6 +124,7 @@ namespace Nz
|
||||||
|
|
||||||
void InvalidateNode(Invalidation invalidation) override;
|
void InvalidateNode(Invalidation invalidation) override;
|
||||||
|
|
||||||
|
Recti GetScissorBox() const;
|
||||||
Rectf GetScissorRect() const;
|
Rectf GetScissorRect() const;
|
||||||
|
|
||||||
virtual bool IsFocusable() const;
|
virtual bool IsFocusable() const;
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,11 @@ namespace Nz
|
||||||
return m_canvas;
|
return m_canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Canvas* BaseWidget::GetCanvas() const
|
||||||
|
{
|
||||||
|
return m_canvas;
|
||||||
|
}
|
||||||
|
|
||||||
inline SystemCursor BaseWidget::GetCursor() const
|
inline SystemCursor BaseWidget::GetCursor() const
|
||||||
{
|
{
|
||||||
return m_cursor;
|
return m_cursor;
|
||||||
|
|
@ -359,4 +364,5 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Widgets/DebugOff.hpp>
|
#include <Nazara/Widgets/DebugOff.hpp>
|
||||||
|
#include "BaseWidget.hpp"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -563,6 +563,9 @@ namespace Nz
|
||||||
std::size_t oldSpriteCount = m_cursors.size();
|
std::size_t oldSpriteCount = m_cursors.size();
|
||||||
if (m_cursors.size() < selectionLineCount)
|
if (m_cursors.size() < selectionLineCount)
|
||||||
{
|
{
|
||||||
|
Recti scissorBox = GetScissorBox();
|
||||||
|
bool isVisible = IsVisible() && HasFocus();
|
||||||
|
|
||||||
m_cursors.resize(selectionLineCount);
|
m_cursors.resize(selectionLineCount);
|
||||||
for (std::size_t i = oldSpriteCount; i < m_cursors.size(); ++i)
|
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].sprite->UpdateRenderLayer(GetBaseRenderLayer() + 1);
|
||||||
|
|
||||||
m_cursors[i].entity = CreateEntity();
|
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);
|
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)
|
else if (m_cursors.size() > selectionLineCount)
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,23 @@ namespace Nz
|
||||||
UpdatePositionAndSize();
|
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
|
Rectf BaseWidget::GetScissorRect() const
|
||||||
{
|
{
|
||||||
Vector2f widgetPos = Vector2f(GetPosition(CoordSys::Global));
|
Vector2f widgetPos = Vector2f(GetPosition(CoordSys::Global));
|
||||||
|
|
@ -419,25 +436,13 @@ namespace Nz
|
||||||
if (IsRegisteredToCanvas())
|
if (IsRegisteredToCanvas())
|
||||||
m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex);
|
m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex);
|
||||||
|
|
||||||
Rectf scissorRect = GetScissorRect();
|
Recti scissorBox = GetScissorBox();
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
auto& registry = GetRegistry();
|
auto& registry = GetRegistry();
|
||||||
for (WidgetEntity& widgetEntity : m_entities)
|
for (WidgetEntity& widgetEntity : m_entities)
|
||||||
{
|
{
|
||||||
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(widgetEntity.handle))
|
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(widgetEntity.handle))
|
||||||
gfx->UpdateScissorBox(fullBounds);
|
gfx->UpdateScissorBox(scissorBox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue