From b99708e7d37bf4a28706dcb2b459df0fa3e8281b Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Sat, 20 Jun 2020 16:34:10 +0100 Subject: [PATCH] Move windows to uptr. Add simple text editing. --- README.md | 2 +- apps/gui-main.cpp | 24 +- src/client/GuiApplication.cpp | 65 +-- src/client/GuiApplication.h | 14 +- src/console/MainApplication.cpp | 34 +- src/console/MainApplication.h | 18 +- src/core/Color.cpp | 41 +- src/core/Color.h | 24 +- src/ui_elements/CMakeLists.txt | 1 + src/ui_elements/desktop_elements/Keyboard.cpp | 6 +- src/ui_elements/desktop_elements/Keyboard.h | 21 +- src/ui_elements/desktop_elements/Window.cpp | 57 ++- src/ui_elements/desktop_elements/Window.h | 35 +- src/ui_elements/ui_events/KeyboardEvent.cpp | 24 +- src/ui_elements/ui_events/KeyboardEvent.h | 30 +- src/ui_elements/ui_events/MouseEvent.cpp | 32 +- src/ui_elements/ui_events/MouseEvent.h | 36 +- src/ui_elements/ui_events/PaintEvent.cpp | 8 +- src/ui_elements/ui_events/PaintEvent.h | 8 +- src/ui_elements/ui_events/UiEvent.cpp | 10 +- src/ui_elements/ui_events/UiEvent.h | 24 +- src/ui_elements/widgets/Button.cpp | 47 +- src/ui_elements/widgets/Button.h | 14 +- src/ui_elements/widgets/HorizontalSpacer.cpp | 37 +- src/ui_elements/widgets/HorizontalSpacer.h | 10 +- src/ui_elements/widgets/Label.cpp | 34 +- src/ui_elements/widgets/Label.h | 12 +- src/ui_elements/widgets/TextBox.cpp | 97 ++++ src/ui_elements/widgets/TextBox.h | 29 ++ src/ui_elements/widgets/Widget.cpp | 189 ++++--- src/ui_elements/widgets/Widget.h | 56 ++- .../widgets/elements/GeometryElement.cpp | 37 +- .../widgets/elements/GeometryElement.h | 44 +- .../widgets/elements/RectangleElement.cpp | 28 +- .../widgets/elements/RectangleElement.h | 23 +- .../widgets/elements/TextElement.cpp | 36 +- .../widgets/elements/TextElement.h | 22 +- .../widgets/elements/VisualLayer.cpp | 37 +- .../widgets/elements/VisualLayer.h | 23 +- src/windows/AbstractDesktopApp.h | 4 +- src/windows/CMakeLists.txt | 1 + src/windows/managers/DesktopManager.cpp | 119 ++--- src/windows/managers/DesktopManager.h | 46 +- src/windows/managers/EventManager.cpp | 24 + src/windows/managers/EventManager.h | 20 + src/windows/managers/WindowManager.cpp | 36 +- src/windows/managers/WindowManager.h | 22 +- .../ui_interfaces/x11/XcbInterface.cpp | 465 +++++++++--------- src/windows/ui_interfaces/x11/XcbInterface.h | 62 +-- src/windows/ui_interfaces/x11/XcbKeyboard.cpp | 25 +- src/windows/ui_interfaces/x11/XcbKeyboard.h | 8 +- .../ui_interfaces/x11/XcbLayerInterface.cpp | 58 +-- .../ui_interfaces/x11/XcbLayerInterface.h | 14 +- .../ui_interfaces/x11/XcbTextInterface.cpp | 48 +- .../ui_interfaces/x11/XcbTextInterface.h | 10 +- 55 files changed, 1257 insertions(+), 994 deletions(-) create mode 100644 src/ui_elements/widgets/TextBox.cpp create mode 100644 src/ui_elements/widgets/TextBox.h create mode 100644 src/windows/managers/EventManager.cpp create mode 100644 src/windows/managers/EventManager.h diff --git a/README.md b/README.md index 7f5faf2..d4d6486 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # limmto -limmto (Light Multi-Media Tool) is a low-dependency C++ library for working with a range of digital media. +limmto (Light Multi-Media Tool) is a free, low-dependency C++ library for working with digital media. ```bash mkdir build diff --git a/apps/gui-main.cpp b/apps/gui-main.cpp index aae106a..c9ce6a3 100644 --- a/apps/gui-main.cpp +++ b/apps/gui-main.cpp @@ -6,19 +6,19 @@ int main(int argc, char *argv[]) { - auto command_line_args = CommandLineArgs::CreateUnique(); - command_line_args->Process(argc, argv); - command_line_args->RecordLaunchPath(); + auto args = CommandLineArgs::CreateUnique(); + args->Process(argc, argv); + args->RecordLaunchPath(); - // Start the main app - auto main_app = MainApplication::Create(); - main_app->Initialize(std::move(command_line_args)); + // Start the main app + auto main_app = MainApplication::Create(); + main_app->Initialize(std::move(args)); - // Start the gui app - auto gui_app = std::make_shared(); - gui_app->SetMainApplication(main_app); - gui_app->Run(); + // Start the gui app + auto gui_app = GuiApplication(); + gui_app.SetMainApplication(main_app); + gui_app.Run(); - main_app->ShutDown(); - return 0; + main_app->ShutDown(); + return 0; } diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index 421a115..fef6b36 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -1,8 +1,8 @@ #include "GuiApplication.h" -#include #include "Widget.h" #include "HorizontalSpacer.h" +#include "TextBox.h" #include "Button.h" #include "Label.h" #include "XcbInterface.h" @@ -12,11 +12,11 @@ #include "WindowManager.h" GuiApplication::GuiApplication() - : AbstractDesktopApp(), - mMainApplication(), - mDesktopManager() + : AbstractDesktopApp(), + mMainApplication(), + mDesktopManager(DesktopManager::Create()) { - mDesktopManager = DesktopManager::Create(); + } GuiApplication::~GuiApplication() @@ -26,45 +26,46 @@ GuiApplication::~GuiApplication() void GuiApplication::SetMainApplication(MainApplicationPtr app) { - mMainApplication = app; - //mDesktopManager->SetMainApp(shared_from_this()); + mMainApplication = app; } void GuiApplication::Run() { - auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); + auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); - mainWindow->SetSize(800, 600); + mainWindow->SetSize(800, 600); - auto label = Label::Create(); - label->SetLabel("Click the button!!"); - label->SetBackgroundColor(Color::Create(0, 200, 200)); + auto label = Label::Create(); + label->SetLabel("Type text!!"); + label->SetBackgroundColor(Color::Create(0, 200, 200)); - auto button = Button::Create(); - button->SetLabel("Ok"); - button->SetBackgroundColor(Color::Create(0, 0, 200)); + auto textBox = TextBox::Create(); - auto spacer = HorizontalSpacer::Create(); - spacer->AddWidget(label); - spacer->AddWidget(button); + auto button = Button::Create(); + button->SetLabel("Save"); + button->SetBackgroundColor(Color::Create(0, 0, 200)); - mainWindow->AddWidget(spacer); + auto spacer = HorizontalSpacer::Create(); + spacer->AddWidget(std::move(label)); + spacer->AddWidget(std::move(textBox)); + spacer->AddWidget(std::move(button)); - mDesktopManager->SetKeyboard(XcbKeyboard::Create()); + mainWindow->AddWidget(std::move(spacer)); + mDesktopManager->SetKeyboard(XcbKeyboard::Create()); - bool useOpenGl = false; - XcbInterface window_interface; - window_interface.SetUseOpenGl(useOpenGl); - window_interface.Initialize(); - window_interface.AddWindow(mainWindow); - window_interface.ShowWindow(mainWindow); - if(useOpenGl) - { - window_interface.CreateOpenGlDrawable(mainWindow); - } + bool useOpenGl = false; + XcbInterface window_interface; + window_interface.SetUseOpenGl(useOpenGl); + window_interface.Initialize(); + window_interface.AddWindow(mainWindow); + window_interface.ShowWindow(mainWindow); + if(useOpenGl) + { + window_interface.CreateOpenGlDrawable(mainWindow); + } - window_interface.Loop(mDesktopManager); + window_interface.Loop(mDesktopManager.get()); - window_interface.ShutDown(); + window_interface.ShutDown(); } diff --git a/src/client/GuiApplication.h b/src/client/GuiApplication.h index c3c9445..27a659c 100644 --- a/src/client/GuiApplication.h +++ b/src/client/GuiApplication.h @@ -6,21 +6,21 @@ #include "AbstractDesktopApp.h" #include "DesktopManager.h" -class GuiApplication : public AbstractDesktopApp, std::enable_shared_from_this +class GuiApplication : public AbstractDesktopApp { private: - DesktopManagerPtr mDesktopManager; - MainApplicationPtr mMainApplication; + DesktopManagerUPtr mDesktopManager; + MainApplicationPtr mMainApplication; public: - GuiApplication(); + GuiApplication(); - ~GuiApplication(); + ~GuiApplication(); - void SetMainApplication(MainApplicationPtr app); + void SetMainApplication(MainApplicationPtr app); - void Run(); + void Run(); }; diff --git a/src/console/MainApplication.cpp b/src/console/MainApplication.cpp index b464f7b..df489b3 100644 --- a/src/console/MainApplication.cpp +++ b/src/console/MainApplication.cpp @@ -6,8 +6,8 @@ #include MainApplication::MainApplication() - : mDatabaseManager(), - mCommandLineArgs() + : mDatabaseManager(), + mCommandLineArgs() { } @@ -22,16 +22,16 @@ void MainApplication::Initialize(CommandLineArgsUPtr commandLineArgs) mCommandLineArgs = std::move(commandLineArgs); std::string launch_path = mCommandLineArgs->GetLaunchPath().string(); - FileLogger::GetInstance().SetWorkDirectory(launch_path); - FileLogger::GetInstance().Open(); - MLOG_INFO("Launched"); + FileLogger::GetInstance().SetWorkDirectory(launch_path); + FileLogger::GetInstance().Open(); + MLOG_INFO("Launched"); - mDatabaseManager = DatabaseManager::Create(); - mDatabaseManager->CreateDatabase(launch_path + "/database.db"); + mDatabaseManager = DatabaseManager::Create(); + mDatabaseManager->CreateDatabase(launch_path + "/database.db"); - mNetworkManager = NetworkManager::Create(); + mNetworkManager = NetworkManager::Create(); - mAudioManager = AudioManager::Create(); + mAudioManager = AudioManager::Create(); } void MainApplication::Run() @@ -77,13 +77,13 @@ void MainApplication::Run() void MainApplication::RunServer() { - mNetworkManager->RunHttpServer(); + mNetworkManager->RunHttpServer(); } void MainApplication::PlayAudio() { - //MidiReader reader; - //reader.Read("/home/james/sample.mid"); + //MidiReader reader; + //reader.Read("/home/james/sample.mid"); auto device = AudioDevice::Create(); mAudioManager->GetAudioInterface()->OpenDevice(device); mAudioManager->GetAudioInterface()->Play(device); @@ -100,13 +100,13 @@ void MainApplication::ConvertDocument(const std::string& inputPath, const std::s void MainApplication::ShutDown() { - mDatabaseManager->OnShutDown(); - mNetworkManager->ShutDown(); - MLOG_INFO("Shut down"); - FileLogger::GetInstance().Close(); + mDatabaseManager->OnShutDown(); + mNetworkManager->ShutDown(); + MLOG_INFO("Shut down"); + FileLogger::GetInstance().Close(); } std::shared_ptr MainApplication::Create() { - return std::make_shared(); + return std::make_shared(); } diff --git a/src/console/MainApplication.h b/src/console/MainApplication.h index 780e6c7..3ab6977 100644 --- a/src/console/MainApplication.h +++ b/src/console/MainApplication.h @@ -14,23 +14,23 @@ class MainApplication private: CommandLineArgsUPtr mCommandLineArgs; - DatabaseManagerPtr mDatabaseManager; - NetworkManagerPtr mNetworkManager; - AudioManagerPtr mAudioManager; + DatabaseManagerPtr mDatabaseManager; + NetworkManagerPtr mNetworkManager; + AudioManagerPtr mAudioManager; public: - MainApplication(); + MainApplication(); - ~MainApplication(); + ~MainApplication(); - void Initialize(CommandLineArgsUPtr commandLineArgs); + void Initialize(CommandLineArgsUPtr commandLineArgs); - void Run(); + void Run(); - void ShutDown(); + void ShutDown(); - static std::shared_ptr Create(); + static std::shared_ptr Create(); private: void RunServer(); diff --git a/src/core/Color.cpp b/src/core/Color.cpp index d914b23..649dd03 100644 --- a/src/core/Color.cpp +++ b/src/core/Color.cpp @@ -1,36 +1,47 @@ #include "Color.h" Color::Color(unsigned r, unsigned g, unsigned b, double a) - : mR(r), - mG(g), - mB(b), - mAlpha(a) + : mR(r), + mG(g), + mB(b), + mAlpha(a) { } -std::shared_ptr Color::Create(unsigned r, unsigned g, unsigned b, - double a ) +std::shared_ptr Color::CreateShared(unsigned r, unsigned g, unsigned b, + double a ) { - return std::make_shared(r, g, b, a); + return std::make_shared(r, g, b, a); } -unsigned Color::GetR() +std::unique_ptr Color::Create(unsigned r, unsigned g, unsigned b, + double a ) { - return mR; + return std::make_unique(r, g, b, a); } -unsigned Color::GetG() +std::unique_ptr Color::Create(const Color& color) { - return mG; + return std::make_unique(color); } -unsigned Color::GetB() +unsigned Color::GetR() const { - return mB; + return mR; } -double Color::GetAlpha() +unsigned Color::GetG() const { - return mAlpha; + return mG; +} + +unsigned Color::GetB() const +{ + return mB; +} + +double Color::GetAlpha() const +{ + return mAlpha; } diff --git a/src/core/Color.h b/src/core/Color.h index 6eb31e8..419173c 100644 --- a/src/core/Color.h +++ b/src/core/Color.h @@ -3,21 +3,23 @@ class Color { - unsigned mR; - unsigned mG; - unsigned mB; - double mAlpha; + unsigned mR; + unsigned mG; + unsigned mB; + double mAlpha; public: + Color(unsigned r, unsigned g, unsigned b, double a = 1.0); - Color(unsigned r, unsigned g, unsigned b, double a = 1.0); + static std::shared_ptr CreateShared(unsigned r, unsigned g, unsigned b, double a = 1.0); + static std::unique_ptr Create(unsigned r, unsigned g, unsigned b, double a = 1.0); + static std::unique_ptr Create(const Color& color); - static std::shared_ptr Create(unsigned r, unsigned g, unsigned b, double a = 1.0); - - unsigned GetR(); - unsigned GetG(); - unsigned GetB(); - double GetAlpha(); + unsigned GetR() const; + unsigned GetG() const; + unsigned GetB() const; + double GetAlpha() const; }; using ColorPtr = std::shared_ptr; +using ColorUPtr = std::unique_ptr; diff --git a/src/ui_elements/CMakeLists.txt b/src/ui_elements/CMakeLists.txt index 6efb425..37a3cb0 100644 --- a/src/ui_elements/CMakeLists.txt +++ b/src/ui_elements/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND ui_elements_LIB_INCLUDES widgets/Button.cpp widgets/Label.cpp widgets/HorizontalSpacer.cpp + widgets/TextBox.cpp widgets/elements/GeometryElement.cpp widgets/elements/RectangleElement.cpp widgets/elements/TextElement.cpp diff --git a/src/ui_elements/desktop_elements/Keyboard.cpp b/src/ui_elements/desktop_elements/Keyboard.cpp index 4bb65fd..8f50236 100644 --- a/src/ui_elements/desktop_elements/Keyboard.cpp +++ b/src/ui_elements/desktop_elements/Keyboard.cpp @@ -1,13 +1,13 @@ #include "Keyboard.h" Keyboard::Keyboard() - :mKeyMap() + :mKeyMap() { } -std::shared_ptr Keyboard::Create() +std::unique_ptr Keyboard::Create() { - return std::make_shared(); + return std::make_unique(); } diff --git a/src/ui_elements/desktop_elements/Keyboard.h b/src/ui_elements/desktop_elements/Keyboard.h index 3bbdeb4..de12d6b 100644 --- a/src/ui_elements/desktop_elements/Keyboard.h +++ b/src/ui_elements/desktop_elements/Keyboard.h @@ -6,21 +6,22 @@ class Keyboard { public: - using KeyCode = unsigned; + using KeyCode = unsigned; protected: - std::map mKeyMap; + std::map mKeyMap; public: - Keyboard(); - virtual ~Keyboard() = default; + Keyboard(); - static std::shared_ptr Create(); + virtual ~Keyboard() = default; - virtual std::string GetKeyString(KeyCode code) - { - return ""; - } + static std::unique_ptr Create(); + + virtual std::string GetKeyString(KeyCode code) + { + return ""; + } }; -using KeyboardPtr = std::shared_ptr; +using KeyboardUPtr = std::unique_ptr; diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp index 8181695..cb0f092 100644 --- a/src/ui_elements/desktop_elements/Window.cpp +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -2,9 +2,9 @@ namespace mt{ Window::Window() - :mWidth(400), - mHeight(300), - mWidget() + :mWidth(400), + mHeight(300), + mWidget() { } @@ -14,54 +14,59 @@ Window::~Window() } -std::vector Window::GetLayers() +std::unique_ptr Window::Create() { - return mLayers; + return std::make_unique(); } -void Window::OnMouseEvent(MouseEventPtr event) +std::vector Window::GetLayers() { - mWidget->OnMouseEvent(event); + return mLayers; } -void Window::OnPaint(PaintEventPtr event) +void Window::OnMouseEvent(const MouseEvent* event) { - mLayers.clear(); - mWidget->SetSize(mWidth, mHeight); - mWidget->OnPaintEvent(event); - - auto layers = mWidget->GetLayers(); - mLayers.insert(mLayers.end(), layers.begin(), layers.end()); + mWidget->OnMouseEvent(event); } -std::shared_ptr Window::Create() +void Window::OnKeyboardEvent(const KeyboardEvent* event) { - return std::make_shared(); + mWidget->OnKeyboardEvent(event); } -void Window::AddWidget(WidgetPtr widget) +void Window::OnPaint(const PaintEvent* event) { - mWidget = widget; + mLayers.clear(); + mWidget->SetSize(mWidth, mHeight); + mWidget->OnPaintEvent(event); + + auto layers = mWidget->GetLayers(); + mLayers.insert(mLayers.end(), layers.begin(), layers.end()); } -WidgetPtr Window::GetWidget() +void Window::AddWidget(WidgetUPtr widget) { - return mWidget; + mWidget = std::move(widget); } -unsigned Window::GetWidth() +Widget* Window::GetWidget() const { - return mWidth; + return mWidget.get(); } -unsigned Window::GetHeight() +unsigned Window::GetWidth() const { - return mHeight; + return mWidth; +} + +unsigned Window::GetHeight() const +{ + return mHeight; } void Window::SetSize(unsigned width, unsigned height) { - mWidth = width; - mHeight = height; + mWidth = width; + mHeight = height; } } diff --git a/src/ui_elements/desktop_elements/Window.h b/src/ui_elements/desktop_elements/Window.h index 5ac4b59..0ed42ab 100644 --- a/src/ui_elements/desktop_elements/Window.h +++ b/src/ui_elements/desktop_elements/Window.h @@ -5,6 +5,7 @@ #include "PaintEvent.h" #include "MouseEvent.h" +#include "KeyboardEvent.h" #include "VisualLayer.h" #include "Widget.h" @@ -16,35 +17,37 @@ class Window private: - WidgetPtr mWidget; - unsigned mWidth; - unsigned mHeight; - std::vector mLayers; + WidgetUPtr mWidget; + unsigned mWidth; + unsigned mHeight; + std::vector mLayers; public: - Window(); + Window(); - ~Window(); + ~Window(); - static std::shared_ptr Create(); + static std::unique_ptr Create(); - void AddWidget(WidgetPtr widget); + void AddWidget(WidgetUPtr widget); - WidgetPtr GetWidget(); + Widget* GetWidget() const; - std::vector GetLayers(); + std::vector GetLayers(); - unsigned GetWidth(); + unsigned GetWidth() const; - unsigned GetHeight(); + unsigned GetHeight() const; - void SetSize(unsigned width, unsigned height); + void SetSize(unsigned width, unsigned height); - void OnPaint(PaintEventPtr event); + void OnPaint(const PaintEvent* event); - void OnMouseEvent(MouseEventPtr event); + void OnMouseEvent(const MouseEvent* event); + + void OnKeyboardEvent(const KeyboardEvent* event); }; } -using WindowPtr = std::shared_ptr; +using WindowUPtr = std::unique_ptr; diff --git a/src/ui_elements/ui_events/KeyboardEvent.cpp b/src/ui_elements/ui_events/KeyboardEvent.cpp index b1deaf2..06e3280 100644 --- a/src/ui_elements/ui_events/KeyboardEvent.cpp +++ b/src/ui_elements/ui_events/KeyboardEvent.cpp @@ -1,11 +1,11 @@ #include "KeyboardEvent.h" KeyboardEvent::KeyboardEvent() - : UiEvent(), - mAction(), - mKeyString() + : UiEvent(), + mAction(), + mKeyString() { - mType = UiEvent::Type::Keyboard; + mType = UiEvent::Type::Keyboard; } KeyboardEvent::~KeyboardEvent() @@ -13,27 +13,27 @@ KeyboardEvent::~KeyboardEvent() } -std::shared_ptr KeyboardEvent::Create() +std::unique_ptr KeyboardEvent::Create() { - return std::make_shared(); + return std::make_unique(); } void KeyboardEvent::SetKeyString(const std::string& key) { - mKeyString = key; + mKeyString = key; } -std::string KeyboardEvent::GetKeyString() +std::string KeyboardEvent::GetKeyString() const { - return mKeyString; + return mKeyString; } void KeyboardEvent::SetAction(Action action) { - mAction = action; + mAction = action; } -KeyboardEvent::Action KeyboardEvent::GetAction() +KeyboardEvent::Action KeyboardEvent::GetAction() const { - return mAction; + return mAction; } diff --git a/src/ui_elements/ui_events/KeyboardEvent.h b/src/ui_elements/ui_events/KeyboardEvent.h index dbba79e..9dcc8f5 100644 --- a/src/ui_elements/ui_events/KeyboardEvent.h +++ b/src/ui_elements/ui_events/KeyboardEvent.h @@ -8,32 +8,32 @@ class KeyboardEvent : public UiEvent { public: - enum class Action - { - Pressed, - Released - }; + enum class Action + { + Pressed, + Released + }; private: - Action mAction; - std::string mKeyString; + Action mAction; + std::string mKeyString; public: - KeyboardEvent(); + KeyboardEvent(); - ~KeyboardEvent(); + ~KeyboardEvent(); - static std::shared_ptr Create(); + static std::unique_ptr Create(); - void SetKeyString(const std::string& key); + void SetKeyString(const std::string& key); - std::string GetKeyString(); + std::string GetKeyString() const; - void SetAction(Action action); + void SetAction(Action action); - Action GetAction(); + Action GetAction() const; }; -using KeyboardEventPtr = std::shared_ptr; +using KeyboardEventUPtr = std::unique_ptr; diff --git a/src/ui_elements/ui_events/MouseEvent.cpp b/src/ui_elements/ui_events/MouseEvent.cpp index f95ddf5..6d018ec 100644 --- a/src/ui_elements/ui_events/MouseEvent.cpp +++ b/src/ui_elements/ui_events/MouseEvent.cpp @@ -1,12 +1,12 @@ #include "MouseEvent.h" MouseEvent::MouseEvent() - : UiEvent(), - mClientLocation(0, 0), - mScreenLocation(0, 0), - mAction() + : UiEvent(), + mClientLocation(0, 0), + mScreenLocation(0, 0), + mAction() { - mType = UiEvent::Type::Mouse; + mType = UiEvent::Type::Mouse; } MouseEvent::~MouseEvent() @@ -14,38 +14,38 @@ MouseEvent::~MouseEvent() } -std::shared_ptr MouseEvent::Create() +std::unique_ptr MouseEvent::Create() { - return std::make_shared(); + return std::make_unique(); } void MouseEvent::SetClientLocation(Pixel location) { - mClientLocation = location; + mClientLocation = location; } void MouseEvent::SetScreenLocation(Pixel location) { - mScreenLocation = location; + mScreenLocation = location; } void MouseEvent::SetAction(MouseEvent::Action action) { - mAction = action; + mAction = action; } -Pixel MouseEvent::GetClientLocation() +Pixel MouseEvent::GetClientLocation() const { - return mClientLocation; + return mClientLocation; } -Pixel MouseEvent::GetScreenLocation() +Pixel MouseEvent::GetScreenLocation() const { - return mScreenLocation; + return mScreenLocation; } -MouseEvent::Action MouseEvent::GetAction() +MouseEvent::Action MouseEvent::GetAction() const { - return mAction; + return mAction; } diff --git a/src/ui_elements/ui_events/MouseEvent.h b/src/ui_elements/ui_events/MouseEvent.h index dfc2540..3c17dfe 100644 --- a/src/ui_elements/ui_events/MouseEvent.h +++ b/src/ui_elements/ui_events/MouseEvent.h @@ -8,35 +8,35 @@ class MouseEvent : public UiEvent { public: - enum class Action - { - Pressed, - Released - }; + enum class Action + { + Pressed, + Released + }; private: - Pixel mClientLocation; - Pixel mScreenLocation; - Action mAction; + Pixel mClientLocation; + Pixel mScreenLocation; + Action mAction; public: - MouseEvent(); + MouseEvent(); - ~MouseEvent(); + ~MouseEvent(); - static std::shared_ptr Create(); + static std::unique_ptr Create(); - void SetClientLocation(Pixel location); + void SetClientLocation(Pixel location); - void SetScreenLocation(Pixel location); + void SetScreenLocation(Pixel location); - void SetAction(Action action); + void SetAction(Action action); - Pixel GetClientLocation(); + Pixel GetClientLocation() const; - Pixel GetScreenLocation(); + Pixel GetScreenLocation() const; - Action GetAction(); + Action GetAction() const; }; -using MouseEventPtr = std::shared_ptr; +using MouseEventUPtr = std::unique_ptr; diff --git a/src/ui_elements/ui_events/PaintEvent.cpp b/src/ui_elements/ui_events/PaintEvent.cpp index 783c2f4..99d1fc9 100644 --- a/src/ui_elements/ui_events/PaintEvent.cpp +++ b/src/ui_elements/ui_events/PaintEvent.cpp @@ -1,9 +1,9 @@ #include "PaintEvent.h" PaintEvent::PaintEvent() - : UiEvent() + : UiEvent() { - mType = UiEvent::Type::Paint; + mType = UiEvent::Type::Paint; } PaintEvent::~PaintEvent() @@ -11,8 +11,8 @@ PaintEvent::~PaintEvent() } -std::shared_ptr PaintEvent::Create() +std::unique_ptr PaintEvent::Create() { - return std::make_shared(); + return std::make_unique(); } diff --git a/src/ui_elements/ui_events/PaintEvent.h b/src/ui_elements/ui_events/PaintEvent.h index 74687b4..b64f988 100644 --- a/src/ui_elements/ui_events/PaintEvent.h +++ b/src/ui_elements/ui_events/PaintEvent.h @@ -8,10 +8,10 @@ class PaintEvent : public UiEvent { public: - PaintEvent(); + PaintEvent(); - ~PaintEvent(); + ~PaintEvent(); - static std::shared_ptr Create(); + static std::unique_ptr Create(); }; -using PaintEventPtr = std::shared_ptr; +using PaintEventUPtr = std::unique_ptr; diff --git a/src/ui_elements/ui_events/UiEvent.cpp b/src/ui_elements/ui_events/UiEvent.cpp index 68dd48a..74533ba 100644 --- a/src/ui_elements/ui_events/UiEvent.cpp +++ b/src/ui_elements/ui_events/UiEvent.cpp @@ -1,7 +1,7 @@ #include "UiEvent.h" UiEvent::UiEvent() - : mType(Type::Unknown) + : mType(Type::Unknown) { } @@ -11,13 +11,13 @@ UiEvent::~UiEvent() } -std::shared_ptr UiEvent::Create() +std::unique_ptr UiEvent::Create() { - return std::make_shared(); + return std::make_unique(); } -UiEvent::Type UiEvent::GetType() +UiEvent::Type UiEvent::GetType() const { - return mType; + return mType; } diff --git a/src/ui_elements/ui_events/UiEvent.h b/src/ui_elements/ui_events/UiEvent.h index 305d1a2..0423fe9 100644 --- a/src/ui_elements/ui_events/UiEvent.h +++ b/src/ui_elements/ui_events/UiEvent.h @@ -6,24 +6,24 @@ class UiEvent { public: - enum class Type{ - Unknown, - Paint, - Mouse, - Keyboard - }; + enum class Type{ + Unknown, + Paint, + Mouse, + Keyboard + }; protected: - UiEvent::Type mType; + UiEvent::Type mType; public: - UiEvent(); + UiEvent(); - virtual ~UiEvent(); + virtual ~UiEvent(); - static std::shared_ptr Create(); + static std::unique_ptr Create(); - Type GetType(); + Type GetType() const; }; -using UiEventPtr = std::shared_ptr; +using UiEventUPtr = std::unique_ptr; diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index f7ab1a3..e077008 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -2,43 +2,42 @@ #include Button::Button() - : Widget(), - mLabel() + : Widget(), + mLabel() { } -std::shared_ptr