From 7c045a50dbe788049ca3cf7f39b666ce970cc234 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 5 Jul 2019 22:25:45 +0200 Subject: [PATCH] SDK/BaseWidget: Add Rendering rect --- ChangeLog.md | 1 + SDK/include/NDK/BaseWidget.hpp | 6 ++++++ SDK/include/NDK/BaseWidget.inl | 12 ++++++++++++ SDK/src/NDK/BaseWidget.cpp | 8 +++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5cc4c9924..e448c5df6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -272,6 +272,7 @@ Nazara Development Kit: - Added Entity::OnEntity[Disabled|Enabled] signals - Added BaseWidget::SetParent - BaseWidget::Show will no longer show entities disabled by the widget +- BaseWidget now has a rendering rect property (allowing to tell a widget what part of it will be rendered) # 0.4: diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index ec69cb813..010abd437 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -39,6 +39,7 @@ namespace Ndk inline void CenterVertical(); void ClearFocus(); + inline void ClearRenderingRect(); void Destroy(); @@ -66,6 +67,8 @@ namespace Ndk inline Nz::Vector2f GetPreferredSize() const; inline float GetPreferredWidth() const; + inline const Nz::Rectf& GetRenderingRect() const; + inline Nz::Vector2f GetSize() const; inline float GetWidth() const; inline std::size_t GetWidgetChildCount() const; @@ -93,6 +96,8 @@ namespace Ndk inline void SetMinimumSize(const Nz::Vector2f& minimumSize); inline void SetMinimumWidth(float minimumWidth); + virtual void SetRenderingRect(const Nz::Rectf& renderingRect); + void Show(bool show = true); BaseWidget& operator=(const BaseWidget&) = delete; @@ -151,6 +156,7 @@ namespace Ndk EntityOwner m_backgroundEntity; WorldHandle m_world; Nz::Color m_backgroundColor; + Nz::Rectf m_renderingRect; Nz::SpriteRef m_backgroundSprite; Nz::SystemCursor m_cursor; Nz::Vector2f m_maximumSize; diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index 4420a7a44..605220774 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -5,6 +5,7 @@ #include #include #include +#include namespace Ndk { @@ -12,6 +13,7 @@ namespace Ndk m_canvasIndex(InvalidCanvasIndex), m_canvas(nullptr), m_backgroundColor(Nz::Color(230, 230, 230, 255)), + m_renderingRect(-std::numeric_limits::infinity(), -std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity()), m_cursor(Nz::SystemCursor_Default), m_size(50.f, 50.f), m_maximumSize(std::numeric_limits::infinity()), @@ -66,6 +68,11 @@ namespace Ndk SetPosition(GetPosition(Nz::CoordSys_Local).x, (parentSize.y - mySize.y) / 2.f); } + inline void BaseWidget::ClearRenderingRect() + { + SetRenderingRect(Nz::Rectf(-std::numeric_limits::infinity(), -std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity())); + } + template inline void BaseWidget::ForEachWidgetChild(F iterator) { @@ -145,6 +152,11 @@ namespace Ndk return m_preferredSize.x; } + inline const Nz::Rectf& BaseWidget::GetRenderingRect() const + { + return m_renderingRect; + } + inline Nz::Vector2f BaseWidget::GetSize() const { return Nz::Vector2f(GetWidth(), GetHeight()); diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index ed3b8265c..647f451c6 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -336,7 +336,13 @@ namespace Ndk Nz::Vector2f widgetPos = Nz::Vector2f(GetPosition()); Nz::Vector2f widgetSize = GetSize(); - Nz::Recti fullBounds(Nz::Rectf(widgetPos.x, widgetPos.y, widgetSize.x, widgetSize.y)); + Nz::Rectf widgetRect(widgetPos.x, widgetPos.y, widgetSize.x, widgetSize.y); + Nz::Rectf widgetRenderingRect(widgetPos.x + m_renderingRect.x, widgetPos.y + m_renderingRect.y, m_renderingRect.width, m_renderingRect.height); + + Nz::Rectf widgetBounds; + widgetRect.Intersect(widgetRenderingRect, &widgetBounds); + + Nz::Recti fullBounds(widgetBounds); for (WidgetEntity& widgetEntity : m_entities) { const Ndk::EntityHandle& entity = widgetEntity.handle;