~ Formatting

This commit is contained in:
REMqb 2020-03-21 12:42:50 +01:00
parent ef791e2f3c
commit 96ea792656
18 changed files with 120 additions and 198 deletions

View File

@ -117,8 +117,8 @@ namespace Ndk
virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button); virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button);
virtual void OnMouseExit(); virtual void OnMouseExit();
virtual void OnParentResized(const Nz::Vector2f& newSize); virtual void OnParentResized(const Nz::Vector2f& newSize);
virtual void OnTextEntered(char32_t character, bool repeated); virtual void OnTextEntered(char32_t character, bool repeated);
virtual void OnTextEdited(const std::array<char, 32>& characters, int length); virtual void OnTextEdited(const std::array<char, 32>& characters, int length);
inline void SetPreferredSize(const Nz::Vector2f& preferredSize); inline void SetPreferredSize(const Nz::Vector2f& preferredSize);

View File

@ -52,8 +52,8 @@ namespace Ndk
void OnEventMouseLeft(const Nz::EventHandler* eventHandler); void OnEventMouseLeft(const Nz::EventHandler* eventHandler);
void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event); void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
void OnEventKeyReleased(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 OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event); void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event);
struct WidgetEntry struct WidgetEntry
{ {
@ -68,8 +68,8 @@ namespace Ndk
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot); NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot); NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot); NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot); NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot);
std::size_t m_keyboardOwner; std::size_t m_keyboardOwner;
std::size_t m_hoveredWidget; std::size_t m_hoveredWidget;

View File

@ -26,8 +26,8 @@ namespace Ndk
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnEventMouseButtonRelease); m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnEventMouseButtonRelease);
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved); m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved);
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft); m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft);
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered); m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered);
m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited); m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited);
} }
inline Canvas::~Canvas() inline Canvas::~Canvas()

View File

@ -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() BaseWidget::~BaseWidget()
{ {
UnregisterFromCanvas(); 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() void BaseWidget::ClearFocus()
{ {
if (IsRegisteredToCanvas()) if (IsRegisteredToCanvas())
@ -56,10 +56,10 @@ namespace Ndk
} }
/*! /*!
* \brief Destroy the widget, deleting it in the process. * \brief Destroy the widget, deleting it in the process.
* *
* Calling this function immediately destroys the widget, freeing its memory. * Calling this function immediately destroys the widget, freeing its memory.
*/ */
void BaseWidget::Destroy() void BaseWidget::Destroy()
{ {
NazaraAssert(this != m_canvas, "Canvas cannot be destroyed by calling 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) void BaseWidget::EnableBackground(bool enable)
{ {
if (m_backgroundEntity.IsValid() == enable) if (m_backgroundEntity.IsValid() == enable)
@ -95,9 +95,9 @@ namespace Ndk
} }
/*! /*!
* \brief Checks if this widget has keyboard focus * \brief Checks if this widget has keyboard focus
* \return true if widget has keyboard focus, false otherwise * \return true if widget has keyboard focus, false otherwise
*/ */
bool BaseWidget::HasFocus() const bool BaseWidget::HasFocus() const
{ {
if (!IsRegisteredToCanvas()) if (!IsRegisteredToCanvas())
@ -242,15 +242,15 @@ namespace Ndk
void BaseWidget::OnParentResized(const Nz::Vector2f& /*newSize*/) void BaseWidget::OnParentResized(const Nz::Vector2f& /*newSize*/)
{ {
} }
void BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/) void BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/)
{ {
} }
void BaseWidget::OnTextEdited(const std::array<char, 32>& /*characters*/, int /*length*/) void BaseWidget::OnTextEdited(const std::array<char, 32>& /*characters*/, int /*length*/)
{ {
} }
void BaseWidget::DestroyChild(BaseWidget* widget) void BaseWidget::DestroyChild(BaseWidget* widget)
{ {

View File

@ -203,11 +203,11 @@ namespace Ndk
{ {
if (m_keyboardOwner != InvalidCanvasIndex) if (m_keyboardOwner != InvalidCanvasIndex)
m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated); m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated);
} }
void Canvas::OnEventTextEdited(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::EditEvent& event) void Canvas::OnEventTextEdited(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::EditEvent& event)
{ {
if (m_keyboardOwner != InvalidCanvasIndex) if (m_keyboardOwner != InvalidCanvasIndex)
m_widgetEntries[m_keyboardOwner].widget->OnTextEdited(event.text, event.length); m_widgetEntries[m_keyboardOwner].widget->OnTextEdited(event.text, event.length);
} }
} }

View File

@ -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

View File

@ -1,58 +0,0 @@
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World
#include <Nazara/Graphics.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NDK/Application.hpp>
#include <NDK/Components.hpp>
#include <NDK/Systems.hpp>
#include <NDK/World.hpp>
#include <NDK/Canvas.hpp>
#include <NDK/Widgets/TextAreaWidget.hpp>
#include <iostream>
int main(int argc, char* argv[])
{
Ndk::Application application(argc, argv);
Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
Ndk::World& world = application.AddWorld();
world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214)));
Ndk::EntityHandle viewEntity = world.CreateEntity();
viewEntity->AddComponent<Ndk::NodeComponent>();
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
viewer.SetTarget(&mainWindow);
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
Ndk::EntityHandle text = world.CreateEntity();
Ndk::NodeComponent& nodeComponent = text->AddComponent<Ndk::NodeComponent>();
Ndk::Canvas canvas(world.CreateHandle(), mainWindow.GetEventHandler(), mainWindow.GetCursorController().CreateHandle());
canvas.SetFixedSize(Nz::Vector2f(mainWindow.GetSize()));
auto textarea = canvas.Add<Ndk::TextAreaWidget>();
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;
}

