Merge branch 'master' into reflection-mapping
This commit is contained in:
commit
c763dea4e1
|
|
@ -27,17 +27,17 @@
|
|||
#ifndef NAZARA_CONFIG_MODULENAME_HPP
|
||||
#define NAZARA_CONFIG_MODULENAME_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
/// Each modification of a parameter needs a recompilation of the module
|
||||
|
||||
// Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
||||
// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
|
||||
#define NAZARA_MODULENAME_MANAGE_MEMORY 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
// Activate the security tests based on the code (Advised for development)
|
||||
#define NAZARA_MODULENAME_SAFE 1
|
||||
|
||||
/// Chaque modification d'un paramètre ci-dessous implique une modification (souvent mineure) du code
|
||||
/// Each modification of a parameter following implies a modification (often minor) of the code
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
/// Checking the values and types of certain constants
|
||||
#include <Nazara/ModuleName/ConfigCheck.hpp>
|
||||
|
||||
#if !defined(NAZARA_STATIC)
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@
|
|||
#ifndef NAZARA_CONFIG_CHECK_MODULENAME_HPP
|
||||
#define NAZARA_CONFIG_CHECK_MODULENAME_HPP
|
||||
|
||||
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
|
||||
/// This file is used to check the constant values defined in Config.hpp
|
||||
|
||||
#include <type_traits>
|
||||
#define CheckType(name, type, err) static_assert(std::is_ ##type <decltype(name)>::value, #type err)
|
||||
#define CheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
// We force the value of MANAGE_MEMORY in debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#undef NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#define NAZARA_MODULENAME_MANAGE_MEMORY 0
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// This file is part of the "Nazara Engine - Module name"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
||||
// We suppose that Debug.hpp is already included, same goes for Config.hpp
|
||||
#if NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#undef delete
|
||||
#undef new
|
||||
|
|
|
|||
|
|
@ -8,13 +8,11 @@
|
|||
#define NDK_APPLICATION_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/EntityOwner.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Console.hpp>
|
||||
|
|
@ -22,7 +20,7 @@
|
|||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <Nazara/Platform/Window.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Application.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <type_traits>
|
||||
#include <NDK/Sdk.hpp>
|
||||
|
||||
namespace Ndk
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Ndk
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@
|
|||
#define NDK_BASESYSTEM_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/EntityList.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -35,17 +33,19 @@ namespace Ndk
|
|||
bool Filters(const Entity* entity) const;
|
||||
|
||||
inline const EntityList& GetEntities() const;
|
||||
inline float GetFixedUpdateRate() const;
|
||||
inline SystemIndex GetIndex() const;
|
||||
inline float GetMaximumUpdateRate() const;
|
||||
inline int GetUpdateOrder() const;
|
||||
inline float GetUpdateRate() const;
|
||||
inline World& GetWorld() const;
|
||||
|
||||
inline bool IsEnabled() const;
|
||||
|
||||
inline bool HasEntity(const Entity* entity) const;
|
||||
|
||||
inline void SetFixedUpdateRate(float updatePerSecond);
|
||||
inline void SetMaximumUpdateRate(float updatePerSecond);
|
||||
void SetUpdateOrder(int updateOrder);
|
||||
inline void SetUpdateRate(float updatePerSecond);
|
||||
|
||||
inline void Update(float elapsedTime);
|
||||
|
||||
|
|
@ -93,8 +93,9 @@ namespace Ndk
|
|||
SystemIndex m_systemIndex;
|
||||
World* m_world;
|
||||
bool m_updateEnabled;
|
||||
float m_fixedUpdateRate;
|
||||
float m_maxUpdateRate;
|
||||
float m_updateCounter;
|
||||
float m_updateRate;
|
||||
int m_updateOrder;
|
||||
|
||||
static SystemIndex s_nextIndex;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
|
|
@ -20,7 +19,8 @@ namespace Ndk
|
|||
m_updateEnabled(true),
|
||||
m_updateOrder(0)
|
||||
{
|
||||
SetUpdateRate(30);
|
||||
SetFixedUpdateRate(0);
|
||||
SetMaximumUpdateRate(30);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -34,8 +34,9 @@ namespace Ndk
|
|||
m_requiredComponents(system.m_requiredComponents),
|
||||
m_systemIndex(system.m_systemIndex),
|
||||
m_updateEnabled(system.m_updateEnabled),
|
||||
m_fixedUpdateRate(system.m_fixedUpdateRate),
|
||||
m_maxUpdateRate(system.m_maxUpdateRate),
|
||||
m_updateCounter(0.f),
|
||||
m_updateRate(system.m_updateRate),
|
||||
m_updateOrder(system.m_updateOrder)
|
||||
{
|
||||
}
|
||||
|
|
@ -61,6 +62,24 @@ namespace Ndk
|
|||
return m_entities;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the maximum rate of update of the system
|
||||
* \return Update rate
|
||||
*/
|
||||
inline float BaseSystem::GetFixedUpdateRate() const
|
||||
{
|
||||
return (m_fixedUpdateRate > 0.f) ? 1.f / m_fixedUpdateRate : 0.f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the maximum rate of update of the system
|
||||
* \return Update rate
|
||||
*/
|
||||
inline float BaseSystem::GetMaximumUpdateRate() const
|
||||
{
|
||||
return (m_maxUpdateRate > 0.f) ? 1.f / m_maxUpdateRate : 0.f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the index of the system
|
||||
* \return Index of the system
|
||||
|
|
@ -82,16 +101,6 @@ namespace Ndk
|
|||
return m_updateOrder;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the rate of update of the system
|
||||
* \return Update rate
|
||||
*/
|
||||
|
||||
inline float BaseSystem::GetUpdateRate() const
|
||||
{
|
||||
return (m_updateRate > 0.f) ? 1.f / m_updateRate : 0.f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the world on which the system operate
|
||||
* \return World in which the system is
|
||||
|
|
@ -125,15 +134,25 @@ namespace Ndk
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the rate of update for the system
|
||||
* \brief Sets the fixed update rate for the system
|
||||
*
|
||||
* \param updatePerSecond Update rate, 0 means update rate is not fixed
|
||||
*/
|
||||
inline void BaseSystem::SetFixedUpdateRate(float updatePerSecond)
|
||||
{
|
||||
m_updateCounter = 0.f;
|
||||
m_fixedUpdateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the maximum update rate for the system
|
||||
*
|
||||
* \param updatePerSecond Update rate, 0 means as much as possible
|
||||
*/
|
||||
|
||||
inline void BaseSystem::SetUpdateRate(float updatePerSecond)
|
||||
inline void BaseSystem::SetMaximumUpdateRate(float updatePerSecond)
|
||||
{
|
||||
m_updateCounter = 0.f;
|
||||
m_updateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
|
||||
m_maxUpdateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -147,18 +166,40 @@ namespace Ndk
|
|||
if (!IsEnabled())
|
||||
return;
|
||||
|
||||
if (m_updateRate > 0.f)
|
||||
{
|
||||
m_updateCounter += elapsedTime;
|
||||
m_updateCounter += elapsedTime;
|
||||
|
||||
while (m_updateCounter >= m_updateRate)
|
||||
if (m_maxUpdateRate > 0.f)
|
||||
{
|
||||
if (m_updateCounter >= m_maxUpdateRate)
|
||||
{
|
||||
OnUpdate(m_updateRate);
|
||||
m_updateCounter -= m_updateRate;
|
||||
if (m_fixedUpdateRate > 0.f)
|
||||
{
|
||||
while (m_updateCounter >= m_fixedUpdateRate)
|
||||
{
|
||||
OnUpdate(m_fixedUpdateRate);
|
||||
m_updateCounter -= m_fixedUpdateRate;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnUpdate(m_maxUpdateRate);
|
||||
m_updateCounter -= m_maxUpdateRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
OnUpdate(elapsedTime);
|
||||
{
|
||||
if (m_fixedUpdateRate > 0.f)
|
||||
{
|
||||
while (m_updateCounter >= m_fixedUpdateRate)
|
||||
{
|
||||
OnUpdate(m_fixedUpdateRate);
|
||||
m_updateCounter -= m_fixedUpdateRate;
|
||||
}
|
||||
}
|
||||
else
|
||||
OnUpdate(elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -12,9 +12,8 @@
|
|||
#include <NDK/EntityOwner.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Utility/Cursor.hpp>
|
||||
#include <Nazara/Utility/Event.hpp>
|
||||
#include <Nazara/Utility/Mouse.hpp>
|
||||
#include <Nazara/Platform/Event.hpp>
|
||||
#include <Nazara/Platform/Mouse.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <limits>
|
||||
|
||||
|
|
@ -38,6 +37,8 @@ namespace Ndk
|
|||
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
|
||||
|
||||
inline void Center();
|
||||
inline void CenterHorizontal();
|
||||
inline void CenterVertical();
|
||||
|
||||
inline void Destroy();
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,24 @@ namespace Ndk
|
|||
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 const Nz::Color& BaseWidget::GetBackgroundColor() const
|
||||
{
|
||||
return m_backgroundColor;
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <Nazara/Utility/CursorController.hpp>
|
||||
#include <Nazara/Utility/EventHandler.hpp>
|
||||
#include <Nazara/Platform/CursorController.hpp>
|
||||
#include <Nazara/Platform/EventHandler.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -44,13 +44,13 @@ namespace Ndk
|
|||
void UnregisterWidget(std::size_t index);
|
||||
|
||||
private:
|
||||
void OnMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||
void OnMouseLeft(const Nz::EventHandler* eventHandler);
|
||||
void OnKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||
void OnKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||
void OnTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
||||
void OnEventMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnEventMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||
void OnEventMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||
void OnEventMouseLeft(const Nz::EventHandler* eventHandler);
|
||||
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);
|
||||
|
||||
struct WidgetBox
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Canvas.hpp>
|
||||
#include <Nazara/Utility/Cursor.hpp>
|
||||
#include <Nazara/Platform/Cursor.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -20,13 +20,13 @@ namespace Ndk
|
|||
RegisterToCanvas();
|
||||
|
||||
// Connect to every meaningful event
|
||||
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnKeyPressed);
|
||||
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnKeyReleased);
|
||||
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnMouseButtonPressed);
|
||||
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnMouseButtonRelease);
|
||||
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnMouseMoved);
|
||||
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnMouseLeft);
|
||||
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnTextEntered);
|
||||
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_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved);
|
||||
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft);
|
||||
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered);
|
||||
|
||||
// Disable padding by default
|
||||
SetPadding(0.f, 0.f, 0.f, 0.f);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
namespace Ndk
|
||||
{
|
||||
class CameraComponent;
|
||||
class Entity;
|
||||
|
||||
using CameraComponentHandle = Nz::ObjectHandle<CameraComponent>;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,18 +8,12 @@
|
|||
#define NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP
|
||||
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RigidBody2D;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
|
||||
class NDK_API CollisionComponent2D : public Component<CollisionComponent2D>
|
||||
{
|
||||
friend class PhysicsSystem2D;
|
||||
|
|
@ -29,6 +23,7 @@ namespace Ndk
|
|||
CollisionComponent2D(const CollisionComponent2D& collision);
|
||||
~CollisionComponent2D() = default;
|
||||
|
||||
Nz::Rectf GetAABB() const;
|
||||
const Nz::Collider2DRef& GetGeom() const;
|
||||
|
||||
void SetGeom(Nz::Collider2DRef geom);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/CollisionComponent2D.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem2D.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
|
|
@ -34,6 +28,16 @@ namespace Ndk
|
|||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the collision box representing the entity
|
||||
* \return The physics collision box
|
||||
*/
|
||||
|
||||
inline Nz::Rectf CollisionComponent2D::GetAABB() const
|
||||
{
|
||||
return m_staticBody->GetAABB();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the geometry representing the entity
|
||||
* \return A constant reference to the physics geometry
|
||||
|
|
|
|||
|
|
@ -8,18 +8,12 @@
|
|||
#define NDK_COMPONENTS_COLLISIONCOMPONENT3D_HPP
|
||||
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RigidBody3D;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
|
||||
class NDK_API CollisionComponent3D : public Component<CollisionComponent3D>
|
||||
{
|
||||
friend class PhysicsSystem3D;
|
||||
|
|
|
|||
|
|
@ -2,11 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/PhysicsComponent3D.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem3D.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#define NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Graphics/ParticleEmitter.hpp>
|
||||
#include <Nazara/Graphics/ParticleGroup.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
|
|
@ -24,7 +23,7 @@ namespace Ndk
|
|||
ParticleEmitterComponent(ParticleEmitterComponent&& emitter) = default;
|
||||
~ParticleEmitterComponent() = default;
|
||||
|
||||
void Enable(bool active = true);
|
||||
inline void Enable(bool active = true);
|
||||
|
||||
inline bool IsActive() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/ParticleEmitterComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||
#include <NDK/Components/ParticleEmitterComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
|
||||
class NDK_API PhysicsComponent2D : public Component<PhysicsComponent2D>
|
||||
{
|
||||
friend class CollisionComponent2D;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include "PhysicsComponent2D.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
|
||||
class NDK_API PhysicsComponent3D : public Component<PhysicsComponent3D>
|
||||
{
|
||||
friend class CollisionComponent3D;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Utility/Event.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NDK/EntityOwner.hpp>
|
||||
|
|
@ -20,12 +19,12 @@
|
|||
namespace Nz
|
||||
{
|
||||
class LuaState;
|
||||
struct WindowEvent;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Console;
|
||||
class Entity;
|
||||
|
||||
using ConsoleHandle = Nz::ObjectHandle<Console>;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include "Console.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,11 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ namespace Ndk
|
|||
inline void Insert(Entity* entity);
|
||||
|
||||
inline void Remove(Entity* entity);
|
||||
inline void Reserve(std::size_t entityCount);
|
||||
|
||||
// STL API
|
||||
inline iterator begin() const;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/EntityList.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
|
|
@ -137,6 +136,16 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reserves enough space to contains entityCount entities
|
||||
*
|
||||
* \param entityCount Number of entities to reserve
|
||||
*/
|
||||
inline void EntityList::Reserve(std::size_t entityCount)
|
||||
{
|
||||
m_entityBits.Reserve(entityCount);
|
||||
}
|
||||
|
||||
// STL Interface
|
||||
inline EntityList::iterator EntityList::begin() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef NDK_LUABINDING_HPP
|
||||
#define NDK_LUABINDING_HPP
|
||||
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
#include <memory>
|
||||
|
|
@ -36,6 +35,7 @@ namespace Ndk
|
|||
std::unique_ptr<LuaBinding_Base> audio;
|
||||
std::unique_ptr<LuaBinding_Base> graphics;
|
||||
std::unique_ptr<LuaBinding_Base> renderer;
|
||||
std::unique_ptr<LuaBinding_Base> platform;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -2,10 +2,37 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Lua/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace Detail
|
||||
{
|
||||
template<bool HasDefaultConstructor>
|
||||
struct AddComponentIf;
|
||||
|
||||
template<>
|
||||
struct AddComponentIf<true>
|
||||
{
|
||||
template<typename T>
|
||||
static int AddComponent(Nz::LuaState& lua, EntityHandle& handle)
|
||||
{
|
||||
T& component = handle->AddComponent<T>();
|
||||
lua.Push(component.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct AddComponentIf<false>
|
||||
{
|
||||
template<typename T>
|
||||
static int AddComponent(Nz::LuaState& lua, EntityHandle& /*handle*/)
|
||||
{
|
||||
lua.Error("Component has no default constructor and cannot be created from Lua yet");
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Binds a component to a name
|
||||
*
|
||||
|
|
@ -13,14 +40,15 @@ namespace Ndk
|
|||
*
|
||||
* \remark Produces a NazaraAssert if name is empty
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void LuaBinding::BindComponent(const Nz::String& name)
|
||||
{
|
||||
NazaraAssert(!name.IsEmpty(), "Component name cannot be empty");
|
||||
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
ComponentBinding binding;
|
||||
binding.adder = &AddComponentOfType<T>;
|
||||
binding.adder = &Detail::AddComponentIf<std::is_default_constructible<T>::value>::template AddComponent<T>;
|
||||
binding.getter = &PushComponentOfType<T>;
|
||||
binding.index = T::componentIndex;
|
||||
binding.name = name;
|
||||
|
|
@ -32,21 +60,9 @@ namespace Ndk
|
|||
m_componentBindingByName[name] = T::componentIndex;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int LuaBinding::AddComponentOfType(Nz::LuaState& lua, EntityHandle& handle)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& component = handle->AddComponent<T>();
|
||||
lua.Push(component.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int LuaBinding::PushComponentOfType(Nz::LuaState& lua, BaseComponent& component)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& rightComponent = static_cast<T&>(component);
|
||||
lua.Push(rightComponent.CreateHandle());
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace Ndk
|
|||
class LuaBinding_Renderer;
|
||||
class LuaBinding_SDK;
|
||||
class LuaBinding_Utility;
|
||||
class LuaBinding_Platform;
|
||||
|
||||
class NDK_API LuaBinding_Base
|
||||
{
|
||||
|
|
@ -43,6 +44,7 @@ namespace Ndk
|
|||
static std::unique_ptr<LuaBinding_Base> BindAudio(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindGraphics(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindRenderer(LuaBinding& binding);
|
||||
static std::unique_ptr<LuaBinding_Base> BindPlatform(LuaBinding& binding);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUABINDING_SYSTEM_HPP
|
||||
#define NDK_LUABINDING_SYSTEM_HPP
|
||||
|
||||
#include <Nazara/Platform/Keyboard.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API LuaBinding_Platform : public LuaBinding_Base
|
||||
{
|
||||
public:
|
||||
LuaBinding_Platform(LuaBinding& binding);
|
||||
~LuaBinding_Platform() = default;
|
||||
|
||||
void Register(Nz::LuaState& state) override;
|
||||
|
||||
// Platform
|
||||
Nz::LuaClass<Nz::Keyboard> keyboard;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_SYSTEM_HPP
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/Font.hpp>
|
||||
#include <Nazara/Utility/Keyboard.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||
|
||||
|
|
@ -26,7 +25,6 @@ namespace Ndk
|
|||
// Utility
|
||||
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;
|
||||
Nz::LuaClass<Nz::FontRef> font;
|
||||
Nz::LuaClass<Nz::Keyboard> keyboard;
|
||||
Nz::LuaClass<Nz::Node> node;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Lua/LuaState.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
|
|
@ -16,7 +15,6 @@
|
|||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio/Music.hpp>
|
||||
|
|
|
|||
|
|
@ -11,16 +11,16 @@
|
|||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
#include <Nazara/Graphics/CullingList.hpp>
|
||||
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/EntityList.hpp>
|
||||
#include <NDK/System.hpp>
|
||||
#include <unordered_map>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class AbstractViewer;
|
||||
|
||||
class NDK_API RenderSystem : public System<RenderSystem>
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@
|
|||
#define NDK_WIDGETS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Widgets/ButtonWidget.hpp>
|
||||
#include <NDK/Widgets/CheckboxWidget.hpp>
|
||||
#include <NDK/Widgets/LabelWidget.hpp>
|
||||
#include <NDK/Widgets/ProgressBarWidget.hpp>
|
||||
#include <NDK/Widgets/TextAreaWidget.hpp>
|
||||
|
||||
#endif // NDK_WIDGETS_GLOBAL_HPP
|
||||
|
|
|
|||
|
|
@ -9,14 +9,17 @@
|
|||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class World;
|
||||
|
||||
class NDK_API ButtonWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
|
|
@ -29,17 +32,44 @@ namespace Ndk
|
|||
|
||||
void ResizeToContent() override;
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -47,6 +77,24 @@ namespace Ndk
|
|||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,93 @@
|
|||
|
||||
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);
|
||||
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,105 @@
|
|||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_CHECKBOXWIDGET_HPP
|
||||
#define NDK_WIDGETS_CHECKBOXWIDGET_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/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 = nullptr);
|
||||
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);
|
||||
|
||||
void ResizeToContent() override;
|
||||
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 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 <NDK/Widgets/CheckboxWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_CHECKBOXWIDGET_HPP
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.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 });
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void CheckboxWidget::SetTextMargin(float margin)
|
||||
{
|
||||
m_textMargin = margin;
|
||||
Layout();
|
||||
}
|
||||
|
||||
inline void CheckboxWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENUMS_SDK_HPP
|
||||
#define NAZARA_ENUMS_SDK_HPP
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
enum CheckboxState
|
||||
{
|
||||
CheckboxState_Checked,
|
||||
CheckboxState_Tristate,
|
||||
CheckboxState_Unchecked,
|
||||
|
||||
CheckboxState_Max = CheckboxState_Unchecked
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENUMS_SDK_HPP
|
||||
|
|
@ -9,13 +9,15 @@
|
|||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class World;
|
||||
|
||||
class NDK_API LabelWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,103 @@
|
|||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_PROGRESSBARWIDGET_HPP
|
||||
#define NDK_WIDGETS_PROGRESSBARWIDGET_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/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 = nullptr);
|
||||
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);
|
||||
|
||||
inline void ResizeToContent() override {}
|
||||
|
||||
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 <NDK/Widgets/ProgressBarWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_PROGRESSBARWIDGET_HPP
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.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 = GetContentSize();
|
||||
m_textSprite->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_value).Append('%'),
|
||||
static_cast<unsigned>(std::min(size.x, size.y) / 2.f), 0u, m_textColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
class World;
|
||||
|
||||
class NDK_API TextAreaWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
|
|
@ -32,7 +30,8 @@ namespace Ndk
|
|||
|
||||
inline void EnableMultiline(bool enable = true);
|
||||
|
||||
inline std::size_t GetCursorPosition() const;
|
||||
inline const Nz::Vector2ui& GetCursorPosition() const;
|
||||
inline std::size_t GetGlyphUnderCursor() const;
|
||||
inline std::size_t GetLineCount() const;
|
||||
inline const Nz::String& GetText() const;
|
||||
inline const Nz::Color& GetTextColor() const;
|
||||
|
|
@ -43,10 +42,12 @@ namespace Ndk
|
|||
inline bool IsReadOnly() const;
|
||||
|
||||
inline void MoveCursor(int offset);
|
||||
inline void MoveCursor(const Nz::Vector2i& offset);
|
||||
|
||||
void ResizeToContent() override;
|
||||
|
||||
inline void SetCursorPosition(std::size_t cursorPosition);
|
||||
inline void SetCursorPosition(std::size_t glyphIndex);
|
||||
inline void SetCursorPosition(Nz::Vector2ui cursorPosition);
|
||||
inline void SetReadOnly(bool readOnly = true);
|
||||
inline void SetText(const Nz::String& text);
|
||||
inline void SetTextColor(const Nz::Color& text);
|
||||
|
|
@ -82,7 +83,8 @@ namespace Ndk
|
|||
Nz::SimpleTextDrawer m_drawer;
|
||||
Nz::SpriteRef m_cursorSprite;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
std::size_t m_cursorPosition;
|
||||
Nz::Vector2ui m_cursorPosition;
|
||||
std::size_t m_cursorGlyph;
|
||||
bool m_multiLineEnabled;
|
||||
bool m_readOnly;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,11 +20,16 @@ namespace Ndk
|
|||
m_multiLineEnabled = enable;
|
||||
}
|
||||
|
||||
inline std::size_t TextAreaWidget::GetCursorPosition() const
|
||||
inline const Nz::Vector2ui& TextAreaWidget::GetCursorPosition() const
|
||||
{
|
||||
return m_cursorPosition;
|
||||
}
|
||||
|
||||
inline std::size_t Ndk::TextAreaWidget::GetGlyphUnderCursor() const
|
||||
{
|
||||
return m_cursorGlyph;
|
||||
}
|
||||
|
||||
inline std::size_t TextAreaWidget::GetLineCount() const
|
||||
{
|
||||
return m_drawer.GetLineCount();
|
||||
|
|
@ -53,22 +58,84 @@ namespace Ndk
|
|||
inline void TextAreaWidget::MoveCursor(int offset)
|
||||
{
|
||||
if (offset >= 0)
|
||||
SetCursorPosition(m_cursorPosition += static_cast<std::size_t>(offset));
|
||||
SetCursorPosition(m_cursorGlyph + static_cast<std::size_t>(offset));
|
||||
else
|
||||
{
|
||||
std::size_t nOffset = static_cast<std::size_t>(-offset);
|
||||
if (nOffset >= m_cursorPosition)
|
||||
if (nOffset >= m_cursorGlyph)
|
||||
SetCursorPosition(0);
|
||||
else
|
||||
SetCursorPosition(m_cursorPosition - nOffset);
|
||||
SetCursorPosition(m_cursorGlyph - nOffset);
|
||||
}
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCursorPosition(std::size_t cursorPosition)
|
||||
inline void TextAreaWidget::MoveCursor(const Nz::Vector2i& offset)
|
||||
{
|
||||
OnTextAreaCursorMove(this, &cursorPosition);
|
||||
auto BoundOffset = [] (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;
|
||||
}
|
||||
};
|
||||
|
||||
m_cursorPosition = std::min(cursorPosition, m_drawer.GetGlyphCount());
|
||||
Nz::Vector2ui cursorPosition = m_cursorPosition;
|
||||
cursorPosition.x = BoundOffset(static_cast<unsigned int>(cursorPosition.x), offset.x);
|
||||
cursorPosition.y = BoundOffset(static_cast<unsigned int>(cursorPosition.y), offset.y);
|
||||
|
||||
SetCursorPosition(cursorPosition);
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCursorPosition(std::size_t glyphIndex)
|
||||
{
|
||||
OnTextAreaCursorMove(this, &glyphIndex);
|
||||
|
||||
m_cursorGlyph = std::min(glyphIndex, m_drawer.GetGlyphCount());
|
||||
|
||||
std::size_t lineCount = m_drawer.GetLineCount();
|
||||
std::size_t line = 0U;
|
||||
for (std::size_t i = line + 1; i < lineCount; ++i)
|
||||
{
|
||||
if (m_drawer.GetLine(i).glyphIndex > m_cursorGlyph)
|
||||
break;
|
||||
|
||||
line = i;
|
||||
}
|
||||
|
||||
const auto& lineInfo = m_drawer.GetLine(line);
|
||||
|
||||
m_cursorPosition.y = line;
|
||||
m_cursorPosition.x = m_cursorGlyph - lineInfo.glyphIndex;
|
||||
|
||||
RefreshCursor();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCursorPosition(Nz::Vector2ui cursorPosition)
|
||||
{
|
||||
std::size_t lineCount = m_drawer.GetLineCount();
|
||||
if (cursorPosition.y >= lineCount)
|
||||
cursorPosition.y = static_cast<unsigned int>(lineCount - 1);
|
||||
|
||||
m_cursorPosition = cursorPosition;
|
||||
|
||||
const auto& lineInfo = m_drawer.GetLine(cursorPosition.y);
|
||||
if (cursorPosition.y + 1 < lineCount)
|
||||
{
|
||||
const auto& nextLineInfo = m_drawer.GetLine(cursorPosition.y + 1);
|
||||
cursorPosition.x = std::min(cursorPosition.x, static_cast<unsigned int>(nextLineInfo.glyphIndex - lineInfo.glyphIndex - 1));
|
||||
}
|
||||
|
||||
std::size_t glyphIndex = lineInfo.glyphIndex + cursorPosition.x;
|
||||
|
||||
OnTextAreaCursorMove(this, &glyphIndex);
|
||||
|
||||
m_cursorGlyph = std::min(glyphIndex, m_drawer.GetGlyphCount());
|
||||
|
||||
RefreshCursor();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -314,7 +314,8 @@ namespace Ndk
|
|||
|
||||
m_systems = std::move(world.m_systems);
|
||||
for (const auto& systemPtr : m_systems)
|
||||
systemPtr->SetWorld(this);
|
||||
if (systemPtr)
|
||||
systemPtr->SetWorld(this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,20 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \ingroup NDK
|
||||
* \class Ndk::BaseWidget
|
||||
* \brief Abstract class serving as a base class for all widgets
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a BaseWidget object using another widget as its parent
|
||||
*
|
||||
* \param parent Parent widget, must be valid and attached to a canvas
|
||||
*
|
||||
* Constructs a BaseWidget object using another widget as a base.
|
||||
* This will also register the widget to the canvas owning the top-most widget.
|
||||
*/
|
||||
BaseWidget::BaseWidget(BaseWidget* parent) :
|
||||
BaseWidget()
|
||||
{
|
||||
|
|
@ -24,11 +38,19 @@ namespace Ndk
|
|||
RegisterToCanvas();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Frees the widget, unregistering it from its canvas
|
||||
*/
|
||||
BaseWidget::~BaseWidget()
|
||||
{
|
||||
UnregisterFromCanvas();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroy the widget, deleting it in the process.
|
||||
*
|
||||
* Calling this function immediately destroys the widget, freeing its memory.
|
||||
*/
|
||||
void BaseWidget::Destroy()
|
||||
{
|
||||
NazaraAssert(this != m_canvas, "Canvas cannot be destroyed by calling Destroy()");
|
||||
|
|
@ -36,6 +58,9 @@ namespace Ndk
|
|||
m_widgetParent->DestroyChild(this); //< This does delete us
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enable or disables the widget background.
|
||||
*/
|
||||
void BaseWidget::EnableBackground(bool enable)
|
||||
{
|
||||
if (m_backgroundEntity.IsValid() == enable)
|
||||
|
|
@ -142,11 +167,11 @@ namespace Ndk
|
|||
m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex);
|
||||
}
|
||||
|
||||
void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
|
||||
void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& /*key*/)
|
||||
{
|
||||
}
|
||||
|
||||
void BaseWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& key)
|
||||
void BaseWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& /*key*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -154,15 +179,15 @@ namespace Ndk
|
|||
{
|
||||
}
|
||||
|
||||
void BaseWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
|
||||
void BaseWidget::OnMouseMoved(int /*x*/, int /*y*/, int /*deltaX*/, int /*deltaY*/)
|
||||
{
|
||||
}
|
||||
|
||||
void BaseWidget::OnMouseButtonPress(int x, int y, Nz::Mouse::Button button)
|
||||
void BaseWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button /*button*/)
|
||||
{
|
||||
}
|
||||
|
||||
void BaseWidget::OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button)
|
||||
void BaseWidget::OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button /*button*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -170,11 +195,11 @@ namespace Ndk
|
|||
{
|
||||
}
|
||||
|
||||
void BaseWidget::OnParentResized(const Nz::Vector2f& newSize)
|
||||
void BaseWidget::OnParentResized(const Nz::Vector2f& /*newSize*/)
|
||||
{
|
||||
}
|
||||
|
||||
void BaseWidget::OnTextEntered(char32_t character, bool repeated)
|
||||
void BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Canvas.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
|
|
@ -48,7 +45,7 @@ namespace Ndk
|
|||
m_widgetBoxes.pop_back();
|
||||
}
|
||||
|
||||
void Canvas::OnMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
|
||||
void Canvas::OnEventMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
|
||||
{
|
||||
if (m_hoveredWidget)
|
||||
{
|
||||
|
|
@ -59,7 +56,7 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
void Canvas::OnMouseButtonRelease(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent & event)
|
||||
void Canvas::OnEventMouseButtonRelease(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent & event)
|
||||
{
|
||||
if (m_hoveredWidget)
|
||||
{
|
||||
|
|
@ -70,7 +67,7 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
void Canvas::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||
void Canvas::OnEventMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||
{
|
||||
const WidgetBox* bestEntry = nullptr;
|
||||
float bestEntryArea = std::numeric_limits<float>::infinity();
|
||||
|
|
@ -120,7 +117,7 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
void Canvas::OnMouseLeft(const Nz::EventHandler* /*eventHandler*/)
|
||||
void Canvas::OnEventMouseLeft(const Nz::EventHandler* /*eventHandler*/)
|
||||
{
|
||||
if (m_hoveredWidget)
|
||||
{
|
||||
|
|
@ -129,19 +126,19 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
void Canvas::OnKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||
void Canvas::OnEventKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||
{
|
||||
if (m_keyboardOwner)
|
||||
m_keyboardOwner->OnKeyPressed(event);
|
||||
}
|
||||
|
||||
void Canvas::OnKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||
void Canvas::OnEventKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||
{
|
||||
if (m_keyboardOwner)
|
||||
m_keyboardOwner->OnKeyReleased(event);
|
||||
}
|
||||
|
||||
void Canvas::OnTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event)
|
||||
void Canvas::OnEventTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event)
|
||||
{
|
||||
if (m_keyboardOwner)
|
||||
m_keyboardOwner->OnTextEntered(event.character, event.repeated);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <NDK/Components/CollisionComponent2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <NDK/Components/CollisionComponent3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/PhysicsComponent3D.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem3D.hpp>
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@
|
|||
|
||||
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/CollisionComponent2D.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem3D.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem2D.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <NDK/Components/PhysicsComponent3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/CollisionComponent3D.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
#include <NDK/Console.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <Nazara/Lua/LuaState.hpp>
|
||||
#include <Nazara/Platform/Event.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace Ndk
|
|||
audio = LuaBinding_Base::BindAudio(*this);
|
||||
renderer = LuaBinding_Base::BindRenderer(*this);
|
||||
graphics = LuaBinding_Base::BindGraphics(*this);
|
||||
platform = LuaBinding_Base::BindPlatform(*this);
|
||||
#endif
|
||||
|
||||
sdk = LuaBinding_Base::BindSDK(*this);
|
||||
|
|
@ -48,6 +49,7 @@ namespace Ndk
|
|||
audio->Register(state);
|
||||
graphics->Register(state);
|
||||
renderer->Register(state);
|
||||
platform->Register(state);
|
||||
#endif
|
||||
|
||||
// ComponentType (fake enumeration to expose component indexes)
|
||||
|
|
|
|||
|
|
@ -32,28 +32,28 @@ namespace Ndk
|
|||
stream.BindMethod("IsWritable", &Nz::Stream::IsWritable);
|
||||
stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
|
||||
|
||||
stream.BindMethod("Read", [] (Nz::LuaState& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int {
|
||||
stream.BindMethod("Read", [] (Nz::LuaState& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
||||
int argIndex = 2;
|
||||
|
||||
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
||||
|
||||
std::unique_ptr<char[]> buffer(new char[length]);
|
||||
std::size_t readLength = stream.Read(buffer.get(), length);
|
||||
std::size_t readLength = instance.Read(buffer.get(), length);
|
||||
|
||||
lua.PushString(Nz::String(buffer.get(), readLength));
|
||||
return 1;
|
||||
});
|
||||
|
||||
stream.BindMethod("Write", [] (Nz::LuaState& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int {
|
||||
stream.BindMethod("Write", [] (Nz::LuaState& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
||||
int argIndex = 2;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
||||
|
||||
if (stream.IsTextModeEnabled())
|
||||
lua.Push(stream.Write(Nz::String(buffer, bufferSize)));
|
||||
if (instance.IsTextModeEnabled())
|
||||
lua.Push(instance.Write(Nz::String(buffer, bufferSize)));
|
||||
else
|
||||
lua.Push(stream.Write(buffer, bufferSize));
|
||||
lua.Push(instance.Write(buffer, bufferSize));
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
|
@ -103,11 +103,11 @@ namespace Ndk
|
|||
clock.BindMethod("Unpause", &Nz::Clock::Unpause);
|
||||
|
||||
// Manual
|
||||
clock.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::Clock& clock, std::size_t /*argumentCount*/) -> int {
|
||||
clock.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int {
|
||||
Nz::StringStream ss("Clock(Elapsed: ");
|
||||
ss << clock.GetSeconds();
|
||||
ss << instance.GetSeconds();
|
||||
ss << "s, Paused: ";
|
||||
ss << clock.IsPaused();
|
||||
ss << instance.IsPaused();
|
||||
ss << ')';
|
||||
|
||||
lua.PushString(ss);
|
||||
|
|
@ -159,9 +159,9 @@ namespace Ndk
|
|||
directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
||||
|
||||
// Manual
|
||||
directory.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::Directory& dir, std::size_t /*argumentCount*/) -> int {
|
||||
directory.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int {
|
||||
Nz::StringStream ss("Directory(");
|
||||
ss << dir.GetPath();
|
||||
ss << instance.GetPath();
|
||||
ss << ')';
|
||||
|
||||
lua.PushString(ss);
|
||||
|
|
@ -237,7 +237,7 @@ namespace Ndk
|
|||
file.BindStaticMethod("Rename", &Nz::File::Rename);
|
||||
|
||||
// Manual
|
||||
file.BindMethod("Open", [] (Nz::LuaState& lua, Nz::File& file, std::size_t argumentCount) -> int
|
||||
file.BindMethod("Open", [] (Nz::LuaState& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
|
|
@ -246,13 +246,13 @@ namespace Ndk
|
|||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return lua.Push(file.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
return lua.Push(instance.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen);
|
||||
return lua.Push(file.Open(filePath, openMode));
|
||||
return lua.Push(instance.Open(filePath, openMode));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ namespace Ndk
|
|||
return 0;
|
||||
});
|
||||
|
||||
file.BindMethod("SetCursorPos", [] (Nz::LuaState& lua, Nz::File& file, std::size_t argumentCount) -> int
|
||||
file.BindMethod("SetCursorPos", [] (Nz::LuaState& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
|
||||
|
|
@ -268,13 +268,13 @@ namespace Ndk
|
|||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
return lua.Push(instance.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::CursorPosition curPos = lua.Check<Nz::CursorPosition>(&argIndex);
|
||||
Nz::Int64 offset = lua.Check<Nz::Int64>(&argIndex);
|
||||
return lua.Push(file.SetCursorPos(curPos, offset));
|
||||
return lua.Push(instance.SetCursorPos(curPos, offset));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -282,10 +282,10 @@ namespace Ndk
|
|||
return 0;
|
||||
});
|
||||
|
||||
file.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::File& file, std::size_t /*argumentCount*/) -> int {
|
||||
file.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int {
|
||||
Nz::StringStream ss("File(");
|
||||
if (file.IsOpen())
|
||||
ss << "Path: " << file.GetPath();
|
||||
if (instance.IsOpen())
|
||||
ss << "Path: " << instance.GetPath();
|
||||
|
||||
ss << ')';
|
||||
|
||||
|
|
@ -321,10 +321,11 @@ namespace Ndk
|
|||
state.SetGlobal("CursorPosition");
|
||||
|
||||
// Nz::HashType
|
||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
state.PushTable(0, 9);
|
||||
static_assert(Nz::HashType_Max + 1 == 10, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
state.PushTable(0, 10);
|
||||
{
|
||||
state.PushField("CRC32", Nz::HashType_CRC32);
|
||||
state.PushField("CRC64", Nz::HashType_CRC64);
|
||||
state.PushField("Fletcher16", Nz::HashType_Fletcher16);
|
||||
state.PushField("MD5", Nz::HashType_MD5);
|
||||
state.PushField("SHA1", Nz::HashType_SHA1);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,133 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Lua/LuaBinding_Platform.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindPlatform(LuaBinding& binding)
|
||||
{
|
||||
return std::make_unique<LuaBinding_Platform>(binding);
|
||||
}
|
||||
|
||||
LuaBinding_Platform::LuaBinding_Platform(LuaBinding& binding) :
|
||||
LuaBinding_Base(binding)
|
||||
{
|
||||
/*********************************** Nz::Keyboard **********************************/
|
||||
keyboard.Reset("Keyboard");
|
||||
{
|
||||
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
||||
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the classes that will be used by the Lua instance
|
||||
*
|
||||
* \param instance Lua instance that will interact with the Utility classes
|
||||
*/
|
||||
void LuaBinding_Platform::Register(Nz::LuaState& state)
|
||||
{
|
||||
keyboard.Register(state);
|
||||
|
||||
keyboard.PushGlobalTable(state);
|
||||
{
|
||||
static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding");
|
||||
|
||||
state.PushField("Undefined", Nz::Keyboard::Undefined);
|
||||
|
||||
// A-Z
|
||||
for (std::size_t i = 0; i < 26; ++i)
|
||||
state.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
||||
|
||||
// Numerical
|
||||
for (std::size_t i = 0; i < 10; ++i)
|
||||
{
|
||||
state.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
||||
state.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
||||
}
|
||||
|
||||
// F1-F15
|
||||
for (std::size_t i = 0; i < 15; ++i)
|
||||
state.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
||||
|
||||
// And all the others...
|
||||
state.PushField("Down", Nz::Keyboard::Down);
|
||||
state.PushField("Left", Nz::Keyboard::Left);
|
||||
state.PushField("Right", Nz::Keyboard::Right);
|
||||
state.PushField("Up", Nz::Keyboard::Up);
|
||||
|
||||
state.PushField("Add", Nz::Keyboard::Add);
|
||||
state.PushField("Decimal", Nz::Keyboard::Decimal);
|
||||
state.PushField("Divide", Nz::Keyboard::Divide);
|
||||
state.PushField("Multiply", Nz::Keyboard::Multiply);
|
||||
state.PushField("Subtract", Nz::Keyboard::Subtract);
|
||||
|
||||
state.PushField("Backslash", Nz::Keyboard::Backslash);
|
||||
state.PushField("Backspace", Nz::Keyboard::Backspace);
|
||||
state.PushField("Clear", Nz::Keyboard::Clear);
|
||||
state.PushField("Comma", Nz::Keyboard::Comma);
|
||||
state.PushField("Dash", Nz::Keyboard::Dash);
|
||||
state.PushField("Delete", Nz::Keyboard::Delete);
|
||||
state.PushField("End", Nz::Keyboard::End);
|
||||
state.PushField("Equal", Nz::Keyboard::Equal);
|
||||
state.PushField("Escape", Nz::Keyboard::Escape);
|
||||
state.PushField("Home", Nz::Keyboard::Home);
|
||||
state.PushField("Insert", Nz::Keyboard::Insert);
|
||||
state.PushField("LAlt", Nz::Keyboard::LAlt);
|
||||
state.PushField("LBracket", Nz::Keyboard::LBracket);
|
||||
state.PushField("LControl", Nz::Keyboard::LControl);
|
||||
state.PushField("LShift", Nz::Keyboard::LShift);
|
||||
state.PushField("LSystem", Nz::Keyboard::LSystem);
|
||||
state.PushField("PageDown", Nz::Keyboard::PageDown);
|
||||
state.PushField("PageUp", Nz::Keyboard::PageUp);
|
||||
state.PushField("Pause", Nz::Keyboard::Pause);
|
||||
state.PushField("Period", Nz::Keyboard::Period);
|
||||
state.PushField("Print", Nz::Keyboard::Print);
|
||||
state.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
||||
state.PushField("Quote", Nz::Keyboard::Quote);
|
||||
state.PushField("RAlt", Nz::Keyboard::RAlt);
|
||||
state.PushField("RBracket", Nz::Keyboard::RBracket);
|
||||
state.PushField("RControl", Nz::Keyboard::RControl);
|
||||
state.PushField("Return", Nz::Keyboard::Return);
|
||||
state.PushField("RShift", Nz::Keyboard::RShift);
|
||||
state.PushField("RSystem", Nz::Keyboard::RSystem);
|
||||
state.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
||||
state.PushField("Slash", Nz::Keyboard::Slash);
|
||||
state.PushField("Space", Nz::Keyboard::Space);
|
||||
state.PushField("Tab", Nz::Keyboard::Tab);
|
||||
state.PushField("Tilde", Nz::Keyboard::Tilde);
|
||||
state.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
||||
state.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
||||
state.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
||||
state.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
||||
state.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
||||
state.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
||||
state.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
||||
state.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
||||
state.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
||||
state.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
||||
state.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
||||
state.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
||||
state.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
||||
state.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
||||
state.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
||||
state.PushField("NumLock", Nz::Keyboard::NumLock);
|
||||
state.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
||||
}
|
||||
state.Pop();
|
||||
|
||||
static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding");
|
||||
state.PushTable(0, Nz::WindowStyle_Max + 1);
|
||||
{
|
||||
state.PushField("None", Nz::WindowStyle_None);
|
||||
state.PushField("Fullscreen", Nz::WindowStyle_Fullscreen);
|
||||
state.PushField("Closable", Nz::WindowStyle_Closable);
|
||||
state.PushField("Resizable", Nz::WindowStyle_Resizable);
|
||||
state.PushField("Titlebar", Nz::WindowStyle_Titlebar);
|
||||
state.PushField("Threaded", Nz::WindowStyle_Threaded);
|
||||
}
|
||||
state.SetGlobal("WindowStyle");
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ namespace Ndk
|
|||
}
|
||||
|
||||
/*********************************** Nz::TextureManager ***********************************/
|
||||
textureManager.Reset("textureManager");
|
||||
textureManager.Reset("TextureManager");
|
||||
{
|
||||
textureManager.BindStaticMethod("Clear", &Nz::TextureManager::Clear);
|
||||
textureManager.BindStaticMethod("Get", &Nz::TextureManager::Get);
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ namespace Ndk
|
|||
console.BindMethod("GetSize", &Console::GetSize);
|
||||
console.BindMethod("GetTextFont", &Console::GetTextFont);
|
||||
|
||||
console.BindMethod("IsValidHandle", &ConsoleHandle::IsValid);
|
||||
console.BindMethod("IsVisible", &Console::IsVisible);
|
||||
|
||||
console.BindMethod("SendCharacter", &Console::SendCharacter);
|
||||
|
|
@ -91,6 +92,7 @@ namespace Ndk
|
|||
entity.BindMethod("Kill", &Entity::Kill);
|
||||
entity.BindMethod("IsEnabled", &Entity::IsEnabled);
|
||||
entity.BindMethod("IsValid", &Entity::IsValid);
|
||||
entity.BindMethod("IsValidHandle", &EntityHandle::IsValid);
|
||||
entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||
entity.BindMethod("__tostring", &EntityHandle::ToString);
|
||||
|
||||
|
|
@ -101,6 +103,14 @@ namespace Ndk
|
|||
return bindingComponent->adder(state, handle);
|
||||
});
|
||||
|
||||
entity.BindMethod("HasComponent", [this](Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);
|
||||
|
||||
state.PushBoolean(handle->HasComponent(bindingComponent->index));
|
||||
return 1;
|
||||
});
|
||||
|
||||
entity.BindMethod("GetComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);
|
||||
|
|
@ -120,6 +130,8 @@ namespace Ndk
|
|||
/*********************************** Ndk::NodeComponent **********************************/
|
||||
nodeComponent.Reset("NodeComponent");
|
||||
{
|
||||
nodeComponent.BindMethod("IsValidHandle", &NodeComponentHandle::IsValid);
|
||||
|
||||
nodeComponent.Inherit<Nz::Node>(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
|
|
@ -129,6 +141,8 @@ namespace Ndk
|
|||
/*********************************** Ndk::VelocityComponent **********************************/
|
||||
velocityComponent.Reset("VelocityComponent");
|
||||
{
|
||||
velocityComponent.BindMethod("IsValidHandle", &VelocityComponentHandle::IsValid);
|
||||
|
||||
velocityComponent.SetGetter([] (Nz::LuaState& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
|
|
@ -165,6 +179,8 @@ namespace Ndk
|
|||
world.BindMethod("CreateEntity", &World::CreateEntity);
|
||||
world.BindMethod("CreateEntities", &World::CreateEntities);
|
||||
world.BindMethod("Clear", &World::Clear);
|
||||
|
||||
world.BindMethod("IsValidHandle", &WorldHandle::IsValid);
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
|
|
@ -176,18 +192,20 @@ namespace Ndk
|
|||
return handle->GetObject();
|
||||
});
|
||||
|
||||
cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV);
|
||||
cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer);
|
||||
cameraComponent.BindMethod("GetFOV", &CameraComponent::GetFOV);
|
||||
cameraComponent.BindMethod("GetLayer", &CameraComponent::GetLayer);
|
||||
|
||||
cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV);
|
||||
cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer);
|
||||
cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType);
|
||||
cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize);
|
||||
//cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget);
|
||||
cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion);
|
||||
cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport);
|
||||
cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar);
|
||||
cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear);
|
||||
cameraComponent.BindMethod("IsValidHandle", &CameraComponentHandle::IsValid);
|
||||
|
||||
cameraComponent.BindMethod("SetFOV", &CameraComponent::SetFOV);
|
||||
cameraComponent.BindMethod("SetLayer", &CameraComponent::SetLayer);
|
||||
cameraComponent.BindMethod("SetProjectionType", &CameraComponent::SetProjectionType);
|
||||
cameraComponent.BindMethod("SetSize", (void(CameraComponent::*)(const Nz::Vector2f&)) &CameraComponent::SetSize);
|
||||
//cameraComponent.BindMethod("SetTarget", &CameraComponent::SetTarget);
|
||||
cameraComponent.BindMethod("SetTargetRegion", &CameraComponent::SetTargetRegion);
|
||||
cameraComponent.BindMethod("SetViewport", &CameraComponent::SetViewport);
|
||||
cameraComponent.BindMethod("SetZFar", &CameraComponent::SetZFar);
|
||||
cameraComponent.BindMethod("SetZNear", &CameraComponent::SetZNear);
|
||||
}
|
||||
|
||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||
|
|
@ -249,6 +267,8 @@ namespace Ndk
|
|||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
graphicsComponent.BindMethod("IsValidHandle", &GraphicsComponentHandle::IsValid);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -161,13 +161,6 @@ namespace Ndk
|
|||
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Keyboard **********************************/
|
||||
keyboard.Reset("Keyboard");
|
||||
{
|
||||
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
||||
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Node **********************************/
|
||||
node.Reset("Node");
|
||||
{
|
||||
|
|
@ -216,29 +209,29 @@ namespace Ndk
|
|||
node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
||||
node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
||||
|
||||
node.BindMethod("Move", [] (Nz::LuaState& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int
|
||||
node.BindMethod("Move", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
|
||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Move(offset, coordSys);
|
||||
instance.Move(offset, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("Rotate", [] (Nz::LuaState& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int
|
||||
node.BindMethod("Rotate", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
|
||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Rotate(rotation, coordSys);
|
||||
instance.Rotate(rotation, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("Scale", [] (Nz::LuaState& lua, Nz::Node& node, std::size_t argumentCount) -> int
|
||||
node.BindMethod("Scale", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
|
|
@ -248,15 +241,15 @@ namespace Ndk
|
|||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.Scale(lua.Check<float>(&argIndex));
|
||||
instance.Scale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +257,7 @@ namespace Ndk
|
|||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("SetScale", [] (Nz::LuaState& lua, Nz::Node& node, std::size_t argumentCount) -> int
|
||||
node.BindMethod("SetScale", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
|
|
@ -278,10 +271,10 @@ namespace Ndk
|
|||
{
|
||||
float scale = lua.Check<float>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.SetScale(scale, coordSys);
|
||||
instance.SetScale(scale, coordSys);
|
||||
}
|
||||
else
|
||||
node.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
instance.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -292,7 +285,7 @@ namespace Ndk
|
|||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
|
||||
node.SetScale(scale, coordSys);
|
||||
instance.SetScale(scale, coordSys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -301,7 +294,7 @@ namespace Ndk
|
|||
return 0;
|
||||
});
|
||||
|
||||
node.BindMethod("SetInitialScale", [] (Nz::LuaState& lua, Nz::Node& node, std::size_t argumentCount) -> int
|
||||
node.BindMethod("SetInitialScale", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||
|
||||
|
|
@ -311,16 +304,16 @@ namespace Ndk
|
|||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.SetInitialScale(lua.Check<float>(&argIndex));
|
||||
instance.SetInitialScale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||
instance.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
node.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
instance.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -339,106 +332,6 @@ namespace Ndk
|
|||
{
|
||||
abstractImage.Register(state);
|
||||
font.Register(state);
|
||||
keyboard.Register(state);
|
||||
node.Register(state);
|
||||
|
||||
keyboard.PushGlobalTable(state);
|
||||
{
|
||||
static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding");
|
||||
|
||||
state.PushField("Undefined", Nz::Keyboard::Undefined);
|
||||
|
||||
// A-Z
|
||||
for (std::size_t i = 0; i < 26; ++i)
|
||||
state.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
||||
|
||||
// Numerical
|
||||
for (std::size_t i = 0; i < 10; ++i)
|
||||
{
|
||||
state.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
||||
state.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
||||
}
|
||||
|
||||
// F1-F15
|
||||
for (std::size_t i = 0; i < 15; ++i)
|
||||
state.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
||||
|
||||
// And all the others...
|
||||
state.PushField("Down", Nz::Keyboard::Down);
|
||||
state.PushField("Left", Nz::Keyboard::Left);
|
||||
state.PushField("Right", Nz::Keyboard::Right);
|
||||
state.PushField("Up", Nz::Keyboard::Up);
|
||||
|
||||
state.PushField("Add", Nz::Keyboard::Add);
|
||||
state.PushField("Decimal", Nz::Keyboard::Decimal);
|
||||
state.PushField("Divide", Nz::Keyboard::Divide);
|
||||
state.PushField("Multiply", Nz::Keyboard::Multiply);
|
||||
state.PushField("Subtract", Nz::Keyboard::Subtract);
|
||||
|
||||
state.PushField("Backslash", Nz::Keyboard::Backslash);
|
||||
state.PushField("Backspace", Nz::Keyboard::Backspace);
|
||||
state.PushField("Clear", Nz::Keyboard::Clear);
|
||||
state.PushField("Comma", Nz::Keyboard::Comma);
|
||||
state.PushField("Dash", Nz::Keyboard::Dash);
|
||||
state.PushField("Delete", Nz::Keyboard::Delete);
|
||||
state.PushField("End", Nz::Keyboard::End);
|
||||
state.PushField("Equal", Nz::Keyboard::Equal);
|
||||
state.PushField("Escape", Nz::Keyboard::Escape);
|
||||
state.PushField("Home", Nz::Keyboard::Home);
|
||||
state.PushField("Insert", Nz::Keyboard::Insert);
|
||||
state.PushField("LAlt", Nz::Keyboard::LAlt);
|
||||
state.PushField("LBracket", Nz::Keyboard::LBracket);
|
||||
state.PushField("LControl", Nz::Keyboard::LControl);
|
||||
state.PushField("LShift", Nz::Keyboard::LShift);
|
||||
state.PushField("LSystem", Nz::Keyboard::LSystem);
|
||||
state.PushField("PageDown", Nz::Keyboard::PageDown);
|
||||
state.PushField("PageUp", Nz::Keyboard::PageUp);
|
||||
state.PushField("Pause", Nz::Keyboard::Pause);
|
||||
state.PushField("Period", Nz::Keyboard::Period);
|
||||
state.PushField("Print", Nz::Keyboard::Print);
|
||||
state.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
||||
state.PushField("Quote", Nz::Keyboard::Quote);
|
||||
state.PushField("RAlt", Nz::Keyboard::RAlt);
|
||||
state.PushField("RBracket", Nz::Keyboard::RBracket);
|
||||
state.PushField("RControl", Nz::Keyboard::RControl);
|
||||
state.PushField("Return", Nz::Keyboard::Return);
|
||||
state.PushField("RShift", Nz::Keyboard::RShift);
|
||||
state.PushField("RSystem", Nz::Keyboard::RSystem);
|
||||
state.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
||||
state.PushField("Slash", Nz::Keyboard::Slash);
|
||||
state.PushField("Space", Nz::Keyboard::Space);
|
||||
state.PushField("Tab", Nz::Keyboard::Tab);
|
||||
state.PushField("Tilde", Nz::Keyboard::Tilde);
|
||||
state.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
||||
state.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
||||
state.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
||||
state.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
||||
state.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
||||
state.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
||||
state.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
||||
state.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
||||
state.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
||||
state.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
||||
state.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
||||
state.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
||||
state.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
||||
state.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
||||
state.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
||||
state.PushField("NumLock", Nz::Keyboard::NumLock);
|
||||
state.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
||||
}
|
||||
state.Pop();
|
||||
|
||||
static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding");
|
||||
state.PushTable(0, Nz::WindowStyle_Max + 1);
|
||||
{
|
||||
state.PushField("None", Nz::WindowStyle_None);
|
||||
state.PushField("Fullscreen", Nz::WindowStyle_Fullscreen);
|
||||
state.PushField("Closable", Nz::WindowStyle_Closable);
|
||||
state.PushField("Resizable", Nz::WindowStyle_Resizable);
|
||||
state.PushField("Titlebar", Nz::WindowStyle_Titlebar);
|
||||
state.PushField("Threaded", Nz::WindowStyle_Threaded);
|
||||
}
|
||||
state.SetGlobal("WindowStyle");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -11,6 +11,7 @@
|
|||
#include <Nazara/Noise/Noise.hpp>
|
||||
#include <Nazara/Physics2D/Physics2D.hpp>
|
||||
#include <Nazara/Physics3D/Physics3D.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
#include <NDK/Systems/ParticleSystem.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Widgets/CheckboxWidget.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
|
|
@ -63,13 +65,6 @@ namespace Ndk
|
|||
// Initialize the engine first
|
||||
|
||||
// Shared modules
|
||||
#ifdef NDK_SERVER
|
||||
Nz::ParameterList parameters;
|
||||
parameters.SetParameter("NoWindowSystem", true);
|
||||
|
||||
Nz::Utility::SetParameters(parameters);
|
||||
#endif
|
||||
|
||||
Nz::Lua::Initialize();
|
||||
Nz::Noise::Initialize();
|
||||
Nz::Physics2D::Initialize();
|
||||
|
|
@ -119,6 +114,13 @@ namespace Ndk
|
|||
InitializeSystem<ListenerSystem>();
|
||||
InitializeSystem<ParticleSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
|
||||
// Widgets
|
||||
if (!CheckboxWidget::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Checkbox Widget");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
|
|
@ -127,7 +129,6 @@ namespace Ndk
|
|||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to initialize NDK: " + Nz::String(e.what()));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -173,6 +174,11 @@ namespace Ndk
|
|||
Nz::Physics3D::Uninitialize();
|
||||
Nz::Utility::Uninitialize();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Widgets
|
||||
CheckboxWidget::Uninitialize();
|
||||
#endif
|
||||
|
||||
NazaraNotice("Uninitialized: SDK");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <Nazara/Graphics/ColorBackground.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/SceneData.hpp>
|
||||
#include <Nazara/Graphics/SkyboxBackground.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
|
|
@ -37,7 +39,7 @@ namespace Ndk
|
|||
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
|
||||
SetDefaultBackground(Nz::ColorBackground::New());
|
||||
SetUpdateOrder(100); //< Render last, after every movement is done
|
||||
SetUpdateRate(0.f); //< We don't want any rate limit
|
||||
SetMaximumUpdateRate(0.f); //< We don't want any rate limit
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -5,17 +5,29 @@
|
|||
#include <NDK/Widgets/ButtonWidget.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
Nz::Color ButtonWidget::s_color { 74, 74, 74 };
|
||||
Nz::Color ButtonWidget::s_cornerColor { 180, 180, 180 };
|
||||
Nz::Color ButtonWidget::s_hoverColor { 128, 128, 128 };
|
||||
Nz::Color ButtonWidget::s_hoverCornerColor { s_cornerColor };
|
||||
Nz::Color ButtonWidget::s_pressColor { s_cornerColor };
|
||||
Nz::Color ButtonWidget::s_pressCornerColor { s_color };
|
||||
|
||||
ButtonWidget::ButtonWidget(BaseWidget* parent) :
|
||||
BaseWidget(parent)
|
||||
BaseWidget(parent),
|
||||
m_color { s_color },
|
||||
m_cornerColor { s_cornerColor },
|
||||
m_hoverColor { s_hoverColor },
|
||||
m_hoverCornerColor { s_hoverCornerColor },
|
||||
m_pressColor { s_pressColor },
|
||||
m_pressCornerColor { s_pressCornerColor }
|
||||
{
|
||||
m_gradientSprite = Nz::Sprite::New();
|
||||
m_gradientSprite->SetColor(Nz::Color(74, 74, 74));
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, Nz::Color(180, 180, 180));
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, Nz::Color(180, 180, 180));
|
||||
m_gradientSprite->SetColor(m_color);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor);
|
||||
m_gradientSprite->SetMaterial(Nz::Material::New("Basic2D"));
|
||||
|
||||
m_gradientEntity = CreateEntity();
|
||||
|
|
@ -31,6 +43,36 @@ namespace Ndk
|
|||
Layout();
|
||||
}
|
||||
|
||||
const Nz::Color& ButtonWidget::GetDefaultColor()
|
||||
{
|
||||
return s_color;
|
||||
}
|
||||
|
||||
const Nz::Color& ButtonWidget::GetDefaultCornerColor()
|
||||
{
|
||||
return s_cornerColor;
|
||||
}
|
||||
|
||||
const Nz::Color& ButtonWidget::GetDefaultHoverColor()
|
||||
{
|
||||
return s_hoverColor;
|
||||
}
|
||||
|
||||
const Nz::Color& ButtonWidget::GetDefaultHoverCornerColor()
|
||||
{
|
||||
return s_hoverCornerColor;
|
||||
}
|
||||
|
||||
const Nz::Color& ButtonWidget::GetDefaultPressColor()
|
||||
{
|
||||
return s_pressColor;
|
||||
}
|
||||
|
||||
const Nz::Color& ButtonWidget::GetDefaultPressCornerColor()
|
||||
{
|
||||
return s_pressCornerColor;
|
||||
}
|
||||
|
||||
void ButtonWidget::ResizeToContent()
|
||||
{
|
||||
SetContentSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()));
|
||||
|
|
@ -46,24 +88,47 @@ namespace Ndk
|
|||
m_gradientEntity->GetComponent<NodeComponent>().SetPosition(origin);
|
||||
m_gradientSprite->SetSize(contentSize);
|
||||
|
||||
Nz::Boxf textBox = m_textEntity->GetComponent<GraphicsComponent>().GetBoundingVolume().aabb;
|
||||
Nz::Boxf textBox = m_textEntity->GetComponent<GraphicsComponent>().GetBoundingVolume().obb.localBox;
|
||||
m_textEntity->GetComponent<NodeComponent>().SetPosition(origin.x + contentSize.x / 2 - textBox.width / 2, origin.y + contentSize.y / 2 - textBox.height / 2);
|
||||
}
|
||||
|
||||
void ButtonWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button)
|
||||
{
|
||||
if (button == Nz::Mouse::Left)
|
||||
{
|
||||
m_gradientSprite->SetColor(m_pressColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_pressCornerColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_pressCornerColor);
|
||||
m_gradientSprite->SetTexture(m_pressTexture, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonWidget::OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button button)
|
||||
{
|
||||
if (button == Nz::Mouse::Left)
|
||||
{
|
||||
m_gradientSprite->SetColor(m_hoverColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_hoverCornerColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_hoverCornerColor);
|
||||
m_gradientSprite->SetTexture(m_hoverTexture, false);
|
||||
|
||||
OnButtonTrigger(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonWidget::OnMouseEnter()
|
||||
{
|
||||
m_gradientSprite->SetColor(Nz::Color(128, 128, 128));
|
||||
m_gradientSprite->SetColor(m_hoverColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_hoverCornerColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_hoverCornerColor);
|
||||
m_gradientSprite->SetTexture(m_hoverTexture, false);
|
||||
}
|
||||
|
||||
|
||||
void ButtonWidget::OnMouseExit()
|
||||
{
|
||||
m_gradientSprite->SetColor(Nz::Color(74, 74, 74));
|
||||
m_gradientSprite->SetColor(m_color);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor);
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor);
|
||||
m_gradientSprite->SetTexture(m_texture, false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,181 @@
|
|||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Widgets/CheckboxWidget.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
Nz::Color CheckboxWidget::s_backgroundColor { Nz::Color::White };
|
||||
Nz::Color CheckboxWidget::s_disabledBackgroundColor { 201, 201, 201 };
|
||||
Nz::Color CheckboxWidget::s_disabledBorderColor { 62, 62, 62 };
|
||||
Nz::Color CheckboxWidget::s_borderColor { Nz::Color::Black };
|
||||
float CheckboxWidget::s_borderScale { 16.f };
|
||||
|
||||
CheckboxWidget::CheckboxWidget(BaseWidget* parent) :
|
||||
BaseWidget(parent),
|
||||
m_adaptativeMargin { true },
|
||||
m_checkboxEnabled { true },
|
||||
m_tristateEnabled { false },
|
||||
m_textMargin { 16.f },
|
||||
m_state { CheckboxState_Unchecked }
|
||||
{
|
||||
m_checkboxBorderSprite = Nz::Sprite::New(Nz::Material::New("Basic2D"));
|
||||
m_checkboxBackgroundSprite = Nz::Sprite::New(Nz::Material::New("Basic2D"));
|
||||
m_checkboxContentSprite = Nz::Sprite::New(Nz::Material::New("Translucent2D"));
|
||||
m_textSprite = Nz::TextSprite::New();
|
||||
|
||||
m_checkboxBorderEntity = CreateEntity();
|
||||
m_checkboxBorderEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_checkboxBorderEntity->AddComponent<GraphicsComponent>().Attach(m_checkboxBorderSprite);
|
||||
|
||||
m_checkboxBackgroundEntity = CreateEntity();
|
||||
m_checkboxBackgroundEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_checkboxBackgroundEntity->AddComponent<GraphicsComponent>().Attach(m_checkboxBackgroundSprite, 1);
|
||||
|
||||
m_checkboxContentEntity = CreateEntity();
|
||||
m_checkboxContentEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_checkboxContentEntity->AddComponent<GraphicsComponent>().Attach(m_checkboxContentSprite, 2);
|
||||
|
||||
m_textEntity = CreateEntity();
|
||||
m_textEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_textEntity->AddComponent<GraphicsComponent>().Attach(m_textSprite);
|
||||
|
||||
m_checkMark = Nz::TextureLibrary::Get("Ndk::CheckboxWidget::checkmark");
|
||||
|
||||
SetCheckboxSize({ 32.f, 32.f });
|
||||
UpdateCheckbox();
|
||||
}
|
||||
|
||||
bool CheckboxWidget::Initialize()
|
||||
{
|
||||
const Nz::UInt8 r_checkmark[] =
|
||||
{
|
||||
#include <NDK/Resources/checkmark.png.h>
|
||||
};
|
||||
|
||||
Nz::TextureRef checkmarkTexture = Nz::Texture::New();
|
||||
if (!checkmarkTexture->LoadFromMemory(r_checkmark, sizeof(r_checkmark) / sizeof(r_checkmark[0])))
|
||||
{
|
||||
NazaraError("Failed to load embedded checkmark");
|
||||
return false;
|
||||
}
|
||||
|
||||
Nz::TextureLibrary::Register("Ndk::CheckboxWidget::checkmark", checkmarkTexture);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CheckboxWidget::Uninitialize()
|
||||
{
|
||||
Nz::TextureLibrary::Unregister("Ndk::CheckboxWidget::checkmark");
|
||||
}
|
||||
|
||||
void CheckboxWidget::SetState(CheckboxState state)
|
||||
{
|
||||
if (!m_checkboxEnabled)
|
||||
return;
|
||||
|
||||
if (state == CheckboxState_Tristate)
|
||||
m_tristateEnabled = true;
|
||||
|
||||
m_state = state;
|
||||
UpdateCheckbox();
|
||||
}
|
||||
|
||||
CheckboxState CheckboxWidget::SwitchToNextState()
|
||||
{
|
||||
if (!m_checkboxEnabled)
|
||||
return m_state;
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case CheckboxState_Unchecked:
|
||||
SetState(CheckboxState_Checked);
|
||||
break;
|
||||
|
||||
case CheckboxState_Checked:
|
||||
SetState(m_tristateEnabled ? CheckboxState_Tristate : CheckboxState_Unchecked);
|
||||
break;
|
||||
|
||||
case CheckboxState_Tristate:
|
||||
SetState(CheckboxState_Unchecked);
|
||||
break;
|
||||
}
|
||||
|
||||
return m_state;
|
||||
}
|
||||
|
||||
void CheckboxWidget::ResizeToContent()
|
||||
{
|
||||
Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
|
||||
Nz::Vector2f checkboxSize = GetCheckboxSize();
|
||||
|
||||
Nz::Vector2f finalSize { checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin) + textSize.x, std::max(textSize.y, checkboxSize.y) };
|
||||
SetContentSize(finalSize);
|
||||
}
|
||||
|
||||
void CheckboxWidget::Layout()
|
||||
{
|
||||
BaseWidget::Layout();
|
||||
|
||||
Nz::Vector2f origin = GetContentOrigin();
|
||||
Nz::Vector2f checkboxSize = GetCheckboxSize();
|
||||
Nz::Vector2f borderSize = GetCheckboxBorderSize();
|
||||
|
||||
m_checkboxBorderEntity->GetComponent<NodeComponent>().SetPosition(origin);
|
||||
m_checkboxBackgroundEntity->GetComponent<NodeComponent>().SetPosition(origin + borderSize);
|
||||
|
||||
Nz::Vector3f checkboxBox = m_checkboxContentSprite->GetBoundingVolume().obb.localBox.GetLengths();
|
||||
m_checkboxContentEntity->GetComponent<NodeComponent>().SetPosition(origin.x + checkboxSize.x / 2.f - checkboxBox.x / 2.f,
|
||||
origin.y + checkboxSize.y / 2.f - checkboxBox.y / 2.f);
|
||||
|
||||
Nz::Vector3f textBox = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
|
||||
m_textEntity->GetComponent<NodeComponent>().SetPosition(origin.x + checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin),
|
||||
origin.y + checkboxSize.y / 2.f - textBox.y / 2.f);
|
||||
}
|
||||
|
||||
void CheckboxWidget::OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button)
|
||||
{
|
||||
if (button == Nz::Mouse::Left && ContainsCheckbox(x, y) && IsCheckboxEnabled())
|
||||
{
|
||||
SwitchToNextState();
|
||||
OnStateChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckboxWidget::UpdateCheckbox()
|
||||
{
|
||||
if (m_checkboxEnabled)
|
||||
{
|
||||
m_checkboxBorderSprite->SetColor(s_borderColor);
|
||||
m_checkboxBackgroundSprite->SetColor(s_backgroundColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_checkboxBorderSprite->SetColor(s_disabledBorderColor);
|
||||
m_checkboxBackgroundSprite->SetColor(s_disabledBackgroundColor);
|
||||
}
|
||||
|
||||
|
||||
if (m_state == CheckboxState_Unchecked)
|
||||
{
|
||||
m_checkboxContentEntity->Enable(false);
|
||||
return;
|
||||
}
|
||||
else if (m_state == CheckboxState_Checked)
|
||||
{
|
||||
m_checkboxContentEntity->Enable();
|
||||
m_checkboxContentSprite->SetColor(Nz::Color::White);
|
||||
m_checkboxContentSprite->SetTexture(m_checkMark, false);
|
||||
}
|
||||
else // Tristate
|
||||
{
|
||||
m_checkboxContentEntity->Enable();
|
||||
m_checkboxContentSprite->SetColor(Nz::Color::Black);
|
||||
m_checkboxContentSprite->SetTexture(Nz::TextureRef {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
#include <NDK/Widgets/LabelWidget.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Widgets/ProgressBarWidget.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
float ProgressBarWidget::s_borderScale { 16.f };
|
||||
Nz::Color ProgressBarWidget::s_borderColor { Nz::Color::Black };
|
||||
Nz::Color ProgressBarWidget::s_barBackgroundColor { Nz::Color { 225, 225, 225 } };
|
||||
Nz::Color ProgressBarWidget::s_barBackgroundCornerColor { Nz::Color { 255, 255, 255 } };
|
||||
Nz::Color ProgressBarWidget::s_barColor { Nz::Color { 0, 225, 0 } };
|
||||
Nz::Color ProgressBarWidget::s_barCornerColor { Nz::Color { 220, 255, 220 } };
|
||||
|
||||
ProgressBarWidget::ProgressBarWidget(BaseWidget* parent) :
|
||||
BaseWidget(parent),
|
||||
m_textColor { Nz::Color::Black },
|
||||
m_textMargin { 16.f },
|
||||
m_value { 0u }
|
||||
{
|
||||
m_borderSprite = Nz::Sprite::New(Nz::Material::New("Basic2D"));
|
||||
m_barBackgroundSprite = Nz::Sprite::New(Nz::Material::New("Basic2D"));
|
||||
m_barSprite = Nz::Sprite::New(Nz::Material::New("Basic2D"));
|
||||
|
||||
m_borderSprite->SetColor(s_borderColor);
|
||||
SetBarBackgroundColor(s_barBackgroundColor, s_barBackgroundCornerColor);
|
||||
SetBarColor(s_barColor, s_barCornerColor);
|
||||
|
||||
|
||||
m_borderEntity = CreateEntity();
|
||||
m_borderEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_borderEntity->AddComponent<GraphicsComponent>().Attach(m_borderSprite);
|
||||
|
||||
m_barEntity = CreateEntity();
|
||||
m_barEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
GraphicsComponent& graphics = m_barEntity->AddComponent<GraphicsComponent>();
|
||||
|
||||
graphics.Attach(m_barBackgroundSprite, 1);
|
||||
graphics.Attach(m_barSprite, 2);
|
||||
|
||||
|
||||
m_textSprite = Nz::TextSprite::New();
|
||||
m_textEntity = CreateEntity();
|
||||
|
||||
m_textEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_textEntity->AddComponent<GraphicsComponent>().Attach(m_textSprite);
|
||||
|
||||
UpdateText();
|
||||
Layout();
|
||||
}
|
||||
|
||||
|
||||
const Nz::Color& ProgressBarWidget::GetDefaultBarColor()
|
||||
{
|
||||
return s_barColor;
|
||||
}
|
||||
|
||||
const Nz::Color& ProgressBarWidget::GetDefaultBarCornerColor()
|
||||
{
|
||||
return s_barCornerColor;
|
||||
}
|
||||
|
||||
const Nz::Color& ProgressBarWidget::GetDefaultBarBackgroundColor()
|
||||
{
|
||||
return s_barBackgroundColor;
|
||||
}
|
||||
|
||||
const Nz::Color& ProgressBarWidget::GetDefaultBarBackgroundCornerColor()
|
||||
{
|
||||
return s_barBackgroundCornerColor;
|
||||
}
|
||||
|
||||
|
||||
void ProgressBarWidget::Layout()
|
||||
{
|
||||
Nz::Vector2f origin = GetContentOrigin();
|
||||
Nz::Vector2f size = GetContentSize();
|
||||
Nz::Vector2f progressBarSize = size;
|
||||
|
||||
if (IsTextEnabled())
|
||||
{
|
||||
UpdateText();
|
||||
|
||||
Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
|
||||
m_textEntity->GetComponent<NodeComponent>().SetPosition(origin.x + size.x - textSize.x, origin.y + size.y / 2.f - textSize.y);
|
||||
|
||||
progressBarSize -= { textSize.x + m_textMargin, 0.f };
|
||||
}
|
||||
|
||||
m_borderSprite->SetSize(progressBarSize);
|
||||
Nz::Vector2f borderSize = GetProgressBarBorderSize();
|
||||
|
||||
m_barBackgroundSprite->SetSize(progressBarSize - (borderSize * 2.f));
|
||||
m_barSprite->SetSize((progressBarSize.x - (borderSize.x * 2.f)) / 100.f * static_cast<float>(m_value), progressBarSize.y - (borderSize.y * 2.f));
|
||||
|
||||
m_borderEntity->GetComponent<NodeComponent>().SetPosition(origin.x, origin.y);
|
||||
m_barEntity->GetComponent<NodeComponent>().SetPosition(origin.x + borderSize.x, origin.y + borderSize.y);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,14 +6,13 @@
|
|||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
TextAreaWidget::TextAreaWidget(BaseWidget* parent) :
|
||||
BaseWidget(parent),
|
||||
m_cursorPosition(0U),
|
||||
m_cursorPosition(0U, 0U),
|
||||
m_cursorGlyph(0),
|
||||
m_multiLineEnabled(false),
|
||||
m_readOnly(false)
|
||||
{
|
||||
|
|
@ -81,7 +80,7 @@ namespace Ndk
|
|||
|
||||
void TextAreaWidget::Write(const Nz::String& text)
|
||||
{
|
||||
if (m_cursorPosition >= m_drawer.GetGlyphCount())
|
||||
if (m_cursorGlyph >= m_drawer.GetGlyphCount())
|
||||
{
|
||||
AppendText(text);
|
||||
SetCursorPosition(m_drawer.GetGlyphCount());
|
||||
|
|
@ -89,10 +88,10 @@ namespace Ndk
|
|||
else
|
||||
{
|
||||
Nz::String currentText = m_drawer.GetText();
|
||||
currentText.Insert(currentText.GetCharacterPosition(m_cursorPosition), text);
|
||||
currentText.Insert(currentText.GetCharacterPosition(m_cursorGlyph), text);
|
||||
SetText(currentText);
|
||||
|
||||
SetCursorPosition(m_cursorPosition + text.GetLength());
|
||||
SetCursorPosition(m_cursorGlyph + text.GetLength());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,11 +113,11 @@ namespace Ndk
|
|||
const Nz::String& text = m_drawer.GetText();
|
||||
|
||||
Nz::String newText;
|
||||
if (m_cursorPosition > 0)
|
||||
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorPosition) - 1));
|
||||
if (m_cursorGlyph > 0)
|
||||
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorGlyph) - 1));
|
||||
|
||||
if (m_cursorPosition < m_drawer.GetGlyphCount())
|
||||
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorPosition + 1)));
|
||||
if (m_cursorGlyph < m_drawer.GetGlyphCount())
|
||||
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorGlyph + 1)));
|
||||
|
||||
m_drawer.SetText(newText);
|
||||
m_textSprite->Update(m_drawer);
|
||||
|
|
@ -133,7 +132,7 @@ namespace Ndk
|
|||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
//TODO
|
||||
MoveCursor({0, 1});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +144,7 @@ namespace Ndk
|
|||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
MoveCursor(-1);
|
||||
MoveCursor({-1, 0});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +156,7 @@ namespace Ndk
|
|||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
MoveCursor(1);
|
||||
MoveCursor({1, 0});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -169,13 +168,16 @@ namespace Ndk
|
|||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
//TODO
|
||||
MoveCursor({0, -1});
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& key)
|
||||
void TextAreaWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& /*key*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +196,7 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
|
||||
void TextAreaWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -221,13 +223,13 @@ namespace Ndk
|
|||
const Nz::String& text = m_drawer.GetText();
|
||||
|
||||
Nz::String newText;
|
||||
if (m_cursorPosition > 1)
|
||||
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorPosition - 1) - 1));
|
||||
if (m_cursorGlyph > 1)
|
||||
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorGlyph - 1) - 1));
|
||||
|
||||
if (m_cursorPosition < m_drawer.GetGlyphCount())
|
||||
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorPosition)));
|
||||
if (m_cursorGlyph < m_drawer.GetGlyphCount())
|
||||
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorGlyph)));
|
||||
|
||||
MoveCursor(-1);
|
||||
MoveCursor({-1, 0});
|
||||
SetText(newText);
|
||||
break;
|
||||
}
|
||||
|
|
@ -258,25 +260,15 @@ namespace Ndk
|
|||
|
||||
void TextAreaWidget::RefreshCursor()
|
||||
{
|
||||
std::size_t lineCount = m_drawer.GetLineCount();
|
||||
std::size_t line = 0U;
|
||||
for (std::size_t i = line + 1; i < lineCount; ++i)
|
||||
{
|
||||
if (m_drawer.GetLine(i).glyphIndex > m_cursorPosition)
|
||||
break;
|
||||
|
||||
line = i;
|
||||
}
|
||||
|
||||
const auto& lineInfo = m_drawer.GetLine(line);
|
||||
const auto& lineInfo = m_drawer.GetLine(m_cursorPosition.y);
|
||||
|
||||
std::size_t glyphCount = m_drawer.GetGlyphCount();
|
||||
float position;
|
||||
if (glyphCount > 0 && lineInfo.glyphIndex < m_cursorPosition)
|
||||
if (glyphCount > 0 && lineInfo.glyphIndex < m_cursorGlyph)
|
||||
{
|
||||
const auto& glyph = m_drawer.GetGlyph(std::min(m_cursorPosition, glyphCount - 1));
|
||||
const auto& glyph = m_drawer.GetGlyph(std::min(m_cursorGlyph, glyphCount - 1));
|
||||
position = glyph.bounds.x;
|
||||
if (m_cursorPosition >= glyphCount)
|
||||
if (m_cursorGlyph >= glyphCount)
|
||||
position += glyph.bounds.width;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ namespace Ndk
|
|||
// This is made to avoid that handle warn uselessly entities before their destruction
|
||||
m_entities.clear();
|
||||
m_entityBlocks.clear();
|
||||
m_freeIdList.clear();
|
||||
m_waitingEntities.clear();
|
||||
|
||||
m_aliveEntities.Clear();
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
premake5 vs2017
|
||||
|
|
@ -16,6 +16,9 @@ Configurations = "Debug,Release" -- "Debug,Release,ReleaseWithDebug"
|
|||
-- Setup additionnals install directories, separated by a semi-colon ; (library binaries will be copied there)
|
||||
--InstallDir = "/usr/local/lib64"
|
||||
|
||||
-- Adds a project which will recall premake with its original arguments when built (only works on Windows for now)
|
||||
PremakeProject = false
|
||||
|
||||
-- Excludes client-only modules/tools/examples
|
||||
ServerMode = false
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,14 @@ ACTION.Function = function ()
|
|||
print("Encoding resources ...")
|
||||
local startClock = os.clock()
|
||||
local modules = os.matchdirs("../src/Nazara/*")
|
||||
table.insert(modules, "../SDK/src/NDK")
|
||||
for k, modulePath in pairs(modules) do
|
||||
local moduleName = modulePath:sub(15, -1)
|
||||
local moduleName
|
||||
if (modulePath:sub(4, 6) == "src") then
|
||||
moduleName = modulePath:sub(15, -1)
|
||||
else
|
||||
moduleName = "SDK"
|
||||
end
|
||||
local files = os.matchfiles(modulePath .. "/Resources/**")
|
||||
for k, filePath in pairs(files) do
|
||||
if (filePath:sub(-2) ~= ".h") then
|
||||
|
|
|
|||
|
|
@ -203,5 +203,5 @@ ACTION.Function = function ()
|
|||
end
|
||||
|
||||
local config = libDir .. " - " .. enabledArchs
|
||||
print(string.format("Package successfully created at \"%s\" (%u MB, %s)", packageDir, size / (1024 * 1024), config))
|
||||
print(string.format("Package successfully created at \"%s\" (%u MB, %s)", packageDir, size // (1024 * 1024), config))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ end
|
|||
|
||||
function NazaraBuild:Execute()
|
||||
if (_ACTION == nil) then -- If no action is specified, the user probably only wants to know how all of this works
|
||||
return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien
|
||||
return
|
||||
end
|
||||
|
||||
local platformData
|
||||
|
|
@ -74,7 +74,6 @@ function NazaraBuild:Execute()
|
|||
includedirs("../extlibs/include")
|
||||
libdirs("../extlibs/lib/common")
|
||||
location(_ACTION)
|
||||
kind("StaticLib")
|
||||
|
||||
for k, libTable in ipairs(self.OrderedExtLibs) do
|
||||
project(libTable.Name)
|
||||
|
|
@ -129,6 +128,13 @@ function NazaraBuild:Execute()
|
|||
language("C++")
|
||||
location(_ACTION)
|
||||
|
||||
if (self.Config["PremakeProject"] and os.ishost("windows")) then
|
||||
local commandLine = "premake5.exe " .. table.concat(_ARGV, ' ')
|
||||
project("_PremakeProject")
|
||||
kind("Utility")
|
||||
prebuildcommands("cd .. && " .. commandLine)
|
||||
end
|
||||
|
||||
-- Modules
|
||||
if (_OPTIONS["united"]) then
|
||||
project("NazaraEngine")
|
||||
|
|
@ -471,10 +477,8 @@ function NazaraBuild:LoadConfig()
|
|||
local content = f:read("*a")
|
||||
f:close()
|
||||
|
||||
local func, err = loadstring(content)
|
||||
local func, err = load(content, "Config file", "t", self.Config)
|
||||
if (func) then
|
||||
setfenv(func, self.Config)
|
||||
|
||||
local status, err = pcall(func)
|
||||
if (not status) then
|
||||
print("Failed to load config.lua: " .. err)
|
||||
|
|
@ -517,9 +521,9 @@ function NazaraBuild:LoadConfig()
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
AddBoolOption("BuildDependencies", "with-extlibs", "Builds the extern libraries")
|
||||
AddBoolOption("BuildExamples", "with-examples", "Builds the examples")
|
||||
AddBoolOption("PremakeProject", "premakeproject", "Add a PremakeProject as a shortcut to call Premake")
|
||||
AddBoolOption("ServerMode", "server", "Excludes client-only modules/tools/examples")
|
||||
AddBoolOption("UniteModules", "united", "Builds all the modules as one united library")
|
||||
|
||||
|
|
@ -601,7 +605,7 @@ function NazaraBuild:LoadConfig()
|
|||
end
|
||||
|
||||
function NazaraBuild:MakeInstallCommands(infoTable)
|
||||
if (os.is("windows")) then
|
||||
if (os.istarget("windows")) then
|
||||
filter("kind:SharedLib")
|
||||
|
||||
postbuildmessage("Copying " .. infoTable.Name .. " library and its dependencies to install/executable directories...")
|
||||
|
|
@ -733,13 +737,13 @@ function NazaraBuild:Process(infoTable)
|
|||
for platform, defineTable in pairs(v) do
|
||||
platform = string.lower(platform)
|
||||
if (platform == "posix") then
|
||||
local osname = os.get()
|
||||
local osname = os.target()
|
||||
if (PosixOSes[osname]) then
|
||||
platform = osname
|
||||
end
|
||||
end
|
||||
|
||||
if (os.is(platform)) then
|
||||
if (os.istarget(platform)) then
|
||||
for k,v in ipairs(defineTable) do
|
||||
table.insert(targetTable, v)
|
||||
end
|
||||
|
|
@ -773,13 +777,14 @@ end
|
|||
|
||||
function NazaraBuild:PrepareGeneric()
|
||||
flags({
|
||||
"C++14",
|
||||
"MultiProcessorCompile",
|
||||
"NoMinimalRebuild",
|
||||
"RelativeLinks",
|
||||
"ShadowedVariables",
|
||||
"UndefinedIdentifiers"
|
||||
})
|
||||
|
||||
cppdialect("C++14")
|
||||
|
||||
self:FilterLibDirectory("../extlibs/lib/", libdirs)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,71 +1,71 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<title>Avancement de Nazara</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="englob">
|
||||
<img style="display: block;margin-left: auto;margin-right: auto;" src="https://github.com/DigitalPulseSoftware/NazaraEngine/raw/master/Logo.png" alt="Nazara Engine" />
|
||||
|
||||
<hr>
|
||||
|
||||
Retrouvez le moteur sur GitHub !<br>
|
||||
<a href="https://github.com/DigitalPulseSoftware/NazaraEngine">Dépôt GitHub</a><br><br>
|
||||
Venez vous renseigner sur les topics dédiés à Nazara présents sur plusieurs sites web :<br>
|
||||
<a href="https://openclassrooms.com/forum/sujet/moteur-de-jeu-nazara-engine-69732">OpenClassrooms</a>, <a href="http://pdp.microjoe.org/forums/sujet/354/projet-nazara-engine-moteur-de-jeu">Progdupeupl</a> ou <a href="https://zestedesavoir.com/forums/sujet/1039/nazara-engine/">ZesteDeSavoir</a>
|
||||
<br><br>
|
||||
... ou pourquoi ne pas venir faire un tour sur <a href="http://forum.digitalpulsesoftware.net">le forum dédié au moteur</a> ?
|
||||
|
||||
<hr>
|
||||
|
||||
<h1>Fonctionnalités de Nazara</h1>
|
||||
|
||||
<div>Dernière mise à jour : <span class="lastupdate">
|
||||
%DATE%
|
||||
</span></div>
|
||||
|
||||
<h2>Important:</h2>
|
||||
<p>Afin de faciliter la mise à jour, la page que vous voyez ici a été générée automatiquement par un <i>script Lua</i>, ce qui m'oblige néanmoins à encoder les fonctionnalités de chaque module dans un premier temps.
|
||||
C'est un travail assez long (pour vous donner une idée, les données du noyau représentent un fichier de 200 lignes), et il n'est pas encore complet, c'est pourquoi des modules manquent sur cette page.<br>
|
||||
Gardez donc à l'esprit que le moteur possède plus de fonctionnalités que ce qui est décrit actuellement sur cette page.</p>
|
||||
|
||||
<p>Oh et bien sûr je ne suis pas concepteur de site web, c'est pourquoi cette page est moche (j'ai <u>essayé</u> de minimiser les dégâts).<br>
|
||||
Si vous sentez en vous l'irrésistible envie d'améliorer cette page, sachez que votre aide serait grandement appréciée (vous pouvez me contacter via le lien de votre choix plus haut).</p>
|
||||
|
||||
<p>Le pourcentage indiqué est calculé automatiquement en fonction des <u>fonctionnalités</u>, cela signifie qu'une fonctionnalité présente sera comptée à 100% à partir du moment où son implémentation de base est considérée fonctionnelle, <u>cela n'est donc pas une assurance qu'aucun bug n'existe concernant cette fonctionnalité</u> (cependant cela signifie que la fonctionnalité est utilisable).<br>
|
||||
Et bien entendu, un module ou une fonctionnalité ayant atteint les 100% peut toujours évoluer par la suite.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<table>
|
||||
<caption>Sommaire</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Module</th>
|
||||
<th>Avancement</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
%MODULELIST%
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
%MODULEDESCRIPTION%
|
||||
<hr>
|
||||
<table>
|
||||
<caption>Sommaire</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Module</th>
|
||||
<th>Pourcentage</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
%MODULELIST%
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<title>Avancement de Nazara</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="englob">
|
||||
<img style="display: block;margin-left: auto;margin-right: auto;" src="https://github.com/DigitalPulseSoftware/NazaraEngine/raw/master/Logo.png" alt="Nazara Engine" />
|
||||
|
||||
<hr>
|
||||
|
||||
Retrouvez le moteur sur GitHub !<br>
|
||||
<a href="https://github.com/DigitalPulseSoftware/NazaraEngine">Dépôt GitHub</a><br><br>
|
||||
Venez vous renseigner sur les topics dédiés à Nazara présents sur plusieurs sites web :<br>
|
||||
<a href="https://openclassrooms.com/forum/sujet/moteur-de-jeu-nazara-engine-69732">OpenClassrooms</a>, <a href="http://pdp.microjoe.org/forums/sujet/354/projet-nazara-engine-moteur-de-jeu">Progdupeupl</a> ou <a href="https://zestedesavoir.com/forums/sujet/1039/nazara-engine/">ZesteDeSavoir</a>
|
||||
<br><br>
|
||||
... ou pourquoi ne pas venir faire un tour sur <a href="http://forum.digitalpulsesoftware.net">le forum dédié au moteur</a> ?
|
||||
|
||||
<hr>
|
||||
|
||||
<h1>Fonctionnalités de Nazara</h1>
|
||||
|
||||
<div>Dernière mise à jour : <span class="lastupdate">
|
||||
%DATE%
|
||||
</span></div>
|
||||
|
||||
<h2>Important:</h2>
|
||||
<p>Afin de faciliter la mise à jour, la page que vous voyez ici a été générée automatiquement par un <i>script Lua</i>, ce qui m'oblige néanmoins à encoder les fonctionnalités de chaque module dans un premier temps.
|
||||
C'est un travail assez long (pour vous donner une idée, les données du noyau représentent un fichier de 200 lignes), et il n'est pas encore complet, c'est pourquoi des modules manquent sur cette page.<br>
|
||||
Gardez donc à l'esprit que le moteur possède plus de fonctionnalités que ce qui est décrit actuellement sur cette page.</p>
|
||||
|
||||
<p>Oh et bien sûr je ne suis pas concepteur de site web, c'est pourquoi cette page est moche (j'ai <u>essayé</u> de minimiser les dégâts).<br>
|
||||
Si vous sentez en vous l'irrésistible envie d'améliorer cette page, sachez que votre aide serait grandement appréciée (vous pouvez me contacter via le lien de votre choix plus haut).</p>
|
||||
|
||||
<p>Le pourcentage indiqué est calculé automatiquement en fonction des <u>fonctionnalités</u>, cela signifie qu'une fonctionnalité présente sera comptée à 100% à partir du moment où son implémentation de base est considérée fonctionnelle, <u>cela n'est donc pas une assurance qu'aucun bug n'existe concernant cette fonctionnalité</u> (cependant cela signifie que la fonctionnalité est utilisable).<br>
|
||||
Et bien entendu, un module ou une fonctionnalité ayant atteint les 100% peut toujours évoluer par la suite.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<table>
|
||||
<caption>Sommaire</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Module</th>
|
||||
<th>Avancement</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
%MODULELIST%
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
%MODULEDESCRIPTION%
|
||||
<hr>
|
||||
<table>
|
||||
<caption>Sommaire</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Module</th>
|
||||
<th>Pourcentage</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
%MODULELIST%
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,121 +1,121 @@
|
|||
/* Je ne suis pas développeur HTML/CSS, je dois y toucher une fois l'an, désolé pour les quelques atrocités que vous pourrez trouver ici */
|
||||
|
||||
body
|
||||
{
|
||||
font-family: sans-serif;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
#englob {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
background-color: white;
|
||||
width: 50%;
|
||||
min-width: 765px;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 0;
|
||||
border: 0;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
color: #007ACC;
|
||||
}
|
||||
|
||||
a:hover
|
||||
{
|
||||
color: lightblue;
|
||||
}
|
||||
|
||||
h1
|
||||
{
|
||||
display: inline;
|
||||
}
|
||||
|
||||
h2
|
||||
{
|
||||
display: inline;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
h4
|
||||
{
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
ol
|
||||
{
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
table
|
||||
{
|
||||
border-collapse: collapse;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
border: white groove;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0px 0px 10px lightblue;
|
||||
}
|
||||
|
||||
th
|
||||
{
|
||||
text-shadow: 2px 2px 4px black;
|
||||
}
|
||||
|
||||
tr
|
||||
{
|
||||
border: 1px solid white;
|
||||
}
|
||||
|
||||
tbody tr:hover
|
||||
{
|
||||
text-shadow: 0px 0px 4px white;
|
||||
}
|
||||
|
||||
.description
|
||||
{
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.lastupdate
|
||||
{
|
||||
font-size: x-large;
|
||||
font-weight: bold;
|
||||
color: #f1c40f;
|
||||
}
|
||||
|
||||
.modulename
|
||||
{
|
||||
font-size: x-large;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 10px #007ACC;
|
||||
}
|
||||
|
||||
.note
|
||||
{
|
||||
margin-left: 20px;
|
||||
color: #007ACC;
|
||||
}
|
||||
|
||||
.notedesc
|
||||
{
|
||||
color: rgb(200, 200, 255);
|
||||
}
|
||||
|
||||
.portability
|
||||
{
|
||||
margin-left: 20px;
|
||||
color: red;
|
||||
/* Je ne suis pas développeur HTML/CSS, je dois y toucher une fois l'an, désolé pour les quelques atrocités que vous pourrez trouver ici */
|
||||
|
||||
body
|
||||
{
|
||||
font-family: sans-serif;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
#englob {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
background-color: white;
|
||||
width: 50%;
|
||||
min-width: 765px;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 0;
|
||||
border: 0;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
color: #007ACC;
|
||||
}
|
||||
|
||||
a:hover
|
||||
{
|
||||
color: lightblue;
|
||||
}
|
||||
|
||||
h1
|
||||
{
|
||||
display: inline;
|
||||
}
|
||||
|
||||
h2
|
||||
{
|
||||
display: inline;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
h4
|
||||
{
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
ol
|
||||
{
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
table
|
||||
{
|
||||
border-collapse: collapse;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
border: white groove;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0px 0px 10px lightblue;
|
||||
}
|
||||
|
||||
th
|
||||
{
|
||||
text-shadow: 2px 2px 4px black;
|
||||
}
|
||||
|
||||
tr
|
||||
{
|
||||
border: 1px solid white;
|
||||
}
|
||||
|
||||
tbody tr:hover
|
||||
{
|
||||
text-shadow: 0px 0px 4px white;
|
||||
}
|
||||
|
||||
.description
|
||||
{
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.lastupdate
|
||||
{
|
||||
font-size: x-large;
|
||||
font-weight: bold;
|
||||
color: #f1c40f;
|
||||
}
|
||||
|
||||
.modulename
|
||||
{
|
||||
font-size: x-large;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 10px #007ACC;
|
||||
}
|
||||
|
||||
.note
|
||||
{
|
||||
margin-left: 20px;
|
||||
color: #007ACC;
|
||||
}
|
||||
|
||||
.notedesc
|
||||
{
|
||||
color: rgb(200, 200, 255);
|
||||
}
|
||||
|
||||
.portability
|
||||
{
|
||||
margin-left: 20px;
|
||||
color: red;
|
||||
}
|
||||
|
|
@ -3,5 +3,6 @@ MODULE.Name = "Graphics"
|
|||
MODULE.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraUtility",
|
||||
"NazaraPlatform",
|
||||
"NazaraRenderer"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
MODULE.Name = "Platform"
|
||||
|
||||
MODULE.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraUtility"
|
||||
}
|
||||
|
||||
MODULE.OsFiles.Windows = {
|
||||
"../src/Nazara/Platform/Win32/**.hpp",
|
||||
"../src/Nazara/Platform/Win32/**.cpp"
|
||||
}
|
||||
|
||||
MODULE.OsFiles.Posix = {
|
||||
"../src/Nazara/Platform/X11/**.hpp",
|
||||
"../src/Nazara/Platform/X11/**.cpp"
|
||||
}
|
||||
|
||||
MODULE.OsLibraries.Windows = {
|
||||
"gdi32"
|
||||
}
|
||||
|
||||
MODULE.OsLibraries.Posix = {
|
||||
"X11",
|
||||
"xcb",
|
||||
"xcb-cursor",
|
||||
"xcb-ewmh",
|
||||
"xcb-icccm",
|
||||
"xcb-keysyms",
|
||||
"xcb-randr"
|
||||
}
|
||||
|
||||
|
|
@ -8,7 +8,8 @@ MODULE.Defines = {
|
|||
|
||||
MODULE.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraUtility"
|
||||
"NazaraUtility",
|
||||
"NazaraPlatform"
|
||||
}
|
||||
|
||||
MODULE.OsFiles.Windows = {
|
||||
|
|
|
|||
|
|
@ -5,29 +5,11 @@ MODULE.Libraries = {
|
|||
"stb_image"
|
||||
}
|
||||
|
||||
MODULE.OsFiles.Windows = {
|
||||
"../src/Nazara/Utility/Win32/**.hpp",
|
||||
"../src/Nazara/Utility/Win32/**.cpp"
|
||||
}
|
||||
|
||||
MODULE.OsFiles.Posix = {
|
||||
"../src/Nazara/Utility/X11/**.hpp",
|
||||
"../src/Nazara/Utility/X11/**.cpp"
|
||||
}
|
||||
|
||||
MODULE.OsLibraries.Windows = {
|
||||
"freetype-s",
|
||||
"gdi32"
|
||||
"freetype-s"
|
||||
}
|
||||
|
||||
MODULE.OsLibraries.Posix = {
|
||||
"freetype",
|
||||
"X11",
|
||||
"xcb",
|
||||
"xcb-cursor",
|
||||
"xcb-ewmh",
|
||||
"xcb-icccm",
|
||||
"xcb-keysyms",
|
||||
"xcb-randr"
|
||||
"freetype"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ TOOL.FilesExcluded = {
|
|||
"../SDK/**/*Widget*.*",
|
||||
"../SDK/**/LuaBinding_Audio.*",
|
||||
"../SDK/**/LuaBinding_Graphics.*",
|
||||
"../SDK/**/LuaBinding_Renderer.*"
|
||||
"../SDK/**/LuaBinding_Renderer.*",
|
||||
"../SDK/**/LuaBinding_Platform.*"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ TOOL.Files = {
|
|||
TOOL.FilesExcluded = {
|
||||
"../tests/Engine/Audio/**",
|
||||
"../tests/Engine/Graphics/**",
|
||||
"../tests/Engine/Utility/**",
|
||||
"../tests/Engine/Platform/**",
|
||||
"../tests/SDK/NDK/Application.cpp",
|
||||
"../tests/SDK/NDK/Systems/ListenerSystem.cpp",
|
||||
"../tests/SDK/NDK/Systems/RenderSystem.cpp"
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ EXAMPLE.Files = {
|
|||
EXAMPLE.Libraries = {
|
||||
"NazaraAudio",
|
||||
"NazaraCore",
|
||||
"NazaraPlatform",
|
||||
"NazaraUtility"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@
|
|||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Thread.hpp> // Thread::Sleep
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/Keyboard.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Platform/Keyboard.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
// NzKeyboard nécessite l'initialisation du module Utilitaire
|
||||
Nz::Initializer<Nz::Audio, Nz::Utility> audio;
|
||||
Nz::Initializer<Nz::Audio, Nz::Platform> audio;
|
||||
if (!audio)
|
||||
{
|
||||
std::cout << "Failed to initialize audio module" << std::endl;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ EXAMPLE.Files = {
|
|||
|
||||
EXAMPLE.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraPlatform",
|
||||
"NazaraRenderer",
|
||||
"NazaraUtility"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ EXAMPLE.Files = {
|
|||
|
||||
EXAMPLE.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraPlatform",
|
||||
"NazaraUtility"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Utility/Joint.hpp>
|
||||
#include <Nazara/Utility/MaterialData.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/Sequence.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ m_name(name)
|
|||
{
|
||||
}
|
||||
|
||||
void ParticleDemo::Enter(Ndk::StateMachine& fsm)
|
||||
void ParticleDemo::Enter(Ndk::StateMachine& /*fsm*/)
|
||||
{
|
||||
m_shared.demoName->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_index+1) + " - " + m_name, 48));
|
||||
m_fpsCounter = 0;
|
||||
|
|
@ -23,7 +23,7 @@ void ParticleDemo::Enter(Ndk::StateMachine& fsm)
|
|||
m_oldBackground3D = renderSystem3D.GetDefaultBackground();
|
||||
}
|
||||
|
||||
void ParticleDemo::Leave(Ndk::StateMachine& fsm)
|
||||
void ParticleDemo::Leave(Ndk::StateMachine& /*fsm*/)
|
||||
{
|
||||
m_shared.world2D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground2D);
|
||||
m_shared.world3D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground3D);
|
||||
|
|
@ -32,7 +32,7 @@ void ParticleDemo::Leave(Ndk::StateMachine& fsm)
|
|||
m_particleGroups.clear();
|
||||
}
|
||||
|
||||
bool ParticleDemo::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
||||
bool ParticleDemo::Update(Ndk::StateMachine& /*fsm*/, float elapsedTime)
|
||||
{
|
||||
m_fpsCounter++;
|
||||
if (m_updateClock.GetMilliseconds() > 1000)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "LogoDemo.hpp"
|
||||
#include <Nazara/Core/OffsetOf.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
|
|
@ -8,12 +9,22 @@
|
|||
namespace
|
||||
{
|
||||
const float duration = 10.f;
|
||||
const float maxVel = 50.f;
|
||||
const float maxSpeed = 100.f;
|
||||
const float maxMouseForce = 1000.f;
|
||||
const float mouseForce = 500.f;
|
||||
const float pauseTime = 3.f;
|
||||
const float startTime = 2.f;
|
||||
const float speed = 3.f;
|
||||
}
|
||||
|
||||
struct ParticleData
|
||||
{
|
||||
Nz::Color color;
|
||||
Nz::Vector2f destination;
|
||||
Nz::Vector2f position;
|
||||
Nz::Vector2f velocity;
|
||||
};
|
||||
|
||||
struct SpriteController : public Nz::ParticleController
|
||||
{
|
||||
void Apply(Nz::ParticleGroup& system, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override
|
||||
|
|
@ -21,15 +32,70 @@ struct SpriteController : public Nz::ParticleController
|
|||
if (!enabled)
|
||||
return;
|
||||
|
||||
auto posPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||
auto velPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||
auto destPtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Userdata0);
|
||||
auto posPtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Position);
|
||||
auto velPtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Velocity);
|
||||
|
||||
std::uniform_real_distribution<float> dis(-1.f, 1.f);
|
||||
|
||||
for (unsigned int i = startId; i <= endId; ++i)
|
||||
posPtr[i] += velPtr[i] * elapsedTime * factor;
|
||||
{
|
||||
Nz::Vector2f newVel = destPtr[i] - posPtr[i];
|
||||
float length;
|
||||
newVel.Normalize(&length);
|
||||
|
||||
float distance = SquaredDistancePointSegment(oldMousePos, actualMousePos, posPtr[i]);
|
||||
if (distance < 250.f)
|
||||
{
|
||||
Nz::Vector2f mouseLine = actualMousePos - oldMousePos;
|
||||
float mouseLength;
|
||||
mouseLine.Normalize(&mouseLength);
|
||||
if (mouseLength > 5.f)
|
||||
{
|
||||
velPtr[i] += mouseLine * std::min(mouseLength * mouseForce, maxMouseForce) * elapsedTime;
|
||||
velPtr[i] += Nz::Vector2f(dis(randomGen), dis(randomGen)) * std::min(mouseLength, maxMouseForce * 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
if (length > 1.f || velPtr[i].GetSquaredLength() > Nz::IntegralPow(30.f, 2))
|
||||
{
|
||||
newVel *= maxSpeed;
|
||||
|
||||
velPtr[i] = Nz::Lerp(velPtr[i], newVel, 0.4f * elapsedTime);
|
||||
posPtr[i] += velPtr[i] * elapsedTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
velPtr[i] = Nz::Vector2f::Zero();
|
||||
posPtr[i] = destPtr[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static float SquaredDistancePointSegment(const Nz::Vector2f& s0, const Nz::Vector2f& s1, const Nz::Vector2f& point)
|
||||
{
|
||||
// http://geomalgorithms.com/a02-_lines.html
|
||||
Nz::Vector2f v = s1 - s0;
|
||||
Nz::Vector2f w = point - s0;
|
||||
|
||||
float c1 = Nz::Vector2f::DotProduct(w, v);
|
||||
if (c1 <= 0.f)
|
||||
return point.SquaredDistance(s0);
|
||||
|
||||
float c2 = Nz::Vector2f::DotProduct(v, v);
|
||||
if (c2 <= c1)
|
||||
return point.SquaredDistance(s1);
|
||||
|
||||
float b = c1 / c2;
|
||||
Nz::Vector2f projPoint = s0 + b * v;
|
||||
return projPoint.SquaredDistance(point);
|
||||
}
|
||||
|
||||
std::mt19937 randomGen;
|
||||
bool enabled = false;
|
||||
float factor = 1.f;
|
||||
float factor = 1000.f;
|
||||
Nz::Vector2f actualMousePos;
|
||||
Nz::Vector2f oldMousePos;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -67,9 +133,9 @@ ParticleDemo("Logo", sharedData)
|
|||
unsigned int height = m_logo.GetHeight();
|
||||
m_pixels.reserve(width * height);
|
||||
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
for (unsigned int x = 0; x < width; ++x)
|
||||
{
|
||||
for (unsigned int x = 0; x < width; ++x)
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
{
|
||||
Nz::Color color = m_logo.GetPixelColor(x, y);
|
||||
if (color.a == 0)
|
||||
|
|
@ -93,6 +159,12 @@ ParticleDemo("Logo", sharedData)
|
|||
|
||||
m_controller = new SpriteController;
|
||||
m_renderer = new SpriteRenderer(std::move(material));
|
||||
|
||||
m_declaration = Nz::ParticleDeclaration::New();
|
||||
m_declaration->EnableComponent(Nz::ParticleComponent_Color, Nz::ComponentType_Color, NazaraOffsetOf(ParticleData, color));
|
||||
m_declaration->EnableComponent(Nz::ParticleComponent_Position, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, position));
|
||||
m_declaration->EnableComponent(Nz::ParticleComponent_Userdata0, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, destination));
|
||||
m_declaration->EnableComponent(Nz::ParticleComponent_Velocity, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, velocity));
|
||||
}
|
||||
|
||||
void LogoExample::Enter(Ndk::StateMachine& fsm)
|
||||
|
|
@ -106,17 +178,20 @@ void LogoExample::Enter(Ndk::StateMachine& fsm)
|
|||
m_shared.world2D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::TextureBackground::New(std::move(backgroundTexture)));
|
||||
|
||||
Ndk::EntityHandle particleGroupEntity = m_shared.world2D->CreateEntity();
|
||||
Ndk::ParticleGroupComponent& particleGroup = particleGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(m_pixels.size(), Nz::ParticleLayout_Sprite);
|
||||
Ndk::ParticleGroupComponent& particleGroup = particleGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(m_pixels.size(), m_declaration);
|
||||
RegisterParticleGroup(particleGroupEntity);
|
||||
|
||||
particleGroup.AddController(m_controller);
|
||||
particleGroup.SetRenderer(m_renderer);
|
||||
|
||||
m_particles = static_cast<Nz::ParticleStruct_Sprite*>(particleGroup.CreateParticles(m_pixels.size()));
|
||||
m_particles = particleGroup.CreateParticles(m_pixels.size());
|
||||
ResetParticles(-duration * (speed / 2.f));
|
||||
|
||||
m_accumulator = pauseTime + duration;
|
||||
m_totalAccumulator = 0.f;
|
||||
|
||||
SpriteController* controller = static_cast<SpriteController*>(m_controller.Get());
|
||||
controller->actualMousePos = controller->oldMousePos = Nz::Vector2f(Nz::Mouse::GetPosition(*m_shared.target));
|
||||
}
|
||||
|
||||
void LogoExample::Leave(Ndk::StateMachine & fsm)
|
||||
|
|
@ -136,35 +211,62 @@ bool LogoExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
|||
m_accumulator += elapsedTime;
|
||||
|
||||
SpriteController* controller = static_cast<SpriteController*>(m_controller.Get());
|
||||
if (m_accumulator > pauseTime + 2.f * duration)
|
||||
controller->enabled = (m_accumulator > pauseTime);
|
||||
|
||||
if (m_mouseClock.GetMilliseconds() > 1000/30)
|
||||
{
|
||||
ResetParticles(0.f);
|
||||
m_accumulator = 0.f;
|
||||
m_mouseClock.Restart();
|
||||
|
||||
controller->oldMousePos = controller->actualMousePos;
|
||||
controller->actualMousePos = Nz::Vector2f(Nz::Mouse::GetPosition(*m_shared.target));
|
||||
}
|
||||
|
||||
controller->enabled = (m_accumulator > pauseTime);
|
||||
controller->factor = -speed + speed * (m_accumulator - pauseTime) / (duration);
|
||||
if (Nz::Mouse::IsButtonPressed(Nz::Mouse::Left))
|
||||
{
|
||||
if (!m_hasClicked)
|
||||
{
|
||||
m_hasClicked = true;
|
||||
std::uniform_real_distribution<float> dis(50.f, 60.f);
|
||||
|
||||
ParticleData* sprite = static_cast<ParticleData*>(m_particles);
|
||||
for (std::size_t i = 0; i < m_pixels.size(); ++i)
|
||||
{
|
||||
Nz::Vector2f particleToMouse = sprite[i].position - controller->actualMousePos;
|
||||
float sqDist = particleToMouse.GetSquaredLength();
|
||||
if (sqDist < 10000.f)
|
||||
{
|
||||
float dist = std::sqrt(sqDist);
|
||||
particleToMouse /= std::max(dist, 1.f);
|
||||
|
||||
sprite[i].velocity += particleToMouse * dis(m_shared.randomGen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
m_hasClicked = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LogoExample::ResetParticles(float elapsed)
|
||||
{
|
||||
Nz::Vector2f center = {m_shared.target->GetWidth() / 2.f, m_shared.target->GetHeight() / 2.f};
|
||||
unsigned int width = m_shared.target->GetWidth();
|
||||
unsigned int height = m_shared.target->GetHeight();
|
||||
|
||||
Nz::Vector2f center = {width / 2.f, height / 2.f};
|
||||
Nz::Vector2f offset = center - Nz::Vector2f(Nz::Vector2ui(m_logo.GetSize()) / 2);
|
||||
|
||||
float ratio = float(m_shared.target->GetWidth()) / m_shared.target->GetHeight();
|
||||
std::uniform_real_distribution<float> disX(-maxVel * ratio, maxVel * ratio);
|
||||
std::uniform_real_distribution<float> disY(-maxVel, maxVel);
|
||||
std::uniform_real_distribution<float> disX(0.f, float(width));
|
||||
std::uniform_real_distribution<float> disY(-float(height) * 0.5f, float(height) * 1.5f);
|
||||
|
||||
Nz::ParticleStruct_Sprite* sprite = m_particles;
|
||||
ParticleData* sprite = static_cast<ParticleData*>(m_particles);
|
||||
for (PixelData& data : m_pixels)
|
||||
{
|
||||
sprite->color = data.color;
|
||||
sprite->position = offset + Nz::Vector2f(data.pos);
|
||||
sprite->rotation = 0.f;
|
||||
sprite->velocity.Set(disX(m_shared.randomGen), disY(m_shared.randomGen), 0.f);
|
||||
sprite->position += sprite->velocity * elapsed;
|
||||
sprite->destination = offset + Nz::Vector2f(data.pos);
|
||||
sprite->position.Set(disX(m_shared.randomGen) - float(width), disY(m_shared.randomGen));
|
||||
sprite->velocity = Nz::Vector2f::Zero();
|
||||
sprite++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,13 @@ class LogoExample : public ParticleDemo
|
|||
|
||||
std::vector<PixelData> m_pixels;
|
||||
Nz::BackgroundRef m_oldBackground;
|
||||
Nz::ParticleStruct_Sprite* m_particles;
|
||||
void* m_particles;
|
||||
Nz::Clock m_mouseClock;
|
||||
Nz::Image m_logo;
|
||||
Nz::ParticleControllerRef m_controller;
|
||||
Nz::ParticleDeclarationRef m_declaration;
|
||||
Nz::ParticleRendererRef m_renderer;
|
||||
bool m_hasClicked;
|
||||
float m_accumulator;
|
||||
float m_totalAccumulator;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <Nazara/Audio/Sound.hpp>
|
||||
#include <Nazara/Core/OffsetOf.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Platform.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Systems.hpp>
|
||||
|
|
@ -317,10 +318,10 @@ ParticleDemo("Space battle", sharedData)
|
|||
m_spaceshipTemplate = m_shared.world3D->CreateEntity();
|
||||
m_spaceshipTemplate->Enable(false);
|
||||
|
||||
m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
|
||||
m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
|
||||
m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
|
||||
auto& gfxComponent = m_spaceshipTemplate->AddComponent<Ndk::GraphicsComponent>();
|
||||
auto& nodeComponent = m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
|
||||
auto& velocityComponent = m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
|
||||
auto& spaceshipComponent = m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
|
||||
gfxComponent.Attach(&m_spaceshipModel);
|
||||
|
||||
m_ambientMusic.OpenFromFile("resources/ambience.ogg");
|
||||
|
|
@ -385,9 +386,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
m_torpedoGroup->AddController(Nz::ParticleFunctionController::New([this] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||
{
|
||||
auto positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||
auto rotationPtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Rotation);
|
||||
auto sizePtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||
auto velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||
|
||||
auto& spaceshipSystem = m_shared.world3D->GetSystem<SpaceshipSystem>();
|
||||
|
||||
|
|
@ -421,7 +420,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
emitter.SetEmissionCount(2);
|
||||
emitter.SetEmissionRate(200.f);
|
||||
|
||||
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& entity, Nz::ParticleMapper& mapper, unsigned int count)
|
||||
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& emitter, Nz::ParticleMapper& particleMapper, unsigned int count)
|
||||
{
|
||||
auto& gen = m_shared.randomGen;
|
||||
|
||||
|
|
@ -433,29 +432,29 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
std::uniform_real_distribution<float> sizeDis(1.0f, 4.f);
|
||||
std::uniform_real_distribution<float> velDis(-maxFireVel, maxFireVel);
|
||||
|
||||
Nz::Vector3f pos = entity->GetComponent<Ndk::NodeComponent>().GetPosition();
|
||||
Nz::Vector3f pos = emitter->GetComponent<Ndk::NodeComponent>().GetPosition();
|
||||
|
||||
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(mapper.GetPointer());
|
||||
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(particleMapper.GetPointer());
|
||||
Nz::ParticleStruct_Billboard* smokeParticles = static_cast<Nz::ParticleStruct_Billboard*>(m_smokeGroup->CreateParticles(count));
|
||||
for (unsigned int i = 0; i < count; ++i)
|
||||
for (unsigned int j = 0; j < count; ++j)
|
||||
{
|
||||
billboards[i].color = Nz::Color::White;
|
||||
billboards[i].life = 1.f + lifeDis(gen);
|
||||
billboards[i].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
|
||||
billboards[i].rotation = rotDis(gen);
|
||||
billboards[i].size = {1.28f, 1.28f};
|
||||
billboards[i].size *= sizeDis(gen);
|
||||
billboards[i].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
|
||||
billboards[i].velocity.Normalize();
|
||||
billboards[i].velocity *= velDis(gen);
|
||||
billboards[j].color = Nz::Color::White;
|
||||
billboards[j].life = 1.f + lifeDis(gen);
|
||||
billboards[j].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
|
||||
billboards[j].rotation = rotDis(gen);
|
||||
billboards[j].size = {1.28f, 1.28f};
|
||||
billboards[j].size *= sizeDis(gen);
|
||||
billboards[j].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
|
||||
billboards[j].velocity.Normalize();
|
||||
billboards[j].velocity *= velDis(gen);
|
||||
|
||||
smokeParticles[i].color = Nz::Color(128, 128, 128, 0);
|
||||
smokeParticles[i].life = maxSmokeLife;
|
||||
smokeParticles[i].position = billboards[i].position;
|
||||
smokeParticles[i].rotation = billboards[i].rotation;
|
||||
smokeParticles[i].size = {2.56f, 2.56f};
|
||||
smokeParticles[i].size *= sizeDis(gen);
|
||||
smokeParticles[i].velocity = billboards[i].velocity / 2.f;
|
||||
smokeParticles[j].color = Nz::Color(128, 128, 128, 0);
|
||||
smokeParticles[j].life = maxSmokeLife;
|
||||
smokeParticles[j].position = billboards[j].position;
|
||||
smokeParticles[j].rotation = billboards[j].rotation;
|
||||
smokeParticles[j].size = {2.56f, 2.56f};
|
||||
smokeParticles[j].size *= sizeDis(gen);
|
||||
smokeParticles[j].velocity = billboards[j].velocity / 2.f;
|
||||
}
|
||||
});
|
||||
m_fireGroup->AddEmitter(entity);
|
||||
|
|
@ -466,12 +465,11 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
}
|
||||
}));
|
||||
|
||||
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||
{
|
||||
auto positionPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||
auto rotationPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
||||
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||
auto velocityPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||
|
||||
renderQueue->AddBillboards(0, sparkleMat1, endId - startId + 1, positionPtr, sizePtr, rotationPtr);
|
||||
for (unsigned int i = startId; i <= endId; ++i)
|
||||
|
|
@ -580,7 +578,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
});
|
||||
|
||||
m_fireGroup->AddController(movementController);
|
||||
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& /*group*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||
{
|
||||
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
||||
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||
|
|
@ -591,7 +589,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
}));
|
||||
|
||||
m_smokeGroup->AddController(movementController);
|
||||
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& /*group*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||
{
|
||||
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
||||
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||
|
|
@ -617,7 +615,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
smokeMat->SetDiffuseColor(Nz::Color(128, 128, 128));
|
||||
smokeMat->SetDiffuseMap("resources/smoke.png");
|
||||
|
||||
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||
{
|
||||
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
||||
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||
|
|
@ -627,7 +625,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|||
renderQueue->AddBillboards(0, fireMat, endId - startId + 1, posPtr, sizePtr, rotPtr, colorPtr);
|
||||
}));
|
||||
|
||||
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||
{
|
||||
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
||||
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||
|
|
@ -815,7 +813,7 @@ void SpacebattleExample::CreateTurret()
|
|||
cannonGfx.Attach(&m_turret.cannonModel);
|
||||
}
|
||||
|
||||
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||
{
|
||||
const float speed = 0.1f;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#include <Nazara/Graphics/ParticleStruct.hpp>
|
||||
#include <Nazara/Graphics/SkyboxBackground.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Utility/EventHandler.hpp>
|
||||
#include <Nazara/Platform/EventHandler.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/State.hpp>
|
||||
#include <vector>
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ int main()
|
|||
fpsNode.SetPosition(5.f, window.GetHeight() - fpsCountBox.height - particleCountBox.height - 5.f);
|
||||
|
||||
|
||||
//shared.demos.push_back(std::make_shared<LogoExample>(shared));
|
||||
shared.demos.push_back(std::make_shared<LogoExample>(shared));
|
||||
shared.demos.push_back(std::make_shared<SpacebattleExample>(shared));
|
||||
|
||||
std::size_t demoIndex = 0;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ EXAMPLE.Libraries = {
|
|||
"NazaraNoise",
|
||||
"NazaraPhysics2D",
|
||||
"NazaraPhysics3D",
|
||||
"NazaraPlatform",
|
||||
"NazaraRenderer",
|
||||
"NazaraUtility",
|
||||
"NazaraSDK"
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue