diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 021beeffc..0b3bdecb7 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -117,8 +117,8 @@ namespace Ndk virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button); virtual void OnMouseExit(); virtual void OnParentResized(const Nz::Vector2f& newSize); - virtual void OnTextEntered(char32_t character, bool repeated); - virtual void OnTextEdited(const std::array& characters, int length); + virtual void OnTextEntered(char32_t character, bool repeated); + virtual void OnTextEdited(const std::array& characters, int length); inline void SetPreferredSize(const Nz::Vector2f& preferredSize); diff --git a/SDK/include/NDK/Canvas.hpp b/SDK/include/NDK/Canvas.hpp index 6b66cdeaf..4d9e9d05a 100644 --- a/SDK/include/NDK/Canvas.hpp +++ b/SDK/include/NDK/Canvas.hpp @@ -52,8 +52,8 @@ namespace Ndk void OnEventMouseLeft(const Nz::EventHandler* eventHandler); void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event); void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event); - void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event); - void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event); + void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event); + void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event); struct WidgetEntry { @@ -68,8 +68,8 @@ namespace Ndk NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot); NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot); NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot); - NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); - NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot); + NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); + NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot); std::size_t m_keyboardOwner; std::size_t m_hoveredWidget; diff --git a/SDK/include/NDK/Canvas.inl b/SDK/include/NDK/Canvas.inl index 649f5f728..8abe9c748 100644 --- a/SDK/include/NDK/Canvas.inl +++ b/SDK/include/NDK/Canvas.inl @@ -26,8 +26,8 @@ namespace Ndk m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnEventMouseButtonRelease); m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved); m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft); - m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered); - m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited); + m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered); + m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited); } inline Canvas::~Canvas() diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index ce900852a..03fb87e97 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -39,16 +39,16 @@ namespace Ndk } /*! - * \brief Frees the widget, unregistering it from its canvas - */ + * \brief Frees the widget, unregistering it from its canvas + */ BaseWidget::~BaseWidget() { UnregisterFromCanvas(); } /*! - * \brief Clears keyboard focus if and only if this widget owns it. - */ + * \brief Clears keyboard focus if and only if this widget owns it. + */ void BaseWidget::ClearFocus() { if (IsRegisteredToCanvas()) @@ -56,10 +56,10 @@ namespace Ndk } /*! - * \brief Destroy the widget, deleting it in the process. - * - * Calling this function immediately destroys the widget, freeing its memory. - */ + * \brief Destroy the widget, deleting it in the process. + * + * Calling this function immediately destroys the widget, freeing its memory. + */ void BaseWidget::Destroy() { NazaraAssert(this != m_canvas, "Canvas cannot be destroyed by calling Destroy()"); @@ -68,8 +68,8 @@ namespace Ndk } /*! - * \brief Enable or disables the widget background. - */ + * \brief Enable or disables the widget background. + */ void BaseWidget::EnableBackground(bool enable) { if (m_backgroundEntity.IsValid() == enable) @@ -95,9 +95,9 @@ namespace Ndk } /*! - * \brief Checks if this widget has keyboard focus - * \return true if widget has keyboard focus, false otherwise - */ + * \brief Checks if this widget has keyboard focus + * \return true if widget has keyboard focus, false otherwise + */ bool BaseWidget::HasFocus() const { if (!IsRegisteredToCanvas()) @@ -242,15 +242,15 @@ namespace Ndk void BaseWidget::OnParentResized(const Nz::Vector2f& /*newSize*/) { - } + } - void BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/) + void BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/) { } - void BaseWidget::OnTextEdited(const std::array& /*characters*/, int /*length*/) - { - } + void BaseWidget::OnTextEdited(const std::array& /*characters*/, int /*length*/) + { + } void BaseWidget::DestroyChild(BaseWidget* widget) { diff --git a/SDK/src/NDK/Canvas.cpp b/SDK/src/NDK/Canvas.cpp index aa1e83328..f628713e2 100644 --- a/SDK/src/NDK/Canvas.cpp +++ b/SDK/src/NDK/Canvas.cpp @@ -203,11 +203,11 @@ namespace Ndk { if (m_keyboardOwner != InvalidCanvasIndex) m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated); - } + } - void Canvas::OnEventTextEdited(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::EditEvent& event) - { - if (m_keyboardOwner != InvalidCanvasIndex) - m_widgetEntries[m_keyboardOwner].widget->OnTextEdited(event.text, event.length); - } + void Canvas::OnEventTextEdited(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::EditEvent& event) + { + if (m_keyboardOwner != InvalidCanvasIndex) + m_widgetEntries[m_keyboardOwner].widget->OnTextEdited(event.text, event.length); + } } diff --git a/examples/Textarea/build.lua b/examples/Textarea/build.lua deleted file mode 100644 index 3436aafef..000000000 --- a/examples/Textarea/build.lua +++ /dev/null @@ -1,15 +0,0 @@ -EXAMPLE.Name = "Textarea" - -EXAMPLE.EnableConsole = true - -EXAMPLE.Files = { - "main.cpp" -} - -EXAMPLE.Libraries = { - "NazaraSDK" -} - -if Config.PlatformSDL2 then - table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") -end diff --git a/examples/Textarea/main.cpp b/examples/Textarea/main.cpp deleted file mode 100644 index 6726aa1f1..000000000 --- a/examples/Textarea/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char* argv[]) -{ - Ndk::Application application(argc, argv); - - Nz::RenderWindow& mainWindow = application.AddWindow(); - mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test"); - - - Ndk::World& world = application.AddWorld(); - world.GetSystem().SetGlobalUp(Nz::Vector3f::Down()); - world.GetSystem().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214))); - - - Ndk::EntityHandle viewEntity = world.CreateEntity(); - viewEntity->AddComponent(); - - Ndk::CameraComponent& viewer = viewEntity->AddComponent(); - viewer.SetTarget(&mainWindow); - viewer.SetProjectionType(Nz::ProjectionType_Orthogonal); - - Ndk::EntityHandle text = world.CreateEntity(); - Ndk::NodeComponent& nodeComponent = text->AddComponent(); - - Ndk::Canvas canvas(world.CreateHandle(), mainWindow.GetEventHandler(), mainWindow.GetCursorController().CreateHandle()); - canvas.SetFixedSize(Nz::Vector2f(mainWindow.GetSize())); - - auto textarea = canvas.Add(); - textarea->EnableBackground(true); - textarea->SetBackgroundColor(Nz::Color(0, 0, 0, 150)); - textarea->SetTextColor(Nz::Color::White); - textarea->EnableMultiline(); - - textarea->SetFixedSize(canvas.GetSize()/2); - - /*Nz::Boxf textBox = mainWindow.GetSize(); - Nz::Vector2ui windowSize = mainWindow.GetSize(); - nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);*/ - - while (application.Run()) - { - mainWindow.Display(); - } - - return EXIT_SUCCESS; -} diff --git a/include/Nazara/Platform/Enums.hpp b/include/Nazara/Platform/Enums.hpp index 6d0c560ab..2ec3c5bf3 100644 --- a/include/Nazara/Platform/Enums.hpp +++ b/include/Nazara/Platform/Enums.hpp @@ -51,10 +51,10 @@ namespace Nz WindowEventType_Moved, WindowEventType_Quit, WindowEventType_Resized, - WindowEventType_TextEdited, + WindowEventType_TextEdited, WindowEventType_TextEntered, - WindowEventType_Max = WindowEventType_TextEntered + WindowEventType_Max = WindowEventType_TextEntered }; enum WindowStyle diff --git a/include/Nazara/Platform/Event.hpp b/include/Nazara/Platform/Event.hpp index ab5e2a906..5c8dfd24f 100644 --- a/include/Nazara/Platform/Event.hpp +++ b/include/Nazara/Platform/Event.hpp @@ -82,15 +82,15 @@ namespace Nz { bool repeated; char32_t character; - }; + }; - // Used by: - // -WindowEventType_TextEdited - struct EditEvent - { - int length; - std::array text; - }; + // Used by: + // -WindowEventType_TextEdited + struct EditEvent + { + int length; + std::array text; + }; WindowEventType type; @@ -126,9 +126,9 @@ namespace Nz // -WindowEventType_TextEntered TextEvent text; - // Used by: - // -WindowEventType_TextEntered - EditEvent edit; + // Used by: + // -WindowEventType_TextEntered + EditEvent edit; }; }; } diff --git a/include/Nazara/Platform/EventHandler.hpp b/include/Nazara/Platform/EventHandler.hpp index e612823ec..be979e65e 100644 --- a/include/Nazara/Platform/EventHandler.hpp +++ b/include/Nazara/Platform/EventHandler.hpp @@ -48,8 +48,8 @@ namespace Nz NazaraSignal(OnMoved, const EventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/); NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/); NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/); - NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/); - NazaraSignal(OnTextEdited, const EventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/); + NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/); + NazaraSignal(OnTextEdited, const EventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/); }; } diff --git a/include/Nazara/Platform/EventHandler.inl b/include/Nazara/Platform/EventHandler.inl index 25f76a4ab..c3edc1cd2 100644 --- a/include/Nazara/Platform/EventHandler.inl +++ b/include/Nazara/Platform/EventHandler.inl @@ -79,9 +79,9 @@ namespace Nz OnTextEntered(this, event.text); break; - case WindowEventType_TextEdited: - OnTextEdited(this, event.edit); - break; + case WindowEventType_TextEdited: + OnTextEdited(this, event.edit); + break; } } } diff --git a/include/Nazara/Platform/Keyboard.hpp b/include/Nazara/Platform/Keyboard.hpp index 36d87d2ee..25bc19756 100644 --- a/include/Nazara/Platform/Keyboard.hpp +++ b/include/Nazara/Platform/Keyboard.hpp @@ -323,8 +323,8 @@ namespace Nz static String GetKeyName(VKey key); static bool IsKeyPressed(Scancode scancode); static bool IsKeyPressed(VKey key); - static void StartTextInput(); - static void StopTextInput(); + static void StartTextInput(); + static void StopTextInput(); static Scancode ToScanCode(VKey key); static VKey ToVirtualKey(Scancode key); }; diff --git a/src/Nazara/Platform/Keyboard.cpp b/src/Nazara/Platform/Keyboard.cpp index 7c68e5164..d2a287e32 100644 --- a/src/Nazara/Platform/Keyboard.cpp +++ b/src/Nazara/Platform/Keyboard.cpp @@ -38,15 +38,15 @@ namespace Nz return EventImpl::IsKeyPressed(key); } - void Keyboard::StartTextInput() - { - EventImpl::StartTextInput(); - } + void Keyboard::StartTextInput() + { + EventImpl::StartTextInput(); + } - void Keyboard::StopTextInput() - { - EventImpl::StopTextInput(); - } + void Keyboard::StopTextInput() + { + EventImpl::StopTextInput(); + } Keyboard::Scancode Keyboard::ToScanCode(VKey key) { diff --git a/src/Nazara/Platform/SDL2/InputImpl.cpp b/src/Nazara/Platform/SDL2/InputImpl.cpp index 9daba650d..9bf2fd40f 100644 --- a/src/Nazara/Platform/SDL2/InputImpl.cpp +++ b/src/Nazara/Platform/SDL2/InputImpl.cpp @@ -100,15 +100,15 @@ namespace Nz NazaraError("Invalid window handle"); } - void EventImpl::StartTextInput() - { - SDL_StartTextInput(); - } + void EventImpl::StartTextInput() + { + SDL_StartTextInput(); + } - void EventImpl::StopTextInput() - { - SDL_StopTextInput(); - } + void EventImpl::StopTextInput() + { + SDL_StopTextInput(); + } Keyboard::Scancode EventImpl::ToScanCode(Keyboard::VKey key) { diff --git a/src/Nazara/Platform/SDL2/InputImpl.hpp b/src/Nazara/Platform/SDL2/InputImpl.hpp index 8aca56985..568acb755 100644 --- a/src/Nazara/Platform/SDL2/InputImpl.hpp +++ b/src/Nazara/Platform/SDL2/InputImpl.hpp @@ -26,8 +26,8 @@ namespace Nz static bool IsMouseButtonPressed(Mouse::Button button); static void SetMousePosition(int x, int y); static void SetMousePosition(int x, int y, const Window& relativeTo); - static void StartTextInput(); - static void StopTextInput(); + static void StartTextInput(); + static void StopTextInput(); static Keyboard::Scancode ToScanCode(Keyboard::VKey key); static Keyboard::VKey ToVirtualKey(Keyboard::Scancode scancode); }; diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp index 3462a1c09..2db2b55be 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.cpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -2,8 +2,6 @@ // This file is part of the "Nazara Engine - Platform module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation - #include #include #include @@ -278,10 +276,10 @@ namespace Nz case SDL_WINDOWEVENT_RESIZED: evt.type = Nz::WindowEventType::WindowEventType_Resized; - evt.size.width = static_cast(std::max(0, event->window.data1)); - evt.size.height = static_cast(std::max(0, event->window.data2)); + evt.size.width = static_cast(std::max(0, event->window.data1)); + evt.size.height = static_cast(std::max(0, event->window.data2)); - window->m_size.Set(evt.size.width, evt.size.height); + window->m_size.Set(evt.size.width, evt.size.height); break; case SDL_WINDOWEVENT_MOVED: @@ -387,38 +385,36 @@ namespace Nz evt.key.shift = (event->key.keysym.mod & KMOD_SHIFT) != 0; evt.key.system = (event->key.keysym.mod & KMOD_GUI) != 0; - // implements X11/Win32 APIs behavior for Enter and Backspace - switch (evt.key.virtualKey) { - case Nz::Keyboard::VKey::NumpadReturn: - case Nz::Keyboard::VKey::Return: - if (window->m_lastEditEventLength != 0) - { - break; - } - window->m_parent->PushEvent(evt); + // implements X11/Win32 APIs behavior for Enter and Backspace + switch (evt.key.virtualKey) { + case Nz::Keyboard::VKey::NumpadReturn: + case Nz::Keyboard::VKey::Return: + if (window->m_lastEditEventLength != 0) + break; + window->m_parent->PushEvent(evt); - evt.type = WindowEventType_TextEntered; + evt.type = WindowEventType_TextEntered; - evt.text.character = U'\n'; - evt.text.repeated = event->key.repeat != 0; + evt.text.character = U'\n'; + evt.text.repeated = event->key.repeat != 0; - window->m_parent->PushEvent(evt); + window->m_parent->PushEvent(evt); - break; - case Nz::Keyboard::VKey::Backspace: - window->m_parent->PushEvent(evt); + break; + case Nz::Keyboard::VKey::Backspace: + window->m_parent->PushEvent(evt); - evt.type = WindowEventType_TextEntered; + evt.type = WindowEventType_TextEntered; - evt.text.character = U'\b'; - evt.text.repeated = event->key.repeat != 0; + evt.text.character = U'\b'; + evt.text.repeated = event->key.repeat != 0; - window->m_parent->PushEvent(evt); + window->m_parent->PushEvent(evt); - break; - default: - break; - } + break; + default: + break; + } break; @@ -443,42 +439,42 @@ namespace Nz return 0; evt.type = WindowEventType_TextEntered; - evt.text.repeated = false; + evt.text.repeated = false; - for (decltype(evt.text.character)codepoint : String::Unicode(event->text.text).Simplify().GetUtf32String()) + for (decltype(evt.text.character) codepoint : String::Unicode(event->text.text).Simplify().GetUtf32String()) { - evt.text.character = codepoint; + evt.text.character = codepoint; window->m_parent->PushEvent(evt); } // prevent post switch event - evt.type = WindowEventType::WindowEventType_Max; + evt.type = WindowEventType::WindowEventType_Max; - break; + break; - case SDL_TEXTEDITING: - if (SDL_GetWindowID(window->m_handle) != event->edit.windowID) - return 0; + case SDL_TEXTEDITING: + if (SDL_GetWindowID(window->m_handle) != event->edit.windowID) + return 0; - evt.type = WindowEventType_TextEdited; - evt.edit.length = event->edit.length; - window->m_lastEditEventLength = evt.edit.length; + evt.type = WindowEventType_TextEdited; + evt.edit.length = event->edit.length; + window->m_lastEditEventLength = evt.edit.length; - for (std::size_t i = 0; i < 32; i++) - { - evt.edit.text[i] = event->edit.text[i]; - } + for (std::size_t i = 0; i < 32; i++) + { + evt.edit.text[i] = event->edit.text[i]; + } - break; + break; } if (evt.type != WindowEventType::WindowEventType_Max) window->m_parent->PushEvent(evt); } catch (std::exception e) - { - NazaraError(e.what()); + { + NazaraError(e.what()); } catch (...) // Don't let any exceptions go thru C calls { @@ -560,11 +556,11 @@ namespace Nz } bool WindowImpl::Initialize() - { + { if (SDL_Init(SDL_INIT_VIDEO) < 0) { NazaraError(SDL_GetError()); - return false; + return false; } if (SDL_GL_LoadLibrary(nullptr) < 0) { @@ -572,7 +568,7 @@ namespace Nz SDL_Quit(); return false; - } + } if (SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, true) < 0) NazaraError("Couldn't set share OpenGL contexes"); diff --git a/src/Nazara/Platform/SDL2/WindowImpl.hpp b/src/Nazara/Platform/SDL2/WindowImpl.hpp index 0ff3206ae..8d960eaff 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.hpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.hpp @@ -87,7 +87,7 @@ namespace Nz //static void WindowThread(SDL_Window* handle, /*DWORD styleEx,*/ const String& title, /*DWORD style,*/ bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition); - int m_lastEditEventLength = 0; + int m_lastEditEventLength = 0; SDL_Cursor* m_cursor; SDL_Window* m_handle; WindowStyleFlags m_style; diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 993add34b..79685d25a 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -744,10 +744,9 @@ namespace Nz #if defined(NAZARA_PLATFORM_SDL2) - if (SDL_VideoInit(NULL) != 0) - { - NazaraError(SDL_GetError()); - } + if (SDL_VideoInit(NULL) != 0) + NazaraError(SDL_GetError()); + #elif defined(NAZARA_PLATFORM_GLX) Initializer display; if (!display)