From 59c6161fdb0cbb8f1b3a71272a13b07a3ff0eb53 Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Sat, 2 May 2020 08:31:03 +0100 Subject: [PATCH] Initial commit. --- .gitignore | 3 + CMakeLists.txt | 11 + apps/CMakeLists.txt | 32 ++ apps/console-main.cpp | 16 + apps/gui-main.cpp | 20 + apps/markdown-practice.cpp | 47 +++ apps/xml-practice.cpp | 38 ++ src/CMakeLists.txt | 11 + src/audio/AudioDevice.cpp | 71 ++++ src/audio/AudioDevice.h | 46 +++ src/audio/AudioManager.cpp | 33 ++ src/audio/AudioManager.h | 32 ++ src/audio/CMakeLists.txt | 13 + src/audio/audio_interfaces/AlsaInterface.cpp | 141 +++++++ src/audio/audio_interfaces/AlsaInterface.h | 39 ++ src/client/CMakeLists.txt | 10 + src/client/GuiApplication.cpp | 70 ++++ src/client/GuiApplication.h | 26 ++ src/console/CMakeLists.txt | 13 + src/console/MainApplication.cpp | 52 +++ src/console/MainApplication.h | 37 ++ src/core/CMakeLists.txt | 13 + src/core/Color.cpp | 36 ++ src/core/Color.h | 23 ++ src/core/CommandLineArgs.cpp | 29 ++ src/core/CommandLineArgs.h | 19 + src/core/Event.cpp | 11 + src/core/Event.h | 8 + src/core/StringUtils.cpp | 14 + src/core/StringUtils.h | 19 + src/core/http/HttpResponse.cpp | 38 ++ src/core/http/HttpResponse.h | 26 ++ src/core/loggers/FileLogger.cpp | 44 ++ src/core/loggers/FileLogger.h | 35 ++ src/database/CMakeLists.txt | 13 + src/database/Database.cpp | 27 ++ src/database/Database.h | 24 ++ src/database/DatabaseManager.cpp | 36 ++ src/database/DatabaseManager.h | 27 ++ .../database_interfaces/SqliteInterface.cpp | 56 +++ .../database_interfaces/SqliteInterface.h | 26 ++ src/geometry/CMakeLists.txt | 7 + src/geometry/DiscretePoint.cpp | 28 ++ src/geometry/DiscretePoint.h | 25 ++ src/geometry/Point.cpp | 18 + src/geometry/Point.h | 19 + src/geometry/Rectangle.cpp | 0 src/geometry/Rectangle.h | 7 + src/graphics/CMakeLists.txt | 5 + src/graphics/OpenGlInterface.cpp | 20 + src/graphics/OpenGlInterface.h | 10 + src/network/CMakeLists.txt | 14 + src/network/NetworkManager.cpp | 36 ++ src/network/NetworkManager.h | 33 ++ src/network/sockets/Socket.cpp | 38 ++ src/network/sockets/Socket.h | 28 ++ src/network/sockets/UnixSocketInterface.cpp | 100 +++++ src/network/sockets/UnixSocketInterface.h | 30 ++ src/ui_elements/CMakeLists.txt | 29 ++ src/ui_elements/desktop_elements/Keyboard.cpp | 13 + src/ui_elements/desktop_elements/Keyboard.h | 26 ++ src/ui_elements/desktop_elements/Screen.cpp | 18 + src/ui_elements/desktop_elements/Screen.h | 17 + src/ui_elements/desktop_elements/Window.cpp | 67 +++ src/ui_elements/desktop_elements/Window.h | 50 +++ src/ui_elements/style/Theme.cpp | 0 src/ui_elements/style/Theme.h | 1 + src/ui_elements/ui_events/KeyboardEvent.cpp | 39 ++ src/ui_elements/ui_events/KeyboardEvent.h | 39 ++ src/ui_elements/ui_events/MouseEvent.cpp | 51 +++ src/ui_elements/ui_events/MouseEvent.h | 42 ++ src/ui_elements/ui_events/PaintEvent.cpp | 18 + src/ui_elements/ui_events/PaintEvent.h | 17 + src/ui_elements/ui_events/UiEvent.cpp | 23 ++ src/ui_elements/ui_events/UiEvent.h | 29 ++ src/ui_elements/widgets/Button.cpp | 44 ++ src/ui_elements/widgets/Button.h | 24 ++ src/ui_elements/widgets/HorizontalSpacer.cpp | 33 ++ src/ui_elements/widgets/HorizontalSpacer.h | 18 + src/ui_elements/widgets/Label.cpp | 35 ++ src/ui_elements/widgets/Label.h | 22 + src/ui_elements/widgets/Widget.cpp | 134 ++++++ src/ui_elements/widgets/Widget.h | 62 +++ .../widgets/elements/GeometryElement.cpp | 36 ++ .../widgets/elements/GeometryElement.h | 39 ++ .../widgets/elements/RectangleElement.cpp | 36 ++ .../widgets/elements/RectangleElement.h | 29 ++ .../widgets/elements/TextElement.cpp | 39 ++ .../widgets/elements/TextElement.h | 31 ++ .../widgets/elements/VisualLayer.cpp | 38 ++ .../widgets/elements/VisualLayer.h | 26 ++ src/web/CMakeLists.txt | 19 + src/web/html/HtmlDocument.cpp | 12 + src/web/html/HtmlDocument.h | 14 + src/web/html/HtmlDomManager.cpp | 0 src/web/html/HtmlDomManager.h | 0 src/web/html/HtmlElement.cpp | 11 + src/web/html/HtmlElement.h | 12 + src/web/html/HtmlWriter.cpp | 11 + src/web/html/HtmlWriter.h | 12 + src/web/html/elements/HtmlBodyElement.cpp | 0 src/web/html/elements/HtmlBodyElement.h | 0 src/web/html/elements/HtmlHeadElement.cpp | 0 src/web/html/elements/HtmlHeadElement.h | 0 .../html/elements/HtmlParagraphElement.cpp | 0 src/web/html/elements/HtmlParagraphElement.h | 0 src/web/markdown/MarkdownParser.cpp | 17 + src/web/markdown/MarkdownParser.h | 16 + src/web/xml/XmlAttribute.cpp | 29 ++ src/web/xml/XmlAttribute.h | 25 ++ src/web/xml/XmlDocument.cpp | 34 ++ src/web/xml/XmlDocument.h | 26 ++ src/web/xml/XmlElement.cpp | 61 +++ src/web/xml/XmlElement.h | 32 ++ src/web/xml/XmlParser.cpp | 380 ++++++++++++++++++ src/web/xml/XmlParser.h | 102 +++++ src/web/xml/XmlProlog.cpp | 54 +++ src/web/xml/XmlProlog.h | 36 ++ src/windows/AbstractDesktopApp.h | 13 + src/windows/CMakeLists.txt | 22 + src/windows/managers/DesktopManager.cpp | 112 ++++++ src/windows/managers/DesktopManager.h | 58 +++ src/windows/managers/WindowManager.cpp | 37 ++ src/windows/managers/WindowManager.h | 36 ++ .../ui_interfaces/x11/GlxInterface.cpp | 113 ++++++ src/windows/ui_interfaces/x11/GlxInterface.h | 32 ++ .../ui_interfaces/x11/XcbInterface.cpp | 348 ++++++++++++++++ src/windows/ui_interfaces/x11/XcbInterface.h | 84 ++++ src/windows/ui_interfaces/x11/XcbKeyboard.cpp | 24 ++ src/windows/ui_interfaces/x11/XcbKeyboard.h | 14 + .../ui_interfaces/x11/XcbLayerInterface.cpp | 50 +++ .../ui_interfaces/x11/XcbLayerInterface.h | 22 + .../ui_interfaces/x11/XcbTextInterface.cpp | 39 ++ .../ui_interfaces/x11/XcbTextInterface.h | 16 + 134 files changed, 4751 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 apps/CMakeLists.txt create mode 100644 apps/console-main.cpp create mode 100644 apps/gui-main.cpp create mode 100644 apps/markdown-practice.cpp create mode 100644 apps/xml-practice.cpp create mode 100644 src/CMakeLists.txt create mode 100644 src/audio/AudioDevice.cpp create mode 100644 src/audio/AudioDevice.h create mode 100644 src/audio/AudioManager.cpp create mode 100644 src/audio/AudioManager.h create mode 100644 src/audio/CMakeLists.txt create mode 100644 src/audio/audio_interfaces/AlsaInterface.cpp create mode 100644 src/audio/audio_interfaces/AlsaInterface.h create mode 100644 src/client/CMakeLists.txt create mode 100644 src/client/GuiApplication.cpp create mode 100644 src/client/GuiApplication.h create mode 100644 src/console/CMakeLists.txt create mode 100644 src/console/MainApplication.cpp create mode 100644 src/console/MainApplication.h create mode 100644 src/core/CMakeLists.txt create mode 100644 src/core/Color.cpp create mode 100644 src/core/Color.h create mode 100644 src/core/CommandLineArgs.cpp create mode 100644 src/core/CommandLineArgs.h create mode 100644 src/core/Event.cpp create mode 100644 src/core/Event.h create mode 100644 src/core/StringUtils.cpp create mode 100644 src/core/StringUtils.h create mode 100644 src/core/http/HttpResponse.cpp create mode 100644 src/core/http/HttpResponse.h create mode 100644 src/core/loggers/FileLogger.cpp create mode 100644 src/core/loggers/FileLogger.h create mode 100644 src/database/CMakeLists.txt create mode 100644 src/database/Database.cpp create mode 100644 src/database/Database.h create mode 100644 src/database/DatabaseManager.cpp create mode 100644 src/database/DatabaseManager.h create mode 100644 src/database/database_interfaces/SqliteInterface.cpp create mode 100644 src/database/database_interfaces/SqliteInterface.h create mode 100644 src/geometry/CMakeLists.txt create mode 100644 src/geometry/DiscretePoint.cpp create mode 100644 src/geometry/DiscretePoint.h create mode 100644 src/geometry/Point.cpp create mode 100644 src/geometry/Point.h create mode 100644 src/geometry/Rectangle.cpp create mode 100644 src/geometry/Rectangle.h create mode 100644 src/graphics/CMakeLists.txt create mode 100644 src/graphics/OpenGlInterface.cpp create mode 100644 src/graphics/OpenGlInterface.h create mode 100644 src/network/CMakeLists.txt create mode 100644 src/network/NetworkManager.cpp create mode 100644 src/network/NetworkManager.h create mode 100644 src/network/sockets/Socket.cpp create mode 100644 src/network/sockets/Socket.h create mode 100644 src/network/sockets/UnixSocketInterface.cpp create mode 100644 src/network/sockets/UnixSocketInterface.h create mode 100644 src/ui_elements/CMakeLists.txt create mode 100644 src/ui_elements/desktop_elements/Keyboard.cpp create mode 100644 src/ui_elements/desktop_elements/Keyboard.h create mode 100644 src/ui_elements/desktop_elements/Screen.cpp create mode 100644 src/ui_elements/desktop_elements/Screen.h create mode 100644 src/ui_elements/desktop_elements/Window.cpp create mode 100644 src/ui_elements/desktop_elements/Window.h create mode 100644 src/ui_elements/style/Theme.cpp create mode 100644 src/ui_elements/style/Theme.h create mode 100644 src/ui_elements/ui_events/KeyboardEvent.cpp create mode 100644 src/ui_elements/ui_events/KeyboardEvent.h create mode 100644 src/ui_elements/ui_events/MouseEvent.cpp create mode 100644 src/ui_elements/ui_events/MouseEvent.h create mode 100644 src/ui_elements/ui_events/PaintEvent.cpp create mode 100644 src/ui_elements/ui_events/PaintEvent.h create mode 100644 src/ui_elements/ui_events/UiEvent.cpp create mode 100644 src/ui_elements/ui_events/UiEvent.h create mode 100644 src/ui_elements/widgets/Button.cpp create mode 100644 src/ui_elements/widgets/Button.h create mode 100644 src/ui_elements/widgets/HorizontalSpacer.cpp create mode 100644 src/ui_elements/widgets/HorizontalSpacer.h create mode 100644 src/ui_elements/widgets/Label.cpp create mode 100644 src/ui_elements/widgets/Label.h create mode 100644 src/ui_elements/widgets/Widget.cpp create mode 100644 src/ui_elements/widgets/Widget.h create mode 100644 src/ui_elements/widgets/elements/GeometryElement.cpp create mode 100644 src/ui_elements/widgets/elements/GeometryElement.h create mode 100644 src/ui_elements/widgets/elements/RectangleElement.cpp create mode 100644 src/ui_elements/widgets/elements/RectangleElement.h create mode 100644 src/ui_elements/widgets/elements/TextElement.cpp create mode 100644 src/ui_elements/widgets/elements/TextElement.h create mode 100644 src/ui_elements/widgets/elements/VisualLayer.cpp create mode 100644 src/ui_elements/widgets/elements/VisualLayer.h create mode 100644 src/web/CMakeLists.txt create mode 100644 src/web/html/HtmlDocument.cpp create mode 100644 src/web/html/HtmlDocument.h create mode 100644 src/web/html/HtmlDomManager.cpp create mode 100644 src/web/html/HtmlDomManager.h create mode 100644 src/web/html/HtmlElement.cpp create mode 100644 src/web/html/HtmlElement.h create mode 100644 src/web/html/HtmlWriter.cpp create mode 100644 src/web/html/HtmlWriter.h create mode 100644 src/web/html/elements/HtmlBodyElement.cpp create mode 100644 src/web/html/elements/HtmlBodyElement.h create mode 100644 src/web/html/elements/HtmlHeadElement.cpp create mode 100644 src/web/html/elements/HtmlHeadElement.h create mode 100644 src/web/html/elements/HtmlParagraphElement.cpp create mode 100644 src/web/html/elements/HtmlParagraphElement.h create mode 100644 src/web/markdown/MarkdownParser.cpp create mode 100644 src/web/markdown/MarkdownParser.h create mode 100644 src/web/xml/XmlAttribute.cpp create mode 100644 src/web/xml/XmlAttribute.h create mode 100644 src/web/xml/XmlDocument.cpp create mode 100644 src/web/xml/XmlDocument.h create mode 100644 src/web/xml/XmlElement.cpp create mode 100644 src/web/xml/XmlElement.h create mode 100644 src/web/xml/XmlParser.cpp create mode 100644 src/web/xml/XmlParser.h create mode 100644 src/web/xml/XmlProlog.cpp create mode 100644 src/web/xml/XmlProlog.h create mode 100644 src/windows/AbstractDesktopApp.h create mode 100644 src/windows/CMakeLists.txt create mode 100644 src/windows/managers/DesktopManager.cpp create mode 100644 src/windows/managers/DesktopManager.h create mode 100644 src/windows/managers/WindowManager.cpp create mode 100644 src/windows/managers/WindowManager.h create mode 100644 src/windows/ui_interfaces/x11/GlxInterface.cpp create mode 100644 src/windows/ui_interfaces/x11/GlxInterface.h create mode 100644 src/windows/ui_interfaces/x11/XcbInterface.cpp create mode 100644 src/windows/ui_interfaces/x11/XcbInterface.h create mode 100644 src/windows/ui_interfaces/x11/XcbKeyboard.cpp create mode 100644 src/windows/ui_interfaces/x11/XcbKeyboard.h create mode 100644 src/windows/ui_interfaces/x11/XcbLayerInterface.cpp create mode 100644 src/windows/ui_interfaces/x11/XcbLayerInterface.h create mode 100644 src/windows/ui_interfaces/x11/XcbTextInterface.cpp create mode 100644 src/windows/ui_interfaces/x11/XcbTextInterface.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c6bc44 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.cproject +.project +.settings/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e197675 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.10) + +# set the project name +project(media-tools) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) +link_libraries(stdc++fs) + +add_subdirectory(src) +add_subdirectory(apps) \ No newline at end of file diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt new file mode 100644 index 0000000..b9565e6 --- /dev/null +++ b/apps/CMakeLists.txt @@ -0,0 +1,32 @@ +# Sample GUI +add_executable(sample_gui gui-main.cpp) +target_include_directories(sample_gui PUBLIC + "${PROJECT_SOURCE_DIR}/src/console" + "${PROJECT_SOURCE_DIR}/src/client" + ) +target_link_libraries(sample_gui PUBLIC client windows console core + network database geometry audio graphics) + +# Sample Console +add_executable(sample_console console-main.cpp) +target_include_directories(sample_console PUBLIC + "${PROJECT_SOURCE_DIR}/src/console" + ) +target_link_libraries(sample_console PUBLIC console core network + database geometry audio) + +# Xml practice +add_executable(xml_practice xml-practice.cpp) +target_include_directories(xml_practice PUBLIC + "${PROJECT_SOURCE_DIR}/src/core" + "${PROJECT_SOURCE_DIR}/src/core/xml" + ) +target_link_libraries(xml_practice PUBLIC core) + +# Markdown practice +add_executable(markdown_practice markdown-practice.cpp) +target_include_directories(markdown_practice PUBLIC + "${PROJECT_SOURCE_DIR}/src/core" + "${PROJECT_SOURCE_DIR}/src/web/markdown" + ) +target_link_libraries(markdown_practice PUBLIC web core) \ No newline at end of file diff --git a/apps/console-main.cpp b/apps/console-main.cpp new file mode 100644 index 0000000..c8a99c4 --- /dev/null +++ b/apps/console-main.cpp @@ -0,0 +1,16 @@ +#include +#include + +#include "MainApplication.h" + +int main() +{ + // Start the main app + auto main_app = MainApplication::Create(); + main_app->Initialize(std::filesystem::current_path()); + + //main_app->RunServer(); + main_app->PlayAudio(); + main_app->ShutDown(); + return 0; +} diff --git a/apps/gui-main.cpp b/apps/gui-main.cpp new file mode 100644 index 0000000..c5490b8 --- /dev/null +++ b/apps/gui-main.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include "GuiApplication.h" +#include "MainApplication.h" + +int main() +{ + // Start the main app + auto main_app = MainApplication::Create(); + main_app->Initialize(std::filesystem::current_path()); + + // Start the gui app + auto gui_app = std::make_shared(); + gui_app->SetMainApplication(main_app); + gui_app->Run(); + + main_app->ShutDown(); + return 0; +} diff --git a/apps/markdown-practice.cpp b/apps/markdown-practice.cpp new file mode 100644 index 0000000..4f605c3 --- /dev/null +++ b/apps/markdown-practice.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include "CommandLineArgs.h" +#include "MarkdownParser.h" +#include "HtmlDocument.h" +#include "HtmlWriter.h" + +int main(int argc, char *argv[]) +{ + CommandLineArgs command_line_args; + command_line_args.Process(argc, argv); + + if(command_line_args.GetNumberOfArgs() < 2) + { + std::cerr << "Expected a filepath argument" << std::endl; + return -1; + } + + MarkdownParser parser; + const auto filepath = command_line_args.GetArg(1); + + if(!std::filesystem::exists(filepath)) + { + std::cerr << "Couldn't find file: " << filepath << std::endl; + return -1; + } + + std::ifstream md_file; + md_file.open(filepath, std::ifstream::in); + while(md_file.good()) + { + std::string line; + std::getline(md_file, line); + parser.ProcessLine(line); + } + md_file.close(); + + auto html_document = parser.GetHtml(); + HtmlWriter writer; + std::string html_string = writer.ToString(html_document); + std::ofstream out("/home/james/test.html"); + out << html_string; + out.close(); + return 0; +} diff --git a/apps/xml-practice.cpp b/apps/xml-practice.cpp new file mode 100644 index 0000000..9d2f3ae --- /dev/null +++ b/apps/xml-practice.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include "CommandLineArgs.h" +#include "XmlParser.h" + +int main(int argc, char *argv[]) +{ + CommandLineArgs command_line_args; + command_line_args.Process(argc, argv); + + if(command_line_args.GetNumberOfArgs() < 2) + { + std::cerr << "Expected a filepath argument" << std::endl; + return -1; + } + + XmlParser parser; + const auto filepath = command_line_args.GetArg(1); + + if(!std::filesystem::exists(filepath)) + { + std::cerr << "Couldn't find file: " << filepath << std::endl; + return -1; + } + + std::ifstream xml_file; + xml_file.open(filepath, std::ifstream::in); + while(xml_file.good()) + { + std::string line; + std::getline(xml_file, line); + parser.ProcessLine(line); + } + xml_file.close(); + + return 0; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..10c3941 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,11 @@ +add_subdirectory(core) +add_subdirectory(database) +add_subdirectory(network) +add_subdirectory(geometry) +add_subdirectory(audio) +add_subdirectory(console) +add_subdirectory(client) +add_subdirectory(graphics) +add_subdirectory(windows) +add_subdirectory(web) +add_subdirectory(ui_elements) \ No newline at end of file diff --git a/src/audio/AudioDevice.cpp b/src/audio/AudioDevice.cpp new file mode 100644 index 0000000..072f5fc --- /dev/null +++ b/src/audio/AudioDevice.cpp @@ -0,0 +1,71 @@ +#include "AudioDevice.h" + +AudioDevice::AudioDevice() + : mName("plughw:1,0"), + mSampleRate(44100), + mNumChannels(2), + mPeriod(2), + mBufferSize() +{ + +} + +AudioDevice::~AudioDevice() +{ + +} + +std::shared_ptr AudioDevice::Create() +{ + return std::make_shared(); +} + +void AudioDevice::SetNumChannels(unsigned numChannels) +{ + mNumChannels = numChannels; +} + +void AudioDevice::SetPeriod(unsigned period) +{ + mPeriod = period; +} + +void AudioDevice::SetBufferSize(std::size_t bufferSize) +{ + mBufferSize = bufferSize; +} + +unsigned AudioDevice::GetNumChannels() +{ + return mNumChannels; +} + +unsigned AudioDevice::GetPeriod() +{ + return mPeriod; +} + +std::size_t AudioDevice::GetBufferSize() +{ + return mBufferSize; +} + +void AudioDevice::SetSampleRate(unsigned rate) +{ + mSampleRate = rate; +} + +unsigned AudioDevice::GetSampleRate() +{ + return mSampleRate; +} + +void AudioDevice::SetName(const std::string& name) +{ + mName = name; +} + +std::string AudioDevice::GetName() +{ + return mName; +} diff --git a/src/audio/AudioDevice.h b/src/audio/AudioDevice.h new file mode 100644 index 0000000..fb0b675 --- /dev/null +++ b/src/audio/AudioDevice.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include + +class AudioDevice +{ + +private: + + std::string mName; + unsigned mSampleRate; + unsigned mNumChannels; + unsigned mPeriod; + std::size_t mBufferSize; + +public: + + AudioDevice(); + + ~AudioDevice(); + + void SetSampleRate(unsigned rate); + + unsigned GetSampleRate(); + + void SetName(const std::string& name); + + void SetNumChannels(unsigned numChannels); + + void SetPeriod(unsigned period); + + void SetBufferSize(std::size_t bufferSize); + + unsigned GetNumChannels(); + + unsigned GetPeriod(); + + std::size_t GetBufferSize(); + + std::string GetName(); + + static std::shared_ptr Create(); +}; + +using AudioDevicePtr = std::shared_ptr; diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp new file mode 100644 index 0000000..9f64cce --- /dev/null +++ b/src/audio/AudioManager.cpp @@ -0,0 +1,33 @@ +#include "AudioManager.h" + +AudioManager::AudioManager() + : mAudioDevices(), + mAudioInterface() +{ + mAudioInterface = AlsaInterface::Create(); +} + +AudioManager::~AudioManager() +{ + +} + +std::shared_ptr AudioManager::Create() +{ + return std::make_shared(); +} + +void AudioManager::AddAudioDevice(AudioDevicePtr device) +{ + mAudioDevices.push_back(device); +} + +AlsaInterfacePtr AudioManager::GetAudioInterface() +{ + return mAudioInterface; +} + +std::vector AudioManager::GetAudioDevices() +{ + return mAudioDevices; +} diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h new file mode 100644 index 0000000..b8e9402 --- /dev/null +++ b/src/audio/AudioManager.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#include "AlsaInterface.h" +#include "AudioDevice.h" + +class AudioManager +{ + +private: + + std::vector mAudioDevices; + AlsaInterfacePtr mAudioInterface; + +public: + + AudioManager(); + + ~AudioManager(); + + static std::shared_ptr Create(); + + void AddAudioDevice(AudioDevicePtr device); + + std::vector GetAudioDevices(); + + AlsaInterfacePtr GetAudioInterface(); +}; + +using AudioManagerPtr = std::shared_ptr; diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt new file mode 100644 index 0000000..a115389 --- /dev/null +++ b/src/audio/CMakeLists.txt @@ -0,0 +1,13 @@ +list(APPEND audio_LIB_INCLUDES + AudioDevice.cpp + AudioManager.cpp + audio_interfaces/AlsaInterface.cpp) + + +add_library(audio SHARED ${audio_LIB_INCLUDES}) +target_include_directories(audio PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/audio_interfaces" + ) + +target_link_libraries(audio PUBLIC asound) \ No newline at end of file diff --git a/src/audio/audio_interfaces/AlsaInterface.cpp b/src/audio/audio_interfaces/AlsaInterface.cpp new file mode 100644 index 0000000..51eacee --- /dev/null +++ b/src/audio/audio_interfaces/AlsaInterface.cpp @@ -0,0 +1,141 @@ +#include "AlsaInterface.h" + +#include + +AlsaInterface::AlsaInterface() + :mHandle(), + mHardwareParams(), + mPeriodSize(8192) +{ + +} + +AlsaInterface::~AlsaInterface() +{ + +} + +std::shared_ptr AlsaInterface::Create() +{ + return std::make_shared(); +} + +void AlsaInterface::OpenDevice(AudioDevicePtr device) +{ + snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK; + if (snd_pcm_open(&mHandle, device->GetName().c_str(), stream, 0) < 0) + { + std::cerr << "Error opening PCM device: " << device->GetName() << std::endl; + return; + } + + snd_pcm_hw_params_alloca(&mHardwareParams); + if (snd_pcm_hw_params_any(mHandle, mHardwareParams) < 0) + { + std::cerr << "Can not configure this PCM device.\n" << std::endl; + return; + } + + SetAccessType(device); + SetSampleFormat(device); + SetSampleRate(device); + SetPeriod(device); + SetBufferSize(device); + SetChannelNumber(device); + + /* Apply HW parameter settings to */ + /* PCM device and prepare device */ + if (snd_pcm_hw_params(mHandle, mHardwareParams) < 0) { + std::cerr << "Error setting HW params." << std::endl; + return; + } +} + +void AlsaInterface::SetAccessType(AudioDevicePtr device) +{ + if (snd_pcm_hw_params_set_access(mHandle, mHardwareParams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) { + std::cerr << "Error setting device access." << std::endl; + return; + } +} + +void AlsaInterface::SetSampleFormat(AudioDevicePtr device) +{ + /* Set sample format */ + if (snd_pcm_hw_params_set_format(mHandle, mHardwareParams, SND_PCM_FORMAT_S16_LE) < 0) { + std::cerr << "Error setting format. " << std::endl; + return; + } +} + +void AlsaInterface::SetSampleRate(AudioDevicePtr device) +{ + unsigned rate = device->GetSampleRate(); + unsigned exact_rate = rate; + if (snd_pcm_hw_params_set_rate_near(mHandle, mHardwareParams, &exact_rate, 0) < 0) + { + std::cerr << "Error setting rate. " << std::endl; + return; + } + if (rate != exact_rate) { + std::cerr << "The rate is not supported by your hardware." << std::endl; + } +} + +void AlsaInterface::SetPeriod(AudioDevicePtr device) +{ + /* Set number of periods. Periods used to be called fragments. */ + if (snd_pcm_hw_params_set_periods(mHandle, mHardwareParams, device->GetPeriod(), 0) < 0) + { + std::cerr << "Error setting periods. " << std::endl; + return; + } +} + +void AlsaInterface::SetBufferSize(AudioDevicePtr device) +{ + snd_pcm_uframes_t periodsize = 8192; /* Periodsize (bytes) */ + int periods = static_cast(device->GetPeriod()); + + /* Set buffer size (in frames). The resulting latency is given by */ + /* latency = periodsize * periods / (rate * bytes_per_frame) */ + if (snd_pcm_hw_params_set_buffer_size(mHandle, mHardwareParams, (mPeriodSize * periods)>>2) < 0) + { + std::cerr << "Error setting buffersize. " << std::endl; + return; + } +} + +void AlsaInterface::SetChannelNumber(AudioDevicePtr device) +{ + /* Set number of channels */ + if (snd_pcm_hw_params_set_channels(mHandle, mHardwareParams, device->GetNumChannels()) < 0) + { + std::cout << "Error setting channels" << std::endl; + return; + } +} + +void AlsaInterface::Play(AudioDevicePtr device) +{ + int num_frames = 10; + unsigned char *data = (unsigned char *)malloc(mPeriodSize); + int frames = mPeriodSize >> 2; + for(int l1 = 0; l1 < 100; l1++) + { + for(int l2 = 0; l2 < num_frames; l2++) + { + short s1 = (l2 % 128) * 100 - 5000; + short s2 = (l2 % 256) * 100 - 5000; + data[4*l2] = (unsigned char)s1; + data[4*l2+1] = s1 >> 8; + data[4*l2+2] = (unsigned char)s2; + data[4*l2+3] = s2 >> 8; + } + while ((snd_pcm_writei(mHandle, data, frames)) < 0) + { + snd_pcm_prepare(mHandle); + fprintf(stderr, "<<<<<<<<<<<<<<< Buffer Underrun >>>>>>>>>>>>>>>\n"); + } + } +} diff --git a/src/audio/audio_interfaces/AlsaInterface.h b/src/audio/audio_interfaces/AlsaInterface.h new file mode 100644 index 0000000..3d9a1d0 --- /dev/null +++ b/src/audio/audio_interfaces/AlsaInterface.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +#include "AudioDevice.h" + +class AlsaInterface +{ + snd_pcm_t* mHandle; + snd_pcm_hw_params_t* mHardwareParams; + snd_pcm_uframes_t mPeriodSize; + +public: + + AlsaInterface(); + + ~AlsaInterface(); + + static std::shared_ptr Create(); + + void OpenDevice(AudioDevicePtr device); + + void SetAccessType(AudioDevicePtr device); + + void SetSampleFormat(AudioDevicePtr device); + + void SetSampleRate(AudioDevicePtr device); + + void SetPeriod(AudioDevicePtr device); + + void SetBufferSize(AudioDevicePtr device); + + void SetChannelNumber(AudioDevicePtr device); + + void Play(AudioDevicePtr device); +}; + +using AlsaInterfacePtr = std::shared_ptr; diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt new file mode 100644 index 0000000..4f900a6 --- /dev/null +++ b/src/client/CMakeLists.txt @@ -0,0 +1,10 @@ +list(APPEND client_LIB_INCLUDES GuiApplication.cpp) + +add_library(client SHARED ${client_LIB_INCLUDES}) + +target_link_libraries(client ui_elements windows core console database geometry) + +target_include_directories(client PUBLIC + "${PROJECT_SOURCE_DIR}/src/console" + "${PROJECT_SOURCE_DIR}/src/ui_elements/widgets" + ) \ No newline at end of file diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp new file mode 100644 index 0000000..421a115 --- /dev/null +++ b/src/client/GuiApplication.cpp @@ -0,0 +1,70 @@ +#include "GuiApplication.h" + +#include +#include "Widget.h" +#include "HorizontalSpacer.h" +#include "Button.h" +#include "Label.h" +#include "XcbInterface.h" +#include "XcbKeyboard.h" +#include "Window.h" +#include "TextElement.h" +#include "WindowManager.h" + +GuiApplication::GuiApplication() + : AbstractDesktopApp(), + mMainApplication(), + mDesktopManager() +{ + mDesktopManager = DesktopManager::Create(); +} + +GuiApplication::~GuiApplication() +{ + +} + +void GuiApplication::SetMainApplication(MainApplicationPtr app) +{ + mMainApplication = app; + //mDesktopManager->SetMainApp(shared_from_this()); +} + +void GuiApplication::Run() +{ + auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); + + mainWindow->SetSize(800, 600); + + auto label = Label::Create(); + label->SetLabel("Click the button!!"); + label->SetBackgroundColor(Color::Create(0, 200, 200)); + + auto button = Button::Create(); + button->SetLabel("Ok"); + button->SetBackgroundColor(Color::Create(0, 0, 200)); + + auto spacer = HorizontalSpacer::Create(); + spacer->AddWidget(label); + spacer->AddWidget(button); + + mainWindow->AddWidget(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); + } + + window_interface.Loop(mDesktopManager); + + window_interface.ShutDown(); + +} diff --git a/src/client/GuiApplication.h b/src/client/GuiApplication.h new file mode 100644 index 0000000..c3c9445 --- /dev/null +++ b/src/client/GuiApplication.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include "MainApplication.h" +#include "AbstractDesktopApp.h" +#include "DesktopManager.h" + +class GuiApplication : public AbstractDesktopApp, std::enable_shared_from_this +{ + +private: + + DesktopManagerPtr mDesktopManager; + MainApplicationPtr mMainApplication; + +public: + + GuiApplication(); + + ~GuiApplication(); + + void SetMainApplication(MainApplicationPtr app); + + void Run(); +}; diff --git a/src/console/CMakeLists.txt b/src/console/CMakeLists.txt new file mode 100644 index 0000000..dfa026e --- /dev/null +++ b/src/console/CMakeLists.txt @@ -0,0 +1,13 @@ +list(APPEND console_LIB_INCLUDES MainApplication.cpp) + +add_library(console SHARED ${console_LIB_INCLUDES}) + +target_include_directories(console PUBLIC + "${PROJECT_SOURCE_DIR}/src/core/loggers" + "${PROJECT_SOURCE_DIR}/src/database" + "${PROJECT_SOURCE_DIR}/src/database/database_interfaces" + "${PROJECT_SOURCE_DIR}/src/network" + "${PROJECT_SOURCE_DIR}/src/network/sockets" + "${PROJECT_SOURCE_DIR}/src/audio" + "${PROJECT_SOURCE_DIR}/src/audio/audio_interfaces" + ) \ No newline at end of file diff --git a/src/console/MainApplication.cpp b/src/console/MainApplication.cpp new file mode 100644 index 0000000..b3501f1 --- /dev/null +++ b/src/console/MainApplication.cpp @@ -0,0 +1,52 @@ +#include "MainApplication.h" + +MainApplication::MainApplication() + :mLogger(), + mDatabaseManager() +{ + +} + +MainApplication::~MainApplication() +{ + +} + +void MainApplication::Initialize(const std::filesystem::path& workDir) +{ + mLogger = FileLogger::Create(); + mLogger->SetWorkDirectory(workDir.string()); + mLogger->Open(); + mLogger->LogLine("Launched"); + + mDatabaseManager = DatabaseManager::Create(); + mDatabaseManager->CreateDatabase(workDir.string() + "/database.db"); + + mNetworkManager = NetworkManager::Create(); + + mAudioManager = AudioManager::Create(); +} + +void MainApplication::RunServer() +{ + mNetworkManager->RunHttpServer(); +} + +void MainApplication::PlayAudio() +{ + auto device = AudioDevice::Create(); + mAudioManager->GetAudioInterface()->OpenDevice(device); + mAudioManager->GetAudioInterface()->Play(device); +} + +void MainApplication::ShutDown() +{ + mLogger->Close(); + mDatabaseManager->OnShutDown(); + mNetworkManager->ShutDown(); +} + +std::shared_ptr MainApplication::Create() +{ + return std::make_shared(); +} diff --git a/src/console/MainApplication.h b/src/console/MainApplication.h new file mode 100644 index 0000000..c3a0fbe --- /dev/null +++ b/src/console/MainApplication.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +#include "AudioManager.h" +#include "FileLogger.h" +#include "DatabaseManager.h" +#include "NetworkManager.h" + +class MainApplication +{ +private: + + FileLoggerPtr mLogger; + DatabaseManagerPtr mDatabaseManager; + NetworkManagerPtr mNetworkManager; + AudioManagerPtr mAudioManager; + +public: + + MainApplication(); + + ~MainApplication(); + + void Initialize(const std::filesystem::path& workDir); + + void RunServer(); + + void PlayAudio(); + + void ShutDown(); + + static std::shared_ptr Create(); +}; + +using MainApplicationPtr = std::shared_ptr; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt new file mode 100644 index 0000000..6776b4c --- /dev/null +++ b/src/core/CMakeLists.txt @@ -0,0 +1,13 @@ +list(APPEND core_LIB_INCLUDES + Event.cpp + Color.cpp + CommandLineArgs.cpp + loggers/FileLogger.cpp + StringUtils.cpp) + +# add the executable +add_library(core SHARED ${core_LIB_INCLUDES}) + +target_include_directories(core PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + ) \ No newline at end of file diff --git a/src/core/Color.cpp b/src/core/Color.cpp new file mode 100644 index 0000000..d914b23 --- /dev/null +++ b/src/core/Color.cpp @@ -0,0 +1,36 @@ +#include "Color.h" + +Color::Color(unsigned r, unsigned g, unsigned b, double a) + : mR(r), + mG(g), + mB(b), + mAlpha(a) +{ + +} + +std::shared_ptr Color::Create(unsigned r, unsigned g, unsigned b, + double a ) +{ + return std::make_shared(r, g, b, a); +} + +unsigned Color::GetR() +{ + return mR; +} + +unsigned Color::GetG() +{ + return mG; +} + +unsigned Color::GetB() +{ + return mB; +} + +double Color::GetAlpha() +{ + return mAlpha; +} diff --git a/src/core/Color.h b/src/core/Color.h new file mode 100644 index 0000000..6eb31e8 --- /dev/null +++ b/src/core/Color.h @@ -0,0 +1,23 @@ +#pragma once +#include + +class Color +{ + unsigned mR; + unsigned mG; + unsigned mB; + double mAlpha; + +public: + + Color(unsigned r, unsigned g, unsigned b, double a = 1.0); + + static std::shared_ptr Create(unsigned r, unsigned g, unsigned b, double a = 1.0); + + unsigned GetR(); + unsigned GetG(); + unsigned GetB(); + double GetAlpha(); +}; + +using ColorPtr = std::shared_ptr; diff --git a/src/core/CommandLineArgs.cpp b/src/core/CommandLineArgs.cpp new file mode 100644 index 0000000..11a5bd2 --- /dev/null +++ b/src/core/CommandLineArgs.cpp @@ -0,0 +1,29 @@ +#include "CommandLineArgs.h" + +CommandLineArgs::CommandLineArgs() + : mArugments() +{ + +} + +void CommandLineArgs::Process(int argc, char *argv[]) +{ + for(int idx=0; idx +#include +#include + +class CommandLineArgs +{ + std::vector mArugments; + +public: + + CommandLineArgs(); + + void Process(int argc, char *argv[]); + + std::size_t GetNumberOfArgs() const; + + std::string GetArg(std::size_t index) const; +}; diff --git a/src/core/Event.cpp b/src/core/Event.cpp new file mode 100644 index 0000000..878d376 --- /dev/null +++ b/src/core/Event.cpp @@ -0,0 +1,11 @@ +#include "Event.h" + +Event::Event() +{ + +} + +Event::~Event() +{ + +} diff --git a/src/core/Event.h b/src/core/Event.h new file mode 100644 index 0000000..eba051e --- /dev/null +++ b/src/core/Event.h @@ -0,0 +1,8 @@ +class Event +{ +public: + + Event(); + + ~Event(); +}; diff --git a/src/core/StringUtils.cpp b/src/core/StringUtils.cpp new file mode 100644 index 0000000..cc91ce5 --- /dev/null +++ b/src/core/StringUtils.cpp @@ -0,0 +1,14 @@ +#include "StringUtils.h" +#include + +bool StringUtils::IsAlphaNumeric(char c) +{ + std::locale loc; + return std::isalnum(c, loc); +} + +bool StringUtils::IsSpace(char c) +{ + std::locale loc; + return std::isspace(c, loc); +} diff --git a/src/core/StringUtils.h b/src/core/StringUtils.h new file mode 100644 index 0000000..8a973a6 --- /dev/null +++ b/src/core/StringUtils.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +class StringUtils +{ +public: + static constexpr char LEFT_BRACKET = '<'; + static constexpr char RIGHT_BRACKET = '>'; + static constexpr char FORWARD_SLASH = '/'; + static constexpr char BACK_SLASH = '\\'; + static constexpr char QUESTION_MARK = '?'; + static constexpr char EQUALS = '='; + static constexpr char DOUBLE_QUOTE = '"'; + static constexpr char SINGLE_QUOTE = '\''; + + static bool IsAlphaNumeric(char c); + static bool IsSpace(char c); +}; diff --git a/src/core/http/HttpResponse.cpp b/src/core/http/HttpResponse.cpp new file mode 100644 index 0000000..1a05d49 --- /dev/null +++ b/src/core/http/HttpResponse.cpp @@ -0,0 +1,38 @@ +#include "HttpResponse.h" + +HttpResponse::HttpResponse() + :mHttpVersion("1.1"), + mResponseCode("200 OK"), + mContentType("text/plain"), + mBody() +{ + +} + +HttpResponse::~HttpResponse() +{ + +} + +void HttpResponse::SetBody(const std::string& body) +{ + mBody = body; +} + +unsigned HttpResponse::GetBodyLength() +{ + return mBody.length(); +} + +std::string HttpResponse::GetHeaderString() +{ + std::string header = "HTTP/" + mHttpVersion + " " + mResponseCode + "\n"; + header += "Content-Type: " + mContentType + "\n"; + header += "Content-Length: " + std::to_string(GetBodyLength()) + "\n"; + return header; +} + +std::string HttpResponse::ToString() +{ + return GetHeaderString() + "\n\n" + mBody; +} diff --git a/src/core/http/HttpResponse.h b/src/core/http/HttpResponse.h new file mode 100644 index 0000000..4acebe3 --- /dev/null +++ b/src/core/http/HttpResponse.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +class HttpResponse +{ + + std::string mHttpVersion; + std::string mResponseCode; + std::string mContentType; + std::string mBody; + +public: + + HttpResponse(); + + ~HttpResponse(); + + void SetBody(const std::string& body); + + unsigned GetBodyLength(); + + std::string GetHeaderString(); + + std::string ToString(); +}; diff --git a/src/core/loggers/FileLogger.cpp b/src/core/loggers/FileLogger.cpp new file mode 100644 index 0000000..33f3ee6 --- /dev/null +++ b/src/core/loggers/FileLogger.cpp @@ -0,0 +1,44 @@ +#include "FileLogger.h" + +FileLogger::FileLogger() + :mWorkDirectory(), + mFileName("MT_Log.txt"), + mFileStream() +{ + +} + +FileLogger::~FileLogger() +{ + +} + +void FileLogger::SetWorkDirectory(const std::string& workDir) +{ + mWorkDirectory = workDir; +} + +void FileLogger::SetFileName(const std::string& fileName) +{ + mFileName = fileName; +} + +void FileLogger::Open() +{ + mFileStream.open(mWorkDirectory + "/" + mFileName); +} + +void FileLogger::Close() +{ + mFileStream.close(); +} + +void FileLogger::LogLine(const std::string& line) +{ + mFileStream << line << std::endl; +} + +std::shared_ptr FileLogger::Create() +{ + return std::make_shared(); +} diff --git a/src/core/loggers/FileLogger.h b/src/core/loggers/FileLogger.h new file mode 100644 index 0000000..0f23688 --- /dev/null +++ b/src/core/loggers/FileLogger.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include + +class FileLogger +{ + std::string mWorkDirectory; + + std::string mFileName; + + std::ofstream mFileStream; + +public: + + FileLogger(); + + ~FileLogger(); + + void SetWorkDirectory(const std::string& workDir); + + void SetFileName(const std::string& fileName); + + void Open(); + + void Close(); + + void LogLine(const std::string& line); + + static std::shared_ptr Create(); + +}; + +using FileLoggerPtr = std::shared_ptr; diff --git a/src/database/CMakeLists.txt b/src/database/CMakeLists.txt new file mode 100644 index 0000000..50e4b85 --- /dev/null +++ b/src/database/CMakeLists.txt @@ -0,0 +1,13 @@ +list(APPEND database_LIB_INCLUDES + Database.cpp + DatabaseManager.cpp + database_interfaces/SqliteInterface.cpp) + +add_library(database SHARED ${database_LIB_INCLUDES}) + +target_include_directories(database PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/database_interfaces" + ) + +target_link_libraries(database PUBLIC sqlite3) \ No newline at end of file diff --git a/src/database/Database.cpp b/src/database/Database.cpp new file mode 100644 index 0000000..12d5d2f --- /dev/null +++ b/src/database/Database.cpp @@ -0,0 +1,27 @@ +#include "Database.h" + +Database::Database() + : mPath() +{ + +} + +Database::~Database() +{ + +} + +std::shared_ptr Database::Create() +{ + return std::make_shared(); +} + +void Database::SetPath(const std::string& path) +{ + mPath = path; +} + +std::string Database::GetPath() +{ + return mPath; +} diff --git a/src/database/Database.h b/src/database/Database.h new file mode 100644 index 0000000..ebbe8f7 --- /dev/null +++ b/src/database/Database.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +class Database +{ + + std::string mPath; + +public: + + Database(); + + ~Database(); + + static std::shared_ptr Create(); + + void SetPath(const std::string& path); + + std::string GetPath(); +}; + +using DatabasePtr = std::shared_ptr; diff --git a/src/database/DatabaseManager.cpp b/src/database/DatabaseManager.cpp new file mode 100644 index 0000000..6f3b552 --- /dev/null +++ b/src/database/DatabaseManager.cpp @@ -0,0 +1,36 @@ +#include "DatabaseManager.h" + +DatabaseManager::DatabaseManager() + : mDatabase(), + mDatabaseInterface() +{ + +} + +DatabaseManager::~DatabaseManager() +{ + +} + +std::shared_ptr DatabaseManager::Create() +{ + return std::make_shared(); +} + + +void DatabaseManager::CreateDatabase(const std::string& path) +{ + mDatabase = Database::Create(); + mDatabase->SetPath(path); + + mDatabaseInterface = SqliteInterface::Create(); + mDatabaseInterface->Open(mDatabase); +} + +void DatabaseManager::OnShutDown() +{ + if(mDatabaseInterface) + { + mDatabaseInterface->Close(); + } +} diff --git a/src/database/DatabaseManager.h b/src/database/DatabaseManager.h new file mode 100644 index 0000000..cb1b401 --- /dev/null +++ b/src/database/DatabaseManager.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include "SqliteInterface.h" +#include "Database.h" + +class DatabaseManager +{ + + DatabasePtr mDatabase; + SqliteInterfacePtr mDatabaseInterface; + +public: + + DatabaseManager(); + + ~DatabaseManager(); + + static std::shared_ptr Create(); + + void CreateDatabase(const std::string& path); + + void OnShutDown(); +}; + +using DatabaseManagerPtr = std::shared_ptr; diff --git a/src/database/database_interfaces/SqliteInterface.cpp b/src/database/database_interfaces/SqliteInterface.cpp new file mode 100644 index 0000000..acddac2 --- /dev/null +++ b/src/database/database_interfaces/SqliteInterface.cpp @@ -0,0 +1,56 @@ +#include "SqliteInterface.h" + +#include + +SqliteInterface::SqliteInterface() + : mSqliteDb(nullptr) +{ + +} + +SqliteInterface::~SqliteInterface() +{ + +} + +std::shared_ptr SqliteInterface::Create() +{ + return std::make_shared(); +} + +void SqliteInterface::Open(DatabasePtr db) +{ + int rc = sqlite3_open(db->GetPath().c_str(), &mSqliteDb); + if( rc ) + { + std::cout << "Can't open database: %s\n" << sqlite3_errmsg(mSqliteDb) << std::endl; + sqlite3_close(mSqliteDb); + } +} + +static int callback(void *NotUsed, int argc, char **argv, char **azColName) +{ + for(int i=0; i +#include + +#include "Database.h" + +class SqliteInterface +{ + sqlite3* mSqliteDb; + +public: + + SqliteInterface(); + + ~SqliteInterface(); + + static std::shared_ptr Create(); + + void Open(DatabasePtr db); + + void Close(); + + void Run(const std::string& statement); +}; + +using SqliteInterfacePtr = std::shared_ptr; diff --git a/src/geometry/CMakeLists.txt b/src/geometry/CMakeLists.txt new file mode 100644 index 0000000..836799d --- /dev/null +++ b/src/geometry/CMakeLists.txt @@ -0,0 +1,7 @@ +list(APPEND geometry_LIB_INCLUDES + DiscretePoint.cpp + Point.cpp) + +# add the library +add_library(geometry SHARED ${geometry_LIB_INCLUDES}) + \ No newline at end of file diff --git a/src/geometry/DiscretePoint.cpp b/src/geometry/DiscretePoint.cpp new file mode 100644 index 0000000..7758a3b --- /dev/null +++ b/src/geometry/DiscretePoint.cpp @@ -0,0 +1,28 @@ +#include "DiscretePoint.h" + + +DiscretePoint::DiscretePoint(unsigned x, unsigned y) + : mX(x), + mY(y) +{ +} + +DiscretePoint::~DiscretePoint() +{ +}; + + +std::shared_ptr DiscretePoint::Create(unsigned x, unsigned y) +{ + return std::make_shared(x, y); +} + +unsigned DiscretePoint::GetX() const +{ + return mX; +} + +unsigned DiscretePoint::GetY() const +{ + return mY; +} diff --git a/src/geometry/DiscretePoint.h b/src/geometry/DiscretePoint.h new file mode 100644 index 0000000..b0b6d0e --- /dev/null +++ b/src/geometry/DiscretePoint.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +class DiscretePoint +{ + unsigned mX; + unsigned mY; + +public: + + DiscretePoint(unsigned x, unsigned y); + + ~DiscretePoint(); + + std::shared_ptr Create(unsigned x, unsigned y); + + unsigned GetX() const; + + unsigned GetY() const; +}; + +using Pixel = DiscretePoint; +using DiscretePointPtr = std::shared_ptr; +using PixelPtr = DiscretePointPtr; diff --git a/src/geometry/Point.cpp b/src/geometry/Point.cpp new file mode 100644 index 0000000..e4b5541 --- /dev/null +++ b/src/geometry/Point.cpp @@ -0,0 +1,18 @@ +#include "Point.h" + + +Point::Point(double x, double y) + : mX(x), + mY(y) +{ +} + +Point::~Point() +{ +}; + + +std::shared_ptr Point::Create(double x, double y) +{ + return std::make_shared(x, y); +} diff --git a/src/geometry/Point.h b/src/geometry/Point.h new file mode 100644 index 0000000..d22051e --- /dev/null +++ b/src/geometry/Point.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +class Point +{ + double mX; + double mY; + +public: + + Point(double x, double y); + + ~Point(); + + std::shared_ptr Create(double x, double y); +}; + +using PointPtr = std::shared_ptr; diff --git a/src/geometry/Rectangle.cpp b/src/geometry/Rectangle.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/geometry/Rectangle.h b/src/geometry/Rectangle.h new file mode 100644 index 0000000..11c121f --- /dev/null +++ b/src/geometry/Rectangle.h @@ -0,0 +1,7 @@ +#pragma once + + +class Rectangle +{ + +}; diff --git a/src/graphics/CMakeLists.txt b/src/graphics/CMakeLists.txt new file mode 100644 index 0000000..a00c567 --- /dev/null +++ b/src/graphics/CMakeLists.txt @@ -0,0 +1,5 @@ +list(APPEND graphics_LIB_INCLUDES OpenGlInterface) + +add_library(graphics SHARED ${graphics_LIB_INCLUDES}) + +target_link_libraries(graphics PUBLIC GL) \ No newline at end of file diff --git a/src/graphics/OpenGlInterface.cpp b/src/graphics/OpenGlInterface.cpp new file mode 100644 index 0000000..c715abd --- /dev/null +++ b/src/graphics/OpenGlInterface.cpp @@ -0,0 +1,20 @@ +#include "OpenGlInterface.h" + +#include + +void OpenGlInterface::draw() +{ + glClearColor(0.4, 0.4, 0.4, 0.4); + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f(1.0, 1.0, 1.0); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + + glBegin(GL_TRIANGLES); + glVertex3f(-0.7, 0.7, 0); + glVertex3f(0.7, 0.7, 0); + glVertex3f(0, -1, 0); + glEnd(); + + glFlush(); +} diff --git a/src/graphics/OpenGlInterface.h b/src/graphics/OpenGlInterface.h new file mode 100644 index 0000000..1b21fe2 --- /dev/null +++ b/src/graphics/OpenGlInterface.h @@ -0,0 +1,10 @@ +#pragma once + +class OpenGlInterface +{ +public: + + static void draw(); +}; + + diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt new file mode 100644 index 0000000..165b4d3 --- /dev/null +++ b/src/network/CMakeLists.txt @@ -0,0 +1,14 @@ +list(APPEND network_LIB_INCLUDES + NetworkManager.cpp + sockets/Socket.cpp + sockets/UnixSocketInterface.cpp) + +add_library(network SHARED ${network_LIB_INCLUDES}) + +target_include_directories(network PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/sockets" + "${PROJECT_SOURCE_DIR}/src/core/http" + ) + +target_link_libraries(network PUBLIC core) \ No newline at end of file diff --git a/src/network/NetworkManager.cpp b/src/network/NetworkManager.cpp new file mode 100644 index 0000000..9884351 --- /dev/null +++ b/src/network/NetworkManager.cpp @@ -0,0 +1,36 @@ +#include "NetworkManager.h" + +NetworkManager::NetworkManager() + : mActiveSockets(), + mSocketInterface() +{ + +} + +NetworkManager::~NetworkManager() +{ + +} + +std::shared_ptr NetworkManager::Create() +{ + return std::make_shared(); +} + +void NetworkManager::Initialize() +{ + mSocketInterface = UnixSocketInterface::Create(); +} + +void NetworkManager::RunHttpServer() +{ + auto socket = Socket::Create(); + mSocketInterface->CreateSocket(socket); + mSocketInterface->Listen(socket); + mSocketInterface->Run(socket); +} + +void NetworkManager::ShutDown() +{ + +} diff --git a/src/network/NetworkManager.h b/src/network/NetworkManager.h new file mode 100644 index 0000000..7240b86 --- /dev/null +++ b/src/network/NetworkManager.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +#include "Socket.h" +#include "UnixSocketInterface.h" + +class NetworkManager +{ + std::vector mActiveSockets; + UnixSocketInterfacePtr mSocketInterface; + +public: + + NetworkManager(); + + ~NetworkManager(); + + static std::shared_ptr Create(); + + void Initialize(); + + void OpenSocket(SocketPtr socket); + + void CloseSocket(SocketPtr socket); + + void RunHttpServer(); + + void ShutDown(); +}; + +using NetworkManagerPtr = std::shared_ptr; diff --git a/src/network/sockets/Socket.cpp b/src/network/sockets/Socket.cpp new file mode 100644 index 0000000..88277c0 --- /dev/null +++ b/src/network/sockets/Socket.cpp @@ -0,0 +1,38 @@ +#include "Socket.h" + +Socket::Socket() + : mPort(8888), + mMessage() +{ + +} + +Socket::~Socket() +{ + +} + +std::shared_ptr Socket::Create() +{ + return std::make_shared(); +} + +std::string Socket::GetMessage() +{ + return mMessage; +} + +void Socket::SetMessage(const std::string& message) +{ + mMessage = message; +} + +void Socket::SetPort(unsigned port) +{ + mPort = port; +} + +unsigned Socket::GetPort() +{ + return mPort; +} diff --git a/src/network/sockets/Socket.h b/src/network/sockets/Socket.h new file mode 100644 index 0000000..093512e --- /dev/null +++ b/src/network/sockets/Socket.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +class Socket +{ + unsigned mPort; + std::string mMessage; + +public: + + Socket(); + + ~Socket(); + + static std::shared_ptr Create(); + + void SetPort(unsigned port); + + unsigned GetPort(); + + std::string GetMessage(); + + void SetMessage(const std::string& message); +}; + +using SocketPtr = std::shared_ptr; diff --git a/src/network/sockets/UnixSocketInterface.cpp b/src/network/sockets/UnixSocketInterface.cpp new file mode 100644 index 0000000..b693951 --- /dev/null +++ b/src/network/sockets/UnixSocketInterface.cpp @@ -0,0 +1,100 @@ +#include "UnixSocketInterface.h" + +#include +#include +#include +#include +#include +#include +#include "HttpResponse.h" + +UnixSocketInterface::UnixSocketInterface() + : mOpeningHandles(), + mBufferSize(1024) +{ + +} + +UnixSocketInterface::~UnixSocketInterface() +{ + +} + +std::shared_ptr UnixSocketInterface::Create() +{ + return std::make_shared(); +} + +void UnixSocketInterface::CreateSocket(SocketPtr socketPtr) +{ + mOpeningHandles[socketPtr] = socket(AF_INET, SOCK_STREAM, 0); +} + +void UnixSocketInterface::Listen(SocketPtr socket) +{ + if(mOpeningHandles[socket] < 0) + { + std::cerr << "Error opening socket" << std::endl; + return; + } + + int port = static_cast(socket->GetPort()); + struct sockaddr_in serv_addr; + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = INADDR_ANY; + serv_addr.sin_port = htons(port); + + int result = bind(mOpeningHandles[socket], (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + if(result< 0) + { + std::cerr << "Error binding socket" << std::endl; + return; + } + + listen(mOpeningHandles[socket], 5); +} + +void UnixSocketInterface::Run(SocketPtr socket) +{ + if(mOpeningHandles[socket] < 0) + { + std::cerr << "Error opening socket" << std::endl; + return; + } + + struct sockaddr_in cli_addr; + socklen_t clilen = sizeof(cli_addr); + while(true) + { + SocketHandle new_socket_handle = accept(mOpeningHandles[socket], + (struct sockaddr *) &cli_addr, &clilen); + if (new_socket_handle < 0) + { + std::cerr << "Error on accept" << std::endl; + return; + } + + char buffer[mBufferSize] = {0}; + int n = read(new_socket_handle, buffer, mBufferSize); + if (n < 0) + { + std::cerr << "Error on read" << std::endl; + return; + } + socket->SetMessage(buffer); + std::cout << "Here is the message: " << buffer << std::endl; + + HttpResponse response; + response.SetBody("Hello world!"); + + std::string response_message = response.ToString(); + n = write(new_socket_handle, response_message.c_str(), response_message.length()); + if (n < 0) + { + std::cerr << "Error on write" << std::endl; + return; + } + close(new_socket_handle); + } +} diff --git a/src/network/sockets/UnixSocketInterface.h b/src/network/sockets/UnixSocketInterface.h new file mode 100644 index 0000000..b131a61 --- /dev/null +++ b/src/network/sockets/UnixSocketInterface.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include + +#include "Socket.h" + +class UnixSocketInterface +{ + using SocketHandle = int; + std::map mOpeningHandles; + std::size_t mBufferSize; + +public: + + UnixSocketInterface(); + + ~UnixSocketInterface(); + + static std::shared_ptr Create(); + + void CreateSocket(SocketPtr socket); + + void Listen(SocketPtr socket); + + void Run(SocketPtr socket); +}; + +using UnixSocketInterfacePtr = std::shared_ptr; diff --git a/src/ui_elements/CMakeLists.txt b/src/ui_elements/CMakeLists.txt new file mode 100644 index 0000000..6efb425 --- /dev/null +++ b/src/ui_elements/CMakeLists.txt @@ -0,0 +1,29 @@ +list(APPEND ui_elements_LIB_INCLUDES + desktop_elements/Keyboard.cpp + desktop_elements/Screen.cpp + desktop_elements/Window.cpp + ui_events/KeyboardEvent.cpp + ui_events/MouseEvent.cpp + ui_events/UiEvent.cpp + ui_events/PaintEvent.cpp + widgets/Widget.cpp + widgets/Button.cpp + widgets/Label.cpp + widgets/HorizontalSpacer.cpp + widgets/elements/GeometryElement.cpp + widgets/elements/RectangleElement.cpp + widgets/elements/TextElement.cpp + widgets/elements/VisualLayer.cpp) + +add_library(ui_elements SHARED ${ui_elements_LIB_INCLUDES}) + +target_include_directories(ui_elements PUBLIC + "${PROJECT_SOURCE_DIR}/src/core/" + "${PROJECT_SOURCE_DIR}/src/geometry/" + "${CMAKE_CURRENT_SOURCE_DIR}/" + "${CMAKE_CURRENT_SOURCE_DIR}/widgets" + "${CMAKE_CURRENT_SOURCE_DIR}/widgets/elements" + "${CMAKE_CURRENT_SOURCE_DIR}/ui_events" + "${CMAKE_CURRENT_SOURCE_DIR}/desktop_elements" + ) +target_link_libraries(ui_elements PUBLIC core geometry) \ No newline at end of file diff --git a/src/ui_elements/desktop_elements/Keyboard.cpp b/src/ui_elements/desktop_elements/Keyboard.cpp new file mode 100644 index 0000000..4bb65fd --- /dev/null +++ b/src/ui_elements/desktop_elements/Keyboard.cpp @@ -0,0 +1,13 @@ +#include "Keyboard.h" + +Keyboard::Keyboard() + :mKeyMap() +{ + +} + +std::shared_ptr Keyboard::Create() +{ + return std::make_shared(); +} + diff --git a/src/ui_elements/desktop_elements/Keyboard.h b/src/ui_elements/desktop_elements/Keyboard.h new file mode 100644 index 0000000..3bbdeb4 --- /dev/null +++ b/src/ui_elements/desktop_elements/Keyboard.h @@ -0,0 +1,26 @@ +#pragma once +#include +#include +#include + +class Keyboard +{ +public: + using KeyCode = unsigned; + +protected: + std::map mKeyMap; + +public: + Keyboard(); + virtual ~Keyboard() = default; + + static std::shared_ptr Create(); + + virtual std::string GetKeyString(KeyCode code) + { + return ""; + } +}; + +using KeyboardPtr = std::shared_ptr; diff --git a/src/ui_elements/desktop_elements/Screen.cpp b/src/ui_elements/desktop_elements/Screen.cpp new file mode 100644 index 0000000..00411ba --- /dev/null +++ b/src/ui_elements/desktop_elements/Screen.cpp @@ -0,0 +1,18 @@ +#include "Screen.h" + +namespace mt{ +Screen::Screen() +{ + +} + +Screen::~Screen() +{ + +} + +std::shared_ptr Screen::Create() +{ + return std::make_shared(); +} +} diff --git a/src/ui_elements/desktop_elements/Screen.h b/src/ui_elements/desktop_elements/Screen.h new file mode 100644 index 0000000..4af5ca8 --- /dev/null +++ b/src/ui_elements/desktop_elements/Screen.h @@ -0,0 +1,17 @@ +#pragma once + +#include +namespace mt{ +class Screen +{ + +public: + + Screen(); + + ~Screen(); + + static std::shared_ptr Create(); +}; +} +using ScreenPtr = std::shared_ptr; diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp new file mode 100644 index 0000000..8181695 --- /dev/null +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -0,0 +1,67 @@ +#include "Window.h" + +namespace mt{ +Window::Window() + :mWidth(400), + mHeight(300), + mWidget() +{ + +} + +Window::~Window() +{ + +} + +std::vector Window::GetLayers() +{ + return mLayers; +} + +void Window::OnMouseEvent(MouseEventPtr event) +{ + mWidget->OnMouseEvent(event); +} + +void Window::OnPaint(PaintEventPtr event) +{ + mLayers.clear(); + mWidget->SetSize(mWidth, mHeight); + mWidget->OnPaintEvent(event); + + auto layers = mWidget->GetLayers(); + mLayers.insert(mLayers.end(), layers.begin(), layers.end()); +} + +std::shared_ptr Window::Create() +{ + return std::make_shared(); +} + +void Window::AddWidget(WidgetPtr widget) +{ + mWidget = widget; +} + +WidgetPtr Window::GetWidget() +{ + return mWidget; +} + +unsigned Window::GetWidth() +{ + return mWidth; +} + +unsigned Window::GetHeight() +{ + return mHeight; +} + +void Window::SetSize(unsigned width, unsigned height) +{ + mWidth = width; + mHeight = height; +} +} diff --git a/src/ui_elements/desktop_elements/Window.h b/src/ui_elements/desktop_elements/Window.h new file mode 100644 index 0000000..5ac4b59 --- /dev/null +++ b/src/ui_elements/desktop_elements/Window.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include + +#include "PaintEvent.h" +#include "MouseEvent.h" +#include "VisualLayer.h" +#include "Widget.h" + +namespace mt +{ + +class Window +{ + +private: + + WidgetPtr mWidget; + unsigned mWidth; + unsigned mHeight; + std::vector mLayers; + +public: + + Window(); + + ~Window(); + + static std::shared_ptr Create(); + + void AddWidget(WidgetPtr widget); + + WidgetPtr GetWidget(); + + std::vector GetLayers(); + + unsigned GetWidth(); + + unsigned GetHeight(); + + void SetSize(unsigned width, unsigned height); + + void OnPaint(PaintEventPtr event); + + void OnMouseEvent(MouseEventPtr event); +}; +} + +using WindowPtr = std::shared_ptr; diff --git a/src/ui_elements/style/Theme.cpp b/src/ui_elements/style/Theme.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/ui_elements/style/Theme.h b/src/ui_elements/style/Theme.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/ui_elements/style/Theme.h @@ -0,0 +1 @@ + diff --git a/src/ui_elements/ui_events/KeyboardEvent.cpp b/src/ui_elements/ui_events/KeyboardEvent.cpp new file mode 100644 index 0000000..b1deaf2 --- /dev/null +++ b/src/ui_elements/ui_events/KeyboardEvent.cpp @@ -0,0 +1,39 @@ +#include "KeyboardEvent.h" + +KeyboardEvent::KeyboardEvent() + : UiEvent(), + mAction(), + mKeyString() +{ + mType = UiEvent::Type::Keyboard; +} + +KeyboardEvent::~KeyboardEvent() +{ + +} + +std::shared_ptr KeyboardEvent::Create() +{ + return std::make_shared(); +} + +void KeyboardEvent::SetKeyString(const std::string& key) +{ + mKeyString = key; +} + +std::string KeyboardEvent::GetKeyString() +{ + return mKeyString; +} + +void KeyboardEvent::SetAction(Action action) +{ + mAction = action; +} + +KeyboardEvent::Action KeyboardEvent::GetAction() +{ + return mAction; +} diff --git a/src/ui_elements/ui_events/KeyboardEvent.h b/src/ui_elements/ui_events/KeyboardEvent.h new file mode 100644 index 0000000..dbba79e --- /dev/null +++ b/src/ui_elements/ui_events/KeyboardEvent.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +#include "UiEvent.h" + +class KeyboardEvent : public UiEvent +{ +public: + enum class Action + { + Pressed, + Released + }; + +private: + + Action mAction; + std::string mKeyString; + +public: + + KeyboardEvent(); + + ~KeyboardEvent(); + + static std::shared_ptr Create(); + + void SetKeyString(const std::string& key); + + std::string GetKeyString(); + + void SetAction(Action action); + + Action GetAction(); + +}; +using KeyboardEventPtr = std::shared_ptr; diff --git a/src/ui_elements/ui_events/MouseEvent.cpp b/src/ui_elements/ui_events/MouseEvent.cpp new file mode 100644 index 0000000..f95ddf5 --- /dev/null +++ b/src/ui_elements/ui_events/MouseEvent.cpp @@ -0,0 +1,51 @@ +#include "MouseEvent.h" + +MouseEvent::MouseEvent() + : UiEvent(), + mClientLocation(0, 0), + mScreenLocation(0, 0), + mAction() +{ + mType = UiEvent::Type::Mouse; +} + +MouseEvent::~MouseEvent() +{ + +} + +std::shared_ptr MouseEvent::Create() +{ + return std::make_shared(); +} + +void MouseEvent::SetClientLocation(Pixel location) +{ + mClientLocation = location; +} + +void MouseEvent::SetScreenLocation(Pixel location) +{ + mScreenLocation = location; +} + +void MouseEvent::SetAction(MouseEvent::Action action) +{ + mAction = action; +} + +Pixel MouseEvent::GetClientLocation() +{ + return mClientLocation; +} + +Pixel MouseEvent::GetScreenLocation() +{ + return mScreenLocation; +} + +MouseEvent::Action MouseEvent::GetAction() +{ + return mAction; +} + diff --git a/src/ui_elements/ui_events/MouseEvent.h b/src/ui_elements/ui_events/MouseEvent.h new file mode 100644 index 0000000..dfc2540 --- /dev/null +++ b/src/ui_elements/ui_events/MouseEvent.h @@ -0,0 +1,42 @@ +#pragma once + +#include + +#include "DiscretePoint.h" +#include "UiEvent.h" + +class MouseEvent : public UiEvent +{ +public: + enum class Action + { + Pressed, + Released + }; + +private: + Pixel mClientLocation; + Pixel mScreenLocation; + Action mAction; + +public: + + MouseEvent(); + + ~MouseEvent(); + + static std::shared_ptr Create(); + + void SetClientLocation(Pixel location); + + void SetScreenLocation(Pixel location); + + void SetAction(Action action); + + Pixel GetClientLocation(); + + Pixel GetScreenLocation(); + + Action GetAction(); +}; +using MouseEventPtr = std::shared_ptr; diff --git a/src/ui_elements/ui_events/PaintEvent.cpp b/src/ui_elements/ui_events/PaintEvent.cpp new file mode 100644 index 0000000..783c2f4 --- /dev/null +++ b/src/ui_elements/ui_events/PaintEvent.cpp @@ -0,0 +1,18 @@ +#include "PaintEvent.h" + +PaintEvent::PaintEvent() + : UiEvent() +{ + mType = UiEvent::Type::Paint; +} + +PaintEvent::~PaintEvent() +{ + +} + +std::shared_ptr PaintEvent::Create() +{ + return std::make_shared(); +} + diff --git a/src/ui_elements/ui_events/PaintEvent.h b/src/ui_elements/ui_events/PaintEvent.h new file mode 100644 index 0000000..74687b4 --- /dev/null +++ b/src/ui_elements/ui_events/PaintEvent.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +#include "UiEvent.h" + +class PaintEvent : public UiEvent +{ +public: + + PaintEvent(); + + ~PaintEvent(); + + static std::shared_ptr Create(); +}; +using PaintEventPtr = std::shared_ptr; diff --git a/src/ui_elements/ui_events/UiEvent.cpp b/src/ui_elements/ui_events/UiEvent.cpp new file mode 100644 index 0000000..68dd48a --- /dev/null +++ b/src/ui_elements/ui_events/UiEvent.cpp @@ -0,0 +1,23 @@ +#include "UiEvent.h" + +UiEvent::UiEvent() + : mType(Type::Unknown) +{ + +} + +UiEvent::~UiEvent() +{ + +} + +std::shared_ptr UiEvent::Create() +{ + return std::make_shared(); +} + +UiEvent::Type UiEvent::GetType() +{ + return mType; +} + diff --git a/src/ui_elements/ui_events/UiEvent.h b/src/ui_elements/ui_events/UiEvent.h new file mode 100644 index 0000000..305d1a2 --- /dev/null +++ b/src/ui_elements/ui_events/UiEvent.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +class UiEvent +{ +public: + + enum class Type{ + Unknown, + Paint, + Mouse, + Keyboard + }; + +protected: + UiEvent::Type mType; + +public: + + UiEvent(); + + virtual ~UiEvent(); + + static std::shared_ptr Create(); + + Type GetType(); +}; +using UiEventPtr = std::shared_ptr; diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp new file mode 100644 index 0000000..f7ab1a3 --- /dev/null +++ b/src/ui_elements/widgets/Button.cpp @@ -0,0 +1,44 @@ +#include "Button.h" +#include + +Button::Button() + : Widget(), + mLabel() +{ + +} + +std::shared_ptr