View File

@ -51,10 +51,10 @@ namespace Nz
WindowEventType_Moved, WindowEventType_Moved,
WindowEventType_Quit, WindowEventType_Quit,
WindowEventType_Resized, WindowEventType_Resized,
WindowEventType_TextEdited, WindowEventType_TextEdited,
WindowEventType_TextEntered, WindowEventType_TextEntered,
WindowEventType_Max = WindowEventType_TextEntered WindowEventType_Max = WindowEventType_TextEntered
}; };
enum WindowStyle enum WindowStyle

View File

@ -82,15 +82,15 @@ namespace Nz
{ {
bool repeated; bool repeated;
char32_t character; char32_t character;
}; };
// Used by: // Used by:
// -WindowEventType_TextEdited // -WindowEventType_TextEdited
struct EditEvent struct EditEvent
{ {
int length; int length;
std::array<char, 32> text; std::array<char, 32> text;
}; };
WindowEventType type; WindowEventType type;
@ -126,9 +126,9 @@ namespace Nz
// -WindowEventType_TextEntered // -WindowEventType_TextEntered
TextEvent text; TextEvent text;
// Used by: // Used by:
// -WindowEventType_TextEntered // -WindowEventType_TextEntered
EditEvent edit; EditEvent edit;
}; };
}; };
} }

View File

@ -48,8 +48,8 @@ namespace Nz
NazaraSignal(OnMoved, const EventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/); NazaraSignal(OnMoved, const EventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/);
NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/); NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/);
NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/); NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/);
NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/); NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/);
NazaraSignal(OnTextEdited, const EventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/); NazaraSignal(OnTextEdited, const EventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/);
}; };
} }

View File

@ -79,9 +79,9 @@ namespace Nz
OnTextEntered(this, event.text); OnTextEntered(this, event.text);
break; break;
case WindowEventType_TextEdited: case WindowEventType_TextEdited:
OnTextEdited(this, event.edit); OnTextEdited(this, event.edit);
break; break;
} }
} }
} }

View File

@ -323,8 +323,8 @@ namespace Nz
static String GetKeyName(VKey key); static String GetKeyName(VKey key);
static bool IsKeyPressed(Scancode scancode); static bool IsKeyPressed(Scancode scancode);
static bool IsKeyPressed(VKey key); static bool IsKeyPressed(VKey key);
static void StartTextInput(); static void StartTextInput();
static void StopTextInput(); static void StopTextInput();
static Scancode ToScanCode(VKey key); static Scancode ToScanCode(VKey key);
static VKey ToVirtualKey(Scancode key); static VKey ToVirtualKey(Scancode key);
}; };

