Merge branch 'master' into vulkan
This commit is contained in:
commit
4c6b5d0546
|
|
@ -0,0 +1,279 @@
|
|||
# Upcoming version:
|
||||
|
||||
Nazara Engine:
|
||||
- VertexMapper:GetComponentPtr no longer throw an error if component is disabled or incompatible with template type, instead a null pointer is returned.
|
||||
- Bitset swap operation is now correctly marked as noexcept`
|
||||
- Mesh loaders now takes MeshParams vertexDeclaration into account
|
||||
- ⚠️ Replaced RenderTarget::Get[Height|Width] by RenderTarget::GetSize
|
||||
- ⚠️ Removed Window::Get[Height|Width] methods
|
||||
- Fix compilation error when including Nazara/Renderer/ShaderBuilder.hpp
|
||||
- Fix reflection sometimes being enabled by default for Materials
|
||||
- Fix built-in unserialization of std::string which was corruption memory
|
||||
- Fix Buffer::Destroy() not really destroying buffer
|
||||
- Fix Bitset::TestAll() returned wrong result on full of '1' bitset
|
||||
- ByteStream now returns the number of bytes written as the other streams
|
||||
- Total rewriting of the color conversions
|
||||
- Fix NormalizeAngle to the correct range
|
||||
- Fix BoundingVolume::Lerp() with Extend_Null
|
||||
- Simplification of methods Matrix4::SetRotation() and Quaternion::MakeRotationBetween()
|
||||
- Fix mouve moved event generated on X11 platform when doing Mouse::SetPosition()
|
||||
- EnumAsFlags specialization no longer require a `value` field to enable flags operators
|
||||
- EnumAsFlags specialization `max` field can be of the same type as the enum
|
||||
- Flags class now use an UInt8 or UInt16 to store the value if possible.
|
||||
- Flags class is now explicitly convertible to any integer type of the same size (or greater size) than the internal size.
|
||||
- Fix String movement constructor, which was leaving a null shared string (which was not reusable)
|
||||
- Add Flags<E>::Test method, in order to test one or multiple flags at once.
|
||||
- ⚠️ Vector2, Vector3 and Vector4 array/pointer constructor is now explicit to prevent some mistakes as `Vector2 vec2; vec2 = 0;`
|
||||
|
||||
|
||||
Nazara Development Kit:
|
||||
- Added ImageWidget (#139)
|
||||
- ⚠️ Removed TextAreaWidget::GetLineCount
|
||||
- Fix World movement which could cause crashes when updating systems
|
||||
- Fix crash occuring sometimes on keyboard event
|
||||
- Add support for EchoMode to TextAreaWidget (which allows to setup password text area)
|
||||
- Add signal OnTextChanged to TextAreaWidget
|
||||
- ⚠️ Removed TextAreaWidget::GetGlyphUnderCursor
|
||||
- Fixed minor issues relative to TextAreaWidget cursor handling
|
||||
- ⚠️ Renamed BaseWidget::GrabKeyboard method to SetFocus
|
||||
- Added BaseWidget::ClearFocus method and OnFocus[Lost|Received] virtual methods
|
||||
- TextAreaWidget will now show a cursor as long as it has focus
|
||||
- Fix BaseWidget linking error on Linux
|
||||
- ⚠️ Rewrite StateMachine to fix instantaneous state changing (state change is no longer effective until the next update call)
|
||||
- Fix entities destruction when coming from World::Clear() (also called by destructor), which invalidated world entities handles before destroying entities (preventing destruction callback to get valid entities handles from world)
|
||||
- Add Entity::Disable method, which is a shortcut to Enable(false)
|
||||
- Add BaseWidget::HasFocus
|
||||
- Fix TextAreaWidget cursor sometimes showing up in readonly mode
|
||||
- ⚠️ BaseWidget::OnKeyPressed now returns a boolean to indicate if it should block default action (such as tab to switch to the previous/next widget)
|
||||
- Pressing tab/shift-tab will now move to the next/previous widget able to be focused on
|
||||
|
||||
# 0.4:
|
||||
|
||||
Build system:
|
||||
- ⚠️ Update premake binaries version to premake5-alpha12
|
||||
- It is now possible to generate a tool project running which will run the premake when built on Windows (PremakeProject=true).
|
||||
- Added VS2017 Windows shortcut
|
||||
|
||||
Nazara Engine:
|
||||
- Improved Particle Demo
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/126 File locking now works properly on Linux
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/136 Fixed std::getline with Nz::String not setting eofbit.
|
||||
- Added support for CRC64
|
||||
- Added MovablePtr utility class
|
||||
- ⚠️ StackAllocation class has been replaced with much-more user-friendly StackArray class.
|
||||
- ⚠️ ParameterList now takes double and long long parameter instead of float and int parameters.
|
||||
- Threads can now be named (for debug purposes)
|
||||
- Added ParameterList::ForEach method
|
||||
- Flags<T> operators works in the global namespace as well
|
||||
- **Added support for skybox reflections, realtime reflections are on the tracks!**
|
||||
- ⚠️ InstancedRenderable now handle materials and skins in a generic way (which means you can use skins on every InstancedRenderable such as Billboard, Sprites, etc.).
|
||||
- **Added support for coroutines (LuaCoroutine class)**
|
||||
- ⚠️ Introduction of a new class, LuaState (inherited by LuaCoroutine and LuaInstance).
|
||||
- **Added ENet protocol support for reliable UDP communication**
|
||||
- ⚠️ SocketPoller is now able to wait on read/write status of socket
|
||||
- ⚠️ SocketPoller::Wait() has now support for infinite waiting (-1)
|
||||
- Added UdpSocket::ReceiveMultiple method
|
||||
- **Added WIP shader build (based on AST, with support for GLSL)**
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/127 Fixed RigidBody2D::GetAABB() wrong AABB
|
||||
- **Added basic support for constraints**
|
||||
- Added support for collision callbacks
|
||||
- Added support for raycast
|
||||
- Added support for nearest body queries
|
||||
- Added support for debug draw
|
||||
- Added support for damping
|
||||
- ⚠️ RigidBody2D created without mass are now kinematic by default instead of statics
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/128 ⚠️ **Platform-specific classes were moved to a new module: Platform** (this means Utility module no longer needs to be linked to X11/xcb or gdi32).
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/135 ⚠️ Improved vertex declarations (they now checks template type with real type)
|
||||
- Mesh index buffer optimization is now disabled by default in debug mode
|
||||
- It is now possible to set the vertex declaration wanted when building/loading a mesh
|
||||
- It is now possible to set index/vertex buffer usage flags when building/loading a mesh
|
||||
- Added VertexMapper::GetVertexBuffer()
|
||||
- Added VertexMapper::GetVertexCount()
|
||||
- Added VertexMapper::HasComponentOfType()
|
||||
- Fixed SimpleTextDrawer bounds computation
|
||||
|
||||
|
||||
Nazara Development Kit:
|
||||
- ⚠️ Components no longer need to be copyable by assignation
|
||||
- Added BaseComponent::GetEntity()
|
||||
- ⚠️Systems are no longer copyable/clonable
|
||||
- ⚠️World::[Get|Set]UpdateRate has been renamed World::[Get|Set]FixedUpdateRate.
|
||||
- Added World::[Get|Set]MaximumUpdateRate.
|
||||
- Added BaseWidget::CenterHorizontal()
|
||||
- Added BaseWidget::CenterVertical()
|
||||
- EntityHandle are now handled in such a way they will never move in memory until a world update is triggered, this means it is now safe to returns const reference to EntityHandle as long as you do not keep them from one world update to another.
|
||||
- Fixed a crash when destroying a hovered widget
|
||||
- Added CollisionComponent2D::GetAABB()
|
||||
- Added Entity::OnEntityDestruction signal
|
||||
- ⚠️EntityList were remade to take less memory and are easier to use but can only be iterated from front to back
|
||||
- Entities are now automatically removed from EntityLists when destroyed.
|
||||
- It is no longer required for a component to have a default constructor to be binded to Lua.
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/123 StateMachine can now handle multiple states at once
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/132 Added ProgressBarWidget
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/133 ButtonWidget color and texture can now be customized
|
||||
- https://github.com/DigitalPulseSoftware/NazaraEngine/pull/130 Added CheckboxWidget
|
||||
- Added OnEntityDestruction() event on components in order to let them do better cleanup.
|
||||
|
||||
# 0.3
|
||||
|
||||
Build system:
|
||||
- Added `Configurations` parameter for build system, with support for ReleaseWithDebug. (67dcf166b80b4de1ecb5256a271a5ac80526435d)
|
||||
|
||||
Nazara Engine:
|
||||
- **Added new particle demo (Space battle)**. (3c6a6cd3a9294e5ba577af9ec3bef695438c28b7)
|
||||
- **Added back automatic Frustum Culling**. (a349b931e6a5b45586316763a458e1d89758542a)
|
||||
- **Added Nz::Flags class to properly handle enum flags**. (d6b793f46178a05998182a4bbe595c425465eb07)
|
||||
- **Refactored Buffer classes to prepare the new Renderer**. (9e0fd0a8e82567d03f063728e76f6dd5571760f2)
|
||||
- **Added a way to override über-shaders used by the engine at runtime**. (d2d6bae47f326562a2c50631f169100e35ecdd09)
|
||||
- ⚠️ **Reworked Nz::Cursor, it now includes default system cursors, allows to retrieve its image and is ref-counted** (6751d480b152a6203262b72e2cbe120007741621, 6751d480b152a6203262b72e2cbe120007741621, 0cab95e8aea4d2fb8a58c9dba2d609e33c748093).
|
||||
- ⚠️ Nz::WindowCursor has been renamed to Nz::SystemCursor. (6751d480b152a6203262b72e2cbe120007741621)
|
||||
- Added Nz::CursorController class, for indirect cursor control. (a2e5e4874469958b658c24d8a52bb9bc274e9398)
|
||||
- Added Nz::UdpSocket::SendMultiple method, allowing to merge multiple buffers into the same datagram. (ea0d42f4234bcca184bb42aef16fb2a4e1346913).
|
||||
- Added [Nz::TcpClient::SendMultiple](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_tcp_client.html#a495c32beb46ed9192699a3b82d358035) method, allowing to send multiple buffers at once.
|
||||
- Added [Nz::PlacementDestroy](https://nazara.digitalpulsesoftware.net/doc/namespace_nz.html#a27c8667def991fc896c5beff3e62668a). (ea985fa76586762f008e4054938db3234eeaf0cb)
|
||||
- Added [Nz::String::Format](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_string.html#a4b699982e7f9ea38f6d44b43ac1e2040) and [Nz::String::FormatVA](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_string.html#abe0fcbce11224b157ac756b60e8dee92) static methods. (cc6e4127dc6c61799a64404770992cef0804ad34).
|
||||
- Added [Nz::ParticleGroup::GetBuffer](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_particle_mapper.html#aefe1b251efc8c9b8668842275561be0c) method. (4dc85789b59e50d964c83321dbd4b6485c04bef6)
|
||||
- Added Nz::ParticleMapper::GetPointer method. (1f4e6c2d1594b7bb9dd6f4ea5480fdd16cf5f208)
|
||||
- ⚠️ Structures provied by ParticleStruct header now have a float life. (472d964d587d906764ad1e05bfcc9ab1bf979483)
|
||||
- Fixed scale property of Nz::TextSprite not affecting its bounding volume. (52b29bac775823294c4ad7de70f4dc3f4adfa743)
|
||||
- ⚠️ Nz:MeshParams::flipUVs has been replaced by texCoordOffset and texCoordScale. (a1a7d908adc060fd7a43491c903dfe3b501d98e5)
|
||||
- Fixed [Nz::Music::Stop](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_music.html#a9f0eb20328d6b35ab290b19364e95ee8) which was not resetting the playing offset. (12d7bc9aa3b672fc855478904072ed18f06e37ca, 24be97447af5c55b444a96e8d5d000e590279171)
|
||||
- Reworked LuaBinding classes to try to improve compile time and generated objects memory. (5555d24afca2ec766c7625bb8e959560677b69c2).
|
||||
- ⚠️ Convert OpenMode to use the new Nz::Flags class. (49dfe31fa036cdac4f531a15972e2bd52fa9ab57)
|
||||
- ⚠️ Convert StreamOption to use the new Nz::Flags class. (49dfe31fa036cdac4f531a15972e2bd52fa9ab57)
|
||||
- ⚠️ Convert WindowStyleFlags to use the new Nz::Flags class. (6c0422350fea520f96253df1113ee7c49233bd06)
|
||||
- ⚠️ Fix typo in OpenMode_MustExist (previously written as "MustExit"). (445ab13ef8a78c07697556ae50086a9276cbf7c2)
|
||||
- Added [Nz::String::GetCharacterPosition](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_string.html#acd89bc8d5afaa808c8baa480501d5f58) method. (2f4ca23cdaefc8350a95d2d6aa741602b5ee00f1)
|
||||
- Exposed Nz::SoftwareBuffer class. (842786d2d482890ad3ed9ba88613f1d2a0f901ba)
|
||||
- ⚠️ Removed Sphere::SquaredDistance method, use Vector3::SquaredDistance with its center instead. (5b017aecfdb86246fe8517453376801b00c23843)
|
||||
- Fixed SceneAmbient shader uniform not being sent by DepthRenderTechnique. (83e345a2fc25073a9f10b0a3547a75692613f9b3)
|
||||
- Fixed light selection bug (causing an object to not have any light on it although it is within its radius). (9c04d79b2906940067a32d84800edd1ffd38d9bd)
|
||||
- Renderer::SetTexture and Renderer::SetTextureSampler now takes `unsigned int` instead of `UInt8` texture indexes. (09c2cbf1c5eeadac52c72459b0fb6df3064fc16a)
|
||||
- When a shader fails to validate, its uniform are now dumped to the log. (0d37a3d4bf68bce9f533ad8c95225809cc312cdd)
|
||||
- When a shader fails to compile, its code is now dumped to the log. (53ee8915fa0255b5c7492952919edd3a70e29b6c)
|
||||
- ⚠️ Texture units used by Nazara are now static, fixes a bug with shadow. (b290a1233d725636d73c3bd8b37c394d93789524)
|
||||
- Nz::Signal move constructor and assignement operators are now `noexcept`. (00144e944e6d8d894aef8b7bced9a6b364091626)
|
||||
- Nz::EventHandler is now a handled object. (498b84fc690bae084a63ef379452cd45173c933a).
|
||||
- Added a way to specify receive and send buffer size per socket. (c4459f5910d1f7e5833e2cbdca1dbd048a9a0416).
|
||||
- Fixed ObjectHandle <= operator. (6f601101d23fe790dd83a1f69a137009116ad91b)
|
||||
- Fixed Nz::UdpSocket::Receive failing when peers suddenly closes its socket. (12401e0e2f0cee0ab8fcd9124cce368e54f8037b)
|
||||
- All noises classes now uses std::mt19937 as a random number generator, to ensure the same results on every machine. (1f5ea9839016964c173d919263827dee69ecb65d)
|
||||
|
||||
Nazara Development Kit:
|
||||
- **Added basic widgets**. (c8a12083b3133e946bf60dd060331a4b4631f8d8)
|
||||
- VelocitySystem will no longer affect entities with PhysicsComponent2D. (a6853234412c744cdcb28344f02f7b0c92704d77)
|
||||
- Fixed EulerAngles constructor in Lua. (d55149a0a70f6230b6f1c3fb50e37dc82a2feb9f)
|
||||
- Fixed Component::OnDetached not being called on entity destruction. (5b777eb4853639d7aeb232ca46d17f0d432f47ca)
|
||||
|
||||
Nazara Engine:
|
||||
|
||||
# 0.2.1
|
||||
|
||||
Nazara Engine:
|
||||
- Nazara binaries are now compiled with Run-Time Type-Information. (a70acdc8f44010627a65282fd3099202116d3e13)
|
||||
- Nazara demos are now compiled with relative dependencies on Linux.
|
||||
(d6fbb4c408d48c4a768fad7b43460c76a0df1777)
|
||||
- Added [**Nz::BitCount**](https://nazara.digitalpulsesoftware.net/doc/group__core.html#ga6bfbcff78eb6cfbe3ddaedcfc8c04196) function. (82e31a3ec8449da6618f41690164c2e1d883edb4)
|
||||
- Added [**Nz::Bitset::AppendBits**](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_bitset.html#a5ca8f365006c86d6d699d02471904f7e) method. (b018a400499a2356c4455a40d9f6a6c12b3cb36b)
|
||||
- Added [**Nz::Bitset::Read**](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_bitset.html#aca204e1d71e36d6c8c2c544ffd9824ac) method. (f0c40ecb2f2f64f5af46f38e4b589d8c1dea824c)
|
||||
- Added [**Nz::Bitset::Reverse**](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_bitset.html#af372e64f33a2114837fb25daffcc1008) method. (0abd1bbfbf6b949e350a78170aae1b45698620eb)
|
||||
- Added [**Nz::Bitset::FromPointer**](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_bitset.html#a487836f91821e6d7901eb753baf47de3) static method. (f0c40ecb2f2f64f5af46f38e4b589d8c1dea824c)
|
||||
- Added an operator<< for `ostream` and `Nz::Bitset`. (9d9efac2baf29842e58b3e73f255ca06cb24d1fb)
|
||||
- Added `Nz::Image::HasAlpha` method. (1029b37d3654aea9fcc4fd2a43e6d32c9842268a)
|
||||
- Added a [**Sprite::SetMaterial**](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_sprite.html#a3074f991b72af8146c5b5ba2fdda42fa) overload taking a material name. (d50f5ed7c88e613e01c76c3765d86b2014773ba8)
|
||||
- Added a [**Sprite::SetTexture**](https://nazara.digitalpulsesoftware.net/doc/class_nz_1_1_sprite.html#a6ddf41ffff1e155a99b06487e72ae47d) overload taking a texture name. (d50f5ed7c88e613e01c76c3765d86b2014773ba8)
|
||||
- Added Nz::SegmentCollider2D class. (0ede1e893aab6ab159b57eea24af273e82d68d16)
|
||||
- Nz::CountBits now returns a `std::size_t`. (63e9d77e77d35f9f0b14529dd8d86b2cd39b751e)
|
||||
- Improved bitset unit tests by checking them with multiple blocks size (f6426a53d77ccee2297a0efa8b811e482f65a48b)
|
||||
- `NDEBUG` is no longer automatically defined by Nazara headers. (fef5337279ea33f0675c55002f1df77234252168)
|
||||
- The engine now asserts on CHAR_BIT equality to 8. (01be79f8524e5f68e713a6070d3b5aacfa595aa5)
|
||||
- Fixed a crash occuring after a RigidBody2D got modified/removed. (874362a606f513be1888997f2f1b87cad4fbca53)
|
||||
- Fixed Nz::Bitset::PerformandsAND (called by &= operator) giving wrong result. (ecfce94461d1c2b96bdab7f957e14856c7100108)
|
||||
- PixelFormats with over 64 bits per components are now rejected. (119b7bcad4dd16f5499e2ec6a9da48c3985b036f)
|
||||
- Fixed `PixelFormatInfo` masks bit order. (62197da39e6dccbe957794e5422454c49c4f039f)
|
||||
- Fixed RigidBody2D collisions. (c99d7fd640a69f18a5f615d2ebc6d7f15d329f6e)
|
||||
- Fixed RigidBody2D::AddForce application point. (7eb240e4a1fa1af16aa68197ec688f71ff3d32c4)
|
||||
- Fixed Nz::Quaternion::Lerp compilation. (739291651eef4bc90ad14342415bf88d20142f0f)
|
||||
|
||||
Nazara Development Kit:
|
||||
- Fixed missing [group **NDK**](https://nazara.digitalpulsesoftware.net/doc/group___n_d_k.html) in documentation. (51c6b0241c074c64319f2347eaea72992951322f)
|
||||
- Fixed CollisionComponent2D position when used alone. (e24d433f7563fcd4156ac3be01570752bd7c734a)
|
||||
- Including the following changes in the Lua API:
|
||||
- CameraComponent is now accessible from Lua (cfb40bf4dc4777012a11fea528f8203ef53c5686).
|
||||
- Methods from EulerAngles and Quaternions classes are now accessible from Lua. (0886292c00ea3826c6c23e1e9d1c76bd6c0cf28d)
|
||||
- Keyboard is now accessible from Lua (e50c9757e4f64aed553ebfa3859d2642c03ba58e)
|
||||
|
||||
# 0.2
|
||||
|
||||
Build system:
|
||||
- Added a .editorconfig file to help consistency (8126c981946591c4e5a4bc0e56268aecbe6a76f1)
|
||||
- Code::Blocks is now supported by Premake5 (40276139b52e0aae7daf20d3f0a84b007e84a993)
|
||||
- Global headers no longer include generation date. (fd3161c8e9bb9e262ed2359d679f1c47564dbac2)
|
||||
- Upgraded Premake5 to alpha10, removing Premake4 in the process. (110064c08f429664f2ecc2a86319afee2441b28e)
|
||||
|
||||
Nazara Engine:
|
||||
- ⚠️**The Physics module has been renamed to Physics3D** (65bfd77623d1bf337849cc828022adf190c1d677)
|
||||
- The PhysObject class has been renamed to RigidBody3D (d2c8ca0f0cfc91869e1802ee759ea2b356fc0a30)
|
||||
- The PhysWorld class has been renamed to PhysWorld3D (d130719c5fd9521062f8c9e48729aba430061c77)
|
||||
- The *Geom classes have been renamed to *Collider3D (fc1ea178c7e1dba7739443afcec339f6622243ae)
|
||||
- The GeomType enum has been renamed to ColliderType3D and is now part of thz Nz namespace (1f75d449d61612909b1e879f2558c89dd41c2394)
|
||||
- **A new Physics2D module has been added, using [chipmunk](https://chipmunk-physics.net)** (e9be18d1813197004a06d5eb13fe87232ccd6168)
|
||||
- ⚠️ **`NAZARA_UTILITY_THREADED_WINDOW` got replaced by the runtime flag `WindowStyle_Threaded`**. (a7dd0e0a20c4c4401c663f4665ea9133dfbca1a5)
|
||||
- LuaClass is now default-constructable and (re)initialized later with its `Reset` method (dc3e125bdac3e0c790743af78fead3a2e28c73b3)
|
||||
- LuaClass is now able to bind classes with deleted destructor (3168e5ae07e29168223666dd23c29cb6cd7788ed)
|
||||
- Added a `LuaInstance::Push` variadic overload able to push multiple arguments (a19edf1676181ec8765d9d61a02c8b0f2533c9df)
|
||||
- The Vector classes now have a std::hash overload (74b446af2fc0898afa170c7fec8eaf6b5cf30614)
|
||||
- The TextEntered event handling on Linux has been improved (7d1c5fa1af98abc2f253fd4a9c6b6d8604dbccaa)
|
||||
- An interactive unit test has been added for testing the window events (34d92320b6252e1bf4e86e3544ecc06dc3126d8d)
|
||||
- `AbstractLogger::IsStdReplicationEnabled()` is now const (5df095c0f178fcb5f772aaf9a9fb4bf79257b008)
|
||||
- `FileLogger::IsTimeLoggingEnabled()` is now const (de0f93116aad07d5893e8d3ba3ec1313d7458bdf)
|
||||
- Fixed `Apply` return type not taking references into account (1eb49d38691798d78c7e6559007d4f496b625db3)
|
||||
- Fixed `LuaInstance::PushInstance` memory corruption (54b77c0f48a005e345109a85f49cbc4b28d93f07)
|
||||
- Fixed `Matrix4::Get(Column|Row)` compilation (728d7b829e6604e314e9b8a6dfa5bd5d85602c7a)
|
||||
- Fixed `ResourceManager::Purge` compilation (c7002830f58f092adb6c055a911397abc949fd4a)
|
||||
- Fixed `Quaterniond::operator*` compilation (19dc95ae7c65b148cc5faeb897ded4880b9fba28)
|
||||
- Fixed the <= operator with two ObjectRef (7597578bbf400e7610103b191e4b8e9e2af0b47f)
|
||||
- ⚠️ LuaClass methods now include an `argumentCount` parameter, and the instance remains at the top of the Lua stack, shifting all parameters by one (9b7947812b4c4a4543a1447daea4472f4f674b7f)
|
||||
- Fixed automatic lua binding of `T& T::Method()`, which will now return the original Lua instance instead of copying it. (d20fa0077a74dbe5e9e914f7adfd0c62faf5fa3a)
|
||||
- `VideoMode` third argument (`bpp`) is now optional. (2ab311e0a68523b2113b25f24244b855cc4712bb)
|
||||
- `ByteArray::ToHex` is now implemented in ByteArray.cpp, to reduce the amount of warnings generated by MSVC because of the `sprintf` call. (41e7e6af601fbd3b2ca96b188e4906c010903ef0)
|
||||
|
||||
Nazara Development Kit:
|
||||
- ⚠️ The Collision and Physics components now have a 3D suffix (6e289fe789d64ac9730ddc0f4cc240e02754e8a3)
|
||||
- Added Collision and Physics components for 2D physics. (b5048dfb3704675b9f7438d080a9347c99884972)
|
||||
- `LuaAPI::GetBinding()` will now implicitly initialize LuaAPI if required (ec161141d8d99db250f4f5a1e739123ad4f91750)
|
||||
- It is now possible to change the update order of a world's systems. (51b6979bb59b6d880d0bcacef1b3d8d7420a5fa6)
|
||||
- By default, the Render and Listener systems update are now performed last. (dd22e5f1054da80b5b6aff5ae96e9832b4425ed7)
|
||||
- PhysicsSystem3D no longer initialize an internal PhysWorld3D if no physical entity gets created (e282442407c028c5d1cff96847b5b7f857a646bb)
|
||||
- Including the following changes in the Lua API:
|
||||
- `GraphicsComponent:Attach` overloads (taking local matrix and render order) are fixed. (d525669f3ae0d40266df9c34b6b1525a10a26d7e)
|
||||
- Material is now accessible from Lua (aed4e1ee91d9875592adb178334220339afb72a0)
|
||||
- Matrix4 is now accessible from Lua (fb518403659455ae79be848b99dd8f6083f1ab58)
|
||||
- Sprite is now accessible from Lua (e034dce76dc6a2fd1f403221e1945c1a2c3e28ee)
|
||||
- SpriteLibrary is now accessible from Lua (013a133f60d46114e1b02fed7eab9f9a9f506068)
|
||||
- Texture is now accessible from Lua (f8b55a5063c058965668ed4277a7e50280ea100d)
|
||||
- TextureLibrary is now accessible from Lua (3a64ef9e136c457a8207440e37361b5b3384e133)
|
||||
- TextureManager is now accessible from Lua (3a64ef9e136c457a8207440e37361b5b3384e133)
|
||||
|
||||
Issues fixed:
|
||||
- #102: Some shaders used by the Graphics module may fail to compile with some drivers.
|
||||
- #104: On Windows, when using threaded windows, the window position obtained by `Window::GetPosition()` never gets updated.
|
||||
- #105: On Windows, when not using threaded windows, a lot of Moved events gets generated instead of just one for every movement.
|
||||
- #111: On Linux, `IsKeyPressed(Keyboard::Q);` returns true if the `A` key is pressed.
|
||||
- #114: Box/cubic sphere submesh generation is broken.
|
||||
|
||||
# 0.1.1
|
||||
|
||||
Additions/Changes:
|
||||
- Nz::Bitset now supports shifting operations (along with <<, >> operators) (37089d9a5fba52ba83f46d603381584a13036ac0).
|
||||
|
||||
Issues fixed:
|
||||
- #73, #81: Nazara fails to compile on Linux with x86 target.
|
||||
- #75: Lua constructors may fail in some cases.
|
||||
- #77: Packaging the engine under Linux fails to copy the executable binaries of the demo and unit tests.
|
||||
- #78: Building with Clang fails.
|
||||
- #79: `SocketPoller::Wait` does not update its `error` parameter on Linux.
|
||||
- #80: When initializing the engine, some pixel format errors occurs, this currently has no side-effect.
|
||||
|
||||
# 0.1
|
||||
- Initial release
|
||||
2
Doxyfile
2
Doxyfile
|
|
@ -38,7 +38,7 @@ PROJECT_NAME = "Nazara Engine"
|
|||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 0.3
|
||||
PROJECT_NUMBER = 0.4
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Ndk
|
|||
static_assert(N-1 <= sizeof(ComponentId), "Name too long for this size of component id");
|
||||
|
||||
ComponentId componentId = 0;
|
||||
for (unsigned int i = 0; i < N; ++i)
|
||||
for (unsigned int i = 0; i < N - 1; ++i)
|
||||
componentId |= static_cast<ComponentId>(name[i]) << i*8;
|
||||
|
||||
return componentId;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -24,28 +22,28 @@ namespace Ndk
|
|||
|
||||
public:
|
||||
inline BaseSystem(SystemIndex systemId);
|
||||
inline BaseSystem(const BaseSystem&);
|
||||
BaseSystem(const BaseSystem&) = delete;
|
||||
BaseSystem(BaseSystem&&) noexcept = default;
|
||||
virtual ~BaseSystem();
|
||||
|
||||
inline void Enable(bool enable = true);
|
||||
|
||||
virtual std::unique_ptr<BaseSystem> Clone() const = 0;
|
||||
|
||||
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 +91,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,24 +19,8 @@ namespace Ndk
|
|||
m_updateEnabled(true),
|
||||
m_updateOrder(0)
|
||||
{
|
||||
SetUpdateRate(30);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a BaseSystem object by copy semantic
|
||||
*
|
||||
* \param system System to copy
|
||||
*/
|
||||
|
||||
inline BaseSystem::BaseSystem(const BaseSystem& system) :
|
||||
m_excludedComponents(system.m_excludedComponents),
|
||||
m_requiredComponents(system.m_requiredComponents),
|
||||
m_systemIndex(system.m_systemIndex),
|
||||
m_updateEnabled(system.m_updateEnabled),
|
||||
m_updateCounter(0.f),
|
||||
m_updateRate(system.m_updateRate),
|
||||
m_updateOrder(system.m_updateOrder)
|
||||
{
|
||||
SetFixedUpdateRate(0);
|
||||
SetMaximumUpdateRate(30);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -61,6 +44,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 +83,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 +116,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 +148,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,8 +37,12 @@ namespace Ndk
|
|||
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
|
||||
|
||||
inline void Center();
|
||||
inline void CenterHorizontal();
|
||||
inline void CenterVertical();
|
||||
|
||||
inline void Destroy();
|
||||
void ClearFocus();
|
||||
|
||||
void Destroy();
|
||||
|
||||
void EnableBackground(bool enable);
|
||||
|
||||
|
|
@ -53,15 +56,16 @@ namespace Ndk
|
|||
inline const Nz::Vector2f& GetContentSize() const;
|
||||
inline Nz::Vector2f GetSize() const;
|
||||
|
||||
inline bool IsVisible() const;
|
||||
bool HasFocus() const;
|
||||
|
||||
void GrabKeyboard();
|
||||
inline bool IsVisible() const;
|
||||
|
||||
virtual void ResizeToContent() = 0;
|
||||
|
||||
void SetBackgroundColor(const Nz::Color& color);
|
||||
void SetCursor(Nz::SystemCursor systemCursor);
|
||||
inline void SetContentSize(const Nz::Vector2f& size);
|
||||
void SetFocus();
|
||||
inline void SetPadding(float left, float top, float right, float bottom);
|
||||
void SetSize(const Nz::Vector2f& size);
|
||||
|
||||
|
|
@ -79,12 +83,15 @@ namespace Ndk
|
|||
};
|
||||
|
||||
protected:
|
||||
EntityHandle CreateEntity();
|
||||
const EntityHandle& CreateEntity();
|
||||
void DestroyEntity(Entity* entity);
|
||||
virtual void Layout();
|
||||
void InvalidateNode() override;
|
||||
|
||||
virtual void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
|
||||
virtual bool IsFocusable() const;
|
||||
virtual void OnFocusLost();
|
||||
virtual void OnFocusReceived();
|
||||
virtual bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
|
||||
virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key);
|
||||
virtual void OnMouseEnter();
|
||||
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -34,12 +34,16 @@ namespace Ndk
|
|||
Canvas& operator=(Canvas&&) = delete;
|
||||
|
||||
protected:
|
||||
inline void ClearKeyboardOwner(std::size_t canvasIndex);
|
||||
|
||||
inline bool IsKeyboardOwner(std::size_t canvasIndex) const;
|
||||
|
||||
inline void NotifyWidgetBoxUpdate(std::size_t index);
|
||||
inline void NotifyWidgetCursorUpdate(std::size_t index);
|
||||
|
||||
std::size_t RegisterWidget(BaseWidget* widget);
|
||||
|
||||
inline void SetKeyboardOwner(BaseWidget* widget);
|
||||
inline void SetKeyboardOwner(std::size_t canvasIndex);
|
||||
|
||||
void UnregisterWidget(std::size_t index);
|
||||
|
||||
|
|
@ -52,7 +56,7 @@ namespace Ndk
|
|||
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
||||
|
||||
struct WidgetBox
|
||||
struct WidgetEntry
|
||||
{
|
||||
BaseWidget* widget;
|
||||
Nz::Boxf box;
|
||||
|
|
@ -67,10 +71,10 @@ namespace Ndk
|
|||
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
|
||||
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
|
||||
|
||||
std::vector<WidgetBox> m_widgetBoxes;
|
||||
std::size_t m_keyboardOwner;
|
||||
std::size_t m_hoveredWidget;
|
||||
std::vector<WidgetEntry> m_widgetEntries;
|
||||
Nz::CursorControllerHandle m_cursorController;
|
||||
const WidgetBox* m_hoveredWidget;
|
||||
BaseWidget* m_keyboardOwner;
|
||||
WorldHandle m_world;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
// 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
|
||||
{
|
||||
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) :
|
||||
m_keyboardOwner(InvalidCanvasIndex),
|
||||
m_hoveredWidget(InvalidCanvasIndex),
|
||||
m_cursorController(cursorController),
|
||||
m_hoveredWidget(nullptr),
|
||||
m_keyboardOwner(nullptr),
|
||||
m_world(std::move(world))
|
||||
{
|
||||
m_canvas = this;
|
||||
|
|
@ -46,9 +46,20 @@ namespace Ndk
|
|||
return m_world;
|
||||
}
|
||||
|
||||
inline void Canvas::ClearKeyboardOwner(std::size_t canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner == canvasIndex)
|
||||
SetKeyboardOwner(InvalidCanvasIndex);
|
||||
}
|
||||
|
||||
inline bool Canvas::IsKeyboardOwner(std::size_t canvasIndex) const
|
||||
{
|
||||
return m_keyboardOwner == canvasIndex;
|
||||
}
|
||||
|
||||
inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index)
|
||||
{
|
||||
WidgetBox& entry = m_widgetBoxes[index];
|
||||
WidgetEntry& entry = m_widgetEntries[index];
|
||||
|
||||
Nz::Vector3f pos = entry.widget->GetPosition();
|
||||
Nz::Vector2f size = entry.widget->GetContentSize();
|
||||
|
|
@ -58,15 +69,24 @@ namespace Ndk
|
|||
|
||||
inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index)
|
||||
{
|
||||
WidgetBox& entry = m_widgetBoxes[index];
|
||||
WidgetEntry& entry = m_widgetEntries[index];
|
||||
|
||||
entry.cursor = entry.widget->GetCursor();
|
||||
if (m_cursorController && m_hoveredWidget == &entry)
|
||||
if (m_cursorController && m_hoveredWidget == index)
|
||||
m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor));
|
||||
}
|
||||
|
||||
inline void Ndk::Canvas::SetKeyboardOwner(BaseWidget* widget)
|
||||
inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex)
|
||||
{
|
||||
m_keyboardOwner = widget;
|
||||
if (m_keyboardOwner != canvasIndex)
|
||||
{
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnFocusLost();
|
||||
|
||||
m_keyboardOwner = canvasIndex;
|
||||
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnFocusReceived();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
|
|
@ -238,10 +237,9 @@ namespace Ndk
|
|||
NazaraAssert(m_target, "Component has no render target");
|
||||
|
||||
// We compute the region necessary to make this view port with the actual size of the target
|
||||
float invWidth = 1.f / m_target->GetWidth();
|
||||
float invHeight = 1.f / m_target->GetHeight();
|
||||
Nz::Vector2f invSize = 1.f / Nz::Vector2f(m_target->GetSize());
|
||||
|
||||
SetTargetRegion(Nz::Rectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height));
|
||||
SetTargetRegion(Nz::Rectf(invSize.x * viewport.x, invSize.y * viewport.y, invSize.x * viewport.width, invSize.y * viewport.height));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -34,13 +35,15 @@ namespace Ndk
|
|||
inline void AddToCullingList(GraphicsComponentCullingList* cullingList) const;
|
||||
void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
|
||||
|
||||
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
inline void Detach(const Nz::InstancedRenderable* renderable);
|
||||
|
||||
inline bool DoesRequireRealTimeReflections() const;
|
||||
|
||||
inline void EnsureBoundingVolumeUpdate() const;
|
||||
inline void EnsureTransformMatrixUpdate() const;
|
||||
|
||||
|
|
@ -57,22 +60,43 @@ namespace Ndk
|
|||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
struct Renderable;
|
||||
|
||||
void ConnectInstancedRenderableSignals(Renderable& renderable);
|
||||
|
||||
inline void InvalidateBoundingVolume() const;
|
||||
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
|
||||
void InvalidateRenderableMaterial(const Nz::InstancedRenderable* renderable, std::size_t skinIndex, std::size_t matIndex, const Nz::MaterialRef& newMat);
|
||||
inline void InvalidateRenderables();
|
||||
void InvalidateReflectionMap();
|
||||
inline void InvalidateTransformMatrix();
|
||||
|
||||
void RegisterMaterial(Nz::Material* material, std::size_t count = 1);
|
||||
|
||||
void OnAttached() override;
|
||||
void OnComponentAttached(BaseComponent& component) override;
|
||||
void OnComponentDetached(BaseComponent& component) override;
|
||||
void OnDetached() override;
|
||||
|
||||
void OnInstancedRenderableResetMaterials(const Nz::InstancedRenderable* renderable, std::size_t newMaterialCount);
|
||||
void OnInstancedRenderableSkinChange(const Nz::InstancedRenderable* renderable, std::size_t newSkinIndex);
|
||||
void OnMaterialReflectionChange(const Nz::Material* material, Nz::ReflectionMode reflectionMode);
|
||||
void OnNodeInvalidated(const Nz::Node* node);
|
||||
|
||||
void UnregisterMaterial(Nz::Material* material);
|
||||
|
||||
void UpdateBoundingVolume() const;
|
||||
void UpdateTransformMatrix() const;
|
||||
|
||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||
|
||||
struct MaterialEntry
|
||||
{
|
||||
NazaraSlot(Nz::Material, OnMaterialReflectionModeChange, reflectionModelChangeSlot);
|
||||
|
||||
std::size_t renderableCounter;
|
||||
};
|
||||
|
||||
struct Renderable
|
||||
{
|
||||
Renderable(const Nz::Matrix4f& transformMatrix) :
|
||||
|
|
@ -81,15 +105,8 @@ namespace Ndk
|
|||
{
|
||||
}
|
||||
|
||||
Renderable(Renderable&& rhs) noexcept :
|
||||
renderableBoundingVolumeInvalidationSlot(std::move(rhs.renderableBoundingVolumeInvalidationSlot)),
|
||||
renderableDataInvalidationSlot(std::move(rhs.renderableDataInvalidationSlot)),
|
||||
renderableReleaseSlot(std::move(rhs.renderableReleaseSlot)),
|
||||
data(std::move(rhs.data)),
|
||||
renderable(std::move(rhs.renderable)),
|
||||
dataUpdated(rhs.dataUpdated)
|
||||
{
|
||||
}
|
||||
Renderable(const Renderable&) = delete;
|
||||
Renderable(Renderable&& rhs) noexcept = default;
|
||||
|
||||
~Renderable()
|
||||
{
|
||||
|
|
@ -97,21 +114,15 @@ namespace Ndk
|
|||
renderableReleaseSlot.Disconnect();
|
||||
}
|
||||
|
||||
Renderable& operator=(Renderable&& r) noexcept
|
||||
{
|
||||
data = std::move(r.data);
|
||||
dataUpdated = r.dataUpdated;
|
||||
renderable = std::move(r.renderable);
|
||||
renderableBoundingVolumeInvalidationSlot = std::move(r.renderableBoundingVolumeInvalidationSlot);
|
||||
renderableDataInvalidationSlot = std::move(r.renderableDataInvalidationSlot);
|
||||
renderableReleaseSlot = std::move(r.renderableReleaseSlot);
|
||||
|
||||
return *this;
|
||||
}
|
||||
Renderable& operator=(const Renderable&) = delete;
|
||||
Renderable& operator=(Renderable&& r) noexcept = default;
|
||||
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateBoundingVolume, renderableBoundingVolumeInvalidationSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableDataInvalidationSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateMaterial, renderableMaterialInvalidationSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableRelease, renderableReleaseSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableResetMaterials, renderableResetMaterialsSlot);
|
||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableSkinChange, renderableSkinChangeSlot);
|
||||
|
||||
mutable Nz::InstancedRenderable::InstanceData data;
|
||||
Nz::InstancedRenderableRef renderable;
|
||||
|
|
@ -127,12 +138,16 @@ namespace Ndk
|
|||
NazaraSlot(GraphicsComponentCullingList, OnCullingListRelease, cullingListReleaseSlot);
|
||||
};
|
||||
|
||||
std::size_t m_reflectiveMaterialCount;
|
||||
mutable std::vector<VolumeCullingEntry> m_volumeCullingEntries;
|
||||
std::vector<Renderable> m_renderables;
|
||||
std::unordered_map<const Nz::Material*, MaterialEntry> m_materialEntries;
|
||||
mutable Nz::BoundingVolumef m_boundingVolume;
|
||||
mutable Nz::Matrix4f m_transformMatrix;
|
||||
Nz::TextureRef m_reflectionMap;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
mutable bool m_transformMatrixUpdated;
|
||||
unsigned int m_reflectionMapSize;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,17 @@ namespace Ndk
|
|||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Attaches a renderable to the entity
|
||||
*
|
||||
* \param renderable Reference to a renderable element
|
||||
* \param renderOrder Render order of the element
|
||||
*/
|
||||
inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder)
|
||||
{
|
||||
return Attach(std::move(renderable), Nz::Matrix4f::Identity(), renderOrder);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears every renderable elements
|
||||
*/
|
||||
|
|
@ -62,12 +73,29 @@ namespace Ndk
|
|||
if (it->renderable == renderable)
|
||||
{
|
||||
InvalidateBoundingVolume();
|
||||
|
||||
std::size_t materialCount = renderable->GetMaterialCount();
|
||||
for (std::size_t i = 0; i < materialCount; ++i)
|
||||
UnregisterMaterial(renderable->GetMaterial(i));
|
||||
|
||||
m_renderables.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks if this graphics component requires real-time reflections to be generated
|
||||
*
|
||||
* If any of the materials attached to a GraphicsComponent (via the attached instanced renderable) needs real-time reflections, this function will return true.
|
||||
*
|
||||
* \return True if real-time reflections needs to be generated or false
|
||||
*/
|
||||
inline bool GraphicsComponent::DoesRequireRealTimeReflections() const
|
||||
{
|
||||
return m_reflectiveMaterialCount != 0 && m_reflectionMap;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the bounding volume is up to date
|
||||
*/
|
||||
|
|
@ -198,4 +226,4 @@ namespace Ndk
|
|||
InvalidateBoundingVolume();
|
||||
InvalidateRenderables();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -24,9 +22,11 @@ namespace Ndk
|
|||
PhysicsComponent2D() = default;
|
||||
PhysicsComponent2D(const PhysicsComponent2D& physics);
|
||||
~PhysicsComponent2D() = default;
|
||||
|
||||
|
||||
void AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
|
||||
void AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
|
||||
void AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys = Nz::CoordSys_Global);
|
||||
void AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
|
||||
void AddTorque(float torque);
|
||||
|
||||
Nz::Rectf GetAABB() const;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -51,7 +50,38 @@ namespace Ndk
|
|||
|
||||
m_object->AddForce(force, point, coordSys);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Applies a impulse to the entity
|
||||
*
|
||||
* \param impulse Impulse to apply on the entity
|
||||
*
|
||||
* \remark Produces a NazaraAssert if the physics object is invalid
|
||||
*/
|
||||
|
||||
inline void PhysicsComponent2D::AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys)
|
||||
{
|
||||
NazaraAssert(m_object, "Invalid physics object");
|
||||
|
||||
m_object->AddImpulse(impulse, coordSys);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Applies a impulse to the entity
|
||||
*
|
||||
* \param impulse Impulse to apply on the entity
|
||||
* \param point Point where the impulse is applied
|
||||
*
|
||||
* \remark Produces a NazaraAssert if the physics object is invalid
|
||||
*/
|
||||
|
||||
inline void PhysicsComponent2D::AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys)
|
||||
{
|
||||
NazaraAssert(m_object, "Invalid physics object");
|
||||
|
||||
m_object->AddImpulse(impulse, point, coordSys);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Applies a torque to the entity
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
|
|
@ -40,6 +41,7 @@ namespace Ndk
|
|||
|
||||
const EntityHandle& Clone() const;
|
||||
|
||||
inline void Disable();
|
||||
inline void Enable(bool enable = true);
|
||||
|
||||
inline BaseComponent& GetComponent(ComponentIndex index);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -29,12 +28,21 @@ namespace Ndk
|
|||
return static_cast<ComponentType&>(AddComponent(std::move(ptr)));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Disables the entity
|
||||
*
|
||||
* This is just a shortcut to Enable(false)
|
||||
*/
|
||||
inline void Entity::Disable()
|
||||
{
|
||||
Enable(false);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enables the entity
|
||||
*
|
||||
* \param enable Should the entity be enabled
|
||||
*/
|
||||
|
||||
inline void Entity::Enable(bool enable)
|
||||
{
|
||||
if (m_enabled != enable)
|
||||
|
|
@ -325,4 +333,4 @@ namespace std
|
|||
return hash<Ndk::EntityId>()(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,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/Lua/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace Detail
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -310,9 +308,22 @@ namespace Nz
|
|||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::Entity** handle, TypeTag<Ndk::Entity*>)
|
||||
{
|
||||
if (!state.IsOfType(index, LuaType_Nil))
|
||||
*handle = *static_cast<Ndk::EntityHandle*>(state.CheckUserdata(index, "Entity"));
|
||||
else
|
||||
*handle = nullptr;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::EntityHandle* handle, TypeTag<Ndk::EntityHandle>)
|
||||
{
|
||||
*handle = *static_cast<Ndk::EntityHandle*>(state.CheckUserdata(index, "Entity"));
|
||||
if (!state.IsOfType(index, LuaType_Nil))
|
||||
*handle = *static_cast<Ndk::EntityHandle*>(state.CheckUserdata(index, "Entity"));
|
||||
else
|
||||
handle->Reset();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,15 +24,13 @@ namespace Ndk
|
|||
|
||||
inline void ChangeState(std::shared_ptr<State> state);
|
||||
|
||||
inline const std::shared_ptr<State>& GetCurrentState() const;
|
||||
|
||||
inline bool IsTopState(const State* state) const;
|
||||
|
||||
inline std::shared_ptr<State> PopState();
|
||||
inline bool PopStatesUntil(std::shared_ptr<State> state);
|
||||
inline void PopState();
|
||||
inline void PopStatesUntil(std::shared_ptr<State> state);
|
||||
inline void PushState(std::shared_ptr<State> state);
|
||||
|
||||
inline void SetState(std::shared_ptr<State> state);
|
||||
inline void ResetState(std::shared_ptr<State> state);
|
||||
|
||||
inline bool Update(float elapsedTime);
|
||||
|
||||
|
|
@ -40,7 +38,21 @@ namespace Ndk
|
|||
StateMachine& operator=(const StateMachine&) = delete;
|
||||
|
||||
private:
|
||||
enum class TransitionType
|
||||
{
|
||||
Pop,
|
||||
PopUntil,
|
||||
Push,
|
||||
};
|
||||
|
||||
struct StateTransition
|
||||
{
|
||||
TransitionType type;
|
||||
std::shared_ptr<State> state;
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<State>> m_states;
|
||||
std::vector<StateTransition> m_transitions;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +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/StateMachine.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <utility>
|
||||
|
||||
|
|
@ -16,66 +17,56 @@ namespace Ndk
|
|||
/*!
|
||||
* \brief Constructs a StateMachine object with an original state
|
||||
*
|
||||
* \param originalState State which is the entry point of the application
|
||||
*
|
||||
* \remark Calls "Enter" on the state
|
||||
* \remark Produces a NazaraAssert if nullptr is given
|
||||
* \param originalState State which is the entry point of the application, a nullptr will create an empty state machine
|
||||
*/
|
||||
|
||||
inline StateMachine::StateMachine(std::shared_ptr<State> originalState)
|
||||
{
|
||||
NazaraAssert(originalState, "StateMachine must have a state to begin with");
|
||||
PushState(std::move(originalState));
|
||||
if (originalState)
|
||||
PushState(std::move(originalState));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object
|
||||
*
|
||||
* \remark Calls "Leave" on all the states
|
||||
* \remark Calls "Leave" on all the states from top to bottom
|
||||
*/
|
||||
|
||||
inline StateMachine::~StateMachine()
|
||||
{
|
||||
for (std::shared_ptr<State>& state : m_states)
|
||||
state->Leave(*this);
|
||||
// Leave state from top to bottom (as if states were popped out)
|
||||
for (auto it = m_states.rbegin(); it != m_states.rend(); ++it)
|
||||
(*it)->Leave(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Replaces the current state on the top of the machine
|
||||
*
|
||||
* \param state State to replace the top one if it is nullptr, no action is performed
|
||||
*
|
||||
* \remark It is forbidden for a state machine to have (at any moment) the same state in its list multiple times
|
||||
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
|
||||
*/
|
||||
|
||||
inline void StateMachine::ChangeState(std::shared_ptr<State> state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
PopState();
|
||||
PushState(std::move(state));
|
||||
// Change state is just a pop followed by a push
|
||||
StateTransition transition;
|
||||
transition.type = TransitionType::Pop;
|
||||
m_transitions.emplace_back(std::move(transition));
|
||||
|
||||
transition.state = std::move(state);
|
||||
transition.type = TransitionType::Push;
|
||||
m_transitions.emplace_back(std::move(transition));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the current state on the top of the machine
|
||||
* \return A constant reference to the state
|
||||
*
|
||||
* \remark The stack is supposed to be non empty, otherwise it is undefined behaviour
|
||||
*
|
||||
* \see PopStatesUntil
|
||||
*/
|
||||
|
||||
inline const std::shared_ptr<State>& StateMachine::GetCurrentState() const
|
||||
{
|
||||
return m_states.back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the state is on the top of the machine
|
||||
* \return true If it is the case
|
||||
*
|
||||
* \param state State to compare the top with
|
||||
* \remark Because all actions popping or pushing a state don't take effect until next state machine update, this can return false on a just pushed state
|
||||
*/
|
||||
|
||||
inline bool StateMachine::IsTopState(const State* state) const
|
||||
{
|
||||
if (m_states.empty())
|
||||
|
|
@ -86,40 +77,36 @@ namespace Ndk
|
|||
|
||||
/*!
|
||||
* \brief Pops the state on the top of the machine
|
||||
* \return Old state on the top, nullptr if stack was empty
|
||||
*
|
||||
* \remark This method can completely empty the stack
|
||||
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
|
||||
*/
|
||||
|
||||
inline std::shared_ptr<State> StateMachine::PopState()
|
||||
inline void StateMachine::PopState()
|
||||
{
|
||||
if (m_states.empty())
|
||||
return nullptr;
|
||||
StateTransition transition;
|
||||
transition.type = TransitionType::Pop;
|
||||
|
||||
m_states.back()->Leave(*this);
|
||||
std::shared_ptr<State> oldTopState = std::move(m_states.back());
|
||||
m_states.pop_back();
|
||||
return oldTopState;
|
||||
m_transitions.emplace_back(std::move(transition));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pops all the states of the machine until a specific one is reached
|
||||
* \return true If that specific state is on top, false if stack is empty
|
||||
* \brief Pops all states of the machine until a specific one is reached
|
||||
*
|
||||
* \param state State to find on the stack if it is nullptr, no action is performed
|
||||
* \param state State to find on the stack. If nullptr is passed, no action is performed
|
||||
*
|
||||
* \remark This method can completely empty the stack
|
||||
* \remark This method will completely empty the stack if state is not present
|
||||
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
|
||||
*/
|
||||
|
||||
inline bool StateMachine::PopStatesUntil(std::shared_ptr<State> state)
|
||||
inline void StateMachine::PopStatesUntil(std::shared_ptr<State> state)
|
||||
{
|
||||
if (!state)
|
||||
return false;
|
||||
if (state)
|
||||
{
|
||||
StateTransition transition;
|
||||
transition.state = std::move(state);
|
||||
transition.type = TransitionType::PopUntil;
|
||||
|
||||
while (!m_states.empty() && !IsTopState(state.get()))
|
||||
PopState();
|
||||
|
||||
return !m_states.empty();
|
||||
m_transitions.emplace_back(std::move(transition));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -127,34 +114,40 @@ namespace Ndk
|
|||
*
|
||||
* \param state Next state to represent if it is nullptr, it performs no action
|
||||
*
|
||||
* \remark Produces a NazaraAssert if the same state is pushed two times on the stack
|
||||
* \remark It is forbidden for a state machine to have (at any moment) the same state in its list multiple times
|
||||
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
|
||||
*/
|
||||
|
||||
inline void StateMachine::PushState(std::shared_ptr<State> state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
NazaraAssert(std::find(m_states.begin(), m_states.end(), state) == m_states.end(), "The same state was pushed two times");
|
||||
StateTransition transition;
|
||||
transition.state = std::move(state);
|
||||
transition.type = TransitionType::Push;
|
||||
|
||||
m_states.push_back(std::move(state));
|
||||
m_states.back()->Enter(*this);
|
||||
m_transitions.emplace_back(std::move(transition));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pops every states of the machine to put a new one
|
||||
*
|
||||
* \param state State to reset the stack with if it is nullptr, no action is performed
|
||||
* \param state State to reset the stack with. If state is invalid, this will clear the state machine
|
||||
*
|
||||
* \remark It is forbidden for a state machine to have (at any moment) the same state in its list multiple times
|
||||
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
|
||||
*/
|
||||
|
||||
inline void StateMachine::SetState(std::shared_ptr<State> state)
|
||||
inline void StateMachine::ResetState(std::shared_ptr<State> state)
|
||||
{
|
||||
StateTransition transition;
|
||||
transition.type = TransitionType::PopUntil; //< Pop until nullptr, which basically clears the state machine
|
||||
m_transitions.emplace_back(std::move(transition));
|
||||
|
||||
if (state)
|
||||
{
|
||||
while (!m_states.empty())
|
||||
PopState();
|
||||
|
||||
PushState(std::move(state));
|
||||
transition.state = std::move(state);
|
||||
transition.type = TransitionType::Push;
|
||||
m_transitions.emplace_back(std::move(transition));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,9 +157,41 @@ namespace Ndk
|
|||
*
|
||||
* \param elapsedTime Delta time used for the update
|
||||
*/
|
||||
|
||||
inline bool StateMachine::Update(float elapsedTime)
|
||||
{
|
||||
for (StateTransition& transition : m_transitions)
|
||||
{
|
||||
switch (transition.type)
|
||||
{
|
||||
case TransitionType::Pop:
|
||||
{
|
||||
std::shared_ptr<State>& topState = m_states.back();
|
||||
topState->Leave(*this); //< Call leave before popping to ensure consistent IsTopState behavior
|
||||
|
||||
m_states.pop_back();
|
||||
break;
|
||||
}
|
||||
|
||||
case TransitionType::PopUntil:
|
||||
{
|
||||
while (!m_states.empty() && m_states.back() != transition.state)
|
||||
{
|
||||
m_states.back()->Leave(*this);
|
||||
m_states.pop_back();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TransitionType::Push:
|
||||
{
|
||||
m_states.emplace_back(std::move(transition.state));
|
||||
m_states.back()->Enter(*this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_transitions.clear();
|
||||
|
||||
return std::all_of(m_states.begin(), m_states.end(), [=](std::shared_ptr<State>& state) {
|
||||
return state->Update(*this, elapsedTime);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,12 +16,10 @@ namespace Ndk
|
|||
{
|
||||
public:
|
||||
System();
|
||||
System(const System&) = default;
|
||||
System(const System&) = delete;
|
||||
System(System&&) = default;
|
||||
virtual ~System();
|
||||
|
||||
std::unique_ptr<BaseSystem> Clone() const override;
|
||||
|
||||
System& operator=(const System&) = delete;
|
||||
System& operator=(System&&) = default;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,22 +28,6 @@ namespace Ndk
|
|||
template<typename SystemType>
|
||||
System<SystemType>::~System() = default;
|
||||
|
||||
/*!
|
||||
* \brief Clones the system
|
||||
* \return The clone newly created
|
||||
*
|
||||
* \remark The system to clone should be trivially copy constructible
|
||||
*/
|
||||
|
||||
template<typename SystemType>
|
||||
std::unique_ptr<BaseSystem> System<SystemType>::Clone() const
|
||||
{
|
||||
///FIXME: Not fully supported in GCC (4.9.2)
|
||||
//static_assert(std::is_trivially_copy_constructible<SystemType>::value, "SystemType should be copy-constructible");
|
||||
|
||||
return std::make_unique<SystemType>(static_cast<const SystemType&>(*this));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the system by assigning it an index
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
@ -52,6 +52,7 @@ namespace Ndk
|
|||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||
void OnUpdate(float elapsedTime) override;
|
||||
|
||||
void UpdateDynamicReflections();
|
||||
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
|
||||
void UpdatePointSpotShadowMaps();
|
||||
|
||||
|
|
@ -63,6 +64,7 @@ namespace Ndk
|
|||
EntityList m_lights;
|
||||
EntityList m_pointSpotLights;
|
||||
EntityList m_particleGroups;
|
||||
EntityList m_realtimeReflected;
|
||||
GraphicsComponentCullingList m_drawableCulling;
|
||||
Nz::BackgroundRef m_background;
|
||||
Nz::DepthRenderTechnique m_shadowTechnique;
|
||||
|
|
|
|||
|
|
@ -4,17 +4,6 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a RenderSystem object by copy semantic
|
||||
*
|
||||
* \param renderSystem RenderSystem to copy
|
||||
*/
|
||||
|
||||
inline RenderSystem::RenderSystem(const RenderSystem& renderSystem) :
|
||||
System(renderSystem)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Changes the render technique used for the system
|
||||
* \return A reference to the render technique type
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
#define NDK_WIDGETS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Widgets/ButtonWidget.hpp>
|
||||
#include <NDK/Widgets/CheckboxWidget.hpp>
|
||||
#include <NDK/Widgets/Enums.hpp>
|
||||
#include <NDK/Widgets/ImageWidget.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,6 +6,89 @@
|
|||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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,31 @@
|
|||
// 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
|
||||
};
|
||||
|
||||
enum EchoMode
|
||||
{
|
||||
EchoMode_Normal,
|
||||
EchoMode_Password,
|
||||
EchoMode_PasswordExceptLast,
|
||||
|
||||
EchoMode_Max = EchoMode_PasswordExceptLast
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENUMS_SDK_HPP
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// 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_IMAGEWIDGET_HPP
|
||||
#define NDK_WIDGETS_IMAGEWIDGET_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ImageWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
ImageWidget(BaseWidget* parent = nullptr);
|
||||
ImageWidget(const ImageWidget&) = delete;
|
||||
ImageWidget(ImageWidget&&) = default;
|
||||
~ImageWidget() = default;
|
||||
|
||||
//virtual ImageWidget* Clone() const = 0;
|
||||
|
||||
void ResizeToContent() override;
|
||||
|
||||
inline const Nz::Color& GetColor() const;
|
||||
inline const Nz::TextureRef& GetTexture() const;
|
||||
inline const Nz::Rectf& GetTextureCoords() const;
|
||||
|
||||
inline void SetColor(const Nz::Color& color);
|
||||
inline void SetTexture(const Nz::TextureRef& texture, bool resizeToContent = true);
|
||||
inline void SetTextureCoords(const Nz::Rectf& coords);
|
||||
inline void SetTextureRect(const Nz::Rectui& rect);
|
||||
|
||||
ImageWidget& operator=(const ImageWidget&) = delete;
|
||||
ImageWidget& operator=(ImageWidget&&) = default;
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
Ndk::EntityHandle m_entity;
|
||||
Nz::SpriteRef m_sprite;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Widgets/ImageWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_IMAGEWIDGET_HPP
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
// 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/ImageWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline const Nz::Color& ImageWidget::GetColor() const
|
||||
{
|
||||
return m_sprite->GetColor();
|
||||
}
|
||||
|
||||
inline const Nz::TextureRef& ImageWidget::GetTexture() const
|
||||
{
|
||||
return m_sprite->GetMaterial()->GetDiffuseMap();
|
||||
}
|
||||
|
||||
inline const Nz::Rectf& ImageWidget::GetTextureCoords() const
|
||||
{
|
||||
return m_sprite->GetTextureCoords();
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetColor(const Nz::Color& color)
|
||||
{
|
||||
m_sprite->SetColor(color);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTexture(const Nz::TextureRef& texture, bool resizeToContent)
|
||||
{
|
||||
m_sprite->SetTexture(texture, false);
|
||||
|
||||
if (resizeToContent)
|
||||
ResizeToContent();
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureCoords(const Nz::Rectf& coords)
|
||||
{
|
||||
m_sprite->SetTextureCoords(coords);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureRect(const Nz::Rectui& rect)
|
||||
{
|
||||
m_sprite->SetTextureRect(rect);
|
||||
}
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,15 +7,13 @@
|
|||
#ifndef NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||
#define NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <NDK/Widgets/Enums.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class World;
|
||||
|
||||
class NDK_API TextAreaWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
|
|
@ -32,9 +30,11 @@ namespace Ndk
|
|||
|
||||
inline void EnableMultiline(bool enable = true);
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const Nz::Vector2ui& GetCursorPosition() const;
|
||||
inline std::size_t GetGlyphUnderCursor() const;
|
||||
inline std::size_t GetLineCount() const;
|
||||
inline const Nz::String& GetDisplayText() const;
|
||||
inline EchoMode GetEchoMode() const;
|
||||
inline std::size_t GetGlyphIndex(const Nz::Vector2ui& cursorPosition);
|
||||
inline const Nz::String& GetText() const;
|
||||
inline const Nz::Color& GetTextColor() const;
|
||||
|
||||
|
|
@ -48,8 +48,10 @@ namespace Ndk
|
|||
|
||||
void ResizeToContent() override;
|
||||
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
inline void SetCursorPosition(std::size_t glyphIndex);
|
||||
inline void SetCursorPosition(Nz::Vector2ui cursorPosition);
|
||||
inline void SetEchoMode(EchoMode echoMode);
|
||||
inline void SetReadOnly(bool readOnly = true);
|
||||
inline void SetText(const Nz::String& text);
|
||||
inline void SetTextColor(const Nz::Color& text);
|
||||
|
|
@ -66,27 +68,30 @@ namespace Ndk
|
|||
NazaraSignal(OnTextAreaKeyReturn, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyRight, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyUp, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextChanged, const TextAreaWidget* /*textArea*/, const Nz::String& /*text*/);
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
|
||||
bool IsFocusable() const override;
|
||||
void OnFocusLost() override;
|
||||
void OnFocusReceived() override;
|
||||
bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
|
||||
void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override;
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
|
||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||
void OnMouseExit() override;
|
||||
void OnTextEntered(char32_t character, bool repeated) override;
|
||||
|
||||
void RefreshCursor();
|
||||
void UpdateDisplayText();
|
||||
|
||||
EchoMode m_echoMode;
|
||||
EntityHandle m_cursorEntity;
|
||||
EntityHandle m_textEntity;
|
||||
Nz::SimpleTextDrawer m_drawer;
|
||||
Nz::SpriteRef m_cursorSprite;
|
||||
Nz::String m_text;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
Nz::Vector2ui m_cursorPosition;
|
||||
std::size_t m_cursorGlyph;
|
||||
bool m_multiLineEnabled;
|
||||
bool m_readOnly;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Ndk
|
|||
{
|
||||
inline void TextAreaWidget::Clear()
|
||||
{
|
||||
m_cursorPosition = 0;
|
||||
m_cursorPosition.MakeZero();
|
||||
m_drawer.Clear();
|
||||
m_textSprite->Update(m_drawer);
|
||||
|
||||
|
|
@ -20,24 +20,40 @@ namespace Ndk
|
|||
m_multiLineEnabled = enable;
|
||||
}
|
||||
|
||||
inline unsigned int TextAreaWidget::GetCharacterSize() const
|
||||
{
|
||||
return m_drawer.GetCharacterSize();
|
||||
}
|
||||
|
||||
inline const Nz::Vector2ui& TextAreaWidget::GetCursorPosition() const
|
||||
{
|
||||
return m_cursorPosition;
|
||||
}
|
||||
|
||||
inline std::size_t Ndk::TextAreaWidget::GetGlyphUnderCursor() const
|
||||
inline const Nz::String& TextAreaWidget::GetDisplayText() const
|
||||
{
|
||||
return m_cursorGlyph;
|
||||
return m_drawer.GetText();
|
||||
}
|
||||
|
||||
inline std::size_t TextAreaWidget::GetLineCount() const
|
||||
inline std::size_t TextAreaWidget::GetGlyphIndex(const Nz::Vector2ui& cursorPosition)
|
||||
{
|
||||
return m_drawer.GetLineCount();
|
||||
std::size_t glyphIndex = m_drawer.GetLine(cursorPosition.y).glyphIndex + cursorPosition.x;
|
||||
if (m_drawer.GetLineCount() > cursorPosition.y + 1)
|
||||
glyphIndex = std::min(glyphIndex, m_drawer.GetLine(cursorPosition.y + 1).glyphIndex - 1);
|
||||
else
|
||||
glyphIndex = std::min(glyphIndex, m_drawer.GetGlyphCount());
|
||||
|
||||
return glyphIndex;
|
||||
}
|
||||
|
||||
inline EchoMode TextAreaWidget::GetEchoMode() const
|
||||
{
|
||||
return m_echoMode;
|
||||
}
|
||||
|
||||
inline const Nz::String& TextAreaWidget::GetText() const
|
||||
{
|
||||
return m_drawer.GetText();
|
||||
return m_text;
|
||||
}
|
||||
|
||||
inline const Nz::Color& TextAreaWidget::GetTextColor() const
|
||||
|
|
@ -57,27 +73,28 @@ namespace Ndk
|
|||
|
||||
inline void TextAreaWidget::MoveCursor(int offset)
|
||||
{
|
||||
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPosition);
|
||||
if (offset >= 0)
|
||||
SetCursorPosition(m_cursorGlyph + static_cast<std::size_t>(offset));
|
||||
SetCursorPosition(cursorGlyph + static_cast<std::size_t>(offset));
|
||||
else
|
||||
{
|
||||
std::size_t nOffset = static_cast<std::size_t>(-offset);
|
||||
if (nOffset >= m_cursorGlyph)
|
||||
if (nOffset >= cursorGlyph)
|
||||
SetCursorPosition(0);
|
||||
else
|
||||
SetCursorPosition(m_cursorGlyph - nOffset);
|
||||
SetCursorPosition(cursorGlyph - nOffset);
|
||||
}
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::MoveCursor(const Nz::Vector2i& offset)
|
||||
{
|
||||
auto BoundOffset = [] (unsigned int cursorPosition, int offset) -> unsigned int
|
||||
auto ClampOffset = [] (unsigned int cursorPosition, int cursorOffset) -> unsigned int
|
||||
{
|
||||
if (offset >= 0)
|
||||
return cursorPosition + offset;
|
||||
if (cursorOffset >= 0)
|
||||
return cursorPosition + cursorOffset;
|
||||
else
|
||||
{
|
||||
unsigned int nOffset = static_cast<unsigned int>(-offset);
|
||||
unsigned int nOffset = static_cast<unsigned int>(-cursorOffset);
|
||||
if (nOffset >= cursorPosition)
|
||||
return 0;
|
||||
else
|
||||
|
|
@ -86,23 +103,28 @@ namespace Ndk
|
|||
};
|
||||
|
||||
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);
|
||||
cursorPosition.x = ClampOffset(static_cast<unsigned int>(cursorPosition.x), offset.x);
|
||||
cursorPosition.y = ClampOffset(static_cast<unsigned int>(cursorPosition.y), offset.y);
|
||||
|
||||
SetCursorPosition(cursorPosition);
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
m_drawer.SetCharacterSize(characterSize);
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCursorPosition(std::size_t glyphIndex)
|
||||
{
|
||||
OnTextAreaCursorMove(this, &glyphIndex);
|
||||
|
||||
m_cursorGlyph = std::min(glyphIndex, m_drawer.GetGlyphCount());
|
||||
|
||||
glyphIndex = 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)
|
||||
if (m_drawer.GetLine(i).glyphIndex > glyphIndex)
|
||||
break;
|
||||
|
||||
line = i;
|
||||
|
|
@ -110,8 +132,8 @@ namespace Ndk
|
|||
|
||||
const auto& lineInfo = m_drawer.GetLine(line);
|
||||
|
||||
m_cursorPosition.y = line;
|
||||
m_cursorPosition.x = m_cursorGlyph - lineInfo.glyphIndex;
|
||||
m_cursorPosition.y = static_cast<unsigned int>(line);
|
||||
m_cursorPosition.x = static_cast<unsigned int>(glyphIndex - lineInfo.glyphIndex);
|
||||
|
||||
RefreshCursor();
|
||||
}
|
||||
|
|
@ -135,25 +157,28 @@ namespace Ndk
|
|||
|
||||
OnTextAreaCursorMove(this, &glyphIndex);
|
||||
|
||||
m_cursorGlyph = std::min(glyphIndex, m_drawer.GetGlyphCount());
|
||||
|
||||
RefreshCursor();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetEchoMode(EchoMode echoMode)
|
||||
{
|
||||
m_echoMode = echoMode;
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetReadOnly(bool readOnly)
|
||||
{
|
||||
m_readOnly = readOnly;
|
||||
|
||||
m_cursorEntity->Enable(!m_readOnly);
|
||||
m_cursorEntity->Enable(!m_readOnly && HasFocus());
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetText(const Nz::String& text)
|
||||
{
|
||||
m_drawer.SetText(text);
|
||||
m_text = text;
|
||||
OnTextChanged(this, m_text);
|
||||
|
||||
m_textSprite->Update(m_drawer);
|
||||
|
||||
SetCursorPosition(m_cursorPosition); //< Refresh cursor position (prevent it from being outside of the text)
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextColor(const Nz::Color& text)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ namespace Ndk
|
|||
*
|
||||
* \param id Identifier of the entity
|
||||
*
|
||||
* \remark Handle referenced by this function can move in memory when updating the world, do not keep a reference to a handle from a world update to another
|
||||
* \remark Handle referenced by this function can move in memory when updating the world, do not keep a handle reference from a world update to another
|
||||
* \remark If an invalid identifier is provided, an error got triggered and an invalid handle is returned
|
||||
*/
|
||||
inline const EntityHandle& World::GetEntity(EntityId id)
|
||||
|
|
@ -306,15 +306,19 @@ namespace Ndk
|
|||
m_killedEntities = std::move(world.m_killedEntities);
|
||||
m_orderedSystems = std::move(world.m_orderedSystems);
|
||||
m_orderedSystemsUpdated = world.m_orderedSystemsUpdated;
|
||||
m_waitingEntities = std::move(world.m_waitingEntities);
|
||||
|
||||
m_entities = std::move(world.m_entities);
|
||||
for (EntityBlock& block : m_entities)
|
||||
block.entity.SetWorld(this);
|
||||
|
||||
m_waitingEntities = std::move(world.m_waitingEntities);
|
||||
for (auto& blockPtr : m_waitingEntities)
|
||||
blockPtr->entity.SetWorld(this);
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -147,7 +148,10 @@ namespace Ndk
|
|||
|
||||
Nz::Vector2ui windowDimensions;
|
||||
if (info.window->IsValid())
|
||||
windowDimensions.Set(info.window->GetWidth(), info.window->GetHeight() / 4);
|
||||
{
|
||||
windowDimensions = info.window->GetSize();
|
||||
windowDimensions.y /= 4;
|
||||
}
|
||||
else
|
||||
windowDimensions.MakeZero();
|
||||
|
||||
|
|
@ -211,7 +215,8 @@ namespace Ndk
|
|||
|
||||
overlay->resizedSlot.Connect(info.renderTarget->OnRenderTargetSizeChange, [&consoleRef] (const Nz::RenderTarget* renderTarget)
|
||||
{
|
||||
consoleRef.SetSize({float(renderTarget->GetWidth()), renderTarget->GetHeight() / 4.f});
|
||||
Nz::Vector2ui size = renderTarget->GetSize();
|
||||
consoleRef.SetSize({float(size.x), size.y / 4.f});
|
||||
});
|
||||
|
||||
info.console = std::move(overlay);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,15 @@ namespace Ndk
|
|||
UnregisterFromCanvas();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears keyboard focus if and only if this widget owns it.
|
||||
*/
|
||||
void BaseWidget::ClearFocus()
|
||||
{
|
||||
if (IsRegisteredToCanvas())
|
||||
m_canvas->ClearKeyboardOwner(m_canvasIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroy the widget, deleting it in the process.
|
||||
*
|
||||
|
|
@ -70,7 +79,7 @@ namespace Ndk
|
|||
{
|
||||
m_backgroundSprite = Nz::Sprite::New();
|
||||
m_backgroundSprite->SetColor(m_backgroundColor);
|
||||
m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D"));
|
||||
m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D")); //< TODO: Use a shared material instead of creating one everytime
|
||||
|
||||
m_backgroundEntity = CreateEntity();
|
||||
m_backgroundEntity->AddComponent<GraphicsComponent>().Attach(m_backgroundSprite, -1);
|
||||
|
|
@ -85,9 +94,16 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
void BaseWidget::GrabKeyboard()
|
||||
/*!
|
||||
* \brief Checks if this widget has keyboard focus
|
||||
* \return true if widget has keyboard focus, false otherwhise
|
||||
*/
|
||||
bool BaseWidget::HasFocus() const
|
||||
{
|
||||
m_canvas->SetKeyboardOwner(this);
|
||||
if (!IsRegisteredToCanvas())
|
||||
return false;
|
||||
|
||||
return m_canvas->IsKeyboardOwner(m_canvasIndex);
|
||||
}
|
||||
|
||||
void BaseWidget::SetBackgroundColor(const Nz::Color& color)
|
||||
|
|
@ -109,6 +125,12 @@ namespace Ndk
|
|||
m_canvas->NotifyWidgetCursorUpdate(m_canvasIndex);
|
||||
}
|
||||
|
||||
void BaseWidget::SetFocus()
|
||||
{
|
||||
if (IsRegisteredToCanvas())
|
||||
m_canvas->SetKeyboardOwner(m_canvasIndex);
|
||||
}
|
||||
|
||||
void BaseWidget::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
SetContentSize({std::max(size.x - m_padding.left - m_padding.right, 0.f), std::max(size.y - m_padding.top - m_padding.bottom, 0.f)});
|
||||
|
|
@ -133,9 +155,9 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
EntityHandle BaseWidget::CreateEntity()
|
||||
const Ndk::EntityHandle& BaseWidget::CreateEntity()
|
||||
{
|
||||
EntityHandle newEntity = m_world->CreateEntity();
|
||||
const EntityHandle& newEntity = m_world->CreateEntity();
|
||||
newEntity->Enable(m_visible);
|
||||
|
||||
m_entities.emplace_back(newEntity);
|
||||
|
|
@ -167,8 +189,22 @@ namespace Ndk
|
|||
m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex);
|
||||
}
|
||||
|
||||
void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& /*key*/)
|
||||
bool BaseWidget::IsFocusable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void BaseWidget::OnFocusLost()
|
||||
{
|
||||
}
|
||||
|
||||
void BaseWidget::OnFocusReceived()
|
||||
{
|
||||
}
|
||||
|
||||
bool BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void BaseWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& /*key*/)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -16,12 +13,12 @@ namespace Ndk
|
|||
|
||||
std::size_t Canvas::RegisterWidget(BaseWidget* widget)
|
||||
{
|
||||
WidgetBox box;
|
||||
WidgetEntry box;
|
||||
box.cursor = widget->GetCursor();
|
||||
box.widget = widget;
|
||||
|
||||
std::size_t index = m_widgetBoxes.size();
|
||||
m_widgetBoxes.emplace_back(box);
|
||||
std::size_t index = m_widgetEntries.size();
|
||||
m_widgetEntries.emplace_back(box);
|
||||
|
||||
NotifyWidgetBoxUpdate(index);
|
||||
return index;
|
||||
|
|
@ -29,91 +26,106 @@ namespace Ndk
|
|||
|
||||
void Canvas::UnregisterWidget(std::size_t index)
|
||||
{
|
||||
WidgetBox& entry = m_widgetBoxes[index];
|
||||
WidgetEntry& entry = m_widgetEntries[index];
|
||||
|
||||
if (m_hoveredWidget == &entry)
|
||||
m_hoveredWidget = nullptr;
|
||||
if (m_hoveredWidget == index)
|
||||
m_hoveredWidget = InvalidCanvasIndex;
|
||||
|
||||
if (m_keyboardOwner == entry.widget)
|
||||
m_keyboardOwner = nullptr;
|
||||
if (m_keyboardOwner == index)
|
||||
m_keyboardOwner = InvalidCanvasIndex;
|
||||
|
||||
if (m_widgetBoxes.size() > 1U)
|
||||
if (m_widgetEntries.size() > 1U)
|
||||
{
|
||||
WidgetBox& lastEntry = m_widgetBoxes.back();
|
||||
WidgetEntry& lastEntry = m_widgetEntries.back();
|
||||
std::size_t lastEntryIndex = m_widgetEntries.size() - 1;
|
||||
|
||||
entry = std::move(lastEntry);
|
||||
entry.widget->UpdateCanvasIndex(index);
|
||||
|
||||
if (m_hoveredWidget == lastEntryIndex)
|
||||
m_hoveredWidget = index;
|
||||
|
||||
if (m_keyboardOwner == lastEntryIndex)
|
||||
m_keyboardOwner = index;
|
||||
}
|
||||
|
||||
m_widgetBoxes.pop_back();
|
||||
m_widgetEntries.pop_back();
|
||||
}
|
||||
|
||||
void Canvas::OnEventMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
|
||||
{
|
||||
if (m_hoveredWidget)
|
||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||
{
|
||||
int x = static_cast<int>(std::round(event.x - m_hoveredWidget->box.x));
|
||||
int y = static_cast<int>(std::round(event.y - m_hoveredWidget->box.y));
|
||||
WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget];
|
||||
|
||||
m_hoveredWidget->widget->OnMouseButtonPress(x, y, event.button);
|
||||
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
||||
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
||||
|
||||
hoveredWidget.widget->OnMouseButtonPress(x, y, event.button);
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::OnEventMouseButtonRelease(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent & event)
|
||||
{
|
||||
if (m_hoveredWidget)
|
||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||
{
|
||||
int x = static_cast<int>(std::round(event.x - m_hoveredWidget->box.x));
|
||||
int y = static_cast<int>(std::round(event.y - m_hoveredWidget->box.y));
|
||||
WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget];
|
||||
|
||||
m_hoveredWidget->widget->OnMouseButtonRelease(x, y, event.button);
|
||||
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
||||
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
||||
|
||||
hoveredWidget.widget->OnMouseButtonRelease(x, y, event.button);
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::OnEventMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||
{
|
||||
const WidgetBox* bestEntry = nullptr;
|
||||
std::size_t bestEntry = InvalidCanvasIndex;
|
||||
float bestEntryArea = std::numeric_limits<float>::infinity();
|
||||
|
||||
Nz::Vector3f mousePos(float(event.x), float(event.y), 0.f);
|
||||
for (const WidgetBox& entry : m_widgetBoxes)
|
||||
for (std::size_t i = 0; i < m_widgetEntries.size(); ++i)
|
||||
{
|
||||
const Nz::Boxf& box = entry.box;
|
||||
const Nz::Boxf& box = m_widgetEntries[i].box;
|
||||
|
||||
if (box.Contains(mousePos))
|
||||
{
|
||||
float area = box.width * box.height;
|
||||
if (area < bestEntryArea)
|
||||
{
|
||||
bestEntry = &entry;
|
||||
bestEntry = i;
|
||||
bestEntryArea = area;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestEntry)
|
||||
if (bestEntry != InvalidCanvasIndex)
|
||||
{
|
||||
if (m_hoveredWidget != bestEntry)
|
||||
{
|
||||
if (m_hoveredWidget)
|
||||
m_hoveredWidget->widget->OnMouseExit();
|
||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||
{
|
||||
WidgetEntry& previouslyHovered = m_widgetEntries[m_hoveredWidget];
|
||||
previouslyHovered.widget->OnMouseExit();
|
||||
}
|
||||
|
||||
m_hoveredWidget = bestEntry;
|
||||
m_hoveredWidget->widget->OnMouseEnter();
|
||||
m_widgetEntries[m_hoveredWidget].widget->OnMouseEnter();
|
||||
|
||||
if (m_cursorController)
|
||||
m_cursorController->UpdateCursor(Nz::Cursor::Get(m_hoveredWidget->cursor));
|
||||
m_cursorController->UpdateCursor(Nz::Cursor::Get(m_widgetEntries[m_hoveredWidget].cursor));
|
||||
}
|
||||
|
||||
int x = static_cast<int>(std::round(event.x - m_hoveredWidget->box.x));
|
||||
int y = static_cast<int>(std::round(event.y - m_hoveredWidget->box.y));
|
||||
WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget];
|
||||
|
||||
bestEntry->widget->OnMouseMoved(x, y, event.deltaX, event.deltaY);
|
||||
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
||||
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
||||
hoveredWidget.widget->OnMouseMoved(x, y, event.deltaX, event.deltaY);
|
||||
}
|
||||
else if (m_hoveredWidget)
|
||||
else if (m_hoveredWidget != InvalidCanvasIndex)
|
||||
{
|
||||
m_hoveredWidget->widget->OnMouseExit();
|
||||
m_hoveredWidget = nullptr;
|
||||
m_widgetEntries[m_hoveredWidget].widget->OnMouseExit();
|
||||
m_hoveredWidget = InvalidCanvasIndex;
|
||||
|
||||
if (m_cursorController)
|
||||
m_cursorController->UpdateCursor(Nz::Cursor::Get(Nz::SystemCursor_Default));
|
||||
|
|
@ -122,28 +134,78 @@ namespace Ndk
|
|||
|
||||
void Canvas::OnEventMouseLeft(const Nz::EventHandler* /*eventHandler*/)
|
||||
{
|
||||
if (m_hoveredWidget)
|
||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||
{
|
||||
m_hoveredWidget->widget->OnMouseExit();
|
||||
m_hoveredWidget = nullptr;
|
||||
m_widgetEntries[m_hoveredWidget].widget->OnMouseExit();
|
||||
m_hoveredWidget = InvalidCanvasIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::OnEventKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||
{
|
||||
if (m_keyboardOwner)
|
||||
m_keyboardOwner->OnKeyPressed(event);
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
{
|
||||
if (m_widgetEntries[m_keyboardOwner].widget->OnKeyPressed(event))
|
||||
return;
|
||||
|
||||
if (event.code == Nz::Keyboard::Tab)
|
||||
{
|
||||
if (!event.shift)
|
||||
{
|
||||
// Forward
|
||||
for (std::size_t i = m_keyboardOwner + 1; i < m_widgetEntries.size(); ++i)
|
||||
{
|
||||
if (m_widgetEntries[i].widget->IsFocusable())
|
||||
{
|
||||
SetKeyboardOwner(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < m_keyboardOwner; ++i)
|
||||
{
|
||||
if (m_widgetEntries[i].widget->IsFocusable())
|
||||
{
|
||||
SetKeyboardOwner(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Backward
|
||||
for (decltype(m_widgetEntries)::reverse_iterator rit{ m_widgetEntries.begin() + m_keyboardOwner }; rit != m_widgetEntries.rend(); ++rit)
|
||||
{
|
||||
if (rit->widget->IsFocusable())
|
||||
{
|
||||
SetKeyboardOwner(std::distance(m_widgetEntries.begin(), rit.base()) - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
decltype(m_widgetEntries)::reverse_iterator rend { m_widgetEntries.begin() + m_keyboardOwner };
|
||||
for (auto rit = m_widgetEntries.rbegin(); rit != rend; ++rit)
|
||||
{
|
||||
if (rit->widget->IsFocusable())
|
||||
{
|
||||
SetKeyboardOwner(std::distance(m_widgetEntries.begin(), rit.base()) - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::OnEventKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||
{
|
||||
if (m_keyboardOwner)
|
||||
m_keyboardOwner->OnKeyReleased(event);
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnKeyReleased(event);
|
||||
}
|
||||
|
||||
void Canvas::OnEventTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event)
|
||||
{
|
||||
if (m_keyboardOwner)
|
||||
m_keyboardOwner->OnTextEntered(event.character, event.repeated);
|
||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||
m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,15 +334,15 @@ namespace Ndk
|
|||
{
|
||||
NazaraAssert(m_target, "CameraComponent has no target");
|
||||
|
||||
unsigned int targetWidth = m_target->GetWidth();
|
||||
unsigned int targetHeight = std::max(m_target->GetHeight(), 1U); // Let's make sure we won't divide by zero
|
||||
Nz::Vector2ui targetSize = m_target->GetSize();
|
||||
targetSize.y = std::max(targetSize.y, 1U); // Let's make sure we won't divide by zero
|
||||
|
||||
// Our target region is expressed as % of the viewport dimensions, let's compute it in pixels
|
||||
Nz::Rectf fViewport(m_targetRegion);
|
||||
fViewport.x *= targetWidth;
|
||||
fViewport.y *= targetHeight;
|
||||
fViewport.width *= targetWidth;
|
||||
fViewport.height *= targetHeight;
|
||||
fViewport.x *= targetSize.x;
|
||||
fViewport.y *= targetSize.y;
|
||||
fViewport.width *= targetSize.x;
|
||||
fViewport.height *= targetSize.y;
|
||||
|
||||
// Compute the new aspect ratio, if it's different we need to invalidate the projection matrix
|
||||
float aspectRatio = fViewport.width/fViewport.height;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -39,17 +39,6 @@ namespace Ndk
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Attaches a renderable to the entity
|
||||
*
|
||||
* \param renderable Reference to a renderable element
|
||||
* \param renderOrder Render order of the element
|
||||
*/
|
||||
void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder)
|
||||
{
|
||||
return Attach(renderable, Nz::Matrix4f::Identity(), renderOrder);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Attaches a renderable to the entity with a specific matrix
|
||||
*
|
||||
|
|
@ -60,26 +49,29 @@ namespace Ndk
|
|||
void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder)
|
||||
{
|
||||
m_renderables.emplace_back(m_transformMatrix);
|
||||
Renderable& r = m_renderables.back();
|
||||
r.data.localMatrix = localMatrix;
|
||||
r.data.renderOrder = renderOrder;
|
||||
r.renderable = std::move(renderable);
|
||||
r.renderableBoundingVolumeInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateBoundingVolume, [this] (const Nz::InstancedRenderable*) { InvalidateBoundingVolume(); });
|
||||
r.renderableDataInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size() - 1));
|
||||
r.renderableReleaseSlot.Connect(r.renderable->OnInstancedRenderableRelease, this, &GraphicsComponent::Detach);
|
||||
Renderable& entry = m_renderables.back();
|
||||
entry.data.localMatrix = localMatrix;
|
||||
entry.data.renderOrder = renderOrder;
|
||||
entry.renderable = std::move(renderable);
|
||||
|
||||
ConnectInstancedRenderableSignals(entry);
|
||||
|
||||
std::size_t materialCount = entry.renderable->GetMaterialCount();
|
||||
for (std::size_t i = 0; i < materialCount; ++i)
|
||||
RegisterMaterial(entry.renderable->GetMaterial(i));
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates the data for renderable
|
||||
*
|
||||
* \param renderable Renderable to invalidate
|
||||
* \param flags Flags for the instance
|
||||
* \param index Index of the renderable to invalidate
|
||||
*
|
||||
* \remark Produces a NazaraAssert if index is out of bound
|
||||
*/
|
||||
void GraphicsComponent::ConnectInstancedRenderableSignals(Renderable& entry)
|
||||
{
|
||||
entry.renderableBoundingVolumeInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateBoundingVolume, [this](const Nz::InstancedRenderable*) { InvalidateBoundingVolume(); });
|
||||
entry.renderableDataInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size() - 1));
|
||||
entry.renderableMaterialInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateMaterial, this, &GraphicsComponent::InvalidateRenderableMaterial);
|
||||
entry.renderableReleaseSlot.Connect(entry.renderable->OnInstancedRenderableRelease, this, &GraphicsComponent::Detach);
|
||||
entry.renderableResetMaterialsSlot.Connect(entry.renderable->OnInstancedRenderableResetMaterials, this, &GraphicsComponent::OnInstancedRenderableResetMaterials);
|
||||
entry.renderableSkinChangeSlot.Connect(entry.renderable->OnInstancedRenderableSkinChange, this, &GraphicsComponent::OnInstancedRenderableSkinChange);
|
||||
}
|
||||
|
||||
void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable , Nz::UInt32 flags, std::size_t index)
|
||||
{
|
||||
|
|
@ -94,6 +86,59 @@ namespace Ndk
|
|||
entry.listEntry.ForceInvalidation();
|
||||
}
|
||||
|
||||
void GraphicsComponent::InvalidateRenderableMaterial(const Nz::InstancedRenderable* renderable, std::size_t skinIndex, std::size_t matIndex, const Nz::MaterialRef& newMat)
|
||||
{
|
||||
// Don't listen to dormant materials
|
||||
if (renderable->GetSkin() != skinIndex)
|
||||
return;
|
||||
|
||||
RegisterMaterial(newMat);
|
||||
|
||||
const Nz::MaterialRef& oldMat = renderable->GetMaterial(skinIndex, matIndex);
|
||||
UnregisterMaterial(oldMat);
|
||||
}
|
||||
|
||||
void Ndk::GraphicsComponent::InvalidateReflectionMap()
|
||||
{
|
||||
m_entity->Invalidate();
|
||||
|
||||
if (m_reflectiveMaterialCount > 0)
|
||||
{
|
||||
if (!m_reflectionMap)
|
||||
{
|
||||
m_reflectionMap = Nz::Texture::New();
|
||||
if (!m_reflectionMap->Create(Nz::ImageType_Cubemap, Nz::PixelFormatType_RGB8, m_reflectionMapSize, m_reflectionMapSize))
|
||||
{
|
||||
NazaraWarning("Failed to create reflection map, reflections will be disabled for this entity");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
m_reflectionMap.Reset();
|
||||
}
|
||||
|
||||
void GraphicsComponent::RegisterMaterial(Nz::Material* material, std::size_t count)
|
||||
{
|
||||
auto it = m_materialEntries.find(material);
|
||||
if (it == m_materialEntries.end())
|
||||
{
|
||||
MaterialEntry matEntry;
|
||||
matEntry.reflectionModelChangeSlot.Connect(material->OnMaterialReflectionModeChange, this, &GraphicsComponent::OnMaterialReflectionChange);
|
||||
matEntry.renderableCounter = count;
|
||||
|
||||
if (material->GetReflectionMode() == Nz::ReflectionMode_RealTime)
|
||||
{
|
||||
if (m_reflectiveMaterialCount++ == 0)
|
||||
InvalidateReflectionMap();
|
||||
}
|
||||
|
||||
m_materialEntries.emplace(material, std::move(matEntry));
|
||||
}
|
||||
else
|
||||
it->second.renderableCounter += count;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operation to perform when component is attached to an entity
|
||||
*/
|
||||
|
|
@ -150,11 +195,39 @@ namespace Ndk
|
|||
InvalidateTransformMatrix();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operation to perform when the node is invalidated
|
||||
*
|
||||
* \param node Pointer to the node
|
||||
*/
|
||||
void GraphicsComponent::OnInstancedRenderableResetMaterials(const Nz::InstancedRenderable* renderable, std::size_t newMaterialCount)
|
||||
{
|
||||
RegisterMaterial(Nz::Material::GetDefault(), newMaterialCount);
|
||||
|
||||
std::size_t materialCount = renderable->GetMaterialCount();
|
||||
for (std::size_t i = 0; i < materialCount; ++i)
|
||||
UnregisterMaterial(renderable->GetMaterial(i));
|
||||
}
|
||||
|
||||
void GraphicsComponent::OnInstancedRenderableSkinChange(const Nz::InstancedRenderable* renderable, std::size_t newSkinIndex)
|
||||
{
|
||||
std::size_t materialCount = renderable->GetMaterialCount();
|
||||
for (std::size_t i = 0; i < materialCount; ++i)
|
||||
RegisterMaterial(renderable->GetMaterial(newSkinIndex, i));
|
||||
|
||||
for (std::size_t i = 0; i < materialCount; ++i)
|
||||
UnregisterMaterial(renderable->GetMaterial(i));
|
||||
}
|
||||
|
||||
void GraphicsComponent::OnMaterialReflectionChange(const Nz::Material* material, Nz::ReflectionMode reflectionMode)
|
||||
{
|
||||
// Since this signal is only called when the new reflection mode is different from the current one, no need to compare both
|
||||
if (material->GetReflectionMode() == Nz::ReflectionMode_RealTime)
|
||||
{
|
||||
if (--m_reflectiveMaterialCount == 0)
|
||||
InvalidateReflectionMap();
|
||||
}
|
||||
else if (reflectionMode == Nz::ReflectionMode_RealTime)
|
||||
{
|
||||
if (m_reflectiveMaterialCount++ == 0)
|
||||
InvalidateReflectionMap();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsComponent::OnNodeInvalidated(const Nz::Node* node)
|
||||
{
|
||||
|
|
@ -168,6 +241,24 @@ namespace Ndk
|
|||
entry.listEntry.ForceInvalidation(); //< Force invalidation on movement
|
||||
}
|
||||
|
||||
void GraphicsComponent::UnregisterMaterial(Nz::Material* material)
|
||||
{
|
||||
auto it = m_materialEntries.find(material);
|
||||
NazaraAssert(it != m_materialEntries.end(), "Material not registered");
|
||||
|
||||
MaterialEntry& matEntry = it->second;
|
||||
if (--matEntry.renderableCounter == 0)
|
||||
{
|
||||
if (material->GetReflectionMode() == Nz::ReflectionMode_RealTime)
|
||||
{
|
||||
if (--m_reflectiveMaterialCount == 0)
|
||||
InvalidateReflectionMap();
|
||||
}
|
||||
|
||||
m_materialEntries.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Updates the bounding volume
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace Ndk
|
|||
|
||||
Entity::~Entity()
|
||||
{
|
||||
if (m_world)
|
||||
if (m_world && m_valid)
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 << ')';
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,40 @@ namespace Ndk
|
|||
/*********************************** Nz::InstancedRenderable ***********************************/
|
||||
instancedRenderable.Reset("InstancedRenderable");
|
||||
{
|
||||
instancedRenderable.BindMethod("GetMaterial", [] (Nz::LuaState& lua, Nz::InstancedRenderable* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
{
|
||||
int argIndex = 2;
|
||||
std::size_t matIndex(lua.Check<std::size_t>(&argIndex, 0));
|
||||
|
||||
return lua.Push(instance->GetMaterial(matIndex));
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
int argIndex = 2;
|
||||
std::size_t skinIndex(lua.Check<std::size_t>(&argIndex));
|
||||
std::size_t matIndex(lua.Check<std::size_t>(&argIndex));
|
||||
|
||||
return lua.Push(instance->GetMaterial(skinIndex, matIndex));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMaterial");
|
||||
return 0;
|
||||
});
|
||||
|
||||
instancedRenderable.BindMethod("GetMaterialCount", &Nz::InstancedRenderable::GetMaterialCount);
|
||||
instancedRenderable.BindMethod("GetSkin", &Nz::InstancedRenderable::GetSkin);
|
||||
instancedRenderable.BindMethod("GetSkinCount", &Nz::InstancedRenderable::GetSkinCount);
|
||||
|
||||
instancedRenderable.BindMethod("SetSkin", &Nz::InstancedRenderable::SetSkin);
|
||||
instancedRenderable.BindMethod("SetSkinCount", &Nz::InstancedRenderable::SetSkinCount);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Material ***********************************/
|
||||
|
|
@ -92,6 +126,7 @@ namespace Ndk
|
|||
material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting);
|
||||
material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite);
|
||||
material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling);
|
||||
material.BindMethod("EnableReflectionMapping", &Nz::Material::EnableReflectionMapping);
|
||||
material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest);
|
||||
material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting);
|
||||
material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive);
|
||||
|
|
@ -117,6 +152,7 @@ namespace Ndk
|
|||
//material.BindMethod("GetPipeline", &Nz::Material::GetPipeline);
|
||||
//material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo);
|
||||
material.BindMethod("GetPointSize", &Nz::Material::GetPointSize);
|
||||
material.BindMethod("GetReflectionMode", &Nz::Material::GetReflectionMode);
|
||||
//material.BindMethod("GetShader", &Nz::Material::GetShader);
|
||||
material.BindMethod("GetShininess", &Nz::Material::GetShininess);
|
||||
material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor);
|
||||
|
|
@ -139,6 +175,7 @@ namespace Ndk
|
|||
material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled);
|
||||
material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled);
|
||||
material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled);
|
||||
material.BindMethod("IsReflectionMappingEnabled", &Nz::Material::IsReflectionMappingEnabled);
|
||||
material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled);
|
||||
material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled);
|
||||
material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled);
|
||||
|
|
@ -160,6 +197,7 @@ namespace Ndk
|
|||
material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling);
|
||||
material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth);
|
||||
material.BindMethod("SetPointSize", &Nz::Material::SetPointSize);
|
||||
material.BindMethod("SetReflectionMode", &Nz::Material::SetReflectionMode);
|
||||
material.BindMethod("SetShininess", &Nz::Material::SetShininess);
|
||||
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
||||
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
||||
|
|
@ -267,22 +305,72 @@ namespace Ndk
|
|||
return true;
|
||||
});
|
||||
|
||||
//model.BindMethod("GetMaterial", &Nz::Model::GetMaterial);
|
||||
model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
||||
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
||||
model.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
||||
model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
||||
|
||||
model.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
||||
model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
||||
|
||||
model.BindMethod("Reset", &Nz::Model::Reset);
|
||||
|
||||
//model.BindMethod("SetMaterial", &Nz::Model::SetMaterial);
|
||||
model.BindMethod("SetMaterial", [] (Nz::LuaState& lua, Nz::Model* instance, std::size_t argumentCount) -> int
|
||||
{
|
||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
std::size_t matIndex(lua.Check<std::size_t>(&argIndex));
|
||||
Nz::MaterialRef mat(lua.Check<Nz::MaterialRef>(&argIndex));
|
||||
|
||||
instance->SetMaterial(matIndex, std::move(mat));
|
||||
return 0;
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, Nz::LuaType_String))
|
||||
{
|
||||
Nz::String subMesh(lua.Check<Nz::String>(&argIndex));
|
||||
Nz::MaterialRef mat(lua.Check<Nz::MaterialRef>(&argIndex));
|
||||
|
||||
instance->SetMaterial(subMesh, std::move(mat));
|
||||
return 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
int argIndex = 2;
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
std::size_t skinIndex(lua.Check<std::size_t>(&argIndex));
|
||||
std::size_t matIndex(lua.Check<std::size_t>(&argIndex));
|
||||
Nz::MaterialRef mat(lua.Check<Nz::MaterialRef>(&argIndex));
|
||||
|
||||
instance->SetMaterial(skinIndex, matIndex, std::move(mat));
|
||||
return 0;
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, Nz::LuaType_String))
|
||||
{
|
||||
std::size_t skinIndex(lua.Check<std::size_t>(&argIndex));
|
||||
Nz::String subMesh(lua.Check<Nz::String>(&argIndex));
|
||||
Nz::MaterialRef materialRef(lua.Check<Nz::MaterialRef>(&argIndex));
|
||||
|
||||
instance->SetMaterial(skinIndex, subMesh, std::move(materialRef));
|
||||
return 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetMaterial");
|
||||
return 0;
|
||||
});
|
||||
|
||||
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
||||
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||
model.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
||||
model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||
}
|
||||
|
||||
/*********************************** Nz::Sprite ***********************************/
|
||||
|
|
@ -301,7 +389,6 @@ namespace Ndk
|
|||
|
||||
sprite.BindMethod("GetColor", &Nz::Sprite::GetColor);
|
||||
sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor);
|
||||
sprite.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial);
|
||||
sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin);
|
||||
sprite.BindMethod("GetSize", &Nz::Sprite::GetSize);
|
||||
sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords);
|
||||
|
|
@ -317,12 +404,28 @@ namespace Ndk
|
|||
sprite.BindMethod("SetMaterial", [] (Nz::LuaState& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
if (lua.IsOfType(argIndex, "Material"))
|
||||
{
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
instance->SetMaterial(*static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetMaterial(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, Nz::LuaType_String))
|
||||
{
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
instance->SetMaterial(lua.ToString(argIndex), resizeSprite);
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
std::size_t skinIndex(lua.Check<std::size_t>(&argIndex));
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
if (lua.IsOfType(argIndex, "Material"))
|
||||
instance->SetMaterial(skinIndex, *static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetMaterial(skinIndex, lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
|
@ -330,12 +433,28 @@ namespace Ndk
|
|||
sprite.BindMethod("SetTexture", [] (Nz::LuaState& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
int argIndex = 2;
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
{
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
instance->SetTexture(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetTexture(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, Nz::LuaType_String))
|
||||
{
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
instance->SetTexture(lua.ToString(argIndex), resizeSprite);
|
||||
}
|
||||
else if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
std::size_t skinIndex(lua.Check<std::size_t>(&argIndex));
|
||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||
|
||||
if (lua.IsOfType(argIndex, "Texture"))
|
||||
instance->SetTexture(skinIndex, *static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||
else
|
||||
instance->SetTexture(skinIndex, lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
|
@ -366,5 +485,15 @@ namespace Ndk
|
|||
model.Register(state);
|
||||
sprite.Register(state);
|
||||
spriteLibrary.Register(state);
|
||||
|
||||
// Nz::ReflectionMode
|
||||
static_assert(Nz::ReflectionMode_Max + 1 == 3, "Nz::ReflectionMode has been updated but change was not reflected to Lua binding");
|
||||
state.PushTable(0, 3);
|
||||
{
|
||||
state.PushField("Probe", Nz::ReflectionMode_Probe);
|
||||
state.PushField("RealTime", Nz::ReflectionMode_RealTime);
|
||||
state.PushField("Skybox", Nz::ReflectionMode_Skybox);
|
||||
}
|
||||
state.SetGlobal("ReflectionMode");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2017 Jérôme Leclercq, Arnaud Cadot
|
||||
// Copyright (C) 2017 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,18 +31,6 @@ namespace Ndk
|
|||
Excludes<PhysicsComponent3D>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a PhysicsSystem object by copy semantic
|
||||
*
|
||||
* \param system PhysicsSystem to copy
|
||||
*/
|
||||
|
||||
PhysicsSystem2D::PhysicsSystem2D(const PhysicsSystem2D& system) :
|
||||
System(system),
|
||||
m_world()
|
||||
{
|
||||
}
|
||||
|
||||
void PhysicsSystem2D::CreatePhysWorld() const
|
||||
{
|
||||
NazaraAssert(!m_world, "Physics world should not be created twice");
|
||||
|
|
|
|||
|
|
@ -31,18 +31,6 @@ namespace Ndk
|
|||
Excludes<PhysicsComponent2D>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a PhysicsSystem object by copy semantic
|
||||
*
|
||||
* \param system PhysicsSystem to copy
|
||||
*/
|
||||
|
||||
PhysicsSystem3D::PhysicsSystem3D(const PhysicsSystem3D& system) :
|
||||
System(system),
|
||||
m_world()
|
||||
{
|
||||
}
|
||||
|
||||
void PhysicsSystem3D::CreatePhysWorld() const
|
||||
{
|
||||
NazaraAssert(!m_world, "Physics world should not be created twice");
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
#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>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
|
|
@ -36,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
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -98,15 +101,19 @@ namespace Ndk
|
|||
{
|
||||
m_drawables.Insert(entity);
|
||||
|
||||
GraphicsComponent& gfxComponent = entity->GetComponent<GraphicsComponent>();
|
||||
if (justAdded)
|
||||
{
|
||||
GraphicsComponent& gfxComponent = entity->GetComponent<GraphicsComponent>();
|
||||
gfxComponent.AddToCullingList(&m_drawableCulling);
|
||||
}
|
||||
|
||||
if (gfxComponent.DoesRequireRealTimeReflections())
|
||||
m_realtimeReflected.Insert(entity);
|
||||
else
|
||||
m_realtimeReflected.Remove(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_drawables.Remove(entity);
|
||||
m_realtimeReflected.Remove(entity);
|
||||
|
||||
if (entity->HasComponent<GraphicsComponent>())
|
||||
{
|
||||
|
|
@ -176,6 +183,7 @@ namespace Ndk
|
|||
m_coordinateSystemInvalidated = false;
|
||||
}
|
||||
|
||||
UpdateDynamicReflections();
|
||||
UpdatePointSpotShadowMaps();
|
||||
|
||||
for (const Ndk::EntityHandle& camera : m_cameras)
|
||||
|
|
@ -231,8 +239,12 @@ namespace Ndk
|
|||
Nz::SceneData sceneData;
|
||||
sceneData.ambientColor = Nz::Color(25, 25, 25);
|
||||
sceneData.background = m_background;
|
||||
sceneData.globalReflectionTexture = nullptr;
|
||||
sceneData.viewer = &camComponent;
|
||||
|
||||
if (m_background && m_background->GetBackgroundType() == Nz::BackgroundType_Skybox)
|
||||
sceneData.globalReflectionTexture = static_cast<Nz::SkyboxBackground*>(m_background.Get())->GetTexture();
|
||||
|
||||
m_renderTechnique->Clear(sceneData);
|
||||
m_renderTechnique->Draw(sceneData);
|
||||
}
|
||||
|
|
@ -244,6 +256,19 @@ namespace Ndk
|
|||
* \param viewer Viewer of the scene
|
||||
*/
|
||||
|
||||
void RenderSystem::UpdateDynamicReflections()
|
||||
{
|
||||
Nz::SceneData dummySceneData;
|
||||
dummySceneData.ambientColor = Nz::Color(0, 0, 0);
|
||||
dummySceneData.background = nullptr;
|
||||
dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer
|
||||
|
||||
for (const Ndk::EntityHandle& handle : m_realtimeReflected)
|
||||
{
|
||||
//NazaraWarning("Realtime reflected: #" + handle->ToString());
|
||||
}
|
||||
}
|
||||
|
||||
void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& /*viewer*/)
|
||||
{
|
||||
if (!m_shadowRT.IsValid())
|
||||
|
|
@ -322,12 +347,12 @@ namespace Ndk
|
|||
{
|
||||
static Nz::Quaternionf rotations[6] =
|
||||
{
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitX()), // nzCubemapFace_PositiveX
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitX()), // nzCubemapFace_NegativeX
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitY()), // nzCubemapFace_PositiveY
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitY()), // nzCubemapFace_NegativeY
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitZ()), // nzCubemapFace_PositiveZ
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitZ()) // nzCubemapFace_NegativeZ
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitX()), // CubemapFace_PositiveX
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitX()), // CubemapFace_NegativeX
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitY()), // CubemapFace_PositiveY
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitY()), // CubemapFace_NegativeY
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitZ()), // CubemapFace_PositiveZ
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitZ()) // CubemapFace_NegativeZ
|
||||
};
|
||||
|
||||
for (unsigned int face = 0; face < 6; ++face)
|
||||
|
|
|
|||
|
|
@ -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,23 +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 {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
// 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/ImageWidget.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ImageWidget::ImageWidget(BaseWidget* parent) :
|
||||
BaseWidget(parent)
|
||||
{
|
||||
m_entity = CreateEntity();
|
||||
m_entity->AddComponent<NodeComponent>();
|
||||
auto& gfx = m_entity->AddComponent<GraphicsComponent>();
|
||||
|
||||
m_sprite = Nz::Sprite::New();
|
||||
gfx.Attach(m_sprite);
|
||||
}
|
||||
|
||||
void ImageWidget::ResizeToContent()
|
||||
{
|
||||
Nz::Vector3ui textureSize = m_sprite->GetMaterial()->GetDiffuseMap()->GetSize();
|
||||
SetSize({ static_cast<float>(textureSize.x), static_cast<float>(textureSize.y) });
|
||||
}
|
||||
|
||||
void ImageWidget::Layout()
|
||||
{
|
||||
BaseWidget::Layout();
|
||||
Nz::Vector2f origin = GetContentOrigin();
|
||||
Nz::Vector2f contentSize = GetContentSize();
|
||||
|
||||
m_entity->GetComponent<NodeComponent>().SetPosition(origin);
|
||||
m_sprite->SetSize(contentSize);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,15 +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_echoMode(EchoMode_Normal),
|
||||
m_cursorPosition(0U, 0U),
|
||||
m_cursorGlyph(0),
|
||||
m_multiLineEnabled(false),
|
||||
m_readOnly(false)
|
||||
{
|
||||
|
|
@ -40,9 +38,38 @@ namespace Ndk
|
|||
|
||||
void TextAreaWidget::AppendText(const Nz::String& text)
|
||||
{
|
||||
m_drawer.AppendText(text);
|
||||
m_text += text;
|
||||
switch (m_echoMode)
|
||||
{
|
||||
case EchoMode_Normal:
|
||||
m_drawer.AppendText(text);
|
||||
break;
|
||||
|
||||
case EchoMode_Password:
|
||||
m_drawer.AppendText(Nz::String(text.GetLength(), '*'));
|
||||
break;
|
||||
|
||||
case EchoMode_PasswordExceptLast:
|
||||
{
|
||||
m_drawer.Clear();
|
||||
std::size_t textLength = m_text.GetLength();
|
||||
if (textLength >= 2)
|
||||
{
|
||||
std::size_t lastCharacterPosition = m_text.GetCharacterPosition(textLength - 2);
|
||||
if (lastCharacterPosition != Nz::String::npos)
|
||||
m_drawer.AppendText(Nz::String(textLength - 1, '*'));
|
||||
}
|
||||
|
||||
if (textLength >= 1)
|
||||
m_drawer.AppendText(m_text.SubString(m_text.GetCharacterPosition(textLength - 1)));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_textSprite->Update(m_drawer);
|
||||
|
||||
OnTextChanged(this, m_text);
|
||||
}
|
||||
|
||||
std::size_t TextAreaWidget::GetHoveredGlyph(float x, float y) const
|
||||
|
|
@ -82,18 +109,19 @@ namespace Ndk
|
|||
|
||||
void TextAreaWidget::Write(const Nz::String& text)
|
||||
{
|
||||
if (m_cursorGlyph >= m_drawer.GetGlyphCount())
|
||||
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPosition);
|
||||
|
||||
if (cursorGlyph >= m_drawer.GetGlyphCount())
|
||||
{
|
||||
AppendText(text);
|
||||
SetCursorPosition(m_drawer.GetGlyphCount());
|
||||
}
|
||||
else
|
||||
{
|
||||
Nz::String currentText = m_drawer.GetText();
|
||||
currentText.Insert(currentText.GetCharacterPosition(m_cursorGlyph), text);
|
||||
SetText(currentText);
|
||||
m_text.Insert(m_text.GetCharacterPosition(cursorGlyph), text);
|
||||
SetText(m_text);
|
||||
|
||||
SetCursorPosition(m_cursorGlyph + text.GetLength());
|
||||
SetCursorPosition(cursorGlyph + text.GetLength());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,24 +134,43 @@ namespace Ndk
|
|||
RefreshCursor();
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
|
||||
bool TextAreaWidget::IsFocusable() const
|
||||
{
|
||||
return !m_readOnly;
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnFocusLost()
|
||||
{
|
||||
m_cursorEntity->Disable();
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnFocusReceived()
|
||||
{
|
||||
if (!m_readOnly)
|
||||
m_cursorEntity->Enable(true);
|
||||
}
|
||||
|
||||
bool TextAreaWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
|
||||
{
|
||||
switch (key.code)
|
||||
{
|
||||
case Nz::Keyboard::Delete:
|
||||
{
|
||||
const Nz::String& text = m_drawer.GetText();
|
||||
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPosition);
|
||||
|
||||
std::size_t textLength = m_text.GetLength();
|
||||
if (cursorGlyph > textLength)
|
||||
return true;
|
||||
|
||||
Nz::String newText;
|
||||
if (m_cursorGlyph > 0)
|
||||
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorGlyph) - 1));
|
||||
if (cursorGlyph > 0)
|
||||
newText.Append(m_text.SubString(0, m_text.GetCharacterPosition(cursorGlyph) - 1));
|
||||
|
||||
if (m_cursorGlyph < m_drawer.GetGlyphCount())
|
||||
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorGlyph + 1)));
|
||||
if (cursorGlyph < textLength)
|
||||
newText.Append(m_text.SubString(m_text.GetCharacterPosition(cursorGlyph + 1)));
|
||||
|
||||
m_drawer.SetText(newText);
|
||||
m_textSprite->Update(m_drawer);
|
||||
break;
|
||||
SetText(newText);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Down:
|
||||
|
|
@ -132,10 +179,10 @@ namespace Ndk
|
|||
OnTextAreaKeyDown(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
return true;
|
||||
|
||||
MoveCursor({0, 1});
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Left:
|
||||
|
|
@ -144,10 +191,10 @@ namespace Ndk
|
|||
OnTextAreaKeyLeft(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
return true;
|
||||
|
||||
MoveCursor({-1, 0});
|
||||
break;
|
||||
MoveCursor(-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Right:
|
||||
|
|
@ -156,10 +203,10 @@ namespace Ndk
|
|||
OnTextAreaKeyRight(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
return true;
|
||||
|
||||
MoveCursor({1, 0});
|
||||
break;
|
||||
MoveCursor(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Up:
|
||||
|
|
@ -168,42 +215,31 @@ namespace Ndk
|
|||
OnTextAreaKeyUp(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
return true;
|
||||
|
||||
MoveCursor({0, -1});
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& key)
|
||||
void TextAreaWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& /*key*/)
|
||||
{
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnMouseEnter()
|
||||
{
|
||||
m_cursorEntity->Enable(true);
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnMouseButtonPress(int x, int y, Nz::Mouse::Button button)
|
||||
{
|
||||
if (button == Nz::Mouse::Left)
|
||||
{
|
||||
GrabKeyboard();
|
||||
SetFocus();
|
||||
|
||||
SetCursorPosition(GetHoveredGlyph(float(x), float(y)));
|
||||
}
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
|
||||
{
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnMouseExit()
|
||||
{
|
||||
m_cursorEntity->Enable(false);
|
||||
}
|
||||
|
||||
void TextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/)
|
||||
{
|
||||
if (m_readOnly)
|
||||
|
|
@ -216,19 +252,19 @@ namespace Ndk
|
|||
bool ignoreDefaultAction = false;
|
||||
OnTextAreaKeyBackspace(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPosition);
|
||||
if (ignoreDefaultAction || cursorGlyph == 0)
|
||||
break;
|
||||
|
||||
const Nz::String& text = m_drawer.GetText();
|
||||
|
||||
Nz::String newText;
|
||||
if (m_cursorGlyph > 1)
|
||||
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorGlyph - 1) - 1));
|
||||
|
||||
if (m_cursorGlyph < m_drawer.GetGlyphCount())
|
||||
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorGlyph)));
|
||||
if (cursorGlyph > 1)
|
||||
newText.Append(m_text.SubString(0, m_text.GetCharacterPosition(cursorGlyph - 1) - 1));
|
||||
|
||||
MoveCursor({-1, 0});
|
||||
if (cursorGlyph < m_text.GetLength())
|
||||
newText.Append(m_text.SubString(m_text.GetCharacterPosition(cursorGlyph)));
|
||||
|
||||
MoveCursor(-1);
|
||||
SetText(newText);
|
||||
break;
|
||||
}
|
||||
|
|
@ -259,15 +295,19 @@ namespace Ndk
|
|||
|
||||
void TextAreaWidget::RefreshCursor()
|
||||
{
|
||||
if (m_readOnly)
|
||||
return;
|
||||
|
||||
const auto& lineInfo = m_drawer.GetLine(m_cursorPosition.y);
|
||||
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPosition);
|
||||
|
||||
std::size_t glyphCount = m_drawer.GetGlyphCount();
|
||||
float position;
|
||||
if (glyphCount > 0 && lineInfo.glyphIndex < m_cursorGlyph)
|
||||
if (glyphCount > 0 && lineInfo.glyphIndex < cursorGlyph)
|
||||
{
|
||||
const auto& glyph = m_drawer.GetGlyph(std::min(m_cursorGlyph, glyphCount - 1));
|
||||
const auto& glyph = m_drawer.GetGlyph(std::min(cursorGlyph, glyphCount - 1));
|
||||
position = glyph.bounds.x;
|
||||
if (m_cursorGlyph >= glyphCount)
|
||||
if (cursorGlyph >= glyphCount)
|
||||
position += glyph.bounds.width;
|
||||
}
|
||||
else
|
||||
|
|
@ -277,4 +317,23 @@ namespace Ndk
|
|||
|
||||
m_cursorEntity->GetComponent<NodeComponent>().SetPosition(contentOrigin.x + position, contentOrigin.y + lineInfo.bounds.y);
|
||||
}
|
||||
|
||||
void TextAreaWidget::UpdateDisplayText()
|
||||
{
|
||||
switch (m_echoMode)
|
||||
{
|
||||
case EchoMode_Normal:
|
||||
m_drawer.SetText(m_text);
|
||||
break;
|
||||
|
||||
case EchoMode_Password:
|
||||
case EchoMode_PasswordExceptLast:
|
||||
m_drawer.SetText(Nz::String(m_text.GetLength(), '*'));
|
||||
break;
|
||||
}
|
||||
|
||||
m_textSprite->Update(m_drawer);
|
||||
|
||||
SetCursorPosition(m_cursorPosition); //< Refresh cursor position (prevent it from being outside of the text)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,10 +115,15 @@ namespace Ndk
|
|||
|
||||
void World::Clear() noexcept
|
||||
{
|
||||
// First, destruction of entities, then handles
|
||||
// This is made to avoid that handle warn uselessly entities before their destruction
|
||||
m_entities.clear();
|
||||
// Destroy every valid entity first, to ensure entities are still accessible by ID while being destroyed
|
||||
for (EntityBlock* entBlock : m_entityBlocks)
|
||||
{
|
||||
if (entBlock->entity.IsValid())
|
||||
entBlock->entity.Destroy();
|
||||
}
|
||||
m_entityBlocks.clear();
|
||||
|
||||
m_entities.clear();
|
||||
m_freeIdList.clear();
|
||||
m_waitingEntities.clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
premake5 vs2017
|
||||
|
|
@ -16,8 +16,8 @@ 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
|
||||
PremakeProject = true
|
||||
-- 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
|
||||
|
|
|
|||
|
|
@ -84,13 +84,13 @@ ACTION.Function = function ()
|
|||
local libFileMasks
|
||||
local exeFileExt
|
||||
local exeFilterFunc
|
||||
if (os.is("windows")) then
|
||||
if (os.ishost("windows")) then
|
||||
binFileMasks = {"**.dll", "**.pdb"}
|
||||
libFileMasks = {"**.lib", "**.a"}
|
||||
exeFileExt = ".exe"
|
||||
exeFilterFunc = function (filePath) return true end
|
||||
else
|
||||
if (os.is("macosx")) then
|
||||
if (os.ishost("macosx")) then
|
||||
binFileMasks = {"**.dynlib"}
|
||||
else
|
||||
binFileMasks = {"**.so"}
|
||||
|
|
@ -183,14 +183,7 @@ ACTION.Function = function ()
|
|||
end
|
||||
end
|
||||
|
||||
local ok, err
|
||||
if (os.is("windows")) then
|
||||
ok, err = os.copyfile(v, targetPath)
|
||||
else
|
||||
-- Workaround: As premake is translating this to "cp %s %s", it fails if space are presents in source/destination paths.
|
||||
ok, err = os.copyfile(string.format("\"%s\"", v), string.format("\"%s\"", targetPath))
|
||||
end
|
||||
|
||||
local ok, err = os.copyfile(v, targetPath)
|
||||
if (not ok) then
|
||||
print("Failed to copy \"" .. v .. "\" to \"" .. targetPath .. "\": " .. err)
|
||||
end
|
||||
|
|
@ -203,5 +196,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
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ function NazaraBuild:Execute()
|
|||
language("C++")
|
||||
location(_ACTION)
|
||||
|
||||
if (self.Config["PremakeProject"]) then
|
||||
if (self.Config["PremakeProject"] and os.ishost("windows")) then
|
||||
local commandLine = "premake5.exe " .. table.concat(_ARGV, ' ')
|
||||
project("_PremakeProject")
|
||||
kind("Utility")
|
||||
|
|
@ -477,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)
|
||||
|
|
@ -607,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...")
|
||||
|
|
@ -739,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
|
||||
|
|
@ -779,13 +777,14 @@ end
|
|||
|
||||
function NazaraBuild:PrepareGeneric()
|
||||
flags({
|
||||
"C++14",
|
||||
"MultiProcessorCompile",
|
||||
"NoMinimalRebuild",
|
||||
"RelativeLinks",
|
||||
"ShadowedVariables",
|
||||
"UndefinedIdentifiers"
|
||||
})
|
||||
|
||||
cppdialect("C++14")
|
||||
|
||||
self:FilterLibDirectory("../extlibs/lib/", libdirs)
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue