Minor fixes

This commit is contained in:
Jérôme Leclercq 2021-11-28 20:19:37 +01:00
parent 0c3bcf6c86
commit 01cd4986cc
20 changed files with 112 additions and 88 deletions

View File

@ -61,7 +61,7 @@
// Number of spinlocks to use with the Windows critical sections (0 to disable)
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096
// Optimize the Windows implementation with technologies of Windows NT 6.0 (and greater) (Break the compatibility with Windows XP)
// Optimize the Windows implementation with technologies of Windows NT 6.0 (and greater) (Breaks the compatibility with Windows XP)
#define NAZARA_CORE_WINDOWS_NT6 1

View File

@ -16,9 +16,15 @@ namespace Nz
inline void Model::SetMaterial(std::size_t subMeshIndex, std::shared_ptr<Material> material)
{
assert(subMeshIndex < m_submeshes.size());
assert(material);
OnMaterialInvalidated(this, subMeshIndex, material);
if (m_submeshes[subMeshIndex].material != material)
{
OnMaterialInvalidated(this, 0, material);
m_submeshes[subMeshIndex].material = std::move(material);
OnElementInvalidated(this);
}
}
}

View File

@ -29,8 +29,8 @@ namespace Nz
inline const Color& GetColor() const;
inline const Color& GetCornerColor(RectCorner corner) const;
const std::shared_ptr<Material>& GetMaterial(std::size_t i = 0) const;
std::size_t GetMaterialCount() const;
const std::shared_ptr<Material>& GetMaterial(std::size_t i = 0) const override;
std::size_t GetMaterialCount() const override;
inline const Rectf& GetTextureCoords() const;
Vector3ui GetTextureSize() const;

View File

@ -41,7 +41,13 @@ namespace Nz
{
assert(material);
if (m_material != material)
{
OnMaterialInvalidated(this, 0, material);
m_material = std::move(material);
OnElementInvalidated(this);
}
}
inline void Sprite::SetSize(const Vector2f& size)
@ -68,7 +74,7 @@ namespace Nz
{
VertexStruct_XYZ_Color_UV* vertices = m_vertices.data();
Vector3f origin = Vector3f::Zero();
Vector3f origin = Vector3f::Zero(); //< TODO
Boxf aabb;
vertices->color = m_color * m_cornerColor[UnderlyingCast(RectCorner::LeftBottom)];

View File

@ -32,8 +32,8 @@ namespace Nz
inline void Clear();
const std::shared_ptr<Material>& GetMaterial(std::size_t i) const;
std::size_t GetMaterialCount() const;
const std::shared_ptr<Material>& GetMaterial(std::size_t i = 0) const override;
std::size_t GetMaterialCount() const override;
inline void SetMaterial(std::shared_ptr<Material> material);

View File

@ -17,7 +17,15 @@ namespace Nz
inline void TextSprite::SetMaterial(std::shared_ptr<Material> material)
{
assert(material);
if (m_material != material)
{
OnMaterialInvalidated(this, 0, material);
m_material = std::move(material);
OnElementInvalidated(this);
}
}
}

View File