View File

@ -38,15 +38,15 @@ namespace Nz
return EventImpl::IsKeyPressed(key); return EventImpl::IsKeyPressed(key);
} }
void Keyboard::StartTextInput() void Keyboard::StartTextInput()
{ {
EventImpl::StartTextInput(); EventImpl::StartTextInput();
} }
void Keyboard::StopTextInput() void Keyboard::StopTextInput()
{ {
EventImpl::StopTextInput(); EventImpl::StopTextInput();
} }
Keyboard::Scancode Keyboard::ToScanCode(VKey key) Keyboard::Scancode Keyboard::ToScanCode(VKey key)
{ {

View File

@ -100,15 +100,15 @@ namespace Nz
NazaraError("Invalid window handle"); NazaraError("Invalid window handle");
} }
void EventImpl::StartTextInput() void EventImpl::StartTextInput()
{ {
SDL_StartTextInput(); SDL_StartTextInput();
} }
void EventImpl::StopTextInput() void EventImpl::StopTextInput()
{ {
SDL_StopTextInput(); SDL_StopTextInput();
} }
Keyboard::Scancode EventImpl::ToScanCode(Keyboard::VKey key) Keyboard::Scancode EventImpl::ToScanCode(Keyboard::VKey key)
{ {

View File

@ -26,8 +26,8 @@ namespace Nz
static bool IsMouseButtonPressed(Mouse::Button button); static bool IsMouseButtonPressed(Mouse::Button button);
static void SetMousePosition(int x, int y); static void SetMousePosition(int x, int y);
static void SetMousePosition(int x, int y, const Window& relativeTo); static void SetMousePosition(int x, int y, const Window& relativeTo);
static void StartTextInput(); static void StartTextInput();
static void StopTextInput(); static void StopTextInput();
static Keyboard::Scancode ToScanCode(Keyboard::VKey key); static Keyboard::Scancode ToScanCode(Keyboard::VKey key);
static Keyboard::VKey ToVirtualKey(Keyboard::Scancode scancode); static Keyboard::VKey ToVirtualKey(Keyboard::Scancode scancode);
}; };

View File

