Remove Graphics module and fix compilation
This commit is contained in:
@@ -15,11 +15,7 @@
|
||||
#include <set>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NazaraSDK/Canvas.hpp>
|
||||
#include <NazaraSDK/Console.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Platform/Window.hpp>
|
||||
#endif
|
||||
|
||||
@@ -28,11 +24,6 @@ namespace Ndk
|
||||
class NDK_API Application
|
||||
{
|
||||
public:
|
||||
#ifndef NDK_SERVER
|
||||
struct ConsoleOverlay;
|
||||
struct FPSCounterOverlay;
|
||||
#endif
|
||||
|
||||
inline Application();
|
||||
Application(int argc, char* argv[]);
|
||||
Application(const Application&) = delete;
|
||||
@@ -44,14 +35,6 @@ namespace Ndk
|
||||
#endif
|
||||
template<typename... Args> World& AddWorld(Args&&... args);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
inline void EnableConsole(bool enable);
|
||||
inline void EnableFPSCounter(bool enable);
|
||||
|
||||
inline ConsoleOverlay& GetConsoleOverlay(std::size_t windowIndex = 0U);
|
||||
inline FPSCounterOverlay& GetFPSCounterOverlay(std::size_t windowIndex = 0U);
|
||||
#endif
|
||||
|
||||
inline const std::set<Nz::String>& GetOptions() const;
|
||||
inline const std::map<Nz::String, Nz::String>& GetParameters() const;
|
||||
|
||||
@@ -78,53 +61,15 @@ namespace Ndk
|
||||
|
||||
inline static Application* Instance();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
struct ConsoleOverlay
|
||||
{
|
||||
Console* console;
|
||||
|
||||
NazaraSlot(Nz::EventHandler, OnEvent, eventSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnKeyPressed, keyPressedSlot);
|
||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, resizedSlot);
|
||||
NazaraSlot(Nz::Log, OnLogWrite, logSlot);
|
||||
};
|
||||
|
||||
struct FPSCounterOverlay
|
||||
{
|
||||
Nz::TextSpriteRef sprite;
|
||||
EntityOwner entity;
|
||||
float elapsedTime = 0.f;
|
||||
unsigned int frameCount = 0;
|
||||
};
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifndef NDK_SERVER
|
||||
enum OverlayFlags
|
||||
{
|
||||
OverlayFlags_Console = 0x1,
|
||||
OverlayFlags_FPSCounter = 0x2
|
||||
};
|
||||
|
||||
struct WindowInfo
|
||||
{
|
||||
inline WindowInfo(std::unique_ptr<Nz::Window>&& window);
|
||||
|
||||
Nz::RenderTarget* renderTarget;
|
||||
std::unique_ptr<Nz::Window> window;
|
||||
std::unique_ptr<ConsoleOverlay> console;
|
||||
std::unique_ptr<Canvas> canvas;
|
||||
std::unique_ptr<FPSCounterOverlay> fpsCounter;
|
||||
std::unique_ptr<World> overlayWorld;
|
||||
};
|
||||
|
||||
void SetupConsole(WindowInfo& info);
|
||||
void SetupFPSCounter(WindowInfo& info);
|
||||
void SetupOverlay(WindowInfo& info);
|
||||
|
||||
template<typename T> void SetupWindow(WindowInfo& info, T* renderTarget, std::true_type /*isRenderTarget*/);
|
||||
template<typename T> void SetupWindow(WindowInfo& /*info*/, T* /*renderTarget*/, std::false_type /*isNotRenderTarget*/);
|
||||
|
||||
std::vector<WindowInfo> m_windows;
|
||||
#endif
|
||||
|
||||
@@ -134,7 +79,6 @@ namespace Ndk
|
||||
Nz::Clock m_updateClock;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
Nz::UInt32 m_overlayFlags;
|
||||
bool m_exitOnClosedWindows;
|
||||
#endif
|
||||
bool m_shouldQuit;
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Ndk
|
||||
*/
|
||||
inline Application::Application() :
|
||||
#ifndef NDK_SERVER
|
||||
m_overlayFlags(0U),
|
||||
m_exitOnClosedWindows(true),
|
||||
#endif
|
||||
m_shouldQuit(false),
|
||||
@@ -65,11 +64,7 @@ namespace Ndk
|
||||
m_windows.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
|
||||
WindowInfo& info = m_windows.back();
|
||||
|
||||
T& window = static_cast<T&>(*info.window.get()); //< Warning: ugly
|
||||
|
||||
SetupWindow(info, &window, std::is_base_of<Nz::RenderTarget, T>());
|
||||
|
||||
return window;
|
||||
return static_cast<T&>(*info.window.get()); //< Warning: ugly
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -87,133 +82,6 @@ namespace Ndk
|
||||
return m_worlds.back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable/disable debug console
|
||||
*
|
||||
* \param enable Should the console overlay be enabled
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline void Application::EnableConsole(bool enable)
|
||||
{
|
||||
if (enable != ((m_overlayFlags & OverlayFlags_Console) != 0))
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
SetupOverlay(info);
|
||||
}
|
||||
|
||||
for (WindowInfo& info : m_windows)
|
||||
{
|
||||
if (info.renderTarget)
|
||||
SetupConsole(info);
|
||||
}
|
||||
|
||||
m_overlayFlags |= OverlayFlags_Console;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.console.reset();
|
||||
|
||||
m_overlayFlags &= ~OverlayFlags_Console;
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.overlayWorld.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Enable/disable debug FPS counter
|
||||
*
|
||||
* \param enable Should the FPS counter be displayed
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline void Application::EnableFPSCounter(bool enable)
|
||||
{
|
||||
if (enable != ((m_overlayFlags & OverlayFlags_FPSCounter) != 0))
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
SetupOverlay(info);
|
||||
}
|
||||
|
||||
for (WindowInfo& info : m_windows)
|
||||
{
|
||||
if (info.renderTarget)
|
||||
SetupFPSCounter(info);
|
||||
}
|
||||
|
||||
m_overlayFlags |= OverlayFlags_FPSCounter;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.fpsCounter.reset();
|
||||
|
||||
m_overlayFlags &= ~OverlayFlags_FPSCounter;
|
||||
if (m_overlayFlags == 0)
|
||||
{
|
||||
for (WindowInfo& info : m_windows)
|
||||
info.overlayWorld.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Gets the console overlay for a specific window
|
||||
*
|
||||
* \param windowIndex Index of the window to get
|
||||
*
|
||||
* \remark The console overlay must be enabled
|
||||
*
|
||||
* \return A reference to the console overlay of the window
|
||||
*
|
||||
* \see IsConsoleOverlayEnabled
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline Application::ConsoleOverlay& Application::GetConsoleOverlay(std::size_t windowIndex)
|
||||
{
|
||||
NazaraAssert(m_overlayFlags & OverlayFlags_Console, "Console overlay is not enabled");
|
||||
NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range");
|
||||
|
||||
return *m_windows[windowIndex].console;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Gets the console overlay for a specific window
|
||||
*
|
||||
* \param windowIndex Index of the window to get
|
||||
*
|
||||
* \remark The console overlay must be enabled
|
||||
*
|
||||
* \return A reference to the console overlay of the window
|
||||
*
|
||||
* \see IsFPSCounterEnabled
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline Application::FPSCounterOverlay& Application::GetFPSCounterOverlay(std::size_t windowIndex)
|
||||
{
|
||||
NazaraAssert(m_overlayFlags & OverlayFlags_FPSCounter, "FPS counter overlay is not enabled");
|
||||
NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range");
|
||||
|
||||
return *m_windows[windowIndex].fpsCounter;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Gets the options used to start the application
|
||||
*
|
||||
@@ -287,35 +155,6 @@ namespace Ndk
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks if the console overlay is enabled
|
||||
*
|
||||
* \remark This has nothing to do with the visibility state of the console
|
||||
*
|
||||
* \return True if the console overlay is enabled
|
||||
*
|
||||
* \see GetConsoleOverlay
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline bool Application::IsConsoleEnabled() const
|
||||
{
|
||||
return (m_overlayFlags & OverlayFlags_Console) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Checks if the FPS counter overlay is enabled
|
||||
* \return True if the FPS counter overlay is enabled
|
||||
*
|
||||
* \see GetFPSCounterOverlay
|
||||
*/
|
||||
#ifndef NDK_SERVER
|
||||
inline bool Application::IsFPSCounterEnabled() const
|
||||
{
|
||||
return (m_overlayFlags & OverlayFlags_FPSCounter) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Makes the application exit when there's no more open window
|
||||
*
|
||||
@@ -348,30 +187,7 @@ namespace Ndk
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T>
|
||||
inline void Application::SetupWindow(WindowInfo& info, T* renderTarget, std::true_type)
|
||||
{
|
||||
info.renderTarget = renderTarget;
|
||||
|
||||
if (m_overlayFlags)
|
||||
{
|
||||
SetupOverlay(info);
|
||||
|
||||
if (m_overlayFlags & OverlayFlags_Console)
|
||||
SetupConsole(info);
|
||||
|
||||
if (m_overlayFlags & OverlayFlags_FPSCounter)
|
||||
SetupFPSCounter(info);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void Application::SetupWindow(WindowInfo&, T*, std::false_type)
|
||||
{
|
||||
}
|
||||
|
||||
inline Application::WindowInfo::WindowInfo(std::unique_ptr<Nz::Window>&& windowPtr) :
|
||||
renderTarget(nullptr),
|
||||
window(std::move(windowPtr))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_BASEWIDGET_HPP
|
||||
#define NDK_BASEWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/Entity.hpp>
|
||||
#include <NazaraSDK/EntityOwner.hpp>
|
||||
#include <NazaraSDK/World.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Platform/Event.hpp>
|
||||
#include <Nazara/Platform/Mouse.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Canvas;
|
||||
|
||||
class NDK_API BaseWidget : public Nz::Node
|
||||
{
|
||||
friend Canvas;
|
||||
|
||||
public:
|
||||
BaseWidget(BaseWidget* parent);
|
||||
BaseWidget(const BaseWidget&) = delete;
|
||||
BaseWidget(BaseWidget&&) = delete;
|
||||
virtual ~BaseWidget();
|
||||
|
||||
template<typename T, typename... Args> T* Add(Args&&... args);
|
||||
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
|
||||
|
||||
inline void Center();
|
||||
inline void CenterHorizontal();
|
||||
inline void CenterVertical();
|
||||
|
||||
void ClearFocus();
|
||||
inline void ClearRenderingRect();
|
||||
|
||||
void Destroy();
|
||||
|
||||
void EnableBackground(bool enable);
|
||||
|
||||
template<typename F> void ForEachWidgetChild(F iterator);
|
||||
template<typename F> void ForEachWidgetChild(F iterator) const;
|
||||
|
||||
//virtual BaseWidget* Clone() const = 0;
|
||||
|
||||
inline const Nz::Color& GetBackgroundColor() const;
|
||||
inline Canvas* GetCanvas();
|
||||
inline Nz::SystemCursor GetCursor() const;
|
||||
inline float GetHeight() const;
|
||||
|
||||
inline float GetMaximumHeight() const;
|
||||
inline Nz::Vector2f GetMaximumSize() const;
|
||||
inline float GetMaximumWidth() const;
|
||||
|
||||
inline float GetMinimumHeight() const;
|
||||
inline Nz::Vector2f GetMinimumSize() const;
|
||||
inline float GetMinimumWidth() const;
|
||||
|
||||
inline float GetPreferredHeight() const;
|
||||
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;
|
||||
|
||||
bool HasFocus() const;
|
||||
|
||||
inline void Hide();
|
||||
inline bool IsVisible() const;
|
||||
|
||||
void Resize(const Nz::Vector2f& size);
|
||||
|
||||
void SetBackgroundColor(const Nz::Color& color);
|
||||
void SetCursor(Nz::SystemCursor systemCursor);
|
||||
void SetFocus();
|
||||
void SetParent(BaseWidget* widget);
|
||||
|
||||
inline void SetFixedHeight(float fixedHeight);
|
||||
inline void SetFixedSize(const Nz::Vector2f& fixedSize);
|
||||
inline void SetFixedWidth(float fixedWidth);
|
||||
|
||||
inline void SetMaximumHeight(float maximumHeight);
|
||||
inline void SetMaximumSize(const Nz::Vector2f& maximumSize);
|
||||
inline void SetMaximumWidth(float maximumWidth);
|
||||
|
||||
inline void SetMinimumHeight(float minimumHeight);
|
||||
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;
|
||||
BaseWidget& operator=(BaseWidget&&) = delete;
|
||||
|
||||
protected:
|
||||
const EntityHandle& CreateEntity();
|
||||
void DestroyEntity(Entity* entity);
|
||||
virtual void Layout();
|
||||
|
||||
void InvalidateNode() override;
|
||||
|
||||
Nz::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 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 OnMouseWheelMoved(int x, int y, float delta);
|
||||
virtual void OnMouseExit();
|
||||
virtual void OnParentResized(const Nz::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);
|
||||
|
||||
virtual void ShowChildren(bool show);
|
||||
|
||||
private:
|
||||
inline BaseWidget();
|
||||
|
||||
void DestroyChild(BaseWidget* widget);
|
||||
void DestroyChildren();
|
||||
inline bool IsRegisteredToCanvas() const;
|
||||
inline void NotifyParentResized(const Nz::Vector2f& newSize);
|
||||
void RegisterToCanvas();
|
||||
inline void UpdateCanvasIndex(std::size_t index);
|
||||
void UnregisterFromCanvas();
|
||||
void UpdatePositionAndSize();
|
||||
|
||||
struct WidgetEntity
|
||||
{
|
||||
EntityOwner 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();
|
||||
|
||||
std::size_t m_canvasIndex;
|
||||
std::vector<WidgetEntity> m_entities;
|
||||
std::vector<std::unique_ptr<BaseWidget>> m_children;
|
||||
Canvas* m_canvas;
|
||||
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;
|
||||
Nz::Vector2f m_minimumSize;
|
||||
Nz::Vector2f m_preferredSize;
|
||||
Nz::Vector2f m_size;
|
||||
BaseWidget* m_widgetParent;
|
||||
bool m_visible;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/BaseWidget.inl>
|
||||
|
||||
#endif // NDK_BASEWIDGET_HPP
|
||||
@@ -1,275 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline BaseWidget::BaseWidget() :
|
||||
m_canvasIndex(InvalidCanvasIndex),
|
||||
m_canvas(nullptr),
|
||||
m_backgroundColor(Nz::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_maximumSize(std::numeric_limits<float>::infinity()),
|
||||
m_minimumSize(0.f),
|
||||
m_preferredSize(-1),
|
||||
m_size(50.f, 50.f),
|
||||
m_widgetParent(nullptr),
|
||||
m_visible(true)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
inline T* BaseWidget::Add(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...);
|
||||
T* widgetPtr = widget.get();
|
||||
AddChild(std::move(widget));
|
||||
|
||||
return widgetPtr;
|
||||
}
|
||||
|
||||
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
|
||||
{
|
||||
widget->Show(m_visible);
|
||||
widget->SetParent(this);
|
||||
m_children.emplace_back(std::move(widget));
|
||||
}
|
||||
|
||||
inline void BaseWidget::Center()
|
||||
{
|
||||
NazaraAssert(m_widgetParent, "Widget has no parent");
|
||||
|
||||
Nz::Vector2f parentSize = m_widgetParent->GetSize();
|
||||
Nz::Vector2f mySize = GetSize();
|
||||
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
|
||||
}
|
||||
|
||||
inline void BaseWidget::CenterHorizontal()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
inline void BaseWidget::ForEachWidgetChild(F iterator)
|
||||
{
|
||||
for (const auto& child : m_children)
|
||||
iterator(child.get());
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
inline void BaseWidget::ForEachWidgetChild(F iterator) const
|
||||
{
|
||||
for (const auto& child : m_children)
|
||||
iterator(static_cast<const BaseWidget*>(child.get()));
|
||||
}
|
||||
|
||||
inline const Nz::Color& BaseWidget::GetBackgroundColor() const
|
||||
{
|
||||
return m_backgroundColor;
|
||||
}
|
||||
|
||||
inline Canvas* BaseWidget::GetCanvas()
|
||||
{
|
||||
return m_canvas;
|
||||
}
|
||||
|
||||
inline Nz::SystemCursor BaseWidget::GetCursor() const
|
||||
{
|
||||
return m_cursor;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetHeight() const
|
||||
{
|
||||
return m_size.y;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMaximumHeight() const
|
||||
{
|
||||
return m_maximumSize.y;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetMaximumSize() const
|
||||
{
|
||||
return m_maximumSize;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMaximumWidth() const
|
||||
{
|
||||
return m_maximumSize.x;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMinimumHeight() const
|
||||
{
|
||||
return m_minimumSize.y;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetMinimumSize() const
|
||||
{
|
||||
return m_minimumSize;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetMinimumWidth() const
|
||||
{
|
||||
return m_minimumSize.x;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetPreferredHeight() const
|
||||
{
|
||||
return m_preferredSize.y;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetPreferredSize() const
|
||||
{
|
||||
return m_preferredSize;
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetPreferredWidth() const
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
inline float BaseWidget::GetWidth() const
|
||||
{
|
||||
return m_size.x;
|
||||
}
|
||||
|
||||
inline std::size_t BaseWidget::GetWidgetChildCount() const
|
||||
{
|
||||
return m_children.size();
|
||||
}
|
||||
|
||||
inline void BaseWidget::Hide()
|
||||
{
|
||||
return Show(false);
|
||||
}
|
||||
|
||||
inline bool BaseWidget::IsVisible() const
|
||||
{
|
||||
return m_visible;
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetFixedHeight(float fixedHeight)
|
||||
{
|
||||
SetMaximumHeight(fixedHeight);
|
||||
SetMinimumHeight(fixedHeight);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetFixedSize(const Nz::Vector2f& fixedSize)
|
||||
{
|
||||
SetMaximumSize(fixedSize);
|
||||
SetMinimumSize(fixedSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetFixedWidth(float fixedWidth)
|
||||
{
|
||||
SetMaximumWidth(fixedWidth);
|
||||
SetMinimumWidth(fixedWidth);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMaximumHeight(float maximumHeight)
|
||||
{
|
||||
Nz::Vector2f maximumSize = GetMaximumSize();
|
||||
maximumSize.y = maximumHeight;
|
||||
|
||||
SetMaximumSize(maximumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMaximumSize(const Nz::Vector2f& maximumSize)
|
||||
{
|
||||
m_maximumSize = maximumSize;
|
||||
|
||||
Nz::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();
|
||||
maximumSize.x = maximumWidth;
|
||||
|
||||
SetMaximumSize(maximumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMinimumHeight(float minimumHeight)
|
||||
{
|
||||
Nz::Vector2f minimumSize = GetMinimumSize();
|
||||
minimumSize.y = minimumHeight;
|
||||
|
||||
SetMinimumSize(minimumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetMinimumSize(const Nz::Vector2f& minimumSize)
|
||||
{
|
||||
m_minimumSize = minimumSize;
|
||||
|
||||
Nz::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();
|
||||
minimumSize.x = minimumWidth;
|
||||
|
||||
SetMinimumSize(minimumSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetPreferredSize(const Nz::Vector2f& preferredSize)
|
||||
{
|
||||
m_preferredSize = preferredSize;
|
||||
|
||||
//Resize(m_preferredSize);
|
||||
}
|
||||
|
||||
inline bool BaseWidget::IsRegisteredToCanvas() const
|
||||
{
|
||||
return m_canvas && m_canvasIndex != InvalidCanvasIndex;
|
||||
}
|
||||
|
||||
inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize)
|
||||
{
|
||||
for (const auto& widgetPtr : m_children)
|
||||
widgetPtr->OnParentResized(newSize);
|
||||
}
|
||||
|
||||
inline void BaseWidget::UpdateCanvasIndex(std::size_t index)
|
||||
{
|
||||
m_canvasIndex = index;
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_CANVAS_HPP
|
||||
#define NDK_CANVAS_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Platform/CursorController.hpp>
|
||||
#include <Nazara/Platform/EventHandler.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API Canvas : public BaseWidget
|
||||
{
|
||||
friend BaseWidget;
|
||||
|
||||
public:
|
||||
struct Padding;
|
||||
|
||||
inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController);
|
||||
Canvas(const Canvas&) = delete;
|
||||
Canvas(Canvas&&) = delete;
|
||||
inline ~Canvas();
|
||||
|
||||
inline const WorldHandle& GetWorld() const;
|
||||
|
||||
Canvas& operator=(const Canvas&) = delete;
|
||||
Canvas& operator=(Canvas&&) = delete;
|
||||
|
||||
NazaraSignal(OnUnhandledKeyPressed, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/);
|
||||
NazaraSignal(OnUnhandledKeyReleased, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/);
|
||||
|
||||
protected:
|
||||
inline void ClearKeyboardOwner(std::size_t canvasIndex);
|
||||
|
||||
inline bool IsKeyboardOwner(std::size_t canvasIndex) const;
|
||||
|
||||
inline void NotifyWidgetBoxUpdate(std::size_t index);
|
||||
inline void NotifyWidgetCursorUpdate(std::size_t index);
|
||||
|
||||
std::size_t RegisterWidget(BaseWidget* widget);
|
||||
|
||||
inline void SetKeyboardOwner(std::size_t canvasIndex);
|
||||
|
||||
void UnregisterWidget(std::size_t index);
|
||||
|
||||
private:
|
||||
void OnEventMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnEventMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnEventMouseLeft(const Nz::EventHandler* eventHandler);
|
||||
void OnEventMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||
void OnEventMouseWheelMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseWheelEvent& event);
|
||||
void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
||||
void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event);
|
||||
|
||||
struct WidgetEntry
|
||||
{
|
||||
BaseWidget* widget;
|
||||
Nz::Boxf box;
|
||||
Nz::SystemCursor cursor;
|
||||
};
|
||||
|
||||
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot);
|
||||
|
||||
std::size_t m_keyboardOwner;
|
||||
std::size_t m_hoveredWidget;
|
||||
std::vector<WidgetEntry> m_widgetEntries;
|
||||
Nz::CursorControllerHandle m_cursorController;
|
||||
WorldHandle m_world;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Canvas.inl>
|
||||
|
||||
#endif // NDK_CANVAS_HPP
|
||||
@@ -1,91 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Canvas.hpp>
|
||||
#include <Nazara/Platform/Cursor.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) :
|
||||
m_keyboardOwner(InvalidCanvasIndex),
|
||||
m_hoveredWidget(InvalidCanvasIndex),
|
||||
m_cursorController(cursorController),
|
||||
m_world(std::move(world))
|
||||
{
|
||||
m_canvas = this;
|
||||
m_widgetParent = nullptr;
|
||||
|
||||
// Register ourselves as a widget to handle cursor change
|
||||
RegisterToCanvas();
|
||||
|
||||
// Connect to every meaningful event
|
||||
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnEventKeyPressed);
|
||||
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnEventKeyReleased);
|
||||
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnEventMouseButtonPressed);
|
||||
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnEventMouseButtonRelease);
|
||||
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft);
|
||||
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved);
|
||||
m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, this, &Canvas::OnEventMouseWheelMoved);
|
||||
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered);
|
||||
m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited);
|
||||
}
|
||||
|
||||
inline Canvas::~Canvas()
|
||||
{
|
||||
// Destroy children explicitly because they signal us when getting destroyed, and that can't happen after our own destruction
|
||||
DestroyChildren();
|
||||
|
||||
// Prevent our parent from trying to call us
|
||||
m_canvasIndex = InvalidCanvasIndex;
|
||||
}
|
||||
|
||||
inline const WorldHandle& Canvas::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline void Canvas::ClearKeyboardOwner(std::size_t canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner == canvasIndex)
|
||||
SetKeyboardOwner(InvalidCanvasIndex);
|
||||
}
|
||||
|
||||
inline bool Canvas::IsKeyboardOwner(std::size_t canvasIndex) const
|
||||
{
|
||||
return m_keyboardOwner == canvasIndex;
|
||||
}
|
||||
|
||||
inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index)
|
||||
{
|
||||
WidgetEntry& entry = m_widgetEntries[index];
|
||||
|
||||
Nz::Vector3f pos = entry.widget->GetPosition(Nz::CoordSys_Global);
|
||||
Nz::Vector2f size = entry.widget->GetSize();
|
||||
|
||||
entry.box.Set(pos.x, pos.y, pos.z, size.x, size.y, 1.f);
|
||||
}
|
||||
|
||||
inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index)
|
||||
{
|
||||
WidgetEntry& entry = m_widgetEntries[index];
|
||||
|
||||
entry.cursor = entry.widget->GetCursor();
|
||||
if (m_cursorController && m_hoveredWidget == index)
|
||||
m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor));
|
||||
}
|
||||
|
||||
inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner != canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnFocusLost();
|
||||
|
||||
m_keyboardOwner = canvasIndex;
|
||||
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnFocusReceived();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <NazaraSDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class CameraComponent;
|
||||
|
||||
using CameraComponentHandle = Nz::ObjectHandle<CameraComponent>;
|
||||
|
||||
class NDK_API CameraComponent : public Component<CameraComponent>, public Nz::AbstractViewer
|
||||
{
|
||||
public:
|
||||
inline CameraComponent();
|
||||
inline CameraComponent(const CameraComponent& camera);
|
||||
~CameraComponent() = default;
|
||||
|
||||
void ApplyView() const override;
|
||||
|
||||
inline void EnsureFrustumUpdate() const;
|
||||
inline void EnsureProjectionMatrixUpdate() const;
|
||||
inline void EnsureViewMatrixUpdate() const;
|
||||
inline void EnsureViewportUpdate() const;
|
||||
|
||||
float GetAspectRatio() const override;
|
||||
Nz::Vector3f GetEyePosition() const override;
|
||||
Nz::Vector3f GetForward() const override;
|
||||
inline float GetFOV() const;
|
||||
const Nz::Frustumf& GetFrustum() const override;
|
||||
inline unsigned int GetLayer() const;
|
||||
const Nz::Matrix4f& GetProjectionMatrix() const override;
|
||||
inline const Nz::Vector3f& GetProjectionScale() const;
|
||||
Nz::ProjectionType GetProjectionType() const override;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
const Nz::RenderTarget* GetTarget() const override;
|
||||
inline const Nz::Rectf& GetTargetRegion() const;
|
||||
const Nz::Matrix4f& GetViewMatrix() const override;
|
||||
const Nz::Recti& GetViewport() const override;
|
||||
float GetZFar() const override;
|
||||
float GetZNear() const override;
|
||||
|
||||
inline void SetFOV(float fov);
|
||||
void SetLayer(unsigned int layer);
|
||||
inline void SetProjectionScale(const Nz::Vector3f& scale);
|
||||
inline void SetProjectionType(Nz::ProjectionType projection);
|
||||
inline void SetSize(const Nz::Vector2f& size);
|
||||
inline void SetSize(float width, float height);
|
||||
inline void SetTarget(const Nz::RenderTarget* renderTarget);
|
||||
inline void SetTargetRegion(const Nz::Rectf& region);
|
||||
inline void SetViewport(const Nz::Recti& viewport);
|
||||
inline void SetZFar(float zFar);
|
||||
inline void SetZNear(float zNear);
|
||||
|
||||
inline bool UpdateVisibility(std::size_t visibilityHash);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
inline void InvalidateFrustum() const;
|
||||
inline void InvalidateProjectionMatrix() const;
|
||||
inline void InvalidateViewMatrix() const;
|
||||
inline void InvalidateViewport() const;
|
||||
|
||||
void OnAttached() override;
|
||||
void OnComponentAttached(BaseComponent& component) override;
|
||||
void OnComponentDetached(BaseComponent& component) override;
|
||||
void OnDetached() override;
|
||||
void OnNodeInvalidated(const Nz::Node* node);
|
||||
void OnRenderTargetRelease(const Nz::RenderTarget* renderTarget);
|
||||
void OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget);
|
||||
|
||||
void UpdateFrustum() const;
|
||||
void UpdateProjectionMatrix() const;
|
||||
void UpdateViewMatrix() const;
|
||||
void UpdateViewport() const;
|
||||
|
||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
|
||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
|
||||
|
||||
std::size_t m_visibilityHash;
|
||||
Nz::ProjectionType m_projectionType;
|
||||
mutable Nz::Frustumf m_frustum;
|
||||
mutable Nz::Matrix4f m_projectionMatrix;
|
||||
mutable Nz::Matrix4f m_viewMatrix;
|
||||
Nz::Rectf m_targetRegion;
|
||||
mutable Nz::Recti m_viewport;
|
||||
const Nz::RenderTarget* m_target;
|
||||
Nz::Vector2f m_size;
|
||||
Nz::Vector3f m_projectionScale;
|
||||
mutable bool m_frustumUpdated;
|
||||
mutable bool m_projectionMatrixUpdated;
|
||||
mutable bool m_viewMatrixUpdated;
|
||||
mutable bool m_viewportUpdated;
|
||||
mutable float m_aspectRatio;
|
||||
float m_fov;
|
||||
float m_zFar;
|
||||
float m_zNear;
|
||||
unsigned int m_layer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Components/CameraComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,353 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs an CameraComponent object by default
|
||||
*/
|
||||
|
||||
inline CameraComponent::CameraComponent() :
|
||||
m_visibilityHash(0U),
|
||||
m_projectionType(Nz::ProjectionType_Perspective),
|
||||
m_targetRegion(0.f, 0.f, 1.f, 1.f),
|
||||
m_target(nullptr),
|
||||
m_size(0.f),
|
||||
m_projectionScale(1.f, 1.f, 1.f),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
m_viewMatrixUpdated(false),
|
||||
m_viewportUpdated(false),
|
||||
m_aspectRatio(0.f),
|
||||
m_fov(70.f),
|
||||
m_zFar(100.f),
|
||||
m_zNear(1.f),
|
||||
m_layer(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a CameraComponent object by copy semantic
|
||||
*
|
||||
* \param camera CameraComponent to copy
|
||||
*/
|
||||
|
||||
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
|
||||
Component(camera),
|
||||
AbstractViewer(camera),
|
||||
m_visibilityHash(camera.m_visibilityHash),
|
||||
m_projectionType(camera.m_projectionType),
|
||||
m_targetRegion(camera.m_targetRegion),
|
||||
m_target(nullptr),
|
||||
m_size(camera.m_size),
|
||||
m_projectionScale(camera.m_projectionScale),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
m_viewMatrixUpdated(false),
|
||||
m_viewportUpdated(false),
|
||||
m_aspectRatio(camera.m_aspectRatio),
|
||||
m_fov(camera.m_fov),
|
||||
m_zFar(camera.m_zFar),
|
||||
m_zNear(camera.m_zNear),
|
||||
m_layer(camera.m_layer)
|
||||
{
|
||||
SetTarget(camera.m_target);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the frustum is up to date
|
||||
*/
|
||||
|
||||
inline void CameraComponent::EnsureFrustumUpdate() const
|
||||
{
|
||||
if (!m_frustumUpdated)
|
||||
UpdateFrustum();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the projection matrix is up to date
|
||||
*/
|
||||
|
||||
inline void CameraComponent::EnsureProjectionMatrixUpdate() const
|
||||
{
|
||||
if (!m_projectionMatrixUpdated)
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the view matrix is up to date
|
||||
*/
|
||||
|
||||
inline void CameraComponent::EnsureViewMatrixUpdate() const
|
||||
{
|
||||
if (!m_viewMatrixUpdated)
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the view port is up to date
|
||||
*/
|
||||
|
||||
inline void CameraComponent::EnsureViewportUpdate() const
|
||||
{
|
||||
if (!m_viewportUpdated)
|
||||
UpdateViewport();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the field of view of the camera
|
||||
* \return Field of view of the camera
|
||||
*/
|
||||
inline float CameraComponent::GetFOV() const
|
||||
{
|
||||
return m_fov;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the layer of the camera
|
||||
* \return Layer of the camera
|
||||
*/
|
||||
|
||||
inline unsigned int CameraComponent::GetLayer() const
|
||||
{
|
||||
return m_layer;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the projection scale of the camera
|
||||
* \return Projection scale
|
||||
*/
|
||||
const Nz::Vector3f& CameraComponent::GetProjectionScale() const
|
||||
{
|
||||
return m_projectionScale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the camera
|
||||
* \return Size of the camera
|
||||
*/
|
||||
inline const Nz::Vector2f & CameraComponent::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the target region of the camera
|
||||
* \return A constant reference to the target region of the camera
|
||||
*/
|
||||
|
||||
inline const Nz::Rectf& CameraComponent::GetTargetRegion() const
|
||||
{
|
||||
return m_targetRegion;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the field of view of the camera
|
||||
*
|
||||
* \param fov Field of view of the camera
|
||||
*
|
||||
* \remark Produces a NazaraAssert if angle is zero
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetFOV(float fov)
|
||||
{
|
||||
NazaraAssert(!Nz::NumberEquals(fov, 0.f), "FOV must be different from zero");
|
||||
m_fov = fov;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the camera projection scale
|
||||
*
|
||||
* \param scale New projection scale
|
||||
*/
|
||||
inline void CameraComponent::SetProjectionScale(const Nz::Vector3f& scale)
|
||||
{
|
||||
m_projectionScale = scale;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the projection type of the camera
|
||||
*
|
||||
* \param projectionType Projection type of the camera
|
||||
*/
|
||||
inline void CameraComponent::SetProjectionType(Nz::ProjectionType projectionType)
|
||||
{
|
||||
m_projectionType = projectionType;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the camera
|
||||
*
|
||||
* \param size Size of the camera
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the camera
|
||||
*
|
||||
* \param width Size in X of the camera
|
||||
* \param height Size in Y of the camera
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetSize(float width, float height)
|
||||
{
|
||||
SetSize({width, height});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the target of the camera
|
||||
*
|
||||
* \param renderTarget A constant reference to the render target of the camera
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget)
|
||||
{
|
||||
m_target = renderTarget;
|
||||
if (m_target)
|
||||
{
|
||||
m_targetResizeSlot.Connect(m_target->OnRenderTargetSizeChange, this, &CameraComponent::OnRenderTargetSizeChange);
|
||||
m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, &CameraComponent::OnRenderTargetRelease);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_targetResizeSlot.Disconnect();
|
||||
m_targetReleaseSlot.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the target region of the camera
|
||||
*
|
||||
* \param region A constant reference to the target region of the camera
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetTargetRegion(const Nz::Rectf& region)
|
||||
{
|
||||
m_targetRegion = region;
|
||||
|
||||
InvalidateViewport();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the view port of the camera
|
||||
*
|
||||
* \param viewport A constant reference to the view port of the camera
|
||||
*
|
||||
* \remark Produces a NazaraAssert if the camera has no target
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetViewport(const Nz::Recti& viewport)
|
||||
{
|
||||
NazaraAssert(m_target, "Component has no render target");
|
||||
|
||||
// We compute the region necessary to make this view port with the actual size of the target
|
||||
Nz::Vector2f invSize = 1.f / Nz::Vector2f(m_target->GetSize());
|
||||
|
||||
SetTargetRegion(Nz::Rectf(invSize.x * viewport.x, invSize.y * viewport.y, invSize.x * viewport.width, invSize.y * viewport.height));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the Z far distance of the camera
|
||||
*
|
||||
* \param zFar Z far distance of the camera
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetZFar(float zFar)
|
||||
{
|
||||
m_zFar = zFar;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the Z near distance of the camera
|
||||
*
|
||||
* \param zNear Z near distance of the camera
|
||||
*
|
||||
* \remark Produces a NazaraAssert if zNear is zero
|
||||
*/
|
||||
|
||||
inline void CameraComponent::SetZNear(float zNear)
|
||||
{
|
||||
NazaraAssert(!Nz::NumberEquals(zNear, 0.f), "zNear cannot be zero");
|
||||
m_zNear = zNear;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Update the camera component visibility hash
|
||||
*
|
||||
* This is used with CullingList (which produce a visibility hash)
|
||||
*
|
||||
* \param visibilityHash New visibility hash
|
||||
*
|
||||
* \return True if the visibility hash is not the same as before
|
||||
*/
|
||||
inline bool CameraComponent::UpdateVisibility(std::size_t visibilityHash)
|
||||
{
|
||||
if (m_visibilityHash != visibilityHash)
|
||||
{
|
||||
m_visibilityHash = visibilityHash;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the frustum
|
||||
*/
|
||||
|
||||
inline void CameraComponent::InvalidateFrustum() const
|
||||
{
|
||||
m_frustumUpdated = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the projection matrix
|
||||
*/
|
||||
|
||||
inline void CameraComponent::InvalidateProjectionMatrix() const
|
||||
{
|
||||
m_frustumUpdated = false;
|
||||
m_projectionMatrixUpdated = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the view matrix
|
||||
*/
|
||||
|
||||
inline void CameraComponent::InvalidateViewMatrix() const
|
||||
{
|
||||
m_frustumUpdated = false;
|
||||
m_viewMatrixUpdated = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the view port
|
||||
*/
|
||||
|
||||
inline void CameraComponent::InvalidateViewport() const
|
||||
{
|
||||
m_frustumUpdated = false;
|
||||
m_projectionMatrixUpdated = false;
|
||||
m_viewportUpdated = false;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_DEBUGCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_DEBUGCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Core/Flags.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <NazaraSDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
enum class DebugDraw
|
||||
{
|
||||
Collider2D,
|
||||
Collider3D,
|
||||
GraphicsAABB,
|
||||
GraphicsOBB,
|
||||
|
||||
Max = GraphicsOBB
|
||||
};
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<>
|
||||
struct EnumAsFlags<Ndk::DebugDraw>
|
||||
{
|
||||
static constexpr Ndk::DebugDraw max = Ndk::DebugDraw::GraphicsOBB;
|
||||
};
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
using DebugDrawFlags = Nz::Flags<DebugDraw>;
|
||||
|
||||
constexpr DebugDrawFlags DebugDraw_None = 0;
|
||||
|
||||
class DebugComponent;
|
||||
class GraphicsComponent;
|
||||
|
||||
using DebugComponentHandle = Nz::ObjectHandle<DebugComponent>;
|
||||
|
||||
class NDK_API DebugComponent : public Component<DebugComponent>
|
||||
{
|
||||
friend class DebugSystem;
|
||||
|
||||
public:
|
||||
inline DebugComponent(DebugDrawFlags flags = DebugDraw_None);
|
||||
inline DebugComponent(const DebugComponent& debug);
|
||||
~DebugComponent() = default;
|
||||
|
||||
inline void Disable(DebugDrawFlags flags);
|
||||
inline void Enable(DebugDrawFlags flags);
|
||||
|
||||
inline DebugDrawFlags GetFlags() const;
|
||||
|
||||
inline bool IsEnabled(DebugDrawFlags flags) const;
|
||||
|
||||
inline DebugComponent& operator=(const DebugComponent& debug);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
void DetachDebugRenderables(GraphicsComponent& gfxComponent);
|
||||
|
||||
inline const Nz::InstancedRenderableRef& GetDebugRenderable(DebugDraw option) const;
|
||||
inline DebugDrawFlags GetEnabledFlags() const;
|
||||
|
||||
void OnComponentDetached(BaseComponent& component) override;
|
||||
void OnDetached() override;
|
||||
|
||||
inline void UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable);
|
||||
inline void UpdateEnabledFlags(DebugDrawFlags flags);
|
||||
|
||||
static constexpr std::size_t DebugModeCount = static_cast<std::size_t>(DebugDraw::Max) + 1;
|
||||
|
||||
std::array<Nz::InstancedRenderableRef, DebugModeCount> m_debugRenderables;
|
||||
DebugDrawFlags m_enabledFlags;
|
||||
DebugDrawFlags m_flags;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Components/DebugComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_DEBUGCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Components/DebugComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline DebugComponent::DebugComponent(DebugDrawFlags flags) :
|
||||
m_flags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
inline DebugComponent::DebugComponent(const DebugComponent& debug) :
|
||||
m_flags(debug.m_flags)
|
||||
{
|
||||
}
|
||||
|
||||
inline void DebugComponent::Disable(DebugDrawFlags flags)
|
||||
{
|
||||
m_flags &= ~flags;
|
||||
|
||||
if (m_entity)
|
||||
m_entity->Invalidate();
|
||||
}
|
||||
|
||||
inline void DebugComponent::Enable(DebugDrawFlags flags)
|
||||
{
|
||||
m_flags |= flags;
|
||||
|
||||
if (m_entity)
|
||||
m_entity->Invalidate();
|
||||
}
|
||||
|
||||
inline DebugDrawFlags DebugComponent::GetFlags() const
|
||||
{
|
||||
return m_flags;
|
||||
}
|
||||
|
||||
inline bool DebugComponent::IsEnabled(DebugDrawFlags flags) const
|
||||
{
|
||||
return (m_flags & flags) == flags;
|
||||
}
|
||||
|
||||
inline DebugComponent& DebugComponent::operator=(const DebugComponent& debug)
|
||||
{
|
||||
m_flags = debug.m_flags;
|
||||
|
||||
if (m_entity)
|
||||
m_entity->Invalidate();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const Nz::InstancedRenderableRef& DebugComponent::GetDebugRenderable(DebugDraw option) const
|
||||
{
|
||||
return m_debugRenderables[static_cast<std::size_t>(option)];
|
||||
}
|
||||
|
||||
inline DebugDrawFlags DebugComponent::GetEnabledFlags() const
|
||||
{
|
||||
return m_enabledFlags;
|
||||
}
|
||||
|
||||
inline void DebugComponent::UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable)
|
||||
{
|
||||
m_debugRenderables[static_cast<std::size_t>(option)] = std::move(renderable);
|
||||
}
|
||||
|
||||
inline void DebugComponent::UpdateEnabledFlags(DebugDrawFlags flags)
|
||||
{
|
||||
m_enabledFlags = flags;
|
||||
}
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Graphics/CullingList.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <NazaraSDK/Component.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class GraphicsComponent;
|
||||
|
||||
using GraphicsComponentCullingList = Nz::CullingList<GraphicsComponent>;
|
||||
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
|
||||
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>
|
||||
{
|
||||
friend class RenderSystem;
|
||||
|
||||
public:
|
||||
using RenderableList = std::vector<Nz::InstancedRenderableRef>;
|
||||
|
||||
inline GraphicsComponent();
|
||||
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
|
||||
~GraphicsComponent() = default;
|
||||
|
||||
inline void AddToCullingList(GraphicsComponentCullingList* cullingList) const;
|
||||
void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
|
||||
void AddToRenderQueueByCulling(const Nz::Frustumf& frustum, Nz::AbstractRenderQueue* renderQueue) const;
|
||||
|
||||
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
inline void Detach(const Nz::InstancedRenderable* renderable);
|
||||
|
||||
inline bool DoesRequireRealTimeReflections() const;
|
||||
|
||||
inline void EnsureBoundingVolumesUpdate() const;
|
||||
inline void EnsureTransformMatrixUpdate() const;
|
||||
|
||||
template<typename Func> void ForEachRenderable(const Func& func) const;
|
||||
|
||||
inline const Nz::Boxf& GetAABB() const;
|
||||
|
||||
inline void GetAttachedRenderables(RenderableList* renderables) const;
|
||||
inline std::size_t GetAttachedRenderableCount() const;
|
||||
|
||||
inline const Nz::BoundingVolumef& GetBoundingVolume(std::size_t renderableIndex) const;
|
||||
inline const Nz::Matrix4f& GetLocalMatrix(std::size_t renderableIndex) const;
|
||||
inline const Nz::Matrix4f& GetTransformMatrix(std::size_t renderableIndex) const;
|
||||
|
||||
inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const;
|
||||
|
||||
inline void SetScissorRect(const Nz::Recti& scissorRect);
|
||||
|
||||
inline void UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix);
|
||||
inline void UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
struct Renderable;
|
||||
|
||||
void ConnectInstancedRenderableSignals(Renderable& renderable);
|
||||
|
||||
inline void ForceCullingInvalidation();
|
||||
inline void InvalidateAABB() const;
|
||||
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
|
||||
void InvalidateRenderableMaterial(const Nz::InstancedRenderable* renderable, std::size_t skinIndex, std::size_t matIndex, const Nz::MaterialRef& newMat);
|
||||
inline void InvalidateRenderables();
|
||||
void InvalidateReflectionMap();
|
||||
inline void InvalidateTransformMatrix();
|
||||
|
||||
void RegisterMaterial(Nz::Material* material, std::size_t count = 1);
|
||||
|
||||
void OnAttached() override;
|
||||
void OnComponentAttached(BaseComponent& component) override;
|
||||
void OnComponentDetached(BaseComponent& component) override;
|
||||
void OnDetached() override;
|
||||
|
||||
void OnInstancedRenderableResetMaterials(const Nz::InstancedRenderable* renderable, std::size_t newMaterialCount);
|
||||
void OnInstancedRenderableSkinChange(const Nz::InstancedRenderable* renderable, std::size_t newSkinIndex);
|
||||
void OnMaterialReflectionChange(const Nz::Material* material, Nz::ReflectionMode reflectionMode);
|
||||
void OnNodeInvalidated(const Nz::Node* node);
|
||||
|
||||
void UnregisterMaterial(Nz::Material* material);
|
||||
|
||||
void UpdateBoundingVolumes() const;
|
||||
void UpdateTransformMatrix() const;
|
||||
|
||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||
|
||||
using CullingListBoxEntry = GraphicsComponentCullingList::BoxEntry;
|
||||
|
||||
struct CullingBoxEntry
|
||||
{
|
||||
CullingListBoxEntry listEntry;
|
||||
|
||||
NazaraSlot(GraphicsComponentCullingList, OnCullingListRelease, cullingListReleaseSlot);
|
||||
};
|
||||
|
||||
struct MaterialEntry
|
||||
{
|
||||
NazaraSlot(Nz::Material, OnMaterialReflectionModeChange, reflectionModelChangeSlot);
|
||||
|
||||
std::size_t renderableCounter;
|
||||
};
|
||||
|
||||
struct Renderable
|
||||
{
|
||||
Renderable(const Nz::Matrix4f& transformMatrix) :
|
||||
data(transformMatrix),
|
||||
dataUpdated(false)
|
||||
{
|
||||
}
|
||||
|
||||
Renderable(const Renderable&) = delete;
|
||||
Renderable(Renderable&& rhs) noexcept = default;
|
||||
|
||||
~Renderable()
|
||||
{
|
||||
// Disconnect release slot before releasing instanced renderable reference
|
||||
renderableReleaseSlot.Disconnect();
|
||||
}
|
||||
|
||||
Renderable& operator=(const Renderable&) = delete;
|
||||
Renderable& operator=(Renderable&& r) noexcept = default;
|
||||
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateBoundingVolume, renderableBoundingVolumeInvalidationSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableDataInvalidationSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateMaterial, renderableMaterialInvalidationSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableRelease, renderableReleaseSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableResetMaterials, renderableResetMaterialsSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableSkinChange, renderableSkinChangeSlot);
|
||||
|
||||
mutable Nz::BoundingVolumef boundingVolume;
|
||||
mutable Nz::InstancedRenderable::InstanceData data;
|
||||
Nz::InstancedRenderableRef renderable;
|
||||
mutable bool dataUpdated;
|
||||
};
|
||||
|
||||
std::size_t m_reflectiveMaterialCount;
|
||||
mutable std::vector<CullingBoxEntry> m_cullingBoxEntries;
|
||||
std::vector<Renderable> m_renderables;
|
||||
std::unordered_map<const Nz::Material*, MaterialEntry> m_materialEntries;
|
||||
mutable Nz::Boxf m_aabb;
|
||||
mutable Nz::Matrix4f m_transformMatrix;
|
||||
Nz::Recti m_scissorRect;
|
||||
Nz::TextureRef m_reflectionMap;
|
||||
mutable bool m_boundingVolumesUpdated;
|
||||
mutable bool m_transformMatrixUpdated;
|
||||
unsigned int m_reflectionMapSize;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Components/GraphicsComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,291 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Components/GraphicsComponent.hpp>
|
||||
#include <NazaraSDK/World.hpp>
|
||||
#include <NazaraSDK/Systems/RenderSystem.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline GraphicsComponent::GraphicsComponent() :
|
||||
m_reflectiveMaterialCount(0),
|
||||
m_scissorRect(-1, -1)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a GraphicsComponent object by copy semantic
|
||||
*
|
||||
* \param graphicsComponent GraphicsComponent to copy
|
||||
*/
|
||||
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
|
||||
Component(graphicsComponent),
|
||||
m_reflectiveMaterialCount(0),
|
||||
m_aabb(graphicsComponent.m_aabb),
|
||||
m_transformMatrix(graphicsComponent.m_transformMatrix),
|
||||
m_scissorRect(graphicsComponent.m_scissorRect),
|
||||
m_boundingVolumesUpdated(graphicsComponent.m_boundingVolumesUpdated),
|
||||
m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated)
|
||||
{
|
||||
m_renderables.reserve(graphicsComponent.m_renderables.size());
|
||||
for (const Renderable& r : graphicsComponent.m_renderables)
|
||||
Attach(r.renderable, r.data.localMatrix, r.data.renderOrder);
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::AddToCullingList(GraphicsComponentCullingList* cullingList) const
|
||||
{
|
||||
m_cullingBoxEntries.emplace_back();
|
||||
CullingBoxEntry& entry = m_cullingBoxEntries.back();
|
||||
entry.cullingListReleaseSlot.Connect(cullingList->OnCullingListRelease, this, &GraphicsComponent::RemoveFromCullingList);
|
||||
entry.listEntry = cullingList->RegisterBoxTest(this);
|
||||
|
||||
InvalidateAABB();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Attaches a renderable to the entity
|
||||
*
|
||||
* \param renderable Reference to a renderable element
|
||||
* \param renderOrder Render order of the element
|
||||
*/
|
||||
inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder)
|
||||
{
|
||||
return Attach(std::move(renderable), Nz::Matrix4f::Identity(), renderOrder);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears every renderable elements
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::Clear()
|
||||
{
|
||||
m_materialEntries.clear();
|
||||
m_renderables.clear();
|
||||
|
||||
if (m_reflectiveMaterialCount > 0)
|
||||
{
|
||||
m_reflectiveMaterialCount = 0;
|
||||
InvalidateReflectionMap();
|
||||
}
|
||||
|
||||
InvalidateAABB();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Detaches a renderable to the entity
|
||||
*
|
||||
* \param renderable Reference to a renderable element
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::Detach(const Nz::InstancedRenderable* renderable)
|
||||
{
|
||||
for (auto it = m_renderables.begin(); it != m_renderables.end(); ++it)
|
||||
{
|
||||
if (it->renderable == renderable)
|
||||
{
|
||||
InvalidateAABB();
|
||||
|
||||
std::size_t materialCount = renderable->GetMaterialCount();
|
||||
for (std::size_t i = 0; i < materialCount; ++i)
|
||||
UnregisterMaterial(renderable->GetMaterial(i));
|
||||
|
||||
m_renderables.erase(it);
|
||||
|
||||
ForceCullingInvalidation();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks if this graphics component requires real-time reflections to be generated
|
||||
*
|
||||
* If any of the materials attached to a GraphicsComponent (via the attached instanced renderable) needs real-time reflections, this function will return true.
|
||||
*
|
||||
* \return True if real-time reflections needs to be generated or false
|
||||
*/
|
||||
inline bool GraphicsComponent::DoesRequireRealTimeReflections() const
|
||||
{
|
||||
return m_reflectiveMaterialCount != 0 && m_reflectionMap;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the bounding volume is up to date
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::EnsureBoundingVolumesUpdate() const
|
||||
{
|
||||
if (!m_boundingVolumesUpdated)
|
||||
UpdateBoundingVolumes();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the transformation matrix is up to date
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
|
||||
{
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the axis-aligned bounding box of the entity
|
||||
* \return A constant reference to the AABB
|
||||
*/
|
||||
inline const Nz::Boxf& GraphicsComponent::GetAABB() const
|
||||
{
|
||||
EnsureBoundingVolumesUpdate();
|
||||
|
||||
return m_aabb;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the set of renderable elements
|
||||
*
|
||||
* \param renderables Pointer to the list of renderables
|
||||
*
|
||||
* \remark Produces a NazaraAssert if renderables is invalid
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::GetAttachedRenderables(RenderableList* renderables) const
|
||||
{
|
||||
NazaraAssert(renderables, "Invalid renderable list");
|
||||
|
||||
renderables->reserve(renderables->size() + m_renderables.size());
|
||||
for (const Renderable& r : m_renderables)
|
||||
renderables->push_back(r.renderable);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the number of renderable elements attached to the entity
|
||||
* \return Number of renderable elements
|
||||
*/
|
||||
|
||||
inline std::size_t GraphicsComponent::GetAttachedRenderableCount() const
|
||||
{
|
||||
return m_renderables.size();
|
||||
}
|
||||
|
||||
inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume(std::size_t renderableIndex) const
|
||||
{
|
||||
EnsureBoundingVolumesUpdate();
|
||||
|
||||
assert(renderableIndex < m_renderables.size());
|
||||
return m_renderables[renderableIndex].boundingVolume;
|
||||
}
|
||||
|
||||
inline const Nz::Matrix4f& GraphicsComponent::GetLocalMatrix(std::size_t renderableIndex) const
|
||||
{
|
||||
assert(renderableIndex < m_renderables.size());
|
||||
return m_renderables[renderableIndex].data.localMatrix;
|
||||
}
|
||||
|
||||
inline const Nz::Matrix4f& GraphicsComponent::GetTransformMatrix(std::size_t renderableIndex) const
|
||||
{
|
||||
EnsureBoundingVolumesUpdate();
|
||||
|
||||
assert(renderableIndex < m_renderables.size());
|
||||
return m_renderables[renderableIndex].data.transformMatrix;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calls a function for every renderable attached to this component
|
||||
*
|
||||
* \param func Callback function which will be called with renderable data
|
||||
*/
|
||||
template<typename Func>
|
||||
void GraphicsComponent::ForEachRenderable(const Func& func) const
|
||||
{
|
||||
for (const auto& renderableData : m_renderables)
|
||||
func(renderableData.renderable, renderableData.data.localMatrix, renderableData.data.renderOrder);
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const
|
||||
{
|
||||
for (auto it = m_cullingBoxEntries.begin(); it != m_cullingBoxEntries.end(); ++it)
|
||||
{
|
||||
if (it->listEntry.GetParent() == cullingList)
|
||||
{
|
||||
if (m_cullingBoxEntries.size() > 1)
|
||||
*it = std::move(m_cullingBoxEntries.back());
|
||||
|
||||
m_cullingBoxEntries.pop_back();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::SetScissorRect(const Nz::Recti& scissorRect)
|
||||
{
|
||||
m_scissorRect = scissorRect;
|
||||
|
||||
for (CullingBoxEntry& entry : m_cullingBoxEntries)
|
||||
entry.listEntry.ForceInvalidation(); //< Invalidate render queues
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix)
|
||||
{
|
||||
for (auto& renderable : m_renderables)
|
||||
{
|
||||
if (renderable.renderable == instancedRenderable)
|
||||
{
|
||||
renderable.data.localMatrix = localMatrix;
|
||||
|
||||
InvalidateAABB();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder)
|
||||
{
|
||||
for (auto& renderable : m_renderables)
|
||||
{
|
||||
if (renderable.renderable == instancedRenderable)
|
||||
{
|
||||
renderable.data.renderOrder = renderOrder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the bounding volume
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::ForceCullingInvalidation()
|
||||
{
|
||||
for (CullingBoxEntry& entry : m_cullingBoxEntries)
|
||||
entry.listEntry.ForceInvalidation(); //< Invalidate render queues
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateAABB() const
|
||||
{
|
||||
m_boundingVolumesUpdated = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates every renderable elements
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::InvalidateRenderables()
|
||||
{
|
||||
for (Renderable& r : m_renderables)
|
||||
r.dataUpdated = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the transformation matrix
|
||||
*/
|
||||
|
||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||
{
|
||||
m_transformMatrixUpdated = false;
|
||||
|
||||
InvalidateAABB();
|
||||
InvalidateRenderables();
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <NazaraSDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LightComponent;
|
||||
|
||||
using LightComponentHandle = Nz::ObjectHandle<LightComponent>;
|
||||
|
||||
class NDK_API LightComponent : public Component<LightComponent>, public Nz::Light
|
||||
{
|
||||
public:
|
||||
inline LightComponent(Nz::LightType lightType = Nz::LightType_Point);
|
||||
LightComponent(const LightComponent& light) = default;
|
||||
~LightComponent() = default;
|
||||
|
||||
LightComponent& operator=(const LightComponent& light) = default;
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Components/LightComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,15 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs an LightComponent object with a light type
|
||||
*/
|
||||
|
||||
inline LightComponent::LightComponent(Nz::LightType lightType) :
|
||||
Nz::Light(lightType)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Graphics/ParticleEmitter.hpp>
|
||||
#include <NazaraSDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class ParticleEmitterComponent;
|
||||
|
||||
using ParticleEmitterComponentHandle = Nz::ObjectHandle<ParticleEmitterComponent>;
|
||||
|
||||
class NDK_API ParticleEmitterComponent : public Component<ParticleEmitterComponent>, public Nz::ParticleEmitter
|
||||
{
|
||||
public:
|
||||
using SetupFunc = std::function<void(const EntityHandle& /*entity*/, Nz::ParticleMapper& /*mapper*/, unsigned int /*count*/)>;
|
||||
|
||||
inline ParticleEmitterComponent();
|
||||
ParticleEmitterComponent(const ParticleEmitterComponent& emitter) = default;
|
||||
ParticleEmitterComponent(ParticleEmitterComponent&& emitter) = default;
|
||||
~ParticleEmitterComponent() = default;
|
||||
|
||||
inline void Enable(bool active = true);
|
||||
|
||||
inline bool IsActive() const;
|
||||
|
||||
inline void SetSetupFunc(SetupFunc func);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
void SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const override;
|
||||
|
||||
SetupFunc m_setupFunc;
|
||||
bool m_isActive;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Components/ParticleEmitterComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs an ParticleEmitterComponent object by default
|
||||
*/
|
||||
|
||||
inline ParticleEmitterComponent::ParticleEmitterComponent() :
|
||||
m_isActive(true)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enables the emission of particles
|
||||
*
|
||||
* \param active Should the emitter be active
|
||||
*/
|
||||
|
||||
inline void Ndk::ParticleEmitterComponent::Enable(bool active)
|
||||
{
|
||||
m_isActive = active;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the emission of particles is activated
|
||||
* \param true If it is the case
|
||||
*/
|
||||
|
||||
inline bool ParticleEmitterComponent::IsActive() const
|
||||
{
|
||||
return m_isActive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the function use for setting up particles
|
||||
*
|
||||
* \param func Function to set up particles
|
||||
*/
|
||||
|
||||
inline void Ndk::ParticleEmitterComponent::SetSetupFunc(SetupFunc func)
|
||||
{
|
||||
m_setupFunc = std::move(func);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Graphics/ParticleGroup.hpp>
|
||||
#include <NazaraSDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class ParticleGroupComponent;
|
||||
|
||||
using ParticleGroupComponentHandle = Nz::ObjectHandle<ParticleGroupComponent>;
|
||||
|
||||
class NDK_API ParticleGroupComponent : public Component<ParticleGroupComponent>, public Nz::ParticleGroup
|
||||
{
|
||||
public:
|
||||
inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout);
|
||||
inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration);
|
||||
ParticleGroupComponent(const ParticleGroupComponent&) = default;
|
||||
~ParticleGroupComponent() = default;
|
||||
|
||||
void AddEmitter(Entity* emitter);
|
||||
using ParticleGroup::AddEmitter;
|
||||
|
||||
void RemoveEmitter(Entity* emitter);
|
||||
using ParticleGroup::RemoveEmitter;
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Components/ParticleGroupComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,76 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Components/ParticleEmitterComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \ingroup NDK
|
||||
* \class Ndk::ParticleGroupComponent
|
||||
* \brief NDK class that represents the component for a group of particles
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a layout
|
||||
*
|
||||
* \param maxParticleCount Maximum number of particles to generate
|
||||
* \param layout Enumeration for the layout of data information for the particles
|
||||
*/
|
||||
|
||||
inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout) :
|
||||
ParticleGroup(maxParticleCount, layout)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a particle declaration
|
||||
*
|
||||
* \param maxParticleCount Maximum number of particles to generate
|
||||
* \param declaration Data information for the particles
|
||||
*/
|
||||
|
||||
inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration) :
|
||||
ParticleGroup(maxParticleCount, std::move(declaration))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds an emitter to the particles
|
||||
*
|
||||
* \param emitter Emitter for the particles
|
||||
*
|
||||
* \remark Produces a NazaraAssert if emitter is invalid
|
||||
* \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent
|
||||
*/
|
||||
|
||||
inline void ParticleGroupComponent::AddEmitter(Entity* emitter)
|
||||
{
|
||||
NazaraAssert(emitter && emitter->IsValid(), "Invalid entity");
|
||||
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a ParticleEmitterComponent");
|
||||
|
||||
auto& emitterComponent = emitter->GetComponent<ParticleEmitterComponent>();
|
||||
ParticleGroup::AddEmitter(&emitterComponent);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Removes an emitter to the particles
|
||||
*
|
||||
* \param emitter Emitter for the particles to remove
|
||||
*
|
||||
* \remark Produces a NazaraAssert if emitter is invalid
|
||||
* \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent
|
||||
*/
|
||||
|
||||
inline void ParticleGroupComponent::RemoveEmitter(Entity* emitter)
|
||||
{
|
||||
NazaraAssert(emitter && emitter->IsValid(), "Invalid entity");
|
||||
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a ParticleEmitterComponent");
|
||||
|
||||
auto& emitterComponent = emitter->GetComponent<ParticleEmitterComponent>();
|
||||
ParticleGroup::RemoveEmitter(&emitterComponent);
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_CONSOLE_HPP
|
||||
#define NDK_CONSOLE_HPP
|
||||
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <NazaraSDK/EntityOwner.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct WindowEvent;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class AbstractTextAreaWidget;
|
||||
class Console;
|
||||
class Entity;
|
||||
class RichTextAreaWidget;
|
||||
class ScrollAreaWidget;
|
||||
class TextAreaWidget;
|
||||
|
||||
using ConsoleHandle = Nz::ObjectHandle<Console>;
|
||||
|
||||
class NDK_API Console : public BaseWidget, public Nz::HandledObject<Console>
|
||||
{
|
||||
public:
|
||||
Console(BaseWidget* parent);
|
||||
Console(const Console& console) = delete;
|
||||
Console(Console&& console) = default;
|
||||
~Console() = default;
|
||||
|
||||
void AddLine(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
|
||||
|
||||
void Clear();
|
||||
void ClearFocus();
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const RichTextAreaWidget* GetHistory() const;
|
||||
inline const TextAreaWidget* GetInput() const;
|
||||
inline const Nz::FontRef& GetTextFont() const;
|
||||
|
||||
void SetCharacterSize(unsigned int size);
|
||||
void SetFocus();
|
||||
void SetTextFont(Nz::FontRef font);
|
||||
|
||||
Console& operator=(const Console& console) = delete;
|
||||
Console& operator=(Console&& console) = default;
|
||||
|
||||
NazaraSignal(OnCommand, Console* /*console*/, const Nz::String& /*command*/);
|
||||
|
||||
private:
|
||||
void ExecuteInput(const AbstractTextAreaWidget* textArea, bool* ignoreDefaultAction);
|
||||
void Layout() override;
|
||||
|
||||
struct Line
|
||||
{
|
||||
Nz::Color color;
|
||||
Nz::String text;
|
||||
};
|
||||
|
||||
std::size_t m_historyPosition;
|
||||
std::vector<Nz::String> m_commandHistory;
|
||||
std::vector<Line> m_historyLines;
|
||||
ScrollAreaWidget* m_historyArea;
|
||||
RichTextAreaWidget* m_history;
|
||||
TextAreaWidget* m_input;
|
||||
Nz::FontRef m_defaultFont;
|
||||
unsigned int m_characterSize;
|
||||
unsigned int m_maxHistoryLines;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Console.inl>
|
||||
|
||||
#endif // NDK_CONSOLE_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Gets the character size
|
||||
* \return Height of the character
|
||||
*/
|
||||
|
||||
inline unsigned int Console::GetCharacterSize() const
|
||||
{
|
||||
return m_characterSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the entity representing the history of the console
|
||||
* \return History of the console
|
||||
*/
|
||||
|
||||
inline const RichTextAreaWidget* Console::GetHistory() const
|
||||
{
|
||||
return m_history;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the entity representing the input of the console
|
||||
* \return Input of the console
|
||||
*/
|
||||
|
||||
inline const TextAreaWidget* Console::GetInput() const
|
||||
{
|
||||
return m_input;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the font used by the console
|
||||
* \return A reference to the font currenty used
|
||||
*/
|
||||
|
||||
inline const Nz::FontRef& Console::GetTextFont() const
|
||||
{
|
||||
return m_defaultFont;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_SYSTEMS_DEBUGSYSTEM_HPP
|
||||
#define NDK_SYSTEMS_DEBUGSYSTEM_HPP
|
||||
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <NazaraSDK/System.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API DebugSystem : public System<DebugSystem>
|
||||
{
|
||||
public:
|
||||
DebugSystem();
|
||||
~DebugSystem() = default;
|
||||
|
||||
void EnableDepthBuffer(bool enable);
|
||||
|
||||
inline bool IsDepthBufferEnabled() const;
|
||||
|
||||
static SystemIndex systemIndex;
|
||||
|
||||
private:
|
||||
Nz::InstancedRenderableRef GenerateBox(Nz::Boxf box);
|
||||
Nz::InstancedRenderableRef GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* offset);
|
||||
Nz::InstancedRenderableRef GenerateCollision3DMesh(Entity* entity);
|
||||
|
||||
std::pair<Nz::IndexBufferRef, Nz::VertexBufferRef> GetBoxMesh();
|
||||
Nz::MaterialRef GetCollisionMaterial();
|
||||
Nz::MaterialRef GetGlobalAABBMaterial();
|
||||
Nz::MaterialRef GetLocalAABBMaterial();
|
||||
Nz::MaterialRef GetOBBMaterial();
|
||||
|
||||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||
void OnUpdate(float elapsedTime) override;
|
||||
|
||||
Nz::MaterialRef m_globalAabbMaterial;
|
||||
Nz::MaterialRef m_localAabbMaterial;
|
||||
Nz::MaterialRef m_collisionMaterial;
|
||||
Nz::MaterialRef m_obbMaterial;
|
||||
Nz::IndexBufferRef m_boxMeshIndexBuffer;
|
||||
Nz::VertexBufferRef m_boxMeshVertexBuffer;
|
||||
bool m_isDepthBufferEnabled;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Systems/DebugSystem.inl>
|
||||
|
||||
#endif // NDK_SYSTEMS_DEBUGSYSTEM_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Systems/DebugSystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline bool DebugSystem::IsDepthBufferEnabled() const
|
||||
{
|
||||
return m_isDepthBufferEnabled;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_SYSTEMS_PARTICLESYSTEM_HPP
|
||||
#define NDK_SYSTEMS_PARTICLESYSTEM_HPP
|
||||
|
||||
#include <NazaraSDK/System.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ParticleSystem : public System<ParticleSystem>
|
||||
{
|
||||
public:
|
||||
ParticleSystem();
|
||||
~ParticleSystem() = default;
|
||||
|
||||
static SystemIndex systemIndex;
|
||||
|
||||
private:
|
||||
void OnUpdate(float elapsedTime) override;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Systems/ParticleSystem.inl>
|
||||
|
||||
#endif // NDK_SYSTEMS_PARTICLESYSTEM_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,3 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
@@ -1,85 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_SYSTEMS_RENDERSYSTEM_HPP
|
||||
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
|
||||
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Graphics/CullingList.hpp>
|
||||
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <NazaraSDK/EntityList.hpp>
|
||||
#include <NazaraSDK/System.hpp>
|
||||
#include <NazaraSDK/Components/GraphicsComponent.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class AbstractViewer;
|
||||
|
||||
class NDK_API RenderSystem : public System<RenderSystem>
|
||||
{
|
||||
public:
|
||||
RenderSystem();
|
||||
~RenderSystem() = default;
|
||||
|
||||
template<typename T> T& ChangeRenderTechnique();
|
||||
inline Nz::AbstractRenderTechnique& ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique);
|
||||
|
||||
inline void EnableCulling(bool enable);
|
||||
|
||||
inline const Nz::BackgroundRef& GetDefaultBackground() const;
|
||||
inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const;
|
||||
inline Nz::Vector3f GetGlobalForward() const;
|
||||
inline Nz::Vector3f GetGlobalRight() const;
|
||||
inline Nz::Vector3f GetGlobalUp() const;
|
||||
inline Nz::AbstractRenderTechnique& GetRenderTechnique() const;
|
||||
|
||||
inline bool IsCullingEnabled() const;
|
||||
|
||||
inline void SetDefaultBackground(Nz::BackgroundRef background);
|
||||
inline void SetGlobalForward(const Nz::Vector3f& direction);
|
||||
inline void SetGlobalRight(const Nz::Vector3f& direction);
|
||||
inline void SetGlobalUp(const Nz::Vector3f& direction);
|
||||
|
||||
static SystemIndex systemIndex;
|
||||
|
||||
private:
|
||||
inline void InvalidateCoordinateSystem();
|
||||
|
||||
void OnEntityRemoved(Entity* entity) override;
|
||||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||
void OnUpdate(float elapsedTime) override;
|
||||
|
||||
void UpdateDynamicReflections();
|
||||
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
|
||||
void UpdatePointSpotShadowMaps();
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
|
||||
std::vector<GraphicsComponentCullingList::VolumeEntry> m_volumeEntries;
|
||||
std::vector<EntityHandle> m_cameras;
|
||||
EntityList m_drawables;
|
||||
EntityList m_directionalLights;
|
||||
EntityList m_lights;
|
||||
EntityList m_pointSpotLights;
|
||||
EntityList m_particleGroups;
|
||||
EntityList m_realtimeReflected;
|
||||
GraphicsComponentCullingList m_drawableCulling;
|
||||
Nz::BackgroundRef m_background;
|
||||
Nz::DepthRenderTechnique m_shadowTechnique;
|
||||
Nz::Matrix4f m_coordinateSystemMatrix;
|
||||
Nz::RenderTexture m_shadowRT;
|
||||
bool m_coordinateSystemInvalidated;
|
||||
bool m_forceRenderQueueInvalidation;
|
||||
bool m_isCullingEnabled;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Systems/RenderSystem.inl>
|
||||
|
||||
#endif // NDK_SYSTEMS_RENDERSYSTEM_HPP
|
||||
#endif // NDK_SERVER
|
||||
@@ -1,186 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Systems/RenderSystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Changes the render technique used for the system
|
||||
* \return A reference to the render technique type
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
inline T& RenderSystem::ChangeRenderTechnique()
|
||||
{
|
||||
static_assert(std::is_base_of<Nz::AbstractRenderTechnique, T>::value, "RenderTechnique is not a subtype of AbstractRenderTechnique");
|
||||
return static_cast<T&>(ChangeRenderTechnique(std::make_unique<T>()));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Changes the render technique used for the system
|
||||
* \return A reference to the abstract render technique
|
||||
*
|
||||
* \param renderTechnique Render technique to use
|
||||
*/
|
||||
|
||||
inline Nz::AbstractRenderTechnique& RenderSystem::ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique)
|
||||
{
|
||||
m_renderTechnique = std::move(renderTechnique);
|
||||
return *m_renderTechnique;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enables/disables object culling
|
||||
*
|
||||
* Object culling is an algorithm used by the render system to detect invisible objects (which will not appear on screen) before they are rendered.
|
||||
* This includes Frustum Culling and potentially Occlusion Culling.
|
||||
*
|
||||
* Disabling this is not recommended, as the system will draw every object in the world which could induce a performance loss.
|
||||
*
|
||||
* \param enable Whether to enable or disable culling
|
||||
*
|
||||
* \see IsCullingEnabled
|
||||
*/
|
||||
inline void RenderSystem::EnableCulling(bool enable)
|
||||
{
|
||||
m_isCullingEnabled = enable;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the background used for rendering
|
||||
* \return A reference to the background
|
||||
*/
|
||||
|
||||
inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const
|
||||
{
|
||||
return m_background;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the coordinates matrix used for rendering
|
||||
* \return A constant reference to the matrix of coordinates
|
||||
*/
|
||||
|
||||
inline const Nz::Matrix4f& RenderSystem::GetCoordinateSystemMatrix() const
|
||||
{
|
||||
return m_coordinateSystemMatrix;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the "forward" global direction
|
||||
* \return The forward direction, by default, it's -UnitZ() (Right hand coordinates)
|
||||
*/
|
||||
|
||||
inline Nz::Vector3f RenderSystem::GetGlobalForward() const
|
||||
{
|
||||
return Nz::Vector3f(-m_coordinateSystemMatrix.m13, -m_coordinateSystemMatrix.m23, -m_coordinateSystemMatrix.m33);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the "right" global direction
|
||||
* \return The right direction, by default, it's UnitX() (Right hand coordinates)
|
||||
*/
|
||||
|
||||
inline Nz::Vector3f RenderSystem::GetGlobalRight() const
|
||||
{
|
||||
return Nz::Vector3f(m_coordinateSystemMatrix.m11, m_coordinateSystemMatrix.m21, m_coordinateSystemMatrix.m31);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the "up" global direction
|
||||
* \return The up direction, by default, it's UnitY() (Right hand coordinates)
|
||||
*/
|
||||
|
||||
inline Nz::Vector3f RenderSystem::GetGlobalUp() const
|
||||
{
|
||||
return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the render technique used for rendering
|
||||
* \return A reference to the abstract render technique being used
|
||||
*/
|
||||
|
||||
inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const
|
||||
{
|
||||
return *m_renderTechnique.get();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Query if culling is enabled (enabled by default)
|
||||
* \return True if culling is enabled, false otherwise
|
||||
*
|
||||
* \see EnableCulling
|
||||
*/
|
||||
inline bool RenderSystem::IsCullingEnabled() const
|
||||
{
|
||||
return m_isCullingEnabled;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the background used for rendering
|
||||
*
|
||||
* \param background A reference to the background
|
||||
*/
|
||||
|
||||
inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background)
|
||||
{
|
||||
m_background = std::move(background);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the "forward" global direction
|
||||
*
|
||||
* \param direction The new forward direction
|
||||
*/
|
||||
|
||||
inline void RenderSystem::SetGlobalForward(const Nz::Vector3f& direction)
|
||||
{
|
||||
m_coordinateSystemMatrix.m13 = -direction.x;
|
||||
m_coordinateSystemMatrix.m23 = -direction.y;
|
||||
m_coordinateSystemMatrix.m33 = -direction.z;
|
||||
|
||||
InvalidateCoordinateSystem();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the "right" global direction
|
||||
*
|
||||
* \param direction The new right direction
|
||||
*/
|
||||
|
||||
inline void RenderSystem::SetGlobalRight(const Nz::Vector3f& direction)
|
||||
{
|
||||
m_coordinateSystemMatrix.m11 = direction.x;
|
||||
m_coordinateSystemMatrix.m21 = direction.y;
|
||||
m_coordinateSystemMatrix.m31 = direction.z;
|
||||
|
||||
InvalidateCoordinateSystem();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the "up" global direction
|
||||
*
|
||||
* \param direction The new up direction
|
||||
*/
|
||||
|
||||
inline void RenderSystem::SetGlobalUp(const Nz::Vector3f& direction)
|
||||
{
|
||||
m_coordinateSystemMatrix.m12 = direction.x;
|
||||
m_coordinateSystemMatrix.m22 = direction.y;
|
||||
m_coordinateSystemMatrix.m32 = direction.z;
|
||||
|
||||
InvalidateCoordinateSystem();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the matrix of coordinates for the system
|
||||
*/
|
||||
|
||||
inline void RenderSystem::InvalidateCoordinateSystem()
|
||||
{
|
||||
m_coordinateSystemInvalidated = true;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// This file was automatically generated
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_GLOBAL_HPP
|
||||
#define NDK_WIDGETS_GLOBAL_HPP
|
||||
|
||||
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/BoxLayout.hpp>
|
||||
#include <NazaraSDK/Widgets/ButtonWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/CheckboxWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/Enums.hpp>
|
||||
#include <NazaraSDK/Widgets/ImageWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/LabelWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/ProgressBarWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/RichTextAreaWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/ScrollAreaWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/TextAreaWidget.hpp>
|
||||
|
||||
#endif // NDK_WIDGETS_GLOBAL_HPP
|
||||
@@ -1,135 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP
|
||||
#define NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/Enums.hpp>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API AbstractTextAreaWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
using CharacterFilter = std::function<bool(char32_t)>;
|
||||
|
||||
AbstractTextAreaWidget(BaseWidget* parent);
|
||||
AbstractTextAreaWidget(const AbstractTextAreaWidget&) = delete;
|
||||
AbstractTextAreaWidget(AbstractTextAreaWidget&&) = default;
|
||||
~AbstractTextAreaWidget() = default;
|
||||
|
||||
virtual void Clear();
|
||||
|
||||
//virtual TextAreaWidget* Clone() const = 0;
|
||||
|
||||
void EnableLineWrap(bool enable = true);
|
||||
inline void EnableMultiline(bool enable = true);
|
||||
inline void EnableTabWriting(bool enable = true);
|
||||
|
||||
inline void Erase(std::size_t glyphPosition);
|
||||
virtual void Erase(std::size_t firstGlyph, std::size_t lastGlyph) = 0;
|
||||
inline void EraseSelection();
|
||||
|
||||
inline const CharacterFilter& GetCharacterFilter() const;
|
||||
inline const Nz::Vector2ui& GetCursorPosition() const;
|
||||
inline Nz::Vector2ui GetCursorPosition(std::size_t glyphIndex) const;
|
||||
inline EchoMode GetEchoMode() const;
|
||||
inline std::size_t GetGlyphIndex() const;
|
||||
inline std::size_t GetGlyphIndex(const Nz::Vector2ui& cursorPosition) const;
|
||||
inline const Nz::String& GetText() const;
|
||||
|
||||
Nz::Vector2ui GetHoveredGlyph(float x, float y) const;
|
||||
|
||||
inline bool HasSelection() const;
|
||||
|
||||
inline bool IsLineWrapEnabled() const;
|
||||
inline bool IsMultilineEnabled() const;
|
||||
inline bool IsReadOnly() const;
|
||||
inline bool IsTabWritingEnabled() const;
|
||||
|
||||
inline void MoveCursor(int offset);
|
||||
inline void MoveCursor(const Nz::Vector2i& offset);
|
||||
|
||||
inline Nz::Vector2ui NormalizeCursorPosition(Nz::Vector2ui cursorPosition) const;
|
||||
|
||||
inline void SetCharacterFilter(CharacterFilter filter);
|
||||
inline void SetCursorPosition(std::size_t glyphIndex);
|
||||
inline void SetCursorPosition(Nz::Vector2ui cursorPosition);
|
||||
inline void SetEchoMode(EchoMode echoMode);
|
||||
inline void SetReadOnly(bool readOnly = true);
|
||||
inline void SetSelection(Nz::Vector2ui fromPosition, Nz::Vector2ui toPosition);
|
||||
|
||||
inline void Write(const Nz::String& text);
|
||||
inline void Write(const Nz::String& text, const Nz::Vector2ui& glyphPosition);
|
||||
virtual void Write(const Nz::String& text, std::size_t glyphPosition) = 0;
|
||||
|
||||
AbstractTextAreaWidget& operator=(const AbstractTextAreaWidget&) = delete;
|
||||
AbstractTextAreaWidget& operator=(AbstractTextAreaWidget&&) = default;
|
||||
|
||||
NazaraSignal(OnTextAreaCursorMove, const AbstractTextAreaWidget* /*textArea*/, Nz::Vector2ui* /*newCursorPosition*/);
|
||||
NazaraSignal(OnTextAreaKeyBackspace, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyDown, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyEnd, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyHome, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyLeft, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyReturn, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyRight, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyUp, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaSelection, const AbstractTextAreaWidget* /*textArea*/, Nz::Vector2ui* /*start*/, Nz::Vector2ui* /*end*/);
|
||||
|
||||
protected:
|
||||
virtual Nz::AbstractTextDrawer& GetTextDrawer() = 0;
|
||||
virtual const Nz::AbstractTextDrawer& GetTextDrawer() const = 0;
|
||||
|
||||
void Layout() override;
|
||||
|
||||
virtual void HandleIndentation(bool add) = 0;
|
||||
virtual void HandleSelectionIndentation(bool add) = 0;
|
||||
virtual void HandleWordCursorMove(bool left) = 0;
|
||||
|
||||
bool IsFocusable() const override;
|
||||
void OnFocusLost() override;
|
||||
void OnFocusReceived() override;
|
||||
bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
|
||||
void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override;
|
||||
void OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
|
||||
void OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||
void OnTextEntered(char32_t character, bool repeated) override;
|
||||
|
||||
inline void SetCursorPositionInternal(std::size_t glyphIndex);
|
||||
inline void SetCursorPositionInternal(Nz::Vector2ui cursorPosition);
|
||||
|
||||
void RefreshCursor();
|
||||
virtual void UpdateDisplayText() = 0;
|
||||
void UpdateTextSprite();
|
||||
|
||||
CharacterFilter m_characterFilter;
|
||||
EchoMode m_echoMode;
|
||||
EntityHandle m_cursorEntity;
|
||||
EntityHandle m_textEntity;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
Nz::Vector2ui m_cursorPositionBegin;
|
||||
Nz::Vector2ui m_cursorPositionEnd;
|
||||
Nz::Vector2ui m_selectionCursor;
|
||||
std::vector<Nz::SpriteRef> m_cursorSprites;
|
||||
bool m_isLineWrapEnabled;
|
||||
bool m_isMouseButtonDown;
|
||||
bool m_multiLineEnabled;
|
||||
bool m_readOnly;
|
||||
bool m_tabEnabled; // writes (Shift+)Tab character if set to true
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP
|
||||
@@ -1,252 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline void AbstractTextAreaWidget::EnableMultiline(bool enable)
|
||||
{
|
||||
m_multiLineEnabled = enable;
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::EnableTabWriting(bool enable)
|
||||
{
|
||||
m_tabEnabled = enable;
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::Erase(std::size_t glyphPosition)
|
||||
{
|
||||
Erase(glyphPosition, glyphPosition + 1U);
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::EraseSelection()
|
||||
{
|
||||
if (!HasSelection())
|
||||
return;
|
||||
|
||||
Erase(GetGlyphIndex(m_cursorPositionBegin), GetGlyphIndex(m_cursorPositionEnd));
|
||||
}
|
||||
|
||||
inline const AbstractTextAreaWidget::CharacterFilter& AbstractTextAreaWidget::GetCharacterFilter() const
|
||||
{
|
||||
return m_characterFilter;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2ui& AbstractTextAreaWidget::GetCursorPosition() const
|
||||
{
|
||||
return m_cursorPositionBegin;
|
||||
}
|
||||
|
||||
Nz::Vector2ui AbstractTextAreaWidget::GetCursorPosition(std::size_t glyphIndex) const
|
||||
{
|
||||
const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer();
|
||||
|
||||
glyphIndex = std::min(glyphIndex, GetTextDrawer().GetGlyphCount());
|
||||
|
||||
std::size_t lineCount = textDrawer.GetLineCount();
|
||||
std::size_t line = 0U;
|
||||
for (std::size_t i = line + 1; i < lineCount; ++i)
|
||||
{
|
||||
if (textDrawer.GetLine(i).glyphIndex > glyphIndex)
|
||||
break;
|
||||
|
||||
line = i;
|
||||
}
|
||||
|
||||
const auto& lineInfo = textDrawer.GetLine(line);
|
||||
|
||||
Nz::Vector2ui cursorPos;
|
||||
cursorPos.y = static_cast<unsigned int>(line);
|
||||
cursorPos.x = static_cast<unsigned int>(glyphIndex - lineInfo.glyphIndex);
|
||||
|
||||
return cursorPos;
|
||||
}
|
||||
|
||||
inline EchoMode AbstractTextAreaWidget::GetEchoMode() const
|
||||
{
|
||||
return m_echoMode;
|
||||
}
|
||||
|
||||
inline std::size_t AbstractTextAreaWidget::GetGlyphIndex() const
|
||||
{
|
||||
return GetGlyphIndex(m_cursorPositionBegin);
|
||||
}
|
||||
|
||||
inline std::size_t AbstractTextAreaWidget::GetGlyphIndex(const Nz::Vector2ui& cursorPosition) const
|
||||
{
|
||||
const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer();
|
||||
|
||||
std::size_t glyphIndex = textDrawer.GetLine(cursorPosition.y).glyphIndex + cursorPosition.x;
|
||||
if (textDrawer.GetLineCount() > cursorPosition.y + 1)
|
||||
glyphIndex = std::min(glyphIndex, textDrawer.GetLine(cursorPosition.y + 1).glyphIndex - 1);
|
||||
else
|
||||
glyphIndex = std::min(glyphIndex, textDrawer.GetGlyphCount());
|
||||
|
||||
return glyphIndex;
|
||||
}
|
||||
|
||||
inline bool AbstractTextAreaWidget::HasSelection() const
|
||||
{
|
||||
return m_cursorPositionBegin != m_cursorPositionEnd;
|
||||
}
|
||||
|
||||
inline bool AbstractTextAreaWidget::IsLineWrapEnabled() const
|
||||
{
|
||||
return m_isLineWrapEnabled;
|
||||
}
|
||||
|
||||
inline bool AbstractTextAreaWidget::IsMultilineEnabled() const
|
||||
{
|
||||
return m_multiLineEnabled;
|
||||
}
|
||||
|
||||
inline bool AbstractTextAreaWidget::IsTabWritingEnabled() const
|
||||
{
|
||||
return m_tabEnabled;
|
||||
}
|
||||
|
||||
inline bool AbstractTextAreaWidget::IsReadOnly() const
|
||||
{
|
||||
return m_readOnly;
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::MoveCursor(int offset)
|
||||
{
|
||||
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPositionBegin);
|
||||
if (offset >= 0)
|
||||
SetCursorPosition(cursorGlyph + static_cast<std::size_t>(offset));
|
||||
else
|
||||
{
|
||||
std::size_t nOffset = static_cast<std::size_t>(-offset);
|
||||
if (nOffset >= cursorGlyph)
|
||||
SetCursorPosition(0);
|
||||
else
|
||||
SetCursorPosition(cursorGlyph - nOffset);
|
||||
}
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::MoveCursor(const Nz::Vector2i& offset)
|
||||
{
|
||||
auto ClampOffset = [] (unsigned int cursorPosition, int cursorOffset) -> unsigned int
|
||||
{
|
||||
if (cursorOffset >= 0)
|
||||
return cursorPosition + cursorOffset;
|
||||
else
|
||||
{
|
||||
unsigned int nOffset = static_cast<unsigned int>(-cursorOffset);
|
||||
if (nOffset >= cursorPosition)
|
||||
return 0;
|
||||
else
|
||||
return cursorPosition - nOffset;
|
||||
}
|
||||
};
|
||||
|
||||
Nz::Vector2ui cursorPosition = m_cursorPositionBegin;
|
||||
cursorPosition.x = ClampOffset(static_cast<unsigned int>(cursorPosition.x), offset.x);
|
||||
cursorPosition.y = ClampOffset(static_cast<unsigned int>(cursorPosition.y), offset.y);
|
||||
|
||||
SetCursorPosition(cursorPosition);
|
||||
}
|
||||
|
||||
inline Nz::Vector2ui AbstractTextAreaWidget::NormalizeCursorPosition(Nz::Vector2ui cursorPosition) const
|
||||
{
|
||||
const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer();
|
||||
|
||||
std::size_t lineCount = textDrawer.GetLineCount();
|
||||
if (cursorPosition.y >= lineCount)
|
||||
cursorPosition.y = static_cast<unsigned int>(lineCount - 1);
|
||||
|
||||
const auto& lineInfo = textDrawer.GetLine(cursorPosition.y);
|
||||
if (cursorPosition.y + 1 < lineCount)
|
||||
{
|
||||
const auto& nextLineInfo = textDrawer.GetLine(cursorPosition.y + 1);
|
||||
cursorPosition.x = std::min(cursorPosition.x, static_cast<unsigned int>(nextLineInfo.glyphIndex - lineInfo.glyphIndex - 1));
|
||||
}
|
||||
|
||||
return cursorPosition;
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::SetCharacterFilter(CharacterFilter filter)
|
||||
{
|
||||
m_characterFilter = std::move(filter);
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::SetCursorPosition(std::size_t glyphIndex)
|
||||
{
|
||||
Nz::Vector2ui position = GetCursorPosition(glyphIndex);
|
||||
Nz::Vector2ui newPosition = position;
|
||||
|
||||
OnTextAreaCursorMove(this, &newPosition);
|
||||
|
||||
if (position == newPosition)
|
||||
SetCursorPositionInternal(position);
|
||||
else
|
||||
SetCursorPositionInternal(GetGlyphIndex(newPosition));
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::SetCursorPosition(Nz::Vector2ui cursorPosition)
|
||||
{
|
||||
OnTextAreaCursorMove(this, &cursorPosition);
|
||||
|
||||
return SetCursorPositionInternal(NormalizeCursorPosition(cursorPosition));
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::SetEchoMode(EchoMode echoMode)
|
||||
{
|
||||
m_echoMode = echoMode;
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::SetReadOnly(bool readOnly)
|
||||
{
|
||||
m_readOnly = readOnly;
|
||||
m_cursorEntity->Enable(!m_readOnly && HasFocus());
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::SetSelection(Nz::Vector2ui fromPosition, Nz::Vector2ui toPosition)
|
||||
{
|
||||
// Ensure begin is before end
|
||||
if (toPosition.y < fromPosition.y || (toPosition.y == fromPosition.y && toPosition.x < fromPosition.x))
|
||||
std::swap(fromPosition, toPosition);
|
||||
|
||||
if (m_cursorPositionBegin != fromPosition || m_cursorPositionEnd != toPosition)
|
||||
{
|
||||
OnTextAreaSelection(this, &fromPosition, &toPosition);
|
||||
|
||||
// Ensure begin is before end a second time (in case signal changed it)
|
||||
if (toPosition.y < fromPosition.y || (toPosition.y == fromPosition.y && toPosition.x < fromPosition.x))
|
||||
std::swap(fromPosition, toPosition);
|
||||
|
||||
m_cursorPositionBegin = NormalizeCursorPosition(fromPosition);
|
||||
m_cursorPositionEnd = NormalizeCursorPosition(toPosition);
|
||||
|
||||
RefreshCursor();
|
||||
}
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::Write(const Nz::String& text)
|
||||
{
|
||||
Write(text, GetGlyphIndex(m_cursorPositionBegin));
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::Write(const Nz::String& text, const Nz::Vector2ui& glyphPosition)
|
||||
{
|
||||
Write(text, GetGlyphIndex(glyphPosition));
|
||||
}
|
||||
|
||||
void AbstractTextAreaWidget::SetCursorPositionInternal(std::size_t glyphIndex)
|
||||
{
|
||||
return SetCursorPositionInternal(GetCursorPosition(glyphIndex));
|
||||
}
|
||||
|
||||
inline void AbstractTextAreaWidget::SetCursorPositionInternal(Nz::Vector2ui cursorPosition)
|
||||
{
|
||||
m_cursorPositionBegin = cursorPosition;
|
||||
m_cursorPositionEnd = m_cursorPositionBegin;
|
||||
|
||||
RefreshCursor();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_BOXLAYOUT_HPP
|
||||
#define NDK_WIDGETS_BOXLAYOUT_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <NazaraSDK/Widgets/Enums.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API BoxLayout : public BaseWidget
|
||||
{
|
||||
public:
|
||||
inline BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation);
|
||||
BoxLayout(const BoxLayout&) = delete;
|
||||
BoxLayout(BoxLayout&&) = default;
|
||||
~BoxLayout() = default;
|
||||
|
||||
void Layout() override;
|
||||
|
||||
BoxLayout& operator=(const BoxLayout&) = delete;
|
||||
BoxLayout& operator=(BoxLayout&&) = default;
|
||||
|
||||
private:
|
||||
struct ChildInfo
|
||||
{
|
||||
BaseWidget* widget;
|
||||
bool isConstrained;
|
||||
float maximumSize;
|
||||
float minimumSize;
|
||||
float size;
|
||||
};
|
||||
|
||||
std::vector<ChildInfo> m_childInfos;
|
||||
BoxLayoutOrientation m_orientation;
|
||||
float m_spacing;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/BoxLayout.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_BOXLAYOUT_HPP
|
||||
@@ -1,15 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/BoxLayout.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
BoxLayout::BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation) :
|
||||
BaseWidget(parent),
|
||||
m_orientation(orientation),
|
||||
m_spacing(5.f)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_BUTTONWIDGET_HPP
|
||||
#define NDK_WIDGETS_BUTTONWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ButtonWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
ButtonWidget(BaseWidget* parent);
|
||||
ButtonWidget(const ButtonWidget&) = delete;
|
||||
ButtonWidget(ButtonWidget&&) = default;
|
||||
~ButtonWidget() = default;
|
||||
|
||||
inline const Nz::Color& GetColor() const;
|
||||
inline const Nz::Color& GetCornerColor() const;
|
||||
inline const Nz::Color& GetHoverColor() const;
|
||||
inline const Nz::Color& GetHoverCornerColor() const;
|
||||
inline const Nz::Color& GetPressColor() const;
|
||||
inline const Nz::Color& GetPressCornerColor() const;
|
||||
|
||||
inline const Nz::TextureRef& GetTexture() const;
|
||||
inline const Nz::TextureRef& GetHoverTexture() const;
|
||||
inline const Nz::TextureRef& GetPressTexture() const;
|
||||
|
||||
inline void SetColor(const Nz::Color& color, const Nz::Color& cornerColor);
|
||||
inline void SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor);
|
||||
inline void SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor);
|
||||
|
||||
inline void SetTexture(const Nz::TextureRef& texture);
|
||||
inline void SetHoverTexture(const Nz::TextureRef& texture);
|
||||
inline void SetPressTexture(const Nz::TextureRef& texture);
|
||||
|
||||
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||
|
||||
ButtonWidget& operator=(const ButtonWidget&) = delete;
|
||||
ButtonWidget& operator=(ButtonWidget&&) = default;
|
||||
|
||||
static const Nz::Color& GetDefaultColor();
|
||||
static const Nz::Color& GetDefaultCornerColor();
|
||||
static const Nz::Color& GetDefaultHoverColor();
|
||||
static const Nz::Color& GetDefaultHoverCornerColor();
|
||||
static const Nz::Color& GetDefaultPressColor();
|
||||
static const Nz::Color& GetDefaultPressCornerColor();
|
||||
|
||||
NazaraSignal(OnButtonTrigger, const ButtonWidget* /*button*/);
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) override;
|
||||
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
|
||||
void OnMouseExit() override;
|
||||
|
||||
EntityHandle m_textEntity;
|
||||
EntityHandle m_gradientEntity;
|
||||
Nz::SpriteRef m_gradientSprite;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
|
||||
Nz::Color m_color;
|
||||
Nz::Color m_cornerColor;
|
||||
Nz::Color m_hoverColor;
|
||||
Nz::Color m_hoverCornerColor;
|
||||
Nz::Color m_pressColor;
|
||||
Nz::Color m_pressCornerColor;
|
||||
|
||||
Nz::TextureRef m_texture;
|
||||
Nz::TextureRef m_hoverTexture;
|
||||
Nz::TextureRef m_pressTexture;
|
||||
|
||||
static Nz::Color s_color;
|
||||
static Nz::Color s_cornerColor;
|
||||
static Nz::Color s_hoverColor;
|
||||
static Nz::Color s_hoverCornerColor;
|
||||
static Nz::Color s_pressColor;
|
||||
static Nz::Color s_pressCornerColor;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/ButtonWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_BUTTONWIDGET_HPP
|
||||
@@ -1,102 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/ButtonWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline const Nz::Color& ButtonWidget::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline const Nz::Color& ButtonWidget::GetCornerColor() const
|
||||
{
|
||||
return m_cornerColor;
|
||||
}
|
||||
|
||||
inline const Nz::Color& ButtonWidget::GetHoverColor() const
|
||||
{
|
||||
return m_hoverColor;
|
||||
}
|
||||
|
||||
inline const Nz::Color& ButtonWidget::GetHoverCornerColor() const
|
||||
{
|
||||
return m_hoverCornerColor;
|
||||
}
|
||||
|
||||
inline const Nz::Color& ButtonWidget::GetPressColor() const
|
||||
{
|
||||
return m_pressColor;
|
||||
}
|
||||
|
||||
inline const Nz::Color& ButtonWidget::GetPressCornerColor() const
|
||||
{
|
||||
return m_pressCornerColor;
|
||||
}
|
||||
|
||||
inline const Nz::TextureRef& ButtonWidget::GetTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
inline const Nz::TextureRef& ButtonWidget::GetHoverTexture() const
|
||||
{
|
||||
return m_hoverTexture;
|
||||
}
|
||||
|
||||
inline const Nz::TextureRef& ButtonWidget::GetPressTexture() const
|
||||
{
|
||||
return m_pressTexture;
|
||||
}
|
||||
|
||||
inline void ButtonWidget::SetColor(const Nz::Color& color, const Nz::Color& cornerColor)
|
||||
{
|
||||
m_color = color;
|
||||
m_cornerColor = cornerColor;
|
||||
|
||||
m_gradientSprite->SetColor(m_color);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor);
|
||||
}
|
||||
|
||||
inline void ButtonWidget::SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor)
|
||||
{
|
||||
m_hoverColor = color;
|
||||
m_hoverCornerColor = cornerColor;
|
||||
}
|
||||
|
||||
inline void ButtonWidget::SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor)
|
||||
{
|
||||
m_pressColor = color;
|
||||
m_pressCornerColor = cornerColor;
|
||||
}
|
||||
|
||||
inline void ButtonWidget::SetTexture(const Nz::TextureRef& texture)
|
||||
{
|
||||
m_texture = texture;
|
||||
m_gradientSprite->SetTexture(m_texture);
|
||||
}
|
||||
|
||||
inline void ButtonWidget::SetHoverTexture(const Nz::TextureRef& texture)
|
||||
{
|
||||
m_hoverTexture = texture;
|
||||
}
|
||||
|
||||
inline void ButtonWidget::SetPressTexture(const Nz::TextureRef& texture)
|
||||
{
|
||||
m_pressTexture = texture;
|
||||
}
|
||||
|
||||
inline void ButtonWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
|
||||
Nz::Vector2f textSize = Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths());
|
||||
SetMinimumSize(textSize);
|
||||
SetPreferredSize(textSize + Nz::Vector2f(20.f, 10.f));
|
||||
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_CHECKBOXWIDGET_HPP
|
||||
#define NDK_WIDGETS_CHECKBOXWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <NazaraSDK/Components/NodeComponent.hpp>
|
||||
#include <NazaraSDK/Widgets/Enums.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API CheckboxWidget : public BaseWidget
|
||||
{
|
||||
friend class Sdk;
|
||||
|
||||
public:
|
||||
CheckboxWidget(BaseWidget* parent);
|
||||
CheckboxWidget(const CheckboxWidget&) = delete;
|
||||
CheckboxWidget(CheckboxWidget&&) = default;
|
||||
~CheckboxWidget() = default;
|
||||
|
||||
//virtual CheckboxWidget* Clone() const = 0;
|
||||
|
||||
inline void EnableAdaptativeMargin(bool enable = true);
|
||||
inline void EnableCheckbox(bool enable = true);
|
||||
inline void EnableTristate(bool enable = true);
|
||||
|
||||
inline bool IsCheckboxEnabled() const;
|
||||
inline bool IsMarginAdaptative() const;
|
||||
inline bool IsTristateEnabled() const;
|
||||
|
||||
inline const Nz::Vector2f& GetCheckboxSize() const;
|
||||
inline Nz::Vector2f GetCheckboxBorderSize() const;
|
||||
inline CheckboxState GetState() const;
|
||||
inline float GetTextMargin() const;
|
||||
|
||||
inline void SetCheckboxSize(const Nz::Vector2f& size);
|
||||
CheckboxState SwitchToNextState();
|
||||
void SetState(CheckboxState state);
|
||||
inline void SetTextMargin(float margin);
|
||||
|
||||
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||
|
||||
|
||||
CheckboxWidget& operator=(const CheckboxWidget&) = delete;
|
||||
CheckboxWidget& operator=(CheckboxWidget&&) = default;
|
||||
|
||||
NazaraSignal(OnStateChanged, const CheckboxWidget* /*checkbox*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
void Layout() override;
|
||||
void UpdateCheckbox();
|
||||
void UpdateSize();
|
||||
|
||||
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
|
||||
inline bool ContainsCheckbox(int x, int y) const;
|
||||
|
||||
|
||||
EntityHandle m_checkboxBorderEntity;
|
||||
EntityHandle m_checkboxBackgroundEntity;
|
||||
EntityHandle m_checkboxContentEntity;
|
||||
EntityHandle m_textEntity;
|
||||
|
||||
Nz::TextureRef m_checkMark;
|
||||
|
||||
Nz::SpriteRef m_checkboxContentSprite;
|
||||
Nz::SpriteRef m_checkboxBorderSprite;
|
||||
Nz::SpriteRef m_checkboxBackgroundSprite;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
|
||||
static Nz::Color s_backgroundColor;
|
||||
static Nz::Color s_disabledBackgroundColor;
|
||||
static Nz::Color s_disabledBorderColor;
|
||||
static Nz::Color s_borderColor;
|
||||
|
||||
bool m_adaptativeMargin;
|
||||
bool m_checkboxEnabled;
|
||||
bool m_tristateEnabled;
|
||||
|
||||
static float s_borderScale;
|
||||
float m_textMargin;
|
||||
CheckboxState m_state;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/CheckboxWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_CHECKBOXWIDGET_HPP
|
||||
@@ -1,94 +0,0 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline void CheckboxWidget::EnableAdaptativeMargin(bool enable)
|
||||
{
|
||||
m_adaptativeMargin = enable;
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void CheckboxWidget::EnableCheckbox(bool enable)
|
||||
{
|
||||
m_checkboxEnabled = enable;
|
||||
UpdateCheckbox();
|
||||
}
|
||||
|
||||
inline void CheckboxWidget::EnableTristate(bool enable)
|
||||
{
|
||||
m_tristateEnabled = enable;
|
||||
|
||||
if (m_tristateEnabled && GetState() == CheckboxState_Tristate)
|
||||
SetState(CheckboxState_Unchecked);
|
||||
}
|
||||
|
||||
inline bool CheckboxWidget::IsCheckboxEnabled() const
|
||||
{
|
||||
return m_checkboxEnabled;
|
||||
}
|
||||
|
||||
inline bool CheckboxWidget::IsMarginAdaptative() const
|
||||
{
|
||||
return m_adaptativeMargin;
|
||||
}
|
||||
|
||||
inline bool CheckboxWidget::IsTristateEnabled() const
|
||||
{
|
||||
return m_tristateEnabled;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2f& CheckboxWidget::GetCheckboxSize() const
|
||||
{
|
||||
return m_checkboxBorderSprite->GetSize();
|
||||
}
|
||||
|
||||
inline Nz::Vector2f CheckboxWidget::GetCheckboxBorderSize() const
|
||||
{
|
||||
return GetCheckboxSize() / s_borderScale;
|
||||
}
|
||||
|
||||
inline CheckboxState CheckboxWidget::GetState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
inline float CheckboxWidget::GetTextMargin() const
|
||||
{
|
||||
return m_textMargin;
|
||||
}
|
||||
|
||||
inline void CheckboxWidget::SetCheckboxSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_checkboxBorderSprite->SetSize(size);
|
||||
m_checkboxBackgroundSprite->SetSize(size - GetCheckboxBorderSize() * 2.f);
|
||||
m_checkboxContentSprite->SetSize(GetCheckboxSize() - GetCheckboxBorderSize() * 2.f - Nz::Vector2f { 4.f, 4.f });
|
||||
|
||||
UpdateSize();
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void CheckboxWidget::SetTextMargin(float margin)
|
||||
{
|
||||
m_textMargin = margin;
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void CheckboxWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
|
||||
UpdateSize();
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline bool CheckboxWidget::ContainsCheckbox(int x, int y) const
|
||||
{
|
||||
Nz::Vector2f checkboxSize = GetCheckboxSize();
|
||||
Nz::Vector3f pos = m_checkboxBorderEntity->GetComponent<NodeComponent>().GetPosition(Nz::CoordSys_Local);
|
||||
|
||||
return x > pos.x && x < pos.x + checkboxSize.x &&
|
||||
y > pos.y && y < pos.y + checkboxSize.y;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENUMS_SDK_HPP
|
||||
#define NAZARA_ENUMS_SDK_HPP
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
enum BoxLayoutOrientation
|
||||
{
|
||||
BoxLayoutOrientation_Horizontal,
|
||||
BoxLayoutOrientation_Vertical
|
||||
};
|
||||
|
||||
enum CheckboxState
|
||||
{
|
||||
CheckboxState_Checked,
|
||||
CheckboxState_Tristate,
|
||||
CheckboxState_Unchecked,
|
||||
|
||||
CheckboxState_Max = CheckboxState_Unchecked
|
||||
};
|
||||
|
||||
enum EchoMode
|
||||
{
|
||||
EchoMode_Normal,
|
||||
EchoMode_Password,
|
||||
EchoMode_PasswordExceptLast,
|
||||
|
||||
EchoMode_Max = EchoMode_PasswordExceptLast
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENUMS_SDK_HPP
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_IMAGEWIDGET_HPP
|
||||
#define NDK_WIDGETS_IMAGEWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <NazaraSDK/Entity.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ImageWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
ImageWidget(BaseWidget* parent);
|
||||
ImageWidget(const ImageWidget&) = delete;
|
||||
ImageWidget(ImageWidget&&) = default;
|
||||
~ImageWidget() = default;
|
||||
|
||||
//virtual ImageWidget* Clone() const = 0;
|
||||
|
||||
inline const Nz::Color& GetColor() const;
|
||||
inline const Nz::TextureRef& GetTexture() const;
|
||||
inline const Nz::Rectf& GetTextureCoords() const;
|
||||
|
||||
inline void SetColor(const Nz::Color& color);
|
||||
inline void SetTexture(const Nz::TextureRef& texture);
|
||||
inline void SetTextureCoords(const Nz::Rectf& coords);
|
||||
inline void SetTextureRect(const Nz::Rectui& rect);
|
||||
|
||||
ImageWidget& operator=(const ImageWidget&) = delete;
|
||||
ImageWidget& operator=(ImageWidget&&) = default;
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
Ndk::EntityHandle m_entity;
|
||||
Nz::SpriteRef m_sprite;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/ImageWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_IMAGEWIDGET_HPP
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/ImageWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline const Nz::Color& ImageWidget::GetColor() const
|
||||
{
|
||||
return m_sprite->GetColor();
|
||||
}
|
||||
|
||||
inline const Nz::TextureRef& ImageWidget::GetTexture() const
|
||||
{
|
||||
return m_sprite->GetMaterial()->GetDiffuseMap();
|
||||
}
|
||||
|
||||
inline const Nz::Rectf& ImageWidget::GetTextureCoords() const
|
||||
{
|
||||
return m_sprite->GetTextureCoords();
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetColor(const Nz::Color& color)
|
||||
{
|
||||
m_sprite->SetColor(color);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTexture(const Nz::TextureRef& texture)
|
||||
{
|
||||
m_sprite->SetTexture(texture, false);
|
||||
|
||||
Nz::Vector2f textureSize = Nz::Vector2f(Nz::Vector2ui(m_sprite->GetMaterial()->GetDiffuseMap()->GetSize()));
|
||||
SetMinimumSize(textureSize);
|
||||
SetPreferredSize(textureSize);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureCoords(const Nz::Rectf& coords)
|
||||
{
|
||||
m_sprite->SetTextureCoords(coords);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureRect(const Nz::Rectui& rect)
|
||||
{
|
||||
m_sprite->SetTextureRect(rect);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_LABELWIDGET_HPP
|
||||
#define NDK_WIDGETS_LABELWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API LabelWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
LabelWidget(BaseWidget* parent);
|
||||
LabelWidget(const LabelWidget&) = delete;
|
||||
LabelWidget(LabelWidget&&) = default;
|
||||
~LabelWidget() = default;
|
||||
|
||||
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||
|
||||
LabelWidget& operator=(const LabelWidget&) = delete;
|
||||
LabelWidget& operator=(LabelWidget&&) = default;
|
||||
|
||||
private:
|
||||
EntityHandle m_textEntity;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/LabelWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_LABELWIDGET_HPP
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/LabelWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline void LabelWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
|
||||
Nz::Vector2f size = Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths());
|
||||
SetMinimumSize(size);
|
||||
SetPreferredSize(size);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_PROGRESSBARWIDGET_HPP
|
||||
#define NDK_WIDGETS_PROGRESSBARWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ProgressBarWidget : public BaseWidget
|
||||
{
|
||||
friend class Sdk;
|
||||
|
||||
public:
|
||||
ProgressBarWidget(BaseWidget* parent);
|
||||
ProgressBarWidget(const ProgressBarWidget&) = delete;
|
||||
ProgressBarWidget(ProgressBarWidget&&) = default;
|
||||
~ProgressBarWidget() = default;
|
||||
|
||||
//virtual ProgressBarWidget* Clone() const = 0;
|
||||
|
||||
inline void EnableText(bool enable = true);
|
||||
inline void EnableBorder(bool enable = true);
|
||||
|
||||
inline bool IsTextEnabled() const;
|
||||
inline bool IsBorderEnabled() const;
|
||||
|
||||
|
||||
inline unsigned GetPercentageValue() const;
|
||||
inline Nz::Vector2f GetProgressBarSize() const;
|
||||
inline Nz::Vector2f GetProgressBarBorderSize() const;
|
||||
inline float GetTextMargin() const;
|
||||
|
||||
|
||||
inline const Nz::Color& GetBarBackgroundColor() const;
|
||||
inline const Nz::Color& GetBarBackgroundCornerColor() const;
|
||||
inline const Nz::Color& GetBarColor() const;
|
||||
inline const Nz::Color& GetBarCornerColor() const;
|
||||
|
||||
inline const Nz::TextureRef& GetBarBackgroundTexture() const;
|
||||
inline const Nz::TextureRef& GetBarTexture() const;
|
||||
|
||||
static const Nz::Color& GetDefaultBarColor();
|
||||
static const Nz::Color& GetDefaultBarCornerColor();
|
||||
static const Nz::Color& GetDefaultBarBackgroundColor();
|
||||
static const Nz::Color& GetDefaultBarBackgroundCornerColor();
|
||||
|
||||
|
||||
inline void SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor);
|
||||
inline void SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors = true);
|
||||
inline void SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor);
|
||||
inline void SetBarTexture(Nz::TextureRef texture, bool resetColors = true);
|
||||
|
||||
|
||||
inline void SetPercentageValue(unsigned percentage);
|
||||
inline void SetTextMargin(float margin);
|
||||
inline void SetTextColor(const Nz::Color& color);
|
||||
|
||||
NazaraSignal(OnValueChanged, const ProgressBarWidget* /*progressBar*/);
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
inline void UpdateText();
|
||||
|
||||
|
||||
EntityHandle m_borderEntity;
|
||||
EntityHandle m_barEntity;
|
||||
EntityHandle m_textEntity;
|
||||
|
||||
static Nz::Color s_borderColor;
|
||||
static Nz::Color s_barBackgroundColor;
|
||||
static Nz::Color s_barBackgroundCornerColor;
|
||||
static Nz::Color s_barColor;
|
||||
static Nz::Color s_barCornerColor;
|
||||
Nz::Color m_textColor;
|
||||
|
||||
Nz::SpriteRef m_borderSprite;
|
||||
Nz::SpriteRef m_barBackgroundSprite;
|
||||
Nz::SpriteRef m_barSprite;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
|
||||
static float s_borderScale;
|
||||
float m_textMargin;
|
||||
unsigned m_value;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/ProgressBarWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_PROGRESSBARWIDGET_HPP
|
||||
@@ -1,155 +0,0 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline void ProgressBarWidget::EnableText(bool enable)
|
||||
{
|
||||
m_textEntity->Enable(enable);
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void ProgressBarWidget::EnableBorder(bool enable)
|
||||
{
|
||||
m_borderEntity->Enable(enable);
|
||||
}
|
||||
|
||||
inline bool ProgressBarWidget::IsTextEnabled() const
|
||||
{
|
||||
return m_textEntity->IsEnabled();
|
||||
}
|
||||
|
||||
inline bool ProgressBarWidget::IsBorderEnabled() const
|
||||
{
|
||||
return m_borderEntity->IsEnabled();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned ProgressBarWidget::GetPercentageValue() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f ProgressBarWidget::GetProgressBarSize() const
|
||||
{
|
||||
Nz::Vector3f progressBarSize = m_borderSprite->GetBoundingVolume().obb.localBox.GetLengths();
|
||||
|
||||
if (IsTextEnabled())
|
||||
{
|
||||
Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
|
||||
progressBarSize -= { textSize.x + m_textMargin, 0.f, 0.f };
|
||||
}
|
||||
|
||||
return { progressBarSize.x, progressBarSize.y };
|
||||
}
|
||||
|
||||
inline Nz::Vector2f ProgressBarWidget::GetProgressBarBorderSize() const
|
||||
{
|
||||
Nz::Vector2f barSize = GetProgressBarSize();
|
||||
return { barSize.y / s_borderScale, barSize.y / s_borderScale };
|
||||
}
|
||||
|
||||
inline float ProgressBarWidget::GetTextMargin() const
|
||||
{
|
||||
return m_textMargin;
|
||||
}
|
||||
|
||||
|
||||
inline const Nz::Color& ProgressBarWidget::GetBarBackgroundColor() const
|
||||
{
|
||||
return m_barBackgroundSprite->GetColor();
|
||||
}
|
||||
|
||||
inline const Nz::Color& ProgressBarWidget::GetBarBackgroundCornerColor() const
|
||||
{
|
||||
return m_barBackgroundSprite->GetCornerColor(Nz::RectCorner_LeftTop);
|
||||
}
|
||||
|
||||
inline const Nz::Color& ProgressBarWidget::GetBarColor() const
|
||||
{
|
||||
return m_barSprite->GetColor();
|
||||
}
|
||||
|
||||
inline const Nz::Color& ProgressBarWidget::GetBarCornerColor() const
|
||||
{
|
||||
return m_barSprite->GetCornerColor(Nz::RectCorner_LeftTop);
|
||||
}
|
||||
|
||||
|
||||
inline const Nz::TextureRef& ProgressBarWidget::GetBarBackgroundTexture() const
|
||||
{
|
||||
return m_barBackgroundSprite->GetMaterial()->GetDiffuseMap();
|
||||
}
|
||||
|
||||
inline const Nz::TextureRef& ProgressBarWidget::GetBarTexture() const
|
||||
{
|
||||
return m_barSprite->GetMaterial()->GetDiffuseMap();
|
||||
}
|
||||
|
||||
|
||||
inline void ProgressBarWidget::SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor)
|
||||
{
|
||||
m_barBackgroundSprite->SetColor(globalColor);
|
||||
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor);
|
||||
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor);
|
||||
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor);
|
||||
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor);
|
||||
}
|
||||
|
||||
inline void ProgressBarWidget::SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors)
|
||||
{
|
||||
m_barBackgroundSprite->SetTexture(texture, false);
|
||||
|
||||
if (resetColors)
|
||||
SetBarBackgroundColor(Nz::Color::White, Nz::Color::White);
|
||||
}
|
||||
|
||||
inline void ProgressBarWidget::SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor)
|
||||
{
|
||||
m_barSprite->SetColor(globalColor);
|
||||
m_barSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor);
|
||||
m_barSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor);
|
||||
m_barSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor);
|
||||
m_barSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor);
|
||||
}
|
||||
|
||||
inline void ProgressBarWidget::SetBarTexture(Nz::TextureRef texture, bool resetColors)
|
||||
{
|
||||
m_barSprite->SetTexture(texture, false);
|
||||
|
||||
if (resetColors)
|
||||
SetBarColor(Nz::Color::White, Nz::Color::White);
|
||||
}
|
||||
|
||||
|
||||
inline void ProgressBarWidget::SetPercentageValue(unsigned percentage)
|
||||
{
|
||||
m_value = percentage;
|
||||
OnValueChanged(this);
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void ProgressBarWidget::SetTextMargin(float margin)
|
||||
{
|
||||
m_textMargin = margin;
|
||||
|
||||
if (IsTextEnabled())
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void ProgressBarWidget::SetTextColor(const Nz::Color& color)
|
||||
{
|
||||
m_textColor = color;
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
inline void ProgressBarWidget::UpdateText()
|
||||
{
|
||||
if (IsTextEnabled())
|
||||
{
|
||||
Nz::Vector2f size = GetSize();
|
||||
m_textSprite->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_value).Append('%'), static_cast<unsigned int>(std::min(size.x, size.y) / 2.f), 0u, m_textColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_RICHTEXTAREAWIDGET_HPP
|
||||
#define NDK_WIDGETS_RICHTEXTAREAWIDGET_HPP
|
||||
|
||||
#include <Nazara/Utility/RichTextDrawer.hpp>
|
||||
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API RichTextAreaWidget : public AbstractTextAreaWidget
|
||||
{
|
||||
public:
|
||||
RichTextAreaWidget(BaseWidget* parent);
|
||||
RichTextAreaWidget(const RichTextAreaWidget&) = delete;
|
||||
RichTextAreaWidget(RichTextAreaWidget&&) = default;
|
||||
~RichTextAreaWidget() = default;
|
||||
|
||||
void AppendText(const Nz::String& text);
|
||||
|
||||
void Clear() override;
|
||||
|
||||
void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override;
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline float GetCharacterSpacingOffset() const;
|
||||
inline float GetLineSpacingOffset() const;
|
||||
inline const Nz::Color& GetTextColor() const;
|
||||
inline Nz::Font* GetTextFont() const;
|
||||
inline const Nz::Color& GetTextOutlineColor() const;
|
||||
inline float GetTextOutlineThickness() const;
|
||||
inline Nz::TextStyleFlags GetTextStyle() const;
|
||||
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
inline void SetCharacterSpacingOffset(float offset);
|
||||
inline void SetLineSpacingOffset(float offset);
|
||||
inline void SetTextColor(const Nz::Color& color);
|
||||
inline void SetTextFont(Nz::FontRef font);
|
||||
inline void SetTextOutlineColor(const Nz::Color& color);
|
||||
inline void SetTextOutlineThickness(float thickness);
|
||||
inline void SetTextStyle(Nz::TextStyleFlags style);
|
||||
|
||||
void Write(const Nz::String& text, std::size_t glyphPosition) override;
|
||||
|
||||
RichTextAreaWidget& operator=(const RichTextAreaWidget&) = delete;
|
||||
RichTextAreaWidget& operator=(RichTextAreaWidget&&) = default;
|
||||
|
||||
private:
|
||||
Nz::AbstractTextDrawer& GetTextDrawer() override;
|
||||
const Nz::AbstractTextDrawer& GetTextDrawer() const override;
|
||||
|
||||
void HandleIndentation(bool add) override;
|
||||
void HandleSelectionIndentation(bool add) override;
|
||||
void HandleWordCursorMove(bool left) override;
|
||||
|
||||
void UpdateDisplayText() override;
|
||||
|
||||
Nz::RichTextDrawer m_drawer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/RichTextAreaWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||
@@ -1,88 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/RichTextAreaWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline unsigned int RichTextAreaWidget::GetCharacterSize() const
|
||||
{
|
||||
return m_drawer.GetDefaultCharacterSize();
|
||||
}
|
||||
|
||||
inline float RichTextAreaWidget::GetCharacterSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetDefaultCharacterSpacingOffset();
|
||||
}
|
||||
|
||||
inline float RichTextAreaWidget::GetLineSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetDefaultLineSpacingOffset();
|
||||
}
|
||||
|
||||
inline const Nz::Color& RichTextAreaWidget::GetTextColor() const
|
||||
{
|
||||
return m_drawer.GetDefaultColor();
|
||||
}
|
||||
|
||||
inline Nz::Font* RichTextAreaWidget::GetTextFont() const
|
||||
{
|
||||
return m_drawer.GetDefaultFont();
|
||||
}
|
||||
|
||||
inline const Nz::Color& RichTextAreaWidget::GetTextOutlineColor() const
|
||||
{
|
||||
return m_drawer.GetDefaultOutlineColor();
|
||||
}
|
||||
|
||||
inline float RichTextAreaWidget::GetTextOutlineThickness() const
|
||||
{
|
||||
return m_drawer.GetDefaultOutlineThickness();
|
||||
}
|
||||
|
||||
inline Nz::TextStyleFlags RichTextAreaWidget::GetTextStyle() const
|
||||
{
|
||||
return m_drawer.GetDefaultStyle();
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
m_drawer.SetDefaultCharacterSize(characterSize);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetCharacterSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetDefaultCharacterSpacingOffset(offset);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetLineSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetDefaultLineSpacingOffset(offset);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextColor(const Nz::Color& color)
|
||||
{
|
||||
m_drawer.SetDefaultColor(color);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextFont(Nz::FontRef font)
|
||||
{
|
||||
m_drawer.SetDefaultFont(std::move(font));
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextOutlineColor(const Nz::Color& color)
|
||||
{
|
||||
m_drawer.SetDefaultOutlineColor(color);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextOutlineThickness(float thickness)
|
||||
{
|
||||
m_drawer.SetDefaultOutlineThickness(thickness);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextStyle(Nz::TextStyleFlags style)
|
||||
{
|
||||
m_drawer.SetDefaultStyle(style);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_SCROLLAREAWIDGET_HPP
|
||||
#define NDK_WIDGETS_SCROLLAREAWIDGET_HPP
|
||||
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
#include <NazaraSDK/BaseWidget.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ScrollAreaWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
ScrollAreaWidget(BaseWidget* parent, BaseWidget* content);
|
||||
ScrollAreaWidget(const ScrollAreaWidget&) = delete;
|
||||
ScrollAreaWidget(ScrollAreaWidget&&) = default;
|
||||
~ScrollAreaWidget() = default;
|
||||
|
||||
void EnableScrollbar(bool enable);
|
||||
|
||||
inline float GetScrollHeight() const;
|
||||
inline float GetScrollRatio() const;
|
||||
|
||||
inline bool HasScrollbar() const;
|
||||
inline bool IsScrollbarEnabled() const;
|
||||
inline bool IsScrollbarVisible() const;
|
||||
|
||||
inline void ScrollToHeight(float height);
|
||||
void ScrollToRatio(float ratio);
|
||||
|
||||
ScrollAreaWidget& operator=(const ScrollAreaWidget&) = delete;
|
||||
ScrollAreaWidget& operator=(ScrollAreaWidget&&) = default;
|
||||
|
||||
private:
|
||||
enum class ScrollBarStatus
|
||||
{
|
||||
Grabbed,
|
||||
Hovered,
|
||||
None
|
||||
};
|
||||
|
||||
Nz::Rectf GetScrollbarRect() const;
|
||||
|
||||
void Layout() override;
|
||||
|
||||
void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) override;
|
||||
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
|
||||
void OnMouseExit() override;
|
||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||
void OnMouseWheelMoved(int x, int y, float delta) override;
|
||||
|
||||
void UpdateScrollbarStatus(ScrollBarStatus status);
|
||||
|
||||
BaseWidget* m_content;
|
||||
EntityHandle m_scrollbarBackgroundEntity;
|
||||
EntityHandle m_scrollbarEntity;
|
||||
Nz::SpriteRef m_scrollbarBackgroundSprite;
|
||||
Nz::SpriteRef m_scrollbarSprite;
|
||||
Nz::Vector2i m_grabbedDelta;
|
||||
ScrollBarStatus m_scrollbarStatus;
|
||||
bool m_isScrollbarEnabled;
|
||||
bool m_hasScrollbar;
|
||||
float m_scrollRatio;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/ScrollAreaWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_SCROLLAREAWIDGET_HPP
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/ScrollAreaWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline float ScrollAreaWidget::GetScrollHeight() const
|
||||
{
|
||||
return m_scrollRatio * m_content->GetHeight();
|
||||
}
|
||||
|
||||
inline float ScrollAreaWidget::GetScrollRatio() const
|
||||
{
|
||||
return m_scrollRatio;
|
||||
}
|
||||
|
||||
inline bool ScrollAreaWidget::HasScrollbar() const
|
||||
{
|
||||
return m_hasScrollbar;
|
||||
}
|
||||
|
||||
inline bool ScrollAreaWidget::IsScrollbarEnabled() const
|
||||
{
|
||||
return m_isScrollbarEnabled;
|
||||
}
|
||||
|
||||
inline bool ScrollAreaWidget::IsScrollbarVisible() const
|
||||
{
|
||||
return HasScrollbar() && IsScrollbarEnabled();
|
||||
}
|
||||
|
||||
inline void ScrollAreaWidget::ScrollToHeight(float height)
|
||||
{
|
||||
float contentHeight = m_content->GetHeight();
|
||||
ScrollToRatio(height / contentHeight);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||
#define NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API TextAreaWidget : public AbstractTextAreaWidget
|
||||
{
|
||||
public:
|
||||
TextAreaWidget(BaseWidget* parent);
|
||||
TextAreaWidget(const TextAreaWidget&) = delete;
|
||||
TextAreaWidget(TextAreaWidget&&) = default;
|
||||
~TextAreaWidget() = default;
|
||||
|
||||
void AppendText(const Nz::String& text);
|
||||
|
||||
void Clear() override;
|
||||
|
||||
using AbstractTextAreaWidget::Erase;
|
||||
void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override;
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const Nz::String& GetDisplayText() const;
|
||||
inline float GetCharacterSpacingOffset() const;
|
||||
inline float GetLineSpacingOffset() const;
|
||||
inline const Nz::String& GetText() const;
|
||||
inline const Nz::Color& GetTextColor() const;
|
||||
inline Nz::Font* GetTextFont() const;
|
||||
inline const Nz::Color& GetTextOulineColor() const;
|
||||
inline float GetTextOulineThickness() const;
|
||||
inline Nz::TextStyleFlags GetTextStyle() const;
|
||||
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
inline void SetCharacterSpacingOffset(float offset);
|
||||
inline void SetLineSpacingOffset(float offset);
|
||||
inline void SetText(const Nz::String& text);
|
||||
inline void SetTextColor(const Nz::Color& text);
|
||||
inline void SetTextFont(Nz::FontRef font);
|
||||
inline void SetTextOutlineColor(const Nz::Color& color);
|
||||
inline void SetTextOutlineThickness(float thickness);
|
||||
inline void SetTextStyle(Nz::TextStyleFlags style);
|
||||
|
||||
using AbstractTextAreaWidget::Write;
|
||||
void Write(const Nz::String& text, std::size_t glyphPosition) override;
|
||||
|
||||
TextAreaWidget& operator=(const TextAreaWidget&) = delete;
|
||||
TextAreaWidget& operator=(TextAreaWidget&&) = default;
|
||||
|
||||
NazaraSignal(OnTextChanged, const AbstractTextAreaWidget* /*textArea*/, const Nz::String& /*text*/);
|
||||
|
||||
private:
|
||||
Nz::AbstractTextDrawer& GetTextDrawer() override;
|
||||
const Nz::AbstractTextDrawer& GetTextDrawer() const override;
|
||||
|
||||
void HandleIndentation(bool add) override;
|
||||
void HandleSelectionIndentation(bool add) override;
|
||||
void HandleWordCursorMove(bool left) override;
|
||||
|
||||
void UpdateDisplayText() override;
|
||||
void UpdateMinimumSize();
|
||||
|
||||
Nz::SimpleTextDrawer m_drawer;
|
||||
Nz::String m_text;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraSDK/Widgets/TextAreaWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||
@@ -1,124 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NazaraSDK/Widgets/TextAreaWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline unsigned int TextAreaWidget::GetCharacterSize() const
|
||||
{
|
||||
return m_drawer.GetCharacterSize();
|
||||
}
|
||||
|
||||
inline const Nz::String& TextAreaWidget::GetDisplayText() const
|
||||
{
|
||||
return m_drawer.GetText();
|
||||
}
|
||||
|
||||
inline float TextAreaWidget::GetCharacterSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetCharacterSpacingOffset();
|
||||
}
|
||||
|
||||
inline float TextAreaWidget::GetLineSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetLineSpacingOffset();
|
||||
}
|
||||
|
||||
inline const Nz::String& TextAreaWidget::GetText() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
inline const Nz::Color& TextAreaWidget::GetTextColor() const
|
||||
{
|
||||
return m_drawer.GetColor();
|
||||
}
|
||||
|
||||
inline Nz::Font* TextAreaWidget::GetTextFont() const
|
||||
{
|
||||
return m_drawer.GetFont();
|
||||
}
|
||||
|
||||
inline const Nz::Color& TextAreaWidget::GetTextOulineColor() const
|
||||
{
|
||||
return m_drawer.GetOutlineColor();
|
||||
}
|
||||
|
||||
inline float TextAreaWidget::GetTextOulineThickness() const
|
||||
{
|
||||
return m_drawer.GetOutlineThickness();
|
||||
}
|
||||
|
||||
inline Nz::TextStyleFlags TextAreaWidget::GetTextStyle() const
|
||||
{
|
||||
return m_drawer.GetStyle();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
m_drawer.SetCharacterSize(characterSize);
|
||||
|
||||
UpdateMinimumSize();
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCharacterSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetCharacterSpacingOffset(offset);
|
||||
|
||||
UpdateMinimumSize();
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetLineSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetLineSpacingOffset(offset);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetText(const Nz::String& text)
|
||||
{
|
||||
m_text = text;
|
||||
OnTextChanged(this, m_text);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextColor(const Nz::Color& text)
|
||||
{
|
||||
m_drawer.SetColor(text);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextFont(Nz::FontRef font)
|
||||
{
|
||||
m_drawer.SetFont(font);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextOutlineColor(const Nz::Color& color)
|
||||
{
|
||||
m_drawer.SetOutlineColor(color);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextOutlineThickness(float thickness)
|
||||
{
|
||||
m_drawer.SetOutlineThickness(thickness);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextStyle(Nz::TextStyleFlags style)
|
||||
{
|
||||
m_drawer.SetStyle(style);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user