@ -15,7 +15,7 @@ namespace Nz
{
/*!
* \ingroup math
* \class Nz::Vector2
* \class Vector2
* \brief Math class that represents an element of the two dimensional vector space
*/
@ -443,10 +443,7 @@ namespace Nz
template<typename T>
std::string Vector2<T>::ToString() const
{
std::ostringstream ss;
ss << *this;
return ss.str();
return "Vector2(" + std::to_string(x) + ", " + std::to_string(y) + ')';
}
/*!

View File

@ -11,6 +11,15 @@
namespace Nz
{
enum class ClipboardContentType
{
Unknown = -1,
Text,
Max = Text
};
enum class SystemCursor
{
Crosshair,

View File

@ -42,6 +42,8 @@ namespace Nz
static void SetPosition(const Vector2i& position, const Window& relativeTo, bool ignoreEvent = true);
static void SetPosition(int x, int y);
static void SetPosition(int x, int y, const Window& relativeTo, bool ignoreEvent = true);
static constexpr std::size_t ButtonCount = static_cast<std::size_t>(Max + 1);
};
}

View File

@ -31,7 +31,7 @@ namespace Nz
class NAZARA_PLATFORM_API Window
{
friend WindowImpl;
friend class EventImpl;
friend class InputImpl;
friend class Mouse;
friend class Platform;

View File

@ -42,7 +42,6 @@ namespace Nz
inline EchoMode GetEchoMode() const;
inline std::size_t GetGlyphIndex() const;
inline std::size_t GetGlyphIndex(const Vector2ui& cursorPosition) const;
inline const std::string& GetText() const;
Vector2ui GetHoveredGlyph(float x, float y) const;

View File

@ -213,6 +213,9 @@ namespace Nz
if (toPosition.y < fromPosition.y || (toPosition.y == fromPosition.y && toPosition.x < fromPosition.x))
std::swap(fromPosition, toPosition);
fromPosition = NormalizeCursorPosition(fromPosition);
toPosition = NormalizeCursorPosition(toPosition);
if (m_cursorPositionBegin != fromPosition || m_cursorPositionEnd != toPosition)
{
OnTextAreaSelection(this, &fromPosition, &toPosition);

View File

@ -52,24 +52,24 @@ namespace Nz
inline const Color& GetBackgroundColor() const;
inline Canvas* GetCanvas();
inline Nz::SystemCursor GetCursor() const;
inline SystemCursor GetCursor() const;
inline float GetHeight() const;
inline float GetMaximumHeight() const;
inline Nz::Vector2f GetMaximumSize() const;
inline Vector2f GetMaximumSize() const;
inline float GetMaximumWidth() const;
inline float GetMinimumHeight() const;
inline Nz::Vector2f GetMinimumSize() const;
inline Vector2f GetMinimumSize() const;
inline float GetMinimumWidth() const;
inline float GetPreferredHeight() const;
inline Nz::Vector2f GetPreferredSize() const;
inline Vector2f GetPreferredSize() const;
inline float GetPreferredWidth() const;
inline const Nz::Rectf& GetRenderingRect() const;
inline const Rectf& GetRenderingRect() const;
inline Nz::Vector2f GetSize() const;
inline Vector2f GetSize() const;
inline float GetWidth() const;
inline std::size_t GetWidgetChildCount() const;
@ -78,26 +78,26 @@ namespace Nz
inline void Hide();
inline bool IsVisible() const;
void Resize(const Nz::Vector2f& size);
void Resize(const Vector2f& size);
void SetBackgroundColor(const Color& color);
void SetCursor(Nz::SystemCursor systemCursor);
void SetCursor(SystemCursor systemCursor);
void SetFocus();
void SetParent(BaseWidget* widget);
inline void SetFixedHeight(float fixedHeight);
inline void SetFixedSize(const Nz::Vector2f& fixedSize);
inline void SetFixedSize(const Vector2f& fixedSize);
inline void SetFixedWidth(float fixedWidth);
inline void SetMaximumHeight(float maximumHeight);
inline void SetMaximumSize(const Nz::Vector2f& maximumSize);
inline void SetMaximumSize(const Vector2f& maximumSize);
inline void SetMaximumWidth(float maximumWidth);
inline void SetMinimumHeight(float minimumHeight);
inline void SetMinimumSize(const Nz::Vector2f& minimumSize);
inline void SetMinimumSize(const Vector2f& minimumSize);
inline void SetMinimumWidth(float minimumWidth);
virtual void SetRenderingRect(const Nz::Rectf& renderingRect);
virtual void SetRenderingRect(const Rectf& renderingRect);
void Show(bool show = true);
@ -105,32 +105,34 @@ namespace Nz
BaseWidget& operator=(BaseWidget&&) = delete;
protected:
entt::entity CreateEntity();
void DestroyEntity(entt::entity entity);
virtual void Layout();
void InvalidateNode() override;
entt::entity CreateEntity();
void DestroyEntity(entt::entity entity);
inline entt::registry& GetRegistry();
inline const entt::registry& GetRegistry() const;
Nz::Rectf GetScissorRect() const;
void InvalidateNode() override;
Rectf GetScissorRect() const;
virtual bool IsFocusable() const;
virtual void OnFocusLost();
virtual void OnFocusReceived();
virtual bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key);
virtual bool OnKeyPressed(const WindowEvent::KeyEvent& key);
virtual void OnKeyReleased(const WindowEvent::KeyEvent& key);
virtual void OnMouseEnter();
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button);
virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button);
virtual void OnMouseButtonPress(int x, int y, Mouse::Button button);
virtual void OnMouseButtonRelease(int x, int y, Mouse::Button button);
virtual void OnMouseWheelMoved(int x, int y, float delta);
virtual void OnMouseExit();
virtual void OnParentResized(const Nz::Vector2f& newSize);
virtual void OnParentResized(const Vector2f& newSize);
virtual void OnTextEntered(char32_t character, bool repeated);
virtual void OnTextEdited(const std::array<char, 32>& characters, int length);
inline void SetPreferredSize(const Nz::Vector2f& preferredSize);
inline void SetPreferredSize(const Vector2f& preferredSize);
virtual void ShowChildren(bool show);
@ -140,7 +142,7 @@ namespace Nz
void DestroyChild(BaseWidget* widget);
void DestroyChildren();
inline bool IsRegisteredToCanvas() const;
inline void NotifyParentResized(const Nz::Vector2f& newSize);
inline void NotifyParentResized(const Vector2f& newSize);
void RegisterToCanvas();
inline void UpdateCanvasIndex(std::size_t index);
void UnregisterFromCanvas();
@ -149,10 +151,6 @@ namespace Nz
struct WidgetEntity
{
entt::entity handle;
bool isEnabled = true;
//NazaraSlot(Ndk::Entity, OnEntityDisabled, onDisabledSlot);
//NazaraSlot(Ndk::Entity, OnEntityEnabled, onEnabledSlot);
};
static constexpr std::size_t InvalidCanvasIndex = std::numeric_limits<std::size_t>::max();

View File

@ -16,7 +16,7 @@ namespace Nz
m_canvas(nullptr),
m_backgroundColor(Color(230, 230, 230, 255)),
m_renderingRect(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()),
m_cursor(Nz::SystemCursor::Default),
m_cursor(SystemCursor::Default),
m_maximumSize(std::numeric_limits<float>::infinity()),
m_minimumSize(0.f),
m_preferredSize(-1),
@ -47,8 +47,8 @@ namespace Nz
{
NazaraAssert(m_widgetParent, "Widget has no parent");
Nz::Vector2f parentSize = m_widgetParent->GetSize();
Nz::Vector2f mySize = GetSize();
Vector2f parentSize = m_widgetParent->GetSize();
Vector2f mySize = GetSize();
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
}
@ -56,23 +56,23 @@ namespace Nz
{
NazaraAssert(m_widgetParent, "Widget has no parent");
Nz::Vector2f parentSize = m_widgetParent->GetSize();
Nz::Vector2f mySize = GetSize();
SetPosition((parentSize.x - mySize.x) / 2.f, GetPosition(Nz::CoordSys::Local).y);
Vector2f parentSize = m_widgetParent->GetSize();
Vector2f mySize = GetSize();
SetPosition((parentSize.x - mySize.x) / 2.f, GetPosition(CoordSys::Local).y);
}
inline void BaseWidget::CenterVertical()
{
NazaraAssert(m_widgetParent, "Widget has no parent");
Nz::Vector2f parentSize = m_widgetParent->GetSize();
Nz::Vector2f mySize = GetSize();
SetPosition(GetPosition(Nz::CoordSys::Local).x, (parentSize.y - mySize.y) / 2.f);
Vector2f parentSize = m_widgetParent->GetSize();
Vector2f mySize = GetSize();
SetPosition(GetPosition(CoordSys::Local).x, (parentSize.y - mySize.y) / 2.f);
}
inline void BaseWidget::ClearRenderingRect()
{
SetRenderingRect(Nz::Rectf(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()));
SetRenderingRect(Rectf(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()));
}
template<typename F>
@ -99,7 +99,7 @@ namespace Nz
return m_canvas;
}
inline Nz::SystemCursor BaseWidget::GetCursor() const
inline SystemCursor BaseWidget::GetCursor() const
{
return m_cursor;
}
@ -114,7 +114,7 @@ namespace Nz
return m_maximumSize.y;
}
inline Nz::Vector2f BaseWidget::GetMaximumSize() const
inline Vector2f BaseWidget::GetMaximumSize() const
{
return m_maximumSize;
}
@ -129,7 +129,7 @@ namespace Nz
return m_minimumSize.y;
}
inline Nz::Vector2f BaseWidget::GetMinimumSize() const
inline Vector2f BaseWidget::GetMinimumSize() const
{
return m_minimumSize;
}
@ -144,7 +144,7 @@ namespace Nz
return m_preferredSize.y;
}
inline Nz::Vector2f BaseWidget::GetPreferredSize() const
inline Vector2f BaseWidget::GetPreferredSize() const
{
return m_preferredSize;
}
@ -154,14 +154,14 @@ namespace Nz
return m_preferredSize.x;
}
inline const Nz::Rectf& BaseWidget::GetRenderingRect() const
inline const Rectf& BaseWidget::GetRenderingRect() const
{
return m_renderingRect;
}
inline Nz::Vector2f BaseWidget::GetSize() const
inline Vector2f BaseWidget::GetSize() const
{
return Nz::Vector2f(GetWidth(), GetHeight());
return Vector2f(GetWidth(), GetHeight());
}
inline float BaseWidget::GetWidth() const
@ -190,7 +190,7 @@ namespace Nz
SetMinimumHeight(fixedHeight);
}
inline void BaseWidget::SetFixedSize(const Nz::Vector2f& fixedSize)
inline void BaseWidget::SetFixedSize(const Vector2f& fixedSize)
{
SetMaximumSize(fixedSize);
SetMinimumSize(fixedSize);
@ -204,24 +204,24 @@ namespace Nz
inline void BaseWidget::SetMaximumHeight(float maximumHeight)
{
Nz::Vector2f maximumSize = GetMaximumSize();
Vector2f maximumSize = GetMaximumSize();
maximumSize.y = maximumHeight;
SetMaximumSize(maximumSize);
}
inline void BaseWidget::SetMaximumSize(const Nz::Vector2f& maximumSize)
inline void BaseWidget::SetMaximumSize(const Vector2f& maximumSize)
{
m_maximumSize = maximumSize;
Nz::Vector2f size = GetSize();
Vector2f size = GetSize();
if (size.x > m_maximumSize.x || size.y > m_maximumSize.y)
Resize(size); //< Will clamp automatically
}
inline void BaseWidget::SetMaximumWidth(float maximumWidth)
{
Nz::Vector2f maximumSize = GetMaximumSize();
Vector2f maximumSize = GetMaximumSize();
maximumSize.x = maximumWidth;
SetMaximumSize(maximumSize);
@ -229,30 +229,30 @@ namespace Nz
inline void BaseWidget::SetMinimumHeight(float minimumHeight)
{
Nz::Vector2f minimumSize = GetMinimumSize();
Vector2f minimumSize = GetMinimumSize();
minimumSize.y = minimumHeight;
SetMinimumSize(minimumSize);
}
inline void BaseWidget::SetMinimumSize(const Nz::Vector2f& minimumSize)
inline void BaseWidget::SetMinimumSize(const Vector2f& minimumSize)
{
m_minimumSize = minimumSize;
Nz::Vector2f size = GetSize();
Vector2f size = GetSize();
if (size.x < m_minimumSize.x || size.y < m_minimumSize.y)
Resize(size); //< Will clamp automatically
}
inline void BaseWidget::SetMinimumWidth(float minimumWidth)
{
Nz::Vector2f minimumSize = GetMinimumSize();
Vector2f minimumSize = GetMinimumSize();
minimumSize.x = minimumWidth;
SetMinimumSize(minimumSize);
}
inline void BaseWidget::SetPreferredSize(const Nz::Vector2f& preferredSize)
inline void BaseWidget::SetPreferredSize(const Vector2f& preferredSize)
{
m_preferredSize = preferredSize;
@ -276,7 +276,7 @@ namespace Nz
return m_canvas && m_canvasIndex != InvalidCanvasIndex;
}
inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize)
inline void BaseWidget::NotifyParentResized(const Vector2f& newSize)
{
for (const auto& widgetPtr : m_children)
widgetPtr->OnParentResized(newSize);

View File

@ -246,6 +246,7 @@ namespace Nz
if (viewerData.rebuildDepthPrepass)
{
renderFrame.PushForRelease(std::move(viewerData.depthPrepassRenderElements));
viewerData.depthPrepassRenderElements.clear();
for (const auto& renderableData : m_visibleRenderables)
@ -268,6 +269,7 @@ namespace Nz
if (viewerData.rebuildForwardPass)
{
renderFrame.PushForRelease(std::move(viewerData.forwardRenderElements));
viewerData.forwardRenderElements.clear();
for (const auto& renderableData : m_visibleRenderables)

View File

@ -194,7 +194,6 @@ namespace Nz
Nz::TextureInfo texInfo;
texInfo.width = texInfo.height = texInfo.depth = texInfo.mipmapLevel = 1;
texInfo.pixelFormat = PixelFormat::L8;
texInfo.type = ImageType::E2D;
std::array<UInt8, 6> whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

View File

@ -75,6 +75,6 @@ namespace Nz
}
// Couldn't get material pass or texture
return Vector3ui::Zero();
return Vector3ui::Unit(); //< prevents division by zero
}
}

View File

@ -43,7 +43,7 @@ namespace Nz
CameraComponent& entityCamera = registry.get<CameraComponent>(entity);
NodeComponent& entityNode = registry.get<NodeComponent>(entity);
m_pipeline->RegisterViewer(&entityCamera);
m_pipeline->RegisterViewer(&entityCamera, entityCamera.GetRenderOrder());
m_invalidatedCameraNode.insert(entity);

View File

@ -120,6 +120,11 @@ namespace Nz
return Vector2ui::Zero();
}
bool AbstractTextAreaWidget::IsFocusable() const
{
return !m_readOnly;
}
void AbstractTextAreaWidget::Layout()
{
BaseWidget::Layout();
@ -135,11 +140,6 @@ namespace Nz
RefreshCursor();
}
bool AbstractTextAreaWidget::IsFocusable() const
{
return !m_readOnly;
}
void AbstractTextAreaWidget::OnFocusLost()
{
// Hide cursors
@ -367,7 +367,7 @@ namespace Nz
m_isMouseButtonDown = false;
}
void AbstractTextAreaWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
void AbstractTextAreaWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
{
if (m_isMouseButtonDown)
SetSelection(m_selectionCursor, GetHoveredGlyph(float(x), float(y)));

View File

@ -186,14 +186,9 @@ namespace Nz
auto& registry = GetRegistry();
for (WidgetEntity& entity : m_entities)
{
if (entity.isEnabled)
{
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(entity.handle))
gfx->Show(show);
entity.isEnabled = true;
}
}
ShowChildren(show);