@ -2,8 +2,6 @@
// This file is part of the "Nazara Engine - Platform module" // This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp // 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 <cstdio> #include <cstdio>
#include <memory> #include <memory>
#include <Nazara/Core/ConditionVariable.hpp> #include <Nazara/Core/ConditionVariable.hpp>
@ -278,10 +276,10 @@ namespace Nz
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
evt.type = Nz::WindowEventType::WindowEventType_Resized; evt.type = Nz::WindowEventType::WindowEventType_Resized;
evt.size.width = static_cast<unsigned int>(std::max(0, event->window.data1)); evt.size.width = static_cast<unsigned int>(std::max(0, event->window.data1));
evt.size.height = static_cast<unsigned int>(std::max(0, event->window.data2)); evt.size.height = static_cast<unsigned int>(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; break;
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:
@ -387,38 +385,36 @@ namespace Nz
evt.key.shift = (event->key.keysym.mod & KMOD_SHIFT) != 0; evt.key.shift = (event->key.keysym.mod & KMOD_SHIFT) != 0;
evt.key.system = (event->key.keysym.mod & KMOD_GUI) != 0; evt.key.system = (event->key.keysym.mod & KMOD_GUI) != 0;
// implements X11/Win32 APIs behavior for Enter and Backspace // implements X11/Win32 APIs behavior for Enter and Backspace
switch (evt.key.virtualKey) { switch (evt.key.virtualKey) {
case Nz::Keyboard::VKey::NumpadReturn: case Nz::Keyboard::VKey::NumpadReturn:
case Nz::Keyboard::VKey::Return: case Nz::Keyboard::VKey::Return:
if (window->m_lastEditEventLength != 0) if (window->m_lastEditEventLength != 0)
{ break;
break; window->m_parent->PushEvent(evt);
}
window->m_parent->PushEvent(evt);
evt.type = WindowEventType_TextEntered; evt.type = WindowEventType_TextEntered;
evt.text.character = U'\n'; evt.text.character = U'\n';
evt.text.repeated = event->key.repeat != 0; evt.text.repeated = event->key.repeat != 0;
window->m_parent->PushEvent(evt); window->m_parent->PushEvent(evt);
break; break;
case Nz::Keyboard::VKey::Backspace: case Nz::Keyboard::VKey::Backspace:
window->m_parent->PushEvent(evt); window->m_parent->PushEvent(evt);
evt.type = WindowEventType_TextEntered; evt.type = WindowEventType_TextEntered;
evt.text.character = U'\b'; evt.text.character = U'\b';
evt.text.repeated = event->key.repeat != 0; evt.text.repeated = event->key.repeat != 0;
window->m_parent->PushEvent(evt); window->m_parent->PushEvent(evt);
break; break;
default: default:
break; break;
} }
break; break;
@ -443,42 +439,42 @@ namespace Nz
return 0; return 0;
evt.type = WindowEventType_TextEntered; 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); window->m_parent->PushEvent(evt);
} }
// prevent post switch event // prevent post switch event
evt.type = WindowEventType::WindowEventType_Max; evt.type = WindowEventType::WindowEventType_Max;
break; break;
case SDL_TEXTEDITING: case SDL_TEXTEDITING:
if (SDL_GetWindowID(window->m_handle) != event->edit.windowID) if (SDL_GetWindowID(window->m_handle) != event->edit.windowID)
return 0; return 0;
evt.type = WindowEventType_TextEdited; evt.type = WindowEventType_TextEdited;
evt.edit.length = event->edit.length; evt.edit.length = event->edit.length;
window->m_lastEditEventLength = evt.edit.length; window->m_lastEditEventLength = evt.edit.length;
for (std::size_t i = 0; i < 32; i++) for (std::size_t i = 0; i < 32; i++)
{ {
evt.edit.text[i] = event->edit.text[i]; evt.edit.text[i] = event->edit.text[i];
} }
break; break;
} }
if (evt.type != WindowEventType::WindowEventType_Max) if (evt.type != WindowEventType::WindowEventType_Max)
window->m_parent->PushEvent(evt); window->m_parent->PushEvent(evt);
} }
catch (std::exception e) catch (std::exception e)
{ {
NazaraError(e.what()); NazaraError(e.what());
} }
catch (...) // Don't let any exceptions go thru C calls catch (...) // Don't let any exceptions go thru C calls
{ {
@ -560,11 +556,11 @@ namespace Nz
} }
bool WindowImpl::Initialize() bool WindowImpl::Initialize()
{ {
if (SDL_Init(SDL_INIT_VIDEO) < 0) if (SDL_Init(SDL_INIT_VIDEO) < 0)
{ {
NazaraError(SDL_GetError()); NazaraError(SDL_GetError());
return false; return false;
} }
if (SDL_GL_LoadLibrary(nullptr) < 0) if (SDL_GL_LoadLibrary(nullptr) < 0)
{ {
@ -572,7 +568,7 @@ namespace Nz
SDL_Quit(); SDL_Quit();
return false; return false;
} }
if (SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, true) < 0) if (SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, true) < 0)
NazaraError("Couldn't set share OpenGL contexes"); NazaraError("Couldn't set share OpenGL contexes");

View File

@ -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); //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_Cursor* m_cursor;
SDL_Window* m_handle; SDL_Window* m_handle;
WindowStyleFlags m_style; WindowStyleFlags m_style;

View File

@ -744,10 +744,9 @@ namespace Nz
#if defined(NAZARA_PLATFORM_SDL2) #if defined(NAZARA_PLATFORM_SDL2)
if (SDL_VideoInit(NULL) != 0) if (SDL_VideoInit(NULL) != 0)
{ NazaraError(SDL_GetError());
NazaraError(SDL_GetError());
}
#elif defined(NAZARA_PLATFORM_GLX) #elif defined(NAZARA_PLATFORM_GLX)
Initializer<X11> display; Initializer<X11> display;
if (!display) if (!display)