Move windows to uptr. Add simple text editing.
This commit is contained in:
parent
2bcc7b3d83
commit
b99708e7d3
55 changed files with 1257 additions and 994 deletions
|
@ -1,5 +1,5 @@
|
||||||
# limmto
|
# 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
|
```bash
|
||||||
mkdir build
|
mkdir build
|
||||||
|
|
|
@ -6,19 +6,19 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
auto command_line_args = CommandLineArgs::CreateUnique();
|
auto args = CommandLineArgs::CreateUnique();
|
||||||
command_line_args->Process(argc, argv);
|
args->Process(argc, argv);
|
||||||
command_line_args->RecordLaunchPath();
|
args->RecordLaunchPath();
|
||||||
|
|
||||||
// Start the main app
|
// Start the main app
|
||||||
auto main_app = MainApplication::Create();
|
auto main_app = MainApplication::Create();
|
||||||
main_app->Initialize(std::move(command_line_args));
|
main_app->Initialize(std::move(args));
|
||||||
|
|
||||||
// Start the gui app
|
// Start the gui app
|
||||||
auto gui_app = std::make_shared<GuiApplication>();
|
auto gui_app = GuiApplication();
|
||||||
gui_app->SetMainApplication(main_app);
|
gui_app.SetMainApplication(main_app);
|
||||||
gui_app->Run();
|
gui_app.Run();
|
||||||
|
|
||||||
main_app->ShutDown();
|
main_app->ShutDown();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "GuiApplication.h"
|
#include "GuiApplication.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include "Widget.h"
|
#include "Widget.h"
|
||||||
#include "HorizontalSpacer.h"
|
#include "HorizontalSpacer.h"
|
||||||
|
#include "TextBox.h"
|
||||||
#include "Button.h"
|
#include "Button.h"
|
||||||
#include "Label.h"
|
#include "Label.h"
|
||||||
#include "XcbInterface.h"
|
#include "XcbInterface.h"
|
||||||
|
@ -12,11 +12,11 @@
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
|
|
||||||
GuiApplication::GuiApplication()
|
GuiApplication::GuiApplication()
|
||||||
: AbstractDesktopApp(),
|
: AbstractDesktopApp(),
|
||||||
mMainApplication(),
|
mMainApplication(),
|
||||||
mDesktopManager()
|
mDesktopManager(DesktopManager::Create())
|
||||||
{
|
{
|
||||||
mDesktopManager = DesktopManager::Create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiApplication::~GuiApplication()
|
GuiApplication::~GuiApplication()
|
||||||
|
@ -26,45 +26,46 @@ GuiApplication::~GuiApplication()
|
||||||
|
|
||||||
void GuiApplication::SetMainApplication(MainApplicationPtr app)
|
void GuiApplication::SetMainApplication(MainApplicationPtr app)
|
||||||
{
|
{
|
||||||
mMainApplication = app;
|
mMainApplication = app;
|
||||||
//mDesktopManager->SetMainApp(shared_from_this());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiApplication::Run()
|
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();
|
auto label = Label::Create();
|
||||||
label->SetLabel("Click the button!!");
|
label->SetLabel("Type text!!");
|
||||||
label->SetBackgroundColor(Color::Create(0, 200, 200));
|
label->SetBackgroundColor(Color::Create(0, 200, 200));
|
||||||
|
|
||||||
auto button = Button::Create();
|
auto textBox = TextBox::Create();
|
||||||
button->SetLabel("Ok");
|
|
||||||
button->SetBackgroundColor(Color::Create(0, 0, 200));
|
|
||||||
|
|
||||||
auto spacer = HorizontalSpacer::Create();
|
auto button = Button::Create();
|
||||||
spacer->AddWidget(label);
|
button->SetLabel("Save");
|
||||||
spacer->AddWidget(button);
|
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;
|
bool useOpenGl = false;
|
||||||
XcbInterface window_interface;
|
XcbInterface window_interface;
|
||||||
window_interface.SetUseOpenGl(useOpenGl);
|
window_interface.SetUseOpenGl(useOpenGl);
|
||||||
window_interface.Initialize();
|
window_interface.Initialize();
|
||||||
window_interface.AddWindow(mainWindow);
|
window_interface.AddWindow(mainWindow);
|
||||||
window_interface.ShowWindow(mainWindow);
|
window_interface.ShowWindow(mainWindow);
|
||||||
if(useOpenGl)
|
if(useOpenGl)
|
||||||
{
|
{
|
||||||
window_interface.CreateOpenGlDrawable(mainWindow);
|
window_interface.CreateOpenGlDrawable(mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
window_interface.Loop(mDesktopManager);
|
window_interface.Loop(mDesktopManager.get());
|
||||||
|
|
||||||
window_interface.ShutDown();
|
window_interface.ShutDown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@
|
||||||
#include "AbstractDesktopApp.h"
|
#include "AbstractDesktopApp.h"
|
||||||
#include "DesktopManager.h"
|
#include "DesktopManager.h"
|
||||||
|
|
||||||
class GuiApplication : public AbstractDesktopApp, std::enable_shared_from_this<GuiApplication>
|
class GuiApplication : public AbstractDesktopApp
|
||||||
{
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
DesktopManagerPtr mDesktopManager;
|
DesktopManagerUPtr mDesktopManager;
|
||||||
MainApplicationPtr mMainApplication;
|
MainApplicationPtr mMainApplication;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GuiApplication();
|
GuiApplication();
|
||||||
|
|
||||||
~GuiApplication();
|
~GuiApplication();
|
||||||
|
|
||||||
void SetMainApplication(MainApplicationPtr app);
|
void SetMainApplication(MainApplicationPtr app);
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
MainApplication::MainApplication()
|
MainApplication::MainApplication()
|
||||||
: mDatabaseManager(),
|
: mDatabaseManager(),
|
||||||
mCommandLineArgs()
|
mCommandLineArgs()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,16 @@ void MainApplication::Initialize(CommandLineArgsUPtr commandLineArgs)
|
||||||
mCommandLineArgs = std::move(commandLineArgs);
|
mCommandLineArgs = std::move(commandLineArgs);
|
||||||
std::string launch_path = mCommandLineArgs->GetLaunchPath().string();
|
std::string launch_path = mCommandLineArgs->GetLaunchPath().string();
|
||||||
|
|
||||||
FileLogger::GetInstance().SetWorkDirectory(launch_path);
|
FileLogger::GetInstance().SetWorkDirectory(launch_path);
|
||||||
FileLogger::GetInstance().Open();
|
FileLogger::GetInstance().Open();
|
||||||
MLOG_INFO("Launched");
|
MLOG_INFO("Launched");
|
||||||
|
|
||||||
mDatabaseManager = DatabaseManager::Create();
|
mDatabaseManager = DatabaseManager::Create();
|
||||||
mDatabaseManager->CreateDatabase(launch_path + "/database.db");
|
mDatabaseManager->CreateDatabase(launch_path + "/database.db");
|
||||||
|
|
||||||
mNetworkManager = NetworkManager::Create();
|
mNetworkManager = NetworkManager::Create();
|
||||||
|
|
||||||
mAudioManager = AudioManager::Create();
|
mAudioManager = AudioManager::Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainApplication::Run()
|
void MainApplication::Run()
|
||||||
|
@ -77,13 +77,13 @@ void MainApplication::Run()
|
||||||
|
|
||||||
void MainApplication::RunServer()
|
void MainApplication::RunServer()
|
||||||
{
|
{
|
||||||
mNetworkManager->RunHttpServer();
|
mNetworkManager->RunHttpServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainApplication::PlayAudio()
|
void MainApplication::PlayAudio()
|
||||||
{
|
{
|
||||||
//MidiReader reader;
|
//MidiReader reader;
|
||||||
//reader.Read("/home/james/sample.mid");
|
//reader.Read("/home/james/sample.mid");
|
||||||
auto device = AudioDevice::Create();
|
auto device = AudioDevice::Create();
|
||||||
mAudioManager->GetAudioInterface()->OpenDevice(device);
|
mAudioManager->GetAudioInterface()->OpenDevice(device);
|
||||||
mAudioManager->GetAudioInterface()->Play(device);
|
mAudioManager->GetAudioInterface()->Play(device);
|
||||||
|
@ -100,13 +100,13 @@ void MainApplication::ConvertDocument(const std::string& inputPath, const std::s
|
||||||
|
|
||||||
void MainApplication::ShutDown()
|
void MainApplication::ShutDown()
|
||||||
{
|
{
|
||||||
mDatabaseManager->OnShutDown();
|
mDatabaseManager->OnShutDown();
|
||||||
mNetworkManager->ShutDown();
|
mNetworkManager->ShutDown();
|
||||||
MLOG_INFO("Shut down");
|
MLOG_INFO("Shut down");
|
||||||
FileLogger::GetInstance().Close();
|
FileLogger::GetInstance().Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<MainApplication> MainApplication::Create()
|
std::shared_ptr<MainApplication> MainApplication::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<MainApplication>();
|
return std::make_shared<MainApplication>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,23 +14,23 @@ class MainApplication
|
||||||
private:
|
private:
|
||||||
|
|
||||||
CommandLineArgsUPtr mCommandLineArgs;
|
CommandLineArgsUPtr mCommandLineArgs;
|
||||||
DatabaseManagerPtr mDatabaseManager;
|
DatabaseManagerPtr mDatabaseManager;
|
||||||
NetworkManagerPtr mNetworkManager;
|
NetworkManagerPtr mNetworkManager;
|
||||||
AudioManagerPtr mAudioManager;
|
AudioManagerPtr mAudioManager;
|
||||||
|
|
||||||
public:
|
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<MainApplication> Create();
|
static std::shared_ptr<MainApplication> Create();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RunServer();
|
void RunServer();
|
||||||
|
|
|
@ -1,36 +1,47 @@
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
|
||||||
Color::Color(unsigned r, unsigned g, unsigned b, double a)
|
Color::Color(unsigned r, unsigned g, unsigned b, double a)
|
||||||
: mR(r),
|
: mR(r),
|
||||||
mG(g),
|
mG(g),
|
||||||
mB(b),
|
mB(b),
|
||||||
mAlpha(a)
|
mAlpha(a)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Color> Color::Create(unsigned r, unsigned g, unsigned b,
|
std::shared_ptr<Color> Color::CreateShared(unsigned r, unsigned g, unsigned b,
|
||||||
double a )
|
double a )
|
||||||
{
|
{
|
||||||
return std::make_shared<Color>(r, g, b, a);
|
return std::make_shared<Color>(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Color::GetR()
|
std::unique_ptr<Color> Color::Create(unsigned r, unsigned g, unsigned b,
|
||||||
|
double a )
|
||||||
{
|
{
|
||||||
return mR;
|
return std::make_unique<Color>(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Color::GetG()
|
std::unique_ptr<Color> Color::Create(const Color& color)
|
||||||
{
|
{
|
||||||
return mG;
|
return std::make_unique<Color>(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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,21 +3,23 @@
|
||||||
|
|
||||||
class Color
|
class Color
|
||||||
{
|
{
|
||||||
unsigned mR;
|
unsigned mR;
|
||||||
unsigned mG;
|
unsigned mG;
|
||||||
unsigned mB;
|
unsigned mB;
|
||||||
double mAlpha;
|
double mAlpha;
|
||||||
|
|
||||||
public:
|
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<Color> CreateShared(unsigned r, unsigned g, unsigned b, double a = 1.0);
|
||||||
|
static std::unique_ptr<Color> Create(unsigned r, unsigned g, unsigned b, double a = 1.0);
|
||||||
|
static std::unique_ptr<Color> Create(const Color& color);
|
||||||
|
|
||||||
static std::shared_ptr<Color> Create(unsigned r, unsigned g, unsigned b, double a = 1.0);
|
unsigned GetR() const;
|
||||||
|
unsigned GetG() const;
|
||||||
unsigned GetR();
|
unsigned GetB() const;
|
||||||
unsigned GetG();
|
double GetAlpha() const;
|
||||||
unsigned GetB();
|
|
||||||
double GetAlpha();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using ColorPtr = std::shared_ptr<Color>;
|
using ColorPtr = std::shared_ptr<Color>;
|
||||||
|
using ColorUPtr = std::unique_ptr<Color>;
|
||||||
|
|
|
@ -10,6 +10,7 @@ list(APPEND ui_elements_LIB_INCLUDES
|
||||||
widgets/Button.cpp
|
widgets/Button.cpp
|
||||||
widgets/Label.cpp
|
widgets/Label.cpp
|
||||||
widgets/HorizontalSpacer.cpp
|
widgets/HorizontalSpacer.cpp
|
||||||
|
widgets/TextBox.cpp
|
||||||
widgets/elements/GeometryElement.cpp
|
widgets/elements/GeometryElement.cpp
|
||||||
widgets/elements/RectangleElement.cpp
|
widgets/elements/RectangleElement.cpp
|
||||||
widgets/elements/TextElement.cpp
|
widgets/elements/TextElement.cpp
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include "Keyboard.h"
|
#include "Keyboard.h"
|
||||||
|
|
||||||
Keyboard::Keyboard()
|
Keyboard::Keyboard()
|
||||||
:mKeyMap()
|
:mKeyMap()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Keyboard> Keyboard::Create()
|
std::unique_ptr<Keyboard> Keyboard::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<Keyboard>();
|
return std::make_unique<Keyboard>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,22 @@
|
||||||
class Keyboard
|
class Keyboard
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using KeyCode = unsigned;
|
using KeyCode = unsigned;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<KeyCode, std::string> mKeyMap;
|
std::map<KeyCode, std::string> mKeyMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Keyboard();
|
Keyboard();
|
||||||
virtual ~Keyboard() = default;
|
|
||||||
|
|
||||||
static std::shared_ptr<Keyboard> Create();
|
virtual ~Keyboard() = default;
|
||||||
|
|
||||||
virtual std::string GetKeyString(KeyCode code)
|
static std::unique_ptr<Keyboard> Create();
|
||||||
{
|
|
||||||
return "";
|
virtual std::string GetKeyString(KeyCode code)
|
||||||
}
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using KeyboardPtr = std::shared_ptr<Keyboard>;
|
using KeyboardUPtr = std::unique_ptr<Keyboard>;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace mt{
|
namespace mt{
|
||||||
Window::Window()
|
Window::Window()
|
||||||
:mWidth(400),
|
:mWidth(400),
|
||||||
mHeight(300),
|
mHeight(300),
|
||||||
mWidget()
|
mWidget()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,54 +14,59 @@ Window::~Window()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<VisualLayerPtr> Window::GetLayers()
|
std::unique_ptr<Window> Window::Create()
|
||||||
{
|
{
|
||||||
return mLayers;
|
return std::make_unique<Window>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OnMouseEvent(MouseEventPtr event)
|
std::vector<VisualLayer*> Window::GetLayers()
|
||||||
{
|
{
|
||||||
mWidget->OnMouseEvent(event);
|
return mLayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OnPaint(PaintEventPtr event)
|
void Window::OnMouseEvent(const MouseEvent* event)
|
||||||
{
|
{
|
||||||
mLayers.clear();
|
mWidget->OnMouseEvent(event);
|
||||||
mWidget->SetSize(mWidth, mHeight);
|
|
||||||
mWidget->OnPaintEvent(event);
|
|
||||||
|
|
||||||
auto layers = mWidget->GetLayers();
|
|
||||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Window> Window::Create()
|
void Window::OnKeyboardEvent(const KeyboardEvent* event)
|
||||||
{
|
{
|
||||||
return std::make_shared<Window>();
|
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)
|
void Window::SetSize(unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
mWidth = width;
|
mWidth = width;
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "PaintEvent.h"
|
#include "PaintEvent.h"
|
||||||
#include "MouseEvent.h"
|
#include "MouseEvent.h"
|
||||||
|
#include "KeyboardEvent.h"
|
||||||
#include "VisualLayer.h"
|
#include "VisualLayer.h"
|
||||||
#include "Widget.h"
|
#include "Widget.h"
|
||||||
|
|
||||||
|
@ -16,35 +17,37 @@ class Window
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
WidgetPtr mWidget;
|
WidgetUPtr mWidget;
|
||||||
unsigned mWidth;
|
unsigned mWidth;
|
||||||
unsigned mHeight;
|
unsigned mHeight;
|
||||||
std::vector<VisualLayerPtr> mLayers;
|
std::vector<VisualLayer*> mLayers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Window();
|
Window();
|
||||||
|
|
||||||
~Window();
|
~Window();
|
||||||
|
|
||||||
static std::shared_ptr<Window> Create();
|
static std::unique_ptr<Window> Create();
|
||||||
|
|
||||||
void AddWidget(WidgetPtr widget);
|
void AddWidget(WidgetUPtr widget);
|
||||||
|
|
||||||
WidgetPtr GetWidget();
|
Widget* GetWidget() const;
|
||||||
|
|
||||||
std::vector<VisualLayerPtr> GetLayers();
|
std::vector<VisualLayer*> 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<mt::Window>;
|
using WindowUPtr = std::unique_ptr<mt::Window>;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "KeyboardEvent.h"
|
#include "KeyboardEvent.h"
|
||||||
|
|
||||||
KeyboardEvent::KeyboardEvent()
|
KeyboardEvent::KeyboardEvent()
|
||||||
: UiEvent(),
|
: UiEvent(),
|
||||||
mAction(),
|
mAction(),
|
||||||
mKeyString()
|
mKeyString()
|
||||||
{
|
{
|
||||||
mType = UiEvent::Type::Keyboard;
|
mType = UiEvent::Type::Keyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardEvent::~KeyboardEvent()
|
KeyboardEvent::~KeyboardEvent()
|
||||||
|
@ -13,27 +13,27 @@ KeyboardEvent::~KeyboardEvent()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<KeyboardEvent> KeyboardEvent::Create()
|
std::unique_ptr<KeyboardEvent> KeyboardEvent::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<KeyboardEvent>();
|
return std::make_unique<KeyboardEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardEvent::SetKeyString(const std::string& key)
|
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)
|
void KeyboardEvent::SetAction(Action action)
|
||||||
{
|
{
|
||||||
mAction = action;
|
mAction = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardEvent::Action KeyboardEvent::GetAction()
|
KeyboardEvent::Action KeyboardEvent::GetAction() const
|
||||||
{
|
{
|
||||||
return mAction;
|
return mAction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,32 +8,32 @@
|
||||||
class KeyboardEvent : public UiEvent
|
class KeyboardEvent : public UiEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Action
|
enum class Action
|
||||||
{
|
{
|
||||||
Pressed,
|
Pressed,
|
||||||
Released
|
Released
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Action mAction;
|
Action mAction;
|
||||||
std::string mKeyString;
|
std::string mKeyString;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
KeyboardEvent();
|
KeyboardEvent();
|
||||||
|
|
||||||
~KeyboardEvent();
|
~KeyboardEvent();
|
||||||
|
|
||||||
static std::shared_ptr<KeyboardEvent> Create();
|
static std::unique_ptr<KeyboardEvent> 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<KeyboardEvent>;
|
using KeyboardEventUPtr = std::unique_ptr<KeyboardEvent>;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include "MouseEvent.h"
|
#include "MouseEvent.h"
|
||||||
|
|
||||||
MouseEvent::MouseEvent()
|
MouseEvent::MouseEvent()
|
||||||
: UiEvent(),
|
: UiEvent(),
|
||||||
mClientLocation(0, 0),
|
mClientLocation(0, 0),
|
||||||
mScreenLocation(0, 0),
|
mScreenLocation(0, 0),
|
||||||
mAction()
|
mAction()
|
||||||
{
|
{
|
||||||
mType = UiEvent::Type::Mouse;
|
mType = UiEvent::Type::Mouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseEvent::~MouseEvent()
|
MouseEvent::~MouseEvent()
|
||||||
|
@ -14,38 +14,38 @@ MouseEvent::~MouseEvent()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<MouseEvent> MouseEvent::Create()
|
std::unique_ptr<MouseEvent> MouseEvent::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<MouseEvent>();
|
return std::make_unique<MouseEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseEvent::SetClientLocation(Pixel location)
|
void MouseEvent::SetClientLocation(Pixel location)
|
||||||
{
|
{
|
||||||
mClientLocation = location;
|
mClientLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseEvent::SetScreenLocation(Pixel location)
|
void MouseEvent::SetScreenLocation(Pixel location)
|
||||||
{
|
{
|
||||||
mScreenLocation = location;
|
mScreenLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseEvent::SetAction(MouseEvent::Action action)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,35 +8,35 @@
|
||||||
class MouseEvent : public UiEvent
|
class MouseEvent : public UiEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Action
|
enum class Action
|
||||||
{
|
{
|
||||||
Pressed,
|
Pressed,
|
||||||
Released
|
Released
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pixel mClientLocation;
|
Pixel mClientLocation;
|
||||||
Pixel mScreenLocation;
|
Pixel mScreenLocation;
|
||||||
Action mAction;
|
Action mAction;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MouseEvent();
|
MouseEvent();
|
||||||
|
|
||||||
~MouseEvent();
|
~MouseEvent();
|
||||||
|
|
||||||
static std::shared_ptr<MouseEvent> Create();
|
static std::unique_ptr<MouseEvent> 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<MouseEvent>;
|
using MouseEventUPtr = std::unique_ptr<MouseEvent>;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "PaintEvent.h"
|
#include "PaintEvent.h"
|
||||||
|
|
||||||
PaintEvent::PaintEvent()
|
PaintEvent::PaintEvent()
|
||||||
: UiEvent()
|
: UiEvent()
|
||||||
{
|
{
|
||||||
mType = UiEvent::Type::Paint;
|
mType = UiEvent::Type::Paint;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintEvent::~PaintEvent()
|
PaintEvent::~PaintEvent()
|
||||||
|
@ -11,8 +11,8 @@ PaintEvent::~PaintEvent()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<PaintEvent> PaintEvent::Create()
|
std::unique_ptr<PaintEvent> PaintEvent::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<PaintEvent>();
|
return std::make_unique<PaintEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ class PaintEvent : public UiEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PaintEvent();
|
PaintEvent();
|
||||||
|
|
||||||
~PaintEvent();
|
~PaintEvent();
|
||||||
|
|
||||||
static std::shared_ptr<PaintEvent> Create();
|
static std::unique_ptr<PaintEvent> Create();
|
||||||
};
|
};
|
||||||
using PaintEventPtr = std::shared_ptr<PaintEvent>;
|
using PaintEventUPtr = std::unique_ptr<PaintEvent>;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "UiEvent.h"
|
#include "UiEvent.h"
|
||||||
|
|
||||||
UiEvent::UiEvent()
|
UiEvent::UiEvent()
|
||||||
: mType(Type::Unknown)
|
: mType(Type::Unknown)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,13 @@ UiEvent::~UiEvent()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<UiEvent> UiEvent::Create()
|
std::unique_ptr<UiEvent> UiEvent::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<UiEvent>();
|
return std::make_unique<UiEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
UiEvent::Type UiEvent::GetType()
|
UiEvent::Type UiEvent::GetType() const
|
||||||
{
|
{
|
||||||
return mType;
|
return mType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,24 +6,24 @@ class UiEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum class Type{
|
enum class Type{
|
||||||
Unknown,
|
Unknown,
|
||||||
Paint,
|
Paint,
|
||||||
Mouse,
|
Mouse,
|
||||||
Keyboard
|
Keyboard
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UiEvent::Type mType;
|
UiEvent::Type mType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UiEvent();
|
UiEvent();
|
||||||
|
|
||||||
virtual ~UiEvent();
|
virtual ~UiEvent();
|
||||||
|
|
||||||
static std::shared_ptr<UiEvent> Create();
|
static std::unique_ptr<UiEvent> Create();
|
||||||
|
|
||||||
Type GetType();
|
Type GetType() const;
|
||||||
};
|
};
|
||||||
using UiEventPtr = std::shared_ptr<UiEvent>;
|
using UiEventUPtr = std::unique_ptr<UiEvent>;
|
||||||
|
|
|
@ -2,43 +2,42 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Button::Button()
|
Button::Button()
|
||||||
: Widget(),
|
: Widget(),
|
||||||
mLabel()
|
mLabel()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Button> Button::Create()
|
std::unique_ptr<Button> Button::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<Button>();
|
return std::make_unique<Button>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::SetLabel(const std::string& text)
|
void Button::SetLabel(const std::string& text)
|
||||||
{
|
{
|
||||||
mLabel = text;
|
mLabel = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::OnMyMouseEvent(MouseEventPtr event)
|
void Button::OnMyMouseEvent(const MouseEvent* event)
|
||||||
{
|
{
|
||||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||||
{
|
{
|
||||||
std::cout << "Clicked !!" << std::endl;
|
std::cout << "Clicked !!" << std::endl;
|
||||||
SetBackgroundColor(Color::Create(0, 255, 0));
|
SetBackgroundColor(Color::Create(0, 255, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::OnPaintEvent(PaintEventPtr event)
|
void Button::OnPaintEvent(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
mLayers.clear();
|
mMyLayers.clear();
|
||||||
AddBackground(event);
|
AddBackground(event);
|
||||||
|
if(!mLabel.empty())
|
||||||
if(!mLabel.empty())
|
{
|
||||||
{
|
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
mLocation.GetY() + mHeight/2);
|
||||||
mLocation.GetY() + mHeight/2);
|
auto textLayer = VisualLayer::Create();
|
||||||
auto text = TextElement::Create(mLabel, middle);
|
textLayer->SetText(TextElement::Create(mLabel, middle));
|
||||||
auto textLayer = VisualLayer::Create();
|
mMyLayers.push_back(std::move(textLayer));
|
||||||
textLayer->SetText(text);
|
}
|
||||||
mLayers.push_back(textLayer);
|
CopyMyLayers();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
class Button : public Widget
|
class Button : public Widget
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string mLabel;
|
std::string mLabel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Button();
|
Button();
|
||||||
|
|
||||||
void SetLabel(const std::string& text);
|
static std::unique_ptr<Button> Create();
|
||||||
|
|
||||||
static std::shared_ptr<Button> Create();
|
void SetLabel(const std::string& text);
|
||||||
|
|
||||||
void OnPaintEvent(PaintEventPtr event);
|
void OnPaintEvent(const PaintEvent* event) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void OnMyMouseEvent(MouseEventPtr event);
|
void OnMyMouseEvent(const MouseEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ButtonPtr = std::shared_ptr<Button>;
|
using ButtonUPtr = std::unique_ptr<Button>;
|
||||||
|
|
|
@ -1,33 +1,34 @@
|
||||||
#include "HorizontalSpacer.h"
|
#include "HorizontalSpacer.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
HorizontalSpacer::HorizontalSpacer()
|
HorizontalSpacer::HorizontalSpacer()
|
||||||
: Widget()
|
: Widget()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<HorizontalSpacer> HorizontalSpacer::Create()
|
std::unique_ptr<HorizontalSpacer> HorizontalSpacer::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<HorizontalSpacer>();
|
return std::make_unique<HorizontalSpacer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HorizontalSpacer::AddChildLayers(PaintEventPtr event)
|
void HorizontalSpacer::AddChildLayers(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
unsigned delta = mHeight / mChildren.size();
|
mLayers.clear();
|
||||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
unsigned delta = mHeight / mChildren.size();
|
||||||
{
|
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||||
auto child = mChildren[idx];
|
{
|
||||||
child->SetSize(mWidth, delta);
|
auto& child = mChildren[idx];
|
||||||
child->SetLocation(DiscretePoint(mLocation.GetX(), mLocation.GetY() + delta*idx));
|
child->SetSize(mWidth, delta);
|
||||||
child->OnPaintEvent(event);
|
child->SetLocation(DiscretePoint(mLocation.GetX(), mLocation.GetY() + delta*idx));
|
||||||
auto layers = child->GetLayers();
|
child->OnPaintEvent(event);
|
||||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
auto layers = child->GetLayers();
|
||||||
}
|
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HorizontalSpacer::OnPaintEvent(PaintEventPtr event)
|
void HorizontalSpacer::OnPaintEvent(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
mLayers.clear();
|
AddChildLayers(event);
|
||||||
|
|
||||||
AddChildLayers(event);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,13 @@ class HorizontalSpacer : public Widget
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HorizontalSpacer();
|
HorizontalSpacer();
|
||||||
|
|
||||||
static std::shared_ptr<HorizontalSpacer> Create();
|
static std::unique_ptr<HorizontalSpacer> Create();
|
||||||
|
|
||||||
void AddChildLayers(PaintEventPtr event) override;
|
void AddChildLayers(const PaintEvent* event) override;
|
||||||
|
|
||||||
void OnPaintEvent(PaintEventPtr event) override;
|
void OnPaintEvent(const PaintEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
using HorizontalSpacerPtr = std::shared_ptr<HorizontalSpacer>;
|
using HorizontalSpacerUPtr = std::unique_ptr<HorizontalSpacer>;
|
||||||
|
|
|
@ -2,34 +2,34 @@
|
||||||
#include "TextElement.h"
|
#include "TextElement.h"
|
||||||
|
|
||||||
Label::Label()
|
Label::Label()
|
||||||
: Widget(),
|
: Widget(),
|
||||||
mLabel()
|
mLabel()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Label> Label::Create()
|
std::unique_ptr<Label> Label::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<Label>();
|
return std::make_unique<Label>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::SetLabel(const std::string& text)
|
void Label::SetLabel(const std::string& text)
|
||||||
{
|
{
|
||||||
mLabel = text;
|
mLabel = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::OnPaintEvent(PaintEventPtr event)
|
void Label::OnPaintEvent(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
mLayers.clear();
|
mMyLayers.clear();
|
||||||
AddBackground(event);
|
AddBackground(event);
|
||||||
|
|
||||||
if(!mLabel.empty())
|
if(!mLabel.empty())
|
||||||
{
|
{
|
||||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||||
mLocation.GetY() + mHeight/2);
|
mLocation.GetY() + mHeight/2);
|
||||||
auto text = TextElement::Create(mLabel, middle);
|
auto textLayer = VisualLayer::Create();
|
||||||
auto textLayer = VisualLayer::Create();
|
textLayer->SetText(TextElement::Create(mLabel, middle));
|
||||||
textLayer->SetText(text);
|
mMyLayers.push_back(std::move(textLayer));
|
||||||
mLayers.push_back(textLayer);
|
}
|
||||||
}
|
CopyMyLayers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,17 @@ class Label : public Widget
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string mLabel;
|
std::string mLabel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Label();
|
Label();
|
||||||
|
|
||||||
void SetLabel(const std::string& text);
|
static std::unique_ptr<Label> Create();
|
||||||
|
|
||||||
static std::shared_ptr<Label> Create();
|
void SetLabel(const std::string& text);
|
||||||
|
|
||||||
void OnPaintEvent(PaintEventPtr event);
|
void OnPaintEvent(const PaintEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
using LabelPtr = std::shared_ptr<Label>;
|
using LabelUPtr = std::unique_ptr<Label>;
|
||||||
|
|
97
src/ui_elements/widgets/TextBox.cpp
Normal file
97
src/ui_elements/widgets/TextBox.cpp
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
#include "TextBox.h"
|
||||||
|
#include "TextElement.h"
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
TextBox::TextBox()
|
||||||
|
: Widget(),
|
||||||
|
mContent(),
|
||||||
|
mCaps(false)
|
||||||
|
{
|
||||||
|
mBackgroundColor = Color::Create(200, 200, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<TextBox> TextBox::Create()
|
||||||
|
{
|
||||||
|
return std::make_unique<TextBox>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextBox::SetContent(const std::string& text)
|
||||||
|
{
|
||||||
|
mContent = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TextBox::GetContent() const
|
||||||
|
{
|
||||||
|
return mContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextBox::AppendContent(const std::string& text)
|
||||||
|
{
|
||||||
|
mContent += text;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextBox::OnMyKeyboardEvent(const KeyboardEvent* event)
|
||||||
|
{
|
||||||
|
if(!event) return false;
|
||||||
|
|
||||||
|
const auto keyString = event->GetKeyString();
|
||||||
|
if (keyString == "KEY_RETURN")
|
||||||
|
{
|
||||||
|
AppendContent("\n");
|
||||||
|
}
|
||||||
|
else if (keyString == "KEY_BACK")
|
||||||
|
{
|
||||||
|
mContent = mContent.substr(0, mContent.size()-1);
|
||||||
|
}
|
||||||
|
else if (keyString == "KEY_SPACE")
|
||||||
|
{
|
||||||
|
AppendContent(" ");
|
||||||
|
}
|
||||||
|
else if (keyString == "KEY_CAPS")
|
||||||
|
{
|
||||||
|
mCaps = !mCaps;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mCaps && !keyString.empty())
|
||||||
|
{
|
||||||
|
const char c = std::toupper(keyString[0]);
|
||||||
|
AppendContent(std::string(&c));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppendContent(keyString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextBox::OnPaintEvent(const PaintEvent* event)
|
||||||
|
{
|
||||||
|
mMyLayers.clear();
|
||||||
|
AddBackground(event);
|
||||||
|
|
||||||
|
double offset = 0;
|
||||||
|
if(!mContent.empty())
|
||||||
|
{
|
||||||
|
std::stringstream stream(mContent);
|
||||||
|
std::string segment;
|
||||||
|
std::vector<std::string> seglist;
|
||||||
|
while(std::getline(stream, segment, '\n'))
|
||||||
|
{
|
||||||
|
seglist.push_back(segment);
|
||||||
|
}
|
||||||
|
for(const auto& line : seglist)
|
||||||
|
{
|
||||||
|
auto loc = DiscretePoint(mLocation.GetX() + mWidth/10,
|
||||||
|
mLocation.GetY() + mHeight/10 + offset);
|
||||||
|
auto textLayer = VisualLayer::Create();
|
||||||
|
textLayer->SetText(TextElement::Create(line, loc));
|
||||||
|
mMyLayers.push_back(std::move(textLayer));
|
||||||
|
offset += 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CopyMyLayers();
|
||||||
|
}
|
29
src/ui_elements/widgets/TextBox.h
Normal file
29
src/ui_elements/widgets/TextBox.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Widget.h"
|
||||||
|
|
||||||
|
class TextBox : public Widget
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::string mContent;
|
||||||
|
bool mCaps;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
TextBox();
|
||||||
|
|
||||||
|
static std::unique_ptr<TextBox> Create();
|
||||||
|
|
||||||
|
void SetContent(const std::string& text);
|
||||||
|
|
||||||
|
std::string GetContent() const;
|
||||||
|
|
||||||
|
void AppendContent(const std::string& text);
|
||||||
|
|
||||||
|
void OnPaintEvent(const PaintEvent* event) override;
|
||||||
|
|
||||||
|
bool OnMyKeyboardEvent(const KeyboardEvent* event) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
using TextBoxUPtr = std::unique_ptr<TextBox>;
|
|
@ -1,13 +1,16 @@
|
||||||
#include "RectangleElement.h"
|
#include "RectangleElement.h"
|
||||||
#include "Widget.h"
|
#include "Widget.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
Widget::Widget()
|
Widget::Widget()
|
||||||
: mLocation(DiscretePoint(0, 0)),
|
: mLocation(DiscretePoint(0, 0)),
|
||||||
mWidth(100),
|
mWidth(100),
|
||||||
mHeight(100),
|
mHeight(100),
|
||||||
mLayers(),
|
mMyLayers(),
|
||||||
mChildren(),
|
mLayers(),
|
||||||
mBackgroundColor(Color::Create(200, 0, 0))
|
mChildren(),
|
||||||
|
mBackgroundColor(Color::Create(200, 0, 0))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,118 +20,148 @@ Widget::~Widget()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::AddWidget(WidgetPtr widget)
|
std::unique_ptr<Widget> Widget::Create()
|
||||||
{
|
{
|
||||||
mChildren.push_back(widget);
|
return std::make_unique<Widget>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::SetSize(unsigned width, unsigned height)
|
void Widget::AddWidget(WidgetUPtr widget)
|
||||||
{
|
{
|
||||||
mWidth = width;
|
mChildren.push_back(std::move(widget));
|
||||||
mHeight = height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Widget> Widget::Create()
|
unsigned Widget::GetWidth() const
|
||||||
{
|
{
|
||||||
return std::make_shared<Widget>();
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscretePoint Widget::GetLocation()
|
unsigned Widget::GetHeight() const
|
||||||
{
|
{
|
||||||
return mLocation;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<VisualLayerPtr> Widget::GetLayers()
|
DiscretePoint Widget::GetLocation() const
|
||||||
{
|
{
|
||||||
return mLayers;
|
return mLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::AddChildLayers(PaintEventPtr event)
|
std::vector<VisualLayer*> Widget::GetLayers() const
|
||||||
{
|
{
|
||||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
return mLayers;
|
||||||
{
|
|
||||||
auto child = mChildren[idx];
|
|
||||||
child->SetSize(mWidth, mHeight);
|
|
||||||
child->SetLocation(mLocation);
|
|
||||||
child->OnPaintEvent(event);
|
|
||||||
auto layers = child->GetLayers();
|
|
||||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::OnPaintEvent(PaintEventPtr event)
|
void Widget::CopyMyLayers()
|
||||||
{
|
{
|
||||||
mLayers.clear();
|
mLayers.clear();
|
||||||
|
mLayers.reserve(mMyLayers.size());
|
||||||
AddBackground(event);
|
auto getRaw = [](const VisualLayerUPtr& uptr){return uptr.get();};
|
||||||
AddChildLayers(event);
|
std::transform(mMyLayers.begin(), mMyLayers.end(), std::back_inserter(mLayers), getRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::Contains(const DiscretePoint& loc)
|
void Widget::AddChildLayers(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
if(loc.GetX() < mLocation.GetX()) return false;
|
for(auto& child: mChildren)
|
||||||
if(loc.GetX() > mLocation.GetX() + mWidth) return false;
|
{
|
||||||
if(loc.GetY() > mLocation.GetY() + mHeight) return false;
|
child->SetSize(mWidth, mHeight);
|
||||||
if(loc.GetY() < mLocation.GetY()) return false;
|
child->SetLocation(mLocation);
|
||||||
return true;
|
child->OnPaintEvent(event);
|
||||||
|
const auto layers = child->GetLayers();
|
||||||
|
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::OnMouseEvent(MouseEventPtr event)
|
void Widget::OnPaintEvent(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
bool inChild = false;
|
mMyLayers.clear();
|
||||||
for(const auto& child : mChildren)
|
AddBackground(event);
|
||||||
{
|
CopyMyLayers();
|
||||||
if(child->OnMouseEvent(event))
|
AddChildLayers(event);
|
||||||
{
|
|
||||||
inChild = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!inChild)
|
|
||||||
{
|
|
||||||
if(Contains(event->GetClientLocation()))
|
|
||||||
{
|
|
||||||
OnMyMouseEvent(event);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::OnMyMouseEvent(MouseEventPtr event)
|
bool Widget::Contains(const DiscretePoint& loc) const
|
||||||
|
{
|
||||||
|
if(loc.GetX() < mLocation.GetX()) return false;
|
||||||
|
if(loc.GetX() > mLocation.GetX() + mWidth) return false;
|
||||||
|
if(loc.GetY() > mLocation.GetY() + mHeight) return false;
|
||||||
|
if(loc.GetY() < mLocation.GetY()) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Widget::OnKeyboardEvent(const KeyboardEvent* event)
|
||||||
|
{
|
||||||
|
bool inChild = false;
|
||||||
|
for(const auto& child : mChildren)
|
||||||
|
{
|
||||||
|
if(child->OnKeyboardEvent(event))
|
||||||
|
{
|
||||||
|
inChild = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!inChild)
|
||||||
|
{
|
||||||
|
return OnMyKeyboardEvent(event);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Widget::OnMyKeyboardEvent(const KeyboardEvent* event)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Widget::OnMouseEvent(const MouseEvent* event)
|
||||||
|
{
|
||||||
|
bool inChild = false;
|
||||||
|
for(const auto& child : mChildren)
|
||||||
|
{
|
||||||
|
if(child->OnMouseEvent(event))
|
||||||
|
{
|
||||||
|
inChild = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!inChild)
|
||||||
|
{
|
||||||
|
if(Contains(event->GetClientLocation()))
|
||||||
|
{
|
||||||
|
OnMyMouseEvent(event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::OnMyMouseEvent(const MouseEvent* event)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::AddBackground(PaintEventPtr event)
|
void Widget::AddBackground(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
auto shape = RectangleElement::Create(mLocation, mWidth, mHeight);
|
auto shape = RectangleElement::Create(mLocation, mWidth, mHeight);
|
||||||
shape->SetFillColor(mBackgroundColor);
|
shape->SetFillColor(Color::Create(*mBackgroundColor));
|
||||||
auto shapeLayer = VisualLayer::Create();
|
auto shapeLayer = VisualLayer::Create();
|
||||||
shapeLayer->SetShape(shape);
|
shapeLayer->SetShape(std::move(shape));
|
||||||
mLayers.push_back(shapeLayer);
|
mMyLayers.push_back(std::move(shapeLayer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::SetBackgroundColor(ColorPtr color)
|
void Widget::SetBackgroundColor(ColorUPtr color)
|
||||||
{
|
{
|
||||||
mBackgroundColor = color;
|
mBackgroundColor = std::move(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::SetLocation(const DiscretePoint& loc)
|
void Widget::SetLocation(const DiscretePoint& loc)
|
||||||
{
|
{
|
||||||
mLocation = loc;
|
mLocation = loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Widget::GetWidth()
|
void Widget::SetSize(unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
return mWidth;
|
mWidth = width;
|
||||||
}
|
mHeight = height;
|
||||||
|
|
||||||
unsigned Widget::GetHeight()
|
|
||||||
{
|
|
||||||
return mHeight;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,55 +8,63 @@
|
||||||
#include "PaintEvent.h"
|
#include "PaintEvent.h"
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
#include "MouseEvent.h"
|
#include "MouseEvent.h"
|
||||||
|
#include "KeyboardEvent.h"
|
||||||
|
|
||||||
class Widget
|
class Widget
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
DiscretePoint mLocation;
|
DiscretePoint mLocation;
|
||||||
unsigned mWidth;
|
unsigned mWidth;
|
||||||
unsigned mHeight;
|
unsigned mHeight;
|
||||||
std::vector<VisualLayerPtr> mLayers;
|
std::vector<VisualLayerUPtr> mMyLayers;
|
||||||
std::vector<std::shared_ptr<Widget> > mChildren;
|
std::vector<VisualLayer*> mLayers;
|
||||||
ColorPtr mBackgroundColor;
|
std::vector<std::unique_ptr<Widget> > mChildren;
|
||||||
|
ColorUPtr mBackgroundColor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Widget();
|
Widget();
|
||||||
|
|
||||||
virtual ~Widget();
|
virtual ~Widget();
|
||||||
|
|
||||||
void AddWidget(std::shared_ptr<Widget> widget);
|
static std::unique_ptr<Widget> Create();
|
||||||
|
|
||||||
void SetBackgroundColor(ColorPtr color);
|
void AddWidget(std::unique_ptr<Widget> widget);
|
||||||
|
|
||||||
void SetSize(unsigned mWidth, unsigned mHeight);
|
unsigned GetWidth() const;
|
||||||
|
|
||||||
DiscretePoint GetLocation();
|
unsigned GetHeight() const;
|
||||||
|
|
||||||
void SetLocation(const DiscretePoint& loc);
|
std::vector<VisualLayer*> GetLayers() const;
|
||||||
|
|
||||||
unsigned GetWidth();
|
DiscretePoint GetLocation() const;
|
||||||
|
|
||||||
unsigned GetHeight();
|
virtual void OnPaintEvent(const PaintEvent* event);
|
||||||
|
|
||||||
std::vector<VisualLayerPtr> GetLayers();
|
virtual bool OnMouseEvent(const MouseEvent* event);
|
||||||
|
|
||||||
static std::shared_ptr<Widget> Create();
|
virtual bool OnKeyboardEvent(const KeyboardEvent* event);
|
||||||
|
|
||||||
virtual void OnPaintEvent(PaintEventPtr event);
|
bool Contains(const DiscretePoint& loc) const;
|
||||||
|
|
||||||
virtual bool OnMouseEvent(MouseEventPtr event);
|
void SetBackgroundColor(ColorUPtr color);
|
||||||
|
|
||||||
bool Contains(const DiscretePoint& loc);
|
void SetSize(unsigned mWidth, unsigned mHeight);
|
||||||
|
|
||||||
|
void SetLocation(const DiscretePoint& loc);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void OnMyMouseEvent(MouseEventPtr event);
|
virtual bool OnMyKeyboardEvent(const KeyboardEvent* event);
|
||||||
|
|
||||||
virtual void AddChildLayers(PaintEventPtr event);
|
virtual void OnMyMouseEvent(const MouseEvent* event);
|
||||||
|
|
||||||
virtual void AddBackground(PaintEventPtr event);
|
virtual void AddChildLayers(const PaintEvent* event);
|
||||||
|
|
||||||
|
virtual void AddBackground(const PaintEvent* event);
|
||||||
|
|
||||||
|
void CopyMyLayers();
|
||||||
};
|
};
|
||||||
|
|
||||||
using WidgetPtr = std::shared_ptr<Widget>;
|
using WidgetUPtr = std::unique_ptr<Widget>;
|
||||||
|
|
|
@ -1,36 +1,39 @@
|
||||||
#include "GeometryElement.h"
|
#include "GeometryElement.h"
|
||||||
|
|
||||||
GeometryElement::GeometryElement()
|
GeometryElement::GeometryElement()
|
||||||
: mFillColor(Color::Create(255, 255, 255)),
|
: mFillColor(Color::Create(255, 255, 255)),
|
||||||
mStrokeColor(Color::Create(0, 0, 0)),
|
mStrokeColor(Color::Create(0, 0, 0)),
|
||||||
mStrokeThickness(1),
|
mStrokeThickness(1),
|
||||||
mType(Type::Path)
|
mType(Type::Path)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorPtr GeometryElement::GetFillColor()
|
Color* GeometryElement::GetFillColor() const
|
||||||
{
|
{
|
||||||
return mFillColor;
|
return mFillColor.get();
|
||||||
}
|
}
|
||||||
ColorPtr GeometryElement::GetStrokeColor()
|
Color* GeometryElement::GetStrokeColor() const
|
||||||
{
|
{
|
||||||
return mStrokeColor;
|
return mStrokeColor.get();
|
||||||
}
|
|
||||||
unsigned GeometryElement::GetStrokeThickness()
|
|
||||||
{
|
|
||||||
return mStrokeThickness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryElement::SetFillColor(ColorPtr color)
|
unsigned GeometryElement::GetStrokeThickness() const
|
||||||
{
|
{
|
||||||
mFillColor = color;
|
return mStrokeThickness;
|
||||||
}
|
}
|
||||||
void GeometryElement::SetStrokeColor(ColorPtr color)
|
|
||||||
|
void GeometryElement::SetFillColor(ColorUPtr color)
|
||||||
{
|
{
|
||||||
mStrokeColor = color;
|
mFillColor = std::move(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometryElement::SetStrokeColor(ColorUPtr color)
|
||||||
|
{
|
||||||
|
mStrokeColor = std::move(color);
|
||||||
|
}
|
||||||
|
|
||||||
void GeometryElement::SetStrokeThickness(unsigned thickness)
|
void GeometryElement::SetStrokeThickness(unsigned thickness)
|
||||||
{
|
{
|
||||||
mStrokeThickness = thickness;
|
mStrokeThickness = thickness;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,35 +5,33 @@
|
||||||
class GeometryElement
|
class GeometryElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum class Type
|
||||||
enum class Type
|
{
|
||||||
{
|
Path,
|
||||||
Path,
|
Rectangle,
|
||||||
Rectangle,
|
Circle,
|
||||||
Circle,
|
Arc
|
||||||
Arc
|
};
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ColorUPtr mFillColor;
|
||||||
ColorPtr mFillColor;
|
ColorUPtr mStrokeColor;
|
||||||
ColorPtr mStrokeColor;
|
unsigned mStrokeThickness;
|
||||||
unsigned mStrokeThickness;
|
Type mType;
|
||||||
Type mType;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GeometryElement();
|
GeometryElement();
|
||||||
virtual ~GeometryElement() = default;
|
virtual ~GeometryElement() = default;
|
||||||
|
|
||||||
ColorPtr GetFillColor();
|
Color* GetFillColor() const;
|
||||||
ColorPtr GetStrokeColor();
|
Color* GetStrokeColor() const;
|
||||||
unsigned GetStrokeThickness();
|
unsigned GetStrokeThickness() const;
|
||||||
virtual Type GetType() = 0;
|
virtual Type GetType() = 0;
|
||||||
|
|
||||||
void SetFillColor(ColorPtr color);
|
void SetFillColor(ColorUPtr color);
|
||||||
void SetStrokeColor(ColorPtr color);
|
void SetStrokeColor(ColorUPtr color);
|
||||||
void SetStrokeThickness(unsigned thickness);
|
void SetStrokeThickness(unsigned thickness);
|
||||||
};
|
};
|
||||||
|
|
||||||
using GeometryElementPtr = std::shared_ptr<GeometryElement>;
|
using GeometryElementUPtr = std::unique_ptr<GeometryElement>;
|
||||||
|
|
|
@ -1,36 +1,36 @@
|
||||||
#include "RectangleElement.h"
|
#include "RectangleElement.h"
|
||||||
|
|
||||||
RectangleElement::RectangleElement(const DiscretePoint& loc,
|
RectangleElement::RectangleElement(const DiscretePoint& loc,
|
||||||
unsigned width, unsigned height)
|
unsigned width, unsigned height)
|
||||||
: mLocation(loc),
|
: mLocation(loc),
|
||||||
mWidth(width),
|
mWidth(width),
|
||||||
mHeight(height)
|
mHeight(height)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
std::unique_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
||||||
unsigned width, unsigned height)
|
unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
return std::make_shared<RectangleElement>(loc, width, height);
|
return std::make_unique<RectangleElement>(loc, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
GeometryElement::Type RectangleElement::GetType()
|
GeometryElement::Type RectangleElement::GetType()
|
||||||
{
|
{
|
||||||
return GeometryElement::Type::Rectangle;
|
return GeometryElement::Type::Rectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscretePoint RectangleElement::GetLocation()
|
DiscretePoint RectangleElement::GetLocation() const
|
||||||
{
|
{
|
||||||
return mLocation;
|
return mLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned RectangleElement::GetWidth()
|
unsigned RectangleElement::GetWidth() const
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned RectangleElement::GetHeight()
|
unsigned RectangleElement::GetHeight() const
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,23 +7,22 @@
|
||||||
|
|
||||||
class RectangleElement : public GeometryElement
|
class RectangleElement : public GeometryElement
|
||||||
{
|
{
|
||||||
DiscretePoint mLocation;
|
DiscretePoint mLocation;
|
||||||
unsigned mWidth;
|
unsigned mWidth;
|
||||||
unsigned mHeight;
|
unsigned mHeight;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RectangleElement(const DiscretePoint& loc,
|
RectangleElement(const DiscretePoint& loc, unsigned width, unsigned height);
|
||||||
unsigned width, unsigned height);
|
static std::unique_ptr<RectangleElement> Create(const DiscretePoint& loc,
|
||||||
static std::shared_ptr<RectangleElement> Create(const DiscretePoint& loc,
|
unsigned width, unsigned height);
|
||||||
unsigned width, unsigned height);
|
GeometryElement::Type GetType() override;
|
||||||
GeometryElement::Type GetType() override;
|
|
||||||
|
|
||||||
DiscretePoint GetLocation();
|
DiscretePoint GetLocation() const;
|
||||||
unsigned GetWidth();
|
unsigned GetWidth() const;
|
||||||
unsigned GetHeight();
|
unsigned GetHeight() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
using RectangleElementPtr = std::shared_ptr<RectangleElement>;
|
using RectangleElementUPtr = std::unique_ptr<RectangleElement>;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "TextElement.h"
|
#include "TextElement.h"
|
||||||
|
|
||||||
TextElement::TextElement(const std::string& content, const DiscretePoint& loc)
|
TextElement::TextElement(const std::string& content, const DiscretePoint& loc)
|
||||||
: mContent(content),
|
: mContent(content),
|
||||||
mLocation(loc),
|
mLocation(loc),
|
||||||
mFontLabel("fixed")
|
mFontLabel("fixed")
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,27 +13,27 @@ TextElement::~TextElement()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TextElement> TextElement::Create(const std::string& content, const DiscretePoint& loc)
|
std::unique_ptr<TextElement> TextElement::Create(const std::string& content, const DiscretePoint& loc)
|
||||||
{
|
{
|
||||||
return std::make_shared<TextElement>(content, loc);
|
return std::make_unique<TextElement>(content, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscretePoint TextElement::GetLocation()
|
DiscretePoint TextElement::GetLocation() const
|
||||||
{
|
{
|
||||||
return mLocation;
|
return mLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TextElement::GetFontLabel() const
|
||||||
|
{
|
||||||
|
return mFontLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TextElement::GetContent() const
|
||||||
|
{
|
||||||
|
return mContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextElement::SetContent(const std::string& content)
|
void TextElement::SetContent(const std::string& content)
|
||||||
{
|
{
|
||||||
mContent = content;
|
mContent = content;
|
||||||
}
|
|
||||||
|
|
||||||
std::string TextElement::GetFontLabel()
|
|
||||||
{
|
|
||||||
return mFontLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string TextElement::GetContent()
|
|
||||||
{
|
|
||||||
return mContent;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,25 +7,25 @@
|
||||||
|
|
||||||
class TextElement
|
class TextElement
|
||||||
{
|
{
|
||||||
std::string mContent;
|
std::string mContent;
|
||||||
DiscretePoint mLocation;
|
DiscretePoint mLocation;
|
||||||
std::string mFontLabel;
|
std::string mFontLabel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TextElement(const std::string& content, const DiscretePoint& loc);
|
TextElement(const std::string& content, const DiscretePoint& loc);
|
||||||
|
|
||||||
~TextElement();
|
~TextElement();
|
||||||
|
|
||||||
static std::shared_ptr<TextElement> Create(const std::string& content, const DiscretePoint& loc);
|
static std::unique_ptr<TextElement> Create(const std::string& content, const DiscretePoint& loc);
|
||||||
|
|
||||||
DiscretePoint GetLocation();
|
DiscretePoint GetLocation() const;
|
||||||
|
|
||||||
std::string GetContent();
|
std::string GetContent() const;
|
||||||
|
|
||||||
void SetContent(const std::string& content);
|
std::string GetFontLabel() const;
|
||||||
|
|
||||||
std::string GetFontLabel();
|
void SetContent(const std::string& content);
|
||||||
};
|
};
|
||||||
|
|
||||||
using TextElementPtr = std::shared_ptr<TextElement>;
|
using TextElementUPtr = std::unique_ptr<TextElement>;
|
||||||
|
|
|
@ -1,38 +1,43 @@
|
||||||
#include "VisualLayer.h"
|
#include "VisualLayer.h"
|
||||||
|
|
||||||
VisualLayer::VisualLayer()
|
VisualLayer::VisualLayer()
|
||||||
: mShape(),
|
: mShape(),
|
||||||
mText()
|
mText()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VisualLayer> VisualLayer::Create()
|
std::unique_ptr<VisualLayer> VisualLayer::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<VisualLayer>();
|
return std::make_unique<VisualLayer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualLayer::SetShape(GeometryElementPtr shape)
|
bool VisualLayer::HasShape() const
|
||||||
{
|
{
|
||||||
mShape = shape;
|
return bool(mShape);
|
||||||
}
|
}
|
||||||
void VisualLayer::SetText(TextElementPtr text)
|
|
||||||
|
bool VisualLayer::HasText() const
|
||||||
{
|
{
|
||||||
mText = text;
|
return bool(mText);
|
||||||
}
|
}
|
||||||
bool VisualLayer::HasShape()
|
|
||||||
|
GeometryElement* VisualLayer::GetShape() const
|
||||||
{
|
{
|
||||||
return bool(mShape);
|
return mShape.get();
|
||||||
}
|
}
|
||||||
bool VisualLayer::HasText()
|
|
||||||
|
TextElement* VisualLayer::GetText() const
|
||||||
{
|
{
|
||||||
return bool(mText);
|
return mText.get();
|
||||||
}
|
}
|
||||||
GeometryElementPtr VisualLayer::GetShape()
|
|
||||||
|
void VisualLayer::SetShape(GeometryElementUPtr shape)
|
||||||
{
|
{
|
||||||
return mShape;
|
mShape = std::move(shape);
|
||||||
}
|
}
|
||||||
TextElementPtr VisualLayer::GetText()
|
|
||||||
|
void VisualLayer::SetText(TextElementUPtr text)
|
||||||
{
|
{
|
||||||
return mText;
|
mText = std::move(text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,20 @@
|
||||||
|
|
||||||
class VisualLayer
|
class VisualLayer
|
||||||
{
|
{
|
||||||
GeometryElementPtr mShape;
|
GeometryElementUPtr mShape;
|
||||||
TextElementPtr mText;
|
TextElementUPtr mText;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VisualLayer();
|
VisualLayer();
|
||||||
|
|
||||||
static std::shared_ptr<VisualLayer> Create();
|
static std::unique_ptr<VisualLayer> Create();
|
||||||
|
|
||||||
void SetShape(GeometryElementPtr shape);
|
|
||||||
void SetText(TextElementPtr text);
|
|
||||||
bool HasShape();
|
|
||||||
bool HasText();
|
|
||||||
GeometryElementPtr GetShape();
|
|
||||||
TextElementPtr GetText();
|
|
||||||
|
|
||||||
|
GeometryElement* GetShape() const;
|
||||||
|
TextElement* GetText() const;
|
||||||
|
bool HasShape() const;
|
||||||
|
bool HasText() const;
|
||||||
|
void SetShape(GeometryElementUPtr shape);
|
||||||
|
void SetText(TextElementUPtr text);
|
||||||
};
|
};
|
||||||
using VisualLayerPtr = std::shared_ptr<VisualLayer>;
|
using VisualLayerUPtr = std::unique_ptr<VisualLayer>;
|
||||||
|
|
|
@ -6,8 +6,8 @@ class AbstractDesktopApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AbstractDesktopApp() = default;
|
AbstractDesktopApp() = default;
|
||||||
virtual ~AbstractDesktopApp() = default;
|
virtual ~AbstractDesktopApp() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
using AbstractDesktopAppPtr = std::shared_ptr<AbstractDesktopApp>;
|
using AbstractDesktopAppPtr = std::shared_ptr<AbstractDesktopApp>;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
list(APPEND windows_LIB_INCLUDES
|
list(APPEND windows_LIB_INCLUDES
|
||||||
managers/WindowManager.cpp
|
managers/WindowManager.cpp
|
||||||
managers/DesktopManager.cpp
|
managers/DesktopManager.cpp
|
||||||
|
managers/EventManager.cpp
|
||||||
ui_interfaces/x11/XcbInterface.cpp
|
ui_interfaces/x11/XcbInterface.cpp
|
||||||
ui_interfaces/x11/XcbLayerInterface.cpp
|
ui_interfaces/x11/XcbLayerInterface.cpp
|
||||||
ui_interfaces/x11/XcbTextInterface.cpp
|
ui_interfaces/x11/XcbTextInterface.cpp
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
DesktopManager::DesktopManager()
|
DesktopManager::DesktopManager()
|
||||||
: mScreens(),
|
: mScreens(),
|
||||||
mWindowManager(),
|
mWindowManager(WindowManager::Create()),
|
||||||
mKeyboard(),
|
mKeyboard(Keyboard::Create()),
|
||||||
mMainApplication(),
|
mMainApplication(),
|
||||||
mModified(false)
|
mModified(false),
|
||||||
|
mEventManager(EventManager::Create())
|
||||||
{
|
{
|
||||||
mWindowManager = WindowManager::Create();
|
|
||||||
mKeyboard = Keyboard::Create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopManager::~DesktopManager()
|
DesktopManager::~DesktopManager()
|
||||||
|
@ -18,95 +18,100 @@ DesktopManager::~DesktopManager()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<DesktopManager> DesktopManager::Create()
|
std::unique_ptr<DesktopManager> DesktopManager::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<DesktopManager>();
|
return std::make_unique<DesktopManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::OnKeyboardEvent(KeyboardEventPtr keyboardEvent)
|
void DesktopManager::ClearEvents()
|
||||||
{
|
{
|
||||||
std::cout << "Key: " << keyboardEvent->GetKeyString() << std::endl;
|
mEventManager->ClearEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::OnPaintEvent(PaintEventPtr paintEvent)
|
void DesktopManager::OnKeyboardEvent(const KeyboardEvent* event)
|
||||||
{
|
{
|
||||||
GetWindowManager()->OnPaintEvent(paintEvent);
|
GetWindowManager()->OnKeyboardEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::OnMouseEvent(MouseEventPtr mouseEvent)
|
void DesktopManager::OnPaintEvent(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
GetWindowManager()->OnMouseEvent(mouseEvent);
|
GetWindowManager()->OnPaintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DesktopManager::IsModified()
|
void DesktopManager::OnMouseEvent(const MouseEvent* event)
|
||||||
{
|
{
|
||||||
return mModified;
|
GetWindowManager()->OnMouseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::OnUiEvent(UiEventPtr event)
|
bool DesktopManager::IsModified() const
|
||||||
{
|
{
|
||||||
mModified = false;
|
return mModified;
|
||||||
switch (event->GetType())
|
}
|
||||||
{
|
|
||||||
case (UiEvent::Type::Paint):
|
|
||||||
{
|
|
||||||
OnPaintEvent(std::dynamic_pointer_cast<PaintEvent>(event));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case (UiEvent::Type::Keyboard):
|
|
||||||
{
|
|
||||||
OnKeyboardEvent(std::dynamic_pointer_cast<KeyboardEvent>(event));
|
|
||||||
//mModified = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case (UiEvent::Type::Mouse):
|
|
||||||
{
|
|
||||||
auto mouseEvent = std::dynamic_pointer_cast<MouseEvent>(event);
|
|
||||||
|
|
||||||
OnMouseEvent(mouseEvent);
|
void DesktopManager::OnUiEvent(UiEventUPtr eventUPtr)
|
||||||
if(mouseEvent->GetAction() == MouseEvent::Action::Pressed)
|
{
|
||||||
{
|
mModified = false;
|
||||||
std::cout << "mouse pressed" << std::endl;
|
const auto event = mEventManager->AddEvent(std::move(eventUPtr));
|
||||||
mModified = true;
|
switch (event->GetType())
|
||||||
}
|
{
|
||||||
break;
|
case (UiEvent::Type::Paint):
|
||||||
}
|
{
|
||||||
default:
|
OnPaintEvent(dynamic_cast<const PaintEvent*>(event));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case (UiEvent::Type::Keyboard):
|
||||||
|
{
|
||||||
|
OnKeyboardEvent(dynamic_cast<const KeyboardEvent*>(event));
|
||||||
|
mModified = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (UiEvent::Type::Mouse):
|
||||||
|
{
|
||||||
|
auto mouseEvent = dynamic_cast<const MouseEvent*>(event);
|
||||||
|
OnMouseEvent(mouseEvent);
|
||||||
|
if(mouseEvent->GetAction() == MouseEvent::Action::Pressed)
|
||||||
|
{
|
||||||
|
std::cout << "mouse pressed" << std::endl;
|
||||||
|
mModified = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::SetIsModified(bool modified)
|
void DesktopManager::SetIsModified(bool modified)
|
||||||
{
|
{
|
||||||
mModified = modified;
|
mModified = modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardPtr DesktopManager::GetKeyboard()
|
Keyboard* DesktopManager::GetKeyboard() const
|
||||||
{
|
{
|
||||||
return mKeyboard;
|
return mKeyboard.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::SetKeyboard(KeyboardPtr keyboard)
|
void DesktopManager::SetKeyboard(KeyboardUPtr keyboard)
|
||||||
{
|
{
|
||||||
mKeyboard = keyboard;
|
mKeyboard = std::move(keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::SetMainApp(AbstractDesktopAppPtr mainApp)
|
void DesktopManager::SetMainApp(AbstractDesktopAppPtr mainApp)
|
||||||
{
|
{
|
||||||
mMainApplication = mainApp;
|
mMainApplication = mainApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractDesktopAppPtr DesktopManager::GetMainApp()
|
AbstractDesktopAppPtr DesktopManager::GetMainApp()
|
||||||
{
|
{
|
||||||
return mMainApplication;
|
return mMainApplication;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopManager::SetWindowManager(WindowManagerPtr windowManager)
|
void DesktopManager::SetWindowManager(WindowManagerUPtr windowManager)
|
||||||
{
|
{
|
||||||
mWindowManager = windowManager;
|
mWindowManager = std::move(windowManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowManagerPtr DesktopManager::GetWindowManager()
|
WindowManager* DesktopManager::GetWindowManager() const
|
||||||
{
|
{
|
||||||
return mWindowManager;
|
return mWindowManager.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,48 +11,50 @@
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
#include "UiEvent.h"
|
#include "UiEvent.h"
|
||||||
#include "AbstractDesktopApp.h"
|
#include "AbstractDesktopApp.h"
|
||||||
|
#include "EventManager.h"
|
||||||
|
|
||||||
class DesktopManager
|
class DesktopManager
|
||||||
{
|
{
|
||||||
std::vector<ScreenPtr> mScreens;
|
std::vector<ScreenPtr> mScreens;
|
||||||
WindowManagerPtr mWindowManager;
|
WindowManagerUPtr mWindowManager;
|
||||||
KeyboardPtr mKeyboard;
|
KeyboardUPtr mKeyboard;
|
||||||
AbstractDesktopAppPtr mMainApplication;
|
EventManagerUPtr mEventManager;
|
||||||
bool mModified;
|
AbstractDesktopAppPtr mMainApplication;
|
||||||
|
bool mModified;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DesktopManager();
|
DesktopManager();
|
||||||
|
|
||||||
~DesktopManager();
|
~DesktopManager();
|
||||||
|
|
||||||
static std::shared_ptr<DesktopManager> Create();
|
static std::unique_ptr<DesktopManager> Create();
|
||||||
|
|
||||||
void SetWindowManager(WindowManagerPtr windowManager);
|
void SetWindowManager(WindowManagerUPtr windowManager);
|
||||||
|
|
||||||
void SetMainApp(AbstractDesktopAppPtr mainApp);
|
void SetMainApp(AbstractDesktopAppPtr mainApp);
|
||||||
|
|
||||||
AbstractDesktopAppPtr GetMainApp();
|
AbstractDesktopAppPtr GetMainApp();
|
||||||
|
|
||||||
WindowManagerPtr GetWindowManager();
|
WindowManager* GetWindowManager() const;
|
||||||
|
|
||||||
KeyboardPtr GetKeyboard();
|
Keyboard* GetKeyboard() const;
|
||||||
|
|
||||||
bool IsModified();
|
bool IsModified() const;
|
||||||
|
|
||||||
void SetIsModified(bool modified);
|
void SetIsModified(bool modified);
|
||||||
|
|
||||||
void SetKeyboard(KeyboardPtr keyboard);
|
void SetKeyboard(KeyboardUPtr keyboard);
|
||||||
|
|
||||||
void OnUiEvent(UiEventPtr event);
|
void OnUiEvent(UiEventUPtr event);
|
||||||
|
|
||||||
void OnKeyboardEvent(KeyboardEventPtr keyboardEvent);
|
void OnKeyboardEvent(const KeyboardEvent* keyboardEvent);
|
||||||
|
|
||||||
void OnMouseEvent(MouseEventPtr mouseEvent);
|
void OnMouseEvent(const MouseEvent* mouseEvent);
|
||||||
|
|
||||||
void OnPaintEvent(PaintEventPtr paintEvent);
|
|
||||||
|
|
||||||
|
void OnPaintEvent(const PaintEvent* paintEvent);
|
||||||
|
|
||||||
|
void ClearEvents();
|
||||||
};
|
};
|
||||||
|
|
||||||
using DesktopManagerPtr = std::shared_ptr<DesktopManager>;
|
using DesktopManagerUPtr = std::unique_ptr<DesktopManager>;
|
||||||
|
|
24
src/windows/managers/EventManager.cpp
Normal file
24
src/windows/managers/EventManager.cpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include "EventManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
EventManager::EventManager()
|
||||||
|
: mEvents()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<EventManager> EventManager::Create()
|
||||||
|
{
|
||||||
|
return std::make_unique<EventManager>();
|
||||||
|
}
|
||||||
|
|
||||||
|
UiEvent* EventManager::AddEvent(UiEventUPtr event)
|
||||||
|
{
|
||||||
|
mEvents.push_back(std::move(event));
|
||||||
|
return mEvents[mEvents.size()-1].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventManager::ClearEvents()
|
||||||
|
{
|
||||||
|
mEvents.clear();
|
||||||
|
}
|
20
src/windows/managers/EventManager.h
Normal file
20
src/windows/managers/EventManager.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include "UiEvent.h"
|
||||||
|
|
||||||
|
class EventManager
|
||||||
|
{
|
||||||
|
std::vector<UiEventUPtr> mEvents;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
EventManager();
|
||||||
|
|
||||||
|
static std::unique_ptr<EventManager> Create();
|
||||||
|
|
||||||
|
UiEvent* AddEvent(UiEventUPtr event);
|
||||||
|
|
||||||
|
void ClearEvents();
|
||||||
|
};
|
||||||
|
|
||||||
|
using EventManagerUPtr = std::unique_ptr<EventManager>;
|
|
@ -1,9 +1,9 @@
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
|
|
||||||
WindowManager::WindowManager()
|
WindowManager::WindowManager()
|
||||||
: mWindows()
|
: mWindows()
|
||||||
{
|
{
|
||||||
AddWindow(mt::Window::Create());
|
AddWindow(mt::Window::Create());
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowManager::~WindowManager()
|
WindowManager::~WindowManager()
|
||||||
|
@ -11,27 +11,39 @@ WindowManager::~WindowManager()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::OnPaintEvent(PaintEventPtr event)
|
std::unique_ptr<WindowManager> WindowManager::Create()
|
||||||
{
|
{
|
||||||
GetMainWindow()->OnPaint(event);
|
return std::make_unique<WindowManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::OnMouseEvent(MouseEventPtr event)
|
void WindowManager::OnPaintEvent(const PaintEvent* event)
|
||||||
{
|
{
|
||||||
GetMainWindow()->OnMouseEvent(event);
|
GetMainWindow()->OnPaint(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::AddWindow(WindowPtr window)
|
void WindowManager::OnMouseEvent(const MouseEvent* event)
|
||||||
{
|
{
|
||||||
mWindows.push_back(window);
|
GetMainWindow()->OnMouseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<WindowManager> WindowManager::Create()
|
void WindowManager::OnKeyboardEvent(const KeyboardEvent* event)
|
||||||
{
|
{
|
||||||
return std::make_shared<WindowManager>();
|
GetMainWindow()->OnKeyboardEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowPtr WindowManager::GetMainWindow()
|
void WindowManager::AddWindow(WindowUPtr window)
|
||||||
{
|
{
|
||||||
return mWindows[0];
|
mWindows.push_back(std::move(window));
|
||||||
|
}
|
||||||
|
|
||||||
|
mt::Window* WindowManager::GetMainWindow() const
|
||||||
|
{
|
||||||
|
if(mWindows.size()>0)
|
||||||
|
{
|
||||||
|
return mWindows[0].get();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,31 +6,33 @@
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "PaintEvent.h"
|
#include "PaintEvent.h"
|
||||||
#include "MouseEvent.h"
|
#include "MouseEvent.h"
|
||||||
|
#include "KeyboardEvent.h"
|
||||||
|
|
||||||
class WindowManager
|
class WindowManager
|
||||||
{
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<WindowPtr> mWindows;
|
std::vector<WindowUPtr> mWindows;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
WindowManager();
|
WindowManager();
|
||||||
|
|
||||||
~WindowManager();
|
~WindowManager();
|
||||||
|
|
||||||
void AddWindow(WindowPtr window);
|
static std::unique_ptr<WindowManager> Create();
|
||||||
|
|
||||||
static std::shared_ptr<WindowManager> Create();
|
void AddWindow(WindowUPtr window);
|
||||||
|
|
||||||
WindowPtr GetMainWindow();
|
mt::Window* GetMainWindow() const;
|
||||||
|
|
||||||
void OnPaintEvent(PaintEventPtr event);
|
void OnPaintEvent(const PaintEvent* event);
|
||||||
|
|
||||||
void OnMouseEvent(MouseEventPtr event);
|
void OnMouseEvent(const MouseEvent* event);
|
||||||
|
|
||||||
|
void OnKeyboardEvent(const KeyboardEvent* event);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using WindowManagerPtr = std::shared_ptr<WindowManager>;
|
using WindowManagerUPtr = std::unique_ptr<WindowManager>;
|
||||||
|
|
|
@ -16,15 +16,15 @@
|
||||||
|
|
||||||
|
|
||||||
XcbInterface::XcbInterface()
|
XcbInterface::XcbInterface()
|
||||||
: mUseOpenGl(true),
|
: mUseOpenGl(true),
|
||||||
mConnection(nullptr),
|
mConnection(nullptr),
|
||||||
mScreen(nullptr),
|
mScreen(nullptr),
|
||||||
mWindows(),
|
mWindows(),
|
||||||
mHandles(),
|
mHandles(),
|
||||||
mDefaultWindow(-1),
|
mDefaultWindow(-1),
|
||||||
mGraphicsContext(-1),
|
mGraphicsContext(-1),
|
||||||
mX11Display(),
|
mX11Display(),
|
||||||
mGlxInterface()
|
mGlxInterface()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,313 +36,314 @@ XcbInterface::~XcbInterface()
|
||||||
|
|
||||||
void XcbInterface::SetUseOpenGl(bool use)
|
void XcbInterface::SetUseOpenGl(bool use)
|
||||||
{
|
{
|
||||||
mUseOpenGl = use;
|
mUseOpenGl = use;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::Initialize()
|
void XcbInterface::Initialize()
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
UpdateScreen();
|
UpdateScreen();
|
||||||
CreateGraphicsContext();
|
CreateGraphicsContext();
|
||||||
|
|
||||||
if(mUseOpenGl)
|
if(mUseOpenGl)
|
||||||
{
|
{
|
||||||
InitializeOpenGl();
|
InitializeOpenGl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::Connect()
|
void XcbInterface::Connect()
|
||||||
{
|
{
|
||||||
if(mUseOpenGl)
|
if(mUseOpenGl)
|
||||||
{
|
{
|
||||||
/* Open Xlib Display */
|
/* Open Xlib Display */
|
||||||
mX11Display = XOpenDisplay(0);
|
mX11Display = XOpenDisplay(0);
|
||||||
if(!mX11Display)
|
if(!mX11Display)
|
||||||
{
|
{
|
||||||
std::cerr << "Can't open X11 display" << std::endl;
|
std::cerr << "Can't open X11 display" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Got display" << std::endl;
|
std::cout << "Got display" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the XCB connection from the display */
|
/* Get the XCB connection from the display */
|
||||||
mConnection = XGetXCBConnection(mX11Display);
|
mConnection = XGetXCBConnection(mX11Display);
|
||||||
if(!mConnection)
|
if(!mConnection)
|
||||||
{
|
{
|
||||||
XCloseDisplay(mX11Display);
|
XCloseDisplay(mX11Display);
|
||||||
std::cerr << "Can't get xcb connection from display" << std::endl;
|
std::cerr << "Can't get xcb connection from display" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout << "Got connection" << std::endl;
|
std::cout << "Got connection" << std::endl;
|
||||||
|
|
||||||
/* Acquire event queue ownership */
|
/* Acquire event queue ownership */
|
||||||
XSetEventQueueOwner(mX11Display, XCBOwnsEventQueue);
|
XSetEventQueueOwner(mX11Display, XCBOwnsEventQueue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mConnection = xcb_connect(nullptr, nullptr);
|
mConnection = xcb_connect(nullptr, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::UpdateScreen()
|
void XcbInterface::UpdateScreen()
|
||||||
{
|
{
|
||||||
if(!mConnection) return;
|
if(!mConnection) return;
|
||||||
|
|
||||||
auto screen_iter = xcb_setup_roots_iterator(xcb_get_setup(mConnection));
|
auto screen_iter = xcb_setup_roots_iterator(xcb_get_setup(mConnection));
|
||||||
if(mUseOpenGl)
|
if(mUseOpenGl)
|
||||||
{
|
{
|
||||||
if(!mX11Display) return;
|
if(!mX11Display) return;
|
||||||
int default_screen = DefaultScreen(mX11Display);
|
int default_screen = DefaultScreen(mX11Display);
|
||||||
for(int screen_num = default_screen;
|
for(int screen_num = default_screen;
|
||||||
screen_iter.rem && screen_num > 0;
|
screen_iter.rem && screen_num > 0;
|
||||||
--screen_num, xcb_screen_next(&screen_iter));
|
--screen_num, xcb_screen_next(&screen_iter));
|
||||||
}
|
}
|
||||||
mScreen = screen_iter.data;
|
mScreen = screen_iter.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::InitializeOpenGl()
|
void XcbInterface::InitializeOpenGl()
|
||||||
{
|
{
|
||||||
mGlxInterface = GlxInterface::Create();
|
mGlxInterface = GlxInterface::Create();
|
||||||
int default_screen = DefaultScreen(mX11Display);
|
int default_screen = DefaultScreen(mX11Display);
|
||||||
mGlxInterface->SetupContext(mX11Display, default_screen);
|
mGlxInterface->SetupContext(mX11Display, default_screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::CreateOpenGlDrawable(WindowPtr window)
|
void XcbInterface::CreateOpenGlDrawable(mt::Window* window)
|
||||||
{
|
{
|
||||||
if(!mUseOpenGl)
|
if(!mUseOpenGl or !window)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto hwnd = mHandles[window];
|
auto hwnd = mHandles[window];
|
||||||
bool result = mGlxInterface->SetupWindow(mX11Display, hwnd);
|
bool result = mGlxInterface->SetupWindow(mX11Display, hwnd);
|
||||||
if(!result)
|
if(!result)
|
||||||
{
|
{
|
||||||
xcb_destroy_window(mConnection, hwnd);
|
xcb_destroy_window(mConnection, hwnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::CreateGraphicsContext()
|
void XcbInterface::CreateGraphicsContext()
|
||||||
{
|
{
|
||||||
if(!mConnection || !mScreen) return;
|
if(!mConnection || !mScreen) return;
|
||||||
mGraphicsContext = xcb_generate_id(mConnection);
|
mGraphicsContext = xcb_generate_id(mConnection);
|
||||||
|
|
||||||
xcb_drawable_t window = mScreen->root;
|
xcb_drawable_t window = mScreen->root;
|
||||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||||
uint32_t values[2] = {XcbLayerInterface::GetColor(240, 240, 240), 0};
|
uint32_t values[2] = {XcbLayerInterface::GetColor(240, 240, 240), 0};
|
||||||
xcb_create_gc(mConnection, mGraphicsContext, window, mask, values);
|
xcb_create_gc(mConnection, mGraphicsContext, window, mask, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::MapWindow(WindowPtr window)
|
void XcbInterface::MapWindow(mt::Window* window)
|
||||||
{
|
{
|
||||||
if(!mConnection) return;
|
if(!mConnection or !window) return;
|
||||||
xcb_map_window(mConnection, mHandles[window]);
|
xcb_map_window(mConnection, mHandles[window]);
|
||||||
xcb_flush(mConnection);
|
xcb_flush(mConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::ShowWindow(WindowPtr window)
|
void XcbInterface::ShowWindow(mt::Window* window)
|
||||||
{
|
{
|
||||||
MapWindow(window);
|
MapWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t XcbInterface::GetEventMask()
|
uint32_t XcbInterface::GetEventMask()
|
||||||
{
|
{
|
||||||
return XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS |
|
return XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS |
|
||||||
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_POINTER_MOTION;
|
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_POINTER_MOTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::AddWindow(WindowPtr window)
|
void XcbInterface::AddWindow(mt::Window* window)
|
||||||
{
|
{
|
||||||
if(!mConnection || !mScreen) return;
|
if(!mConnection || !mScreen || !window) return;
|
||||||
auto hwnd = xcb_generate_id(mConnection);
|
auto hwnd = xcb_generate_id(mConnection);
|
||||||
|
|
||||||
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||||
uint32_t values[2] = {mScreen->white_pixel, GetEventMask()};
|
uint32_t values[2] = {mScreen->white_pixel, GetEventMask()};
|
||||||
|
|
||||||
xcb_create_window (mConnection, /* connection */
|
xcb_create_window (mConnection, /* connection */
|
||||||
XCB_COPY_FROM_PARENT, /* depth */
|
XCB_COPY_FROM_PARENT, /* depth */
|
||||||
hwnd, /* window Id */
|
hwnd, /* window Id */
|
||||||
mScreen->root, /* parent window */
|
mScreen->root, /* parent window */
|
||||||
0, 0, /* x, y */
|
0, 0, /* x, y */
|
||||||
window->GetWidth(), window->GetHeight(), /* width, height */
|
window->GetWidth(), window->GetHeight(), /* width, height */
|
||||||
10, /* border_width */
|
10, /* border_width */
|
||||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
|
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
|
||||||
mScreen->root_visual, /* visual */
|
mScreen->root_visual, /* visual */
|
||||||
mask, values ); /* masks */
|
mask, values ); /* masks */
|
||||||
mWindows[hwnd] = window;
|
mWindows[hwnd] = window;
|
||||||
mHandles[window] = hwnd;
|
mHandles[window] = hwnd;
|
||||||
mDefaultWindow = hwnd;
|
mDefaultWindow = hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::onPaint(DesktopManagerPtr desktopManager)
|
void XcbInterface::onPaint(DesktopManager* desktopManager)
|
||||||
{
|
{
|
||||||
auto ui_event = PaintEvent::Create();
|
desktopManager->OnUiEvent(PaintEvent::Create());
|
||||||
desktopManager->OnUiEvent(ui_event);
|
PaintWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
||||||
|
|
||||||
PaintWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::PaintWindow(WindowPtr window)
|
void XcbInterface::PaintWindow(mt::Window* window)
|
||||||
{
|
{
|
||||||
const auto hwnd = mHandles[window];
|
if(!window) return;
|
||||||
for(const auto& layer : window->GetLayers())
|
|
||||||
{
|
const auto hwnd = mHandles[window];
|
||||||
XcbLayerInterface::AddLayer(mConnection, mScreen,
|
for(const auto& layer : window->GetLayers())
|
||||||
hwnd, mGraphicsContext, layer);
|
{
|
||||||
}
|
XcbLayerInterface::AddLayer(mConnection, mScreen,
|
||||||
|
hwnd, mGraphicsContext, layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::OnKeyPress(xcb_key_press_event_t* event, DesktopManagerPtr desktopManager)
|
void XcbInterface::OnKeyPress(xcb_key_press_event_t* event, DesktopManager* desktopManager)
|
||||||
{
|
{
|
||||||
auto ui_event = KeyboardEvent::Create();
|
auto ui_event = KeyboardEvent::Create();
|
||||||
ui_event->SetAction(KeyboardEvent::Action::Pressed);
|
ui_event->SetAction(KeyboardEvent::Action::Pressed);
|
||||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||||
ui_event->SetKeyString(keyVal);
|
ui_event->SetKeyString(keyVal);
|
||||||
desktopManager->OnUiEvent(ui_event);
|
desktopManager->OnUiEvent(std::move(ui_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::OnKeyRelease(xcb_key_release_event_t* event, DesktopManagerPtr desktopManager)
|
void XcbInterface::OnKeyRelease(xcb_key_release_event_t* event, DesktopManager* desktopManager)
|
||||||
{
|
{
|
||||||
auto ui_event = KeyboardEvent::Create();
|
auto ui_event = KeyboardEvent::Create();
|
||||||
ui_event->SetAction(KeyboardEvent::Action::Released);
|
ui_event->SetAction(KeyboardEvent::Action::Released);
|
||||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||||
ui_event->SetKeyString(keyVal);
|
ui_event->SetKeyString(keyVal);
|
||||||
desktopManager->OnUiEvent(ui_event);
|
desktopManager->OnUiEvent(std::move(ui_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::OnButtonPress(xcb_button_press_event_t* event, DesktopManagerPtr desktopManager)
|
void XcbInterface::OnButtonPress(xcb_button_press_event_t* event, DesktopManager* desktopManager)
|
||||||
{
|
{
|
||||||
auto ui_event = MouseEvent::Create();
|
auto ui_event = MouseEvent::Create();
|
||||||
auto x = static_cast<unsigned>(event->event_x);
|
auto x = static_cast<unsigned>(event->event_x);
|
||||||
auto y = static_cast<unsigned>(event->event_y);
|
auto y = static_cast<unsigned>(event->event_y);
|
||||||
ui_event->SetClientLocation(DiscretePoint(x, y));
|
ui_event->SetClientLocation(DiscretePoint(x, y));
|
||||||
|
|
||||||
auto screen_x = static_cast<unsigned>(event->root_x);
|
auto screen_x = static_cast<unsigned>(event->root_x);
|
||||||
auto screen_y = static_cast<unsigned>(event->root_y);
|
auto screen_y = static_cast<unsigned>(event->root_y);
|
||||||
ui_event->SetScreenLocation(DiscretePoint(x, y));
|
ui_event->SetScreenLocation(DiscretePoint(x, y));
|
||||||
|
|
||||||
ui_event->SetAction(MouseEvent::Action::Pressed);
|
ui_event->SetAction(MouseEvent::Action::Pressed);
|
||||||
desktopManager->OnUiEvent(ui_event);
|
desktopManager->OnUiEvent(std::move(ui_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::LoopOpenGl(std::shared_ptr<DesktopManager> desktopManager)
|
void XcbInterface::LoopOpenGl(DesktopManager* desktopManager)
|
||||||
{
|
{
|
||||||
int running = 1;
|
int running = 1;
|
||||||
while(running)
|
while(running)
|
||||||
{
|
{
|
||||||
/* Wait for event */
|
/* Wait for event */
|
||||||
xcb_generic_event_t *event = xcb_wait_for_event(mConnection);
|
xcb_generic_event_t *event = xcb_wait_for_event(mConnection);
|
||||||
if(!event)
|
if(!event)
|
||||||
{
|
{
|
||||||
std::cout << "i/o error in xcb_wait_for_event" << std::endl;
|
std::cout << "i/o error in xcb_wait_for_event" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(event->response_type & ~0x80)
|
switch(event->response_type & ~0x80)
|
||||||
{
|
{
|
||||||
case XCB_KEY_PRESS:
|
case XCB_KEY_PRESS:
|
||||||
/* Quit on key press */
|
/* Quit on key press */
|
||||||
std::cout << "got key" << std::endl;
|
std::cout << "got key" << std::endl;
|
||||||
running = 0;
|
running = 0;
|
||||||
break;
|
break;
|
||||||
case XCB_KEY_RELEASE:
|
case XCB_KEY_RELEASE:
|
||||||
/* Quit on key press */
|
/* Quit on key press */
|
||||||
std::cout << "got key" << std::endl;
|
std::cout << "got key" << std::endl;
|
||||||
running = 0;
|
running = 0;
|
||||||
break;
|
break;
|
||||||
case XCB_EXPOSE:
|
case XCB_EXPOSE:
|
||||||
std::cout << "got expose" << std::endl;
|
std::cout << "got expose" << std::endl;
|
||||||
/* Handle expose event, draw and swap buffers */
|
/* Handle expose event, draw and swap buffers */
|
||||||
mGlxInterface->Draw();
|
mGlxInterface->Draw();
|
||||||
mGlxInterface->SwapBuffers(mX11Display);
|
mGlxInterface->SwapBuffers(mX11Display);
|
||||||
std::cout << "end expose" << std::endl;
|
std::cout << "end expose" << std::endl;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cout << "got something else" << std::endl;
|
std::cout << "got something else" << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(event);
|
free(event);
|
||||||
}
|
}
|
||||||
mGlxInterface->DestroyWindow(mX11Display);
|
mGlxInterface->DestroyWindow(mX11Display);
|
||||||
//xcb_destroy_window(mConnection, window);
|
//xcb_destroy_window(mConnection, window);
|
||||||
mGlxInterface->DestroyContext(mX11Display);
|
mGlxInterface->DestroyContext(mX11Display);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::ClearWindow(WindowPtr window)
|
void XcbInterface::ClearWindow(mt::Window* window)
|
||||||
{
|
{
|
||||||
xcb_clear_area(mConnection, 1, mHandles[window], 0, 0,
|
if(!window) return;
|
||||||
window->GetWidth(), window->GetHeight());
|
xcb_clear_area(mConnection, 1, mHandles[window], 0, 0,
|
||||||
xcb_flush(mConnection);
|
window->GetWidth(), window->GetHeight());
|
||||||
|
xcb_flush(mConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::Loop(DesktopManagerPtr desktopManager)
|
void XcbInterface::Loop(DesktopManager* desktopManager)
|
||||||
{
|
{
|
||||||
if(!mConnection) return;
|
if(!mConnection) return;
|
||||||
|
|
||||||
if(mUseOpenGl)
|
if(mUseOpenGl)
|
||||||
{
|
{
|
||||||
LoopOpenGl(desktopManager);
|
LoopOpenGl(desktopManager);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_generic_event_t *event;
|
xcb_generic_event_t *event;
|
||||||
while ((event = xcb_wait_for_event(mConnection)))
|
while ((event = xcb_wait_for_event(mConnection)))
|
||||||
{
|
{
|
||||||
switch (event->response_type & ~0x80)
|
switch (event->response_type & ~0x80)
|
||||||
{
|
{
|
||||||
case XCB_EXPOSE:{
|
case XCB_EXPOSE:{
|
||||||
auto expose_event = reinterpret_cast<xcb_expose_event_t*>(event);
|
auto expose_event = reinterpret_cast<xcb_expose_event_t*>(event);
|
||||||
|
|
||||||
// Update the window
|
// Update the window
|
||||||
auto window = mWindows[expose_event->window];
|
auto window = mWindows[expose_event->window];
|
||||||
window->SetSize(expose_event->width, expose_event->height);
|
window->SetSize(expose_event->width, expose_event->height);
|
||||||
|
|
||||||
onPaint(desktopManager);
|
onPaint(desktopManager);
|
||||||
/* flush the request */
|
/* flush the request */
|
||||||
xcb_flush(mConnection);
|
xcb_flush(mConnection);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case XCB_KEY_PRESS: {
|
case XCB_KEY_PRESS: {
|
||||||
auto kr = reinterpret_cast<xcb_key_press_event_t*>(event);
|
auto kr = reinterpret_cast<xcb_key_press_event_t*>(event);
|
||||||
OnKeyPress(kr, desktopManager);
|
OnKeyPress(kr, desktopManager);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case XCB_KEY_RELEASE: {
|
case XCB_KEY_RELEASE: {
|
||||||
auto kr = reinterpret_cast<xcb_key_release_event_t*>(event);
|
auto kr = reinterpret_cast<xcb_key_release_event_t*>(event);
|
||||||
OnKeyRelease(kr, desktopManager);
|
OnKeyRelease(kr, desktopManager);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case XCB_BUTTON_PRESS: {
|
case XCB_BUTTON_PRESS: {
|
||||||
auto press = reinterpret_cast<xcb_button_press_event_t*>(event);
|
auto press = reinterpret_cast<xcb_button_press_event_t*>(event);
|
||||||
OnButtonPress(press, desktopManager);
|
OnButtonPress(press, desktopManager);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
/* Unknown event type, ignore it */
|
/* Unknown event type, ignore it */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(desktopManager->IsModified())
|
if(desktopManager->IsModified())
|
||||||
{
|
{
|
||||||
desktopManager->SetIsModified(false);
|
desktopManager->SetIsModified(false);
|
||||||
ClearWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
ClearWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
free (event);
|
free (event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::ShutDown()
|
void XcbInterface::ShutDown()
|
||||||
{
|
{
|
||||||
if(!mConnection) return;
|
if(!mConnection) return;
|
||||||
std::cout << "starting shutdown" << std::endl;
|
std::cout << "starting shutdown" << std::endl;
|
||||||
xcb_disconnect(mConnection);
|
xcb_disconnect(mConnection);
|
||||||
if(mUseOpenGl && mX11Display)
|
if(mUseOpenGl && mX11Display)
|
||||||
{
|
{
|
||||||
//XCloseDisplay(mX11Display);
|
//XCloseDisplay(mX11Display);
|
||||||
}
|
}
|
||||||
std::cout << "ending shutdown" << std::endl;
|
std::cout << "ending shutdown" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,62 +23,62 @@ class XcbInterface
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool mUseOpenGl;
|
bool mUseOpenGl;
|
||||||
std::map<unsigned, WindowPtr> mWindows;
|
std::map<unsigned, mt::Window*> mWindows;
|
||||||
std::map<WindowPtr, unsigned> mHandles;
|
std::map<mt::Window*, unsigned> mHandles;
|
||||||
unsigned mDefaultWindow;
|
unsigned mDefaultWindow;
|
||||||
xcb_connection_t* mConnection;
|
xcb_connection_t* mConnection;
|
||||||
xcb_screen_t* mScreen;
|
xcb_screen_t* mScreen;
|
||||||
unsigned mGraphicsContext;
|
unsigned mGraphicsContext;
|
||||||
_XDisplay* mX11Display;
|
_XDisplay* mX11Display;
|
||||||
GlxInterfacePtr mGlxInterface;
|
GlxInterfacePtr mGlxInterface;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
XcbInterface();
|
XcbInterface();
|
||||||
|
|
||||||
~XcbInterface();
|
~XcbInterface();
|
||||||
|
|
||||||
void SetUseOpenGl(bool use);
|
void SetUseOpenGl(bool use);
|
||||||
void onPaint(std::shared_ptr<DesktopManager> desktopManager);
|
void onPaint(DesktopManager* desktopManager);
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
void InitializeOpenGl();
|
void InitializeOpenGl();
|
||||||
|
|
||||||
void CreateOpenGlDrawable(WindowPtr window);
|
void CreateOpenGlDrawable(mt::Window* window);
|
||||||
|
|
||||||
void Loop(std::shared_ptr<DesktopManager> desktopManager);
|
void Loop(DesktopManager* desktopManager);
|
||||||
|
|
||||||
void LoopOpenGl(std::shared_ptr<DesktopManager> desktopManager);
|
void LoopOpenGl(DesktopManager* desktopManager);
|
||||||
|
|
||||||
void ShutDown();
|
void ShutDown();
|
||||||
|
|
||||||
void AddWindow(WindowPtr window);
|
void AddWindow(mt::Window* window);
|
||||||
|
|
||||||
void ShowWindow(WindowPtr window);
|
void ShowWindow(mt::Window* window);
|
||||||
|
|
||||||
void PaintWindow(WindowPtr window);
|
void PaintWindow(mt::Window* window);
|
||||||
|
|
||||||
void ClearWindow(WindowPtr window);
|
void ClearWindow(mt::Window* window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Connect();
|
void Connect();
|
||||||
|
|
||||||
void UpdateScreen();
|
void UpdateScreen();
|
||||||
|
|
||||||
uint32_t GetEventMask();
|
uint32_t GetEventMask();
|
||||||
|
|
||||||
void OnKeyPress(xcb_key_press_event_t* event, DesktopManagerPtr);
|
void OnKeyPress(xcb_key_press_event_t* event, DesktopManager*);
|
||||||
|
|
||||||
void OnKeyRelease(xcb_key_press_event_t* event, DesktopManagerPtr);
|
void OnKeyRelease(xcb_key_press_event_t* event, DesktopManager*);
|
||||||
|
|
||||||
void OnButtonPress(xcb_button_press_event_t* event, DesktopManagerPtr);
|
void OnButtonPress(xcb_button_press_event_t* event, DesktopManager*);
|
||||||
|
|
||||||
void MapWindow(WindowPtr window);
|
void MapWindow(mt::Window* window);
|
||||||
|
|
||||||
void CreateGraphicsContext();
|
void CreateGraphicsContext();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
#include "XcbKeyboard.h"
|
#include "XcbKeyboard.h"
|
||||||
|
|
||||||
|
|
||||||
XcbKeyboard::XcbKeyboard()
|
XcbKeyboard::XcbKeyboard()
|
||||||
: Keyboard()
|
: Keyboard()
|
||||||
{
|
{
|
||||||
mKeyMap = {{24, "q"}, {25, "w"},
|
mKeyMap = {{10, "1"}, {11, "2"}, {12, "3"}, {13, "4"}, {14, "5"}, {15, "6"},
|
||||||
{26, "e"}, {27, "r"},
|
{16, "7"}, {17, "8"}, {18, "9"}, {19, "0"}, {20, "-"}, {21, "+"}, {22, "KEY_BACK"},
|
||||||
{28, "t"}, {29, "y"}, {30, "u"}, {31, "i"}, {32, "o"},
|
{24, "q"}, {25, "w"}, {26, "e"}, {27, "r"}, {28, "t"}, {29, "y"},
|
||||||
{33, "p"}, {38, "a"}, {39, "s"}, {40, "d"}, {41, "f"},
|
{30, "u"}, {31, "i"}, {32, "o"}, {33, "p"}, {34, "["}, {35, "]"}, {36, "KEY_RETURN"},
|
||||||
{42, "g"}, {43, "h"}, {44, "j"}, {45, "k"}, {46, "l"},
|
{38, "a"}, {39, "s"}, {40, "d"}, {41, "f"}, {42, "g"}, {43, "h"},
|
||||||
{52, "z"}, {53, "x"}, {54, "c"}, {55, "v"}, {56, "b"},
|
{44, "j"}, {45, "k"}, {46, "l"}, {47, ":"}, {48, "'"}, {49, "#"},
|
||||||
{57, "n"}, {58, "m"}};
|
{52, "z"}, {53, "x"}, {54, "c"}, {55, "v"}, {56, "b"},
|
||||||
|
{57, "n"}, {58, "m"}, {59, ","}, {60, "."}, {61, "/"},
|
||||||
|
{65, "KEY_SPACE"}, {66, "KEY_CAPS"}};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<XcbKeyboard> XcbKeyboard::Create()
|
std::unique_ptr<XcbKeyboard> XcbKeyboard::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<XcbKeyboard>();
|
return std::make_unique<XcbKeyboard>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string XcbKeyboard::GetKeyString(KeyCode keyCode)
|
std::string XcbKeyboard::GetKeyString(KeyCode keyCode)
|
||||||
{
|
{
|
||||||
return mKeyMap[keyCode];
|
return mKeyMap[keyCode];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
class XcbKeyboard : public Keyboard
|
class XcbKeyboard : public Keyboard
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XcbKeyboard();
|
XcbKeyboard();
|
||||||
|
|
||||||
static std::shared_ptr<XcbKeyboard> Create();
|
static std::unique_ptr<XcbKeyboard> Create();
|
||||||
|
|
||||||
std::string GetKeyString(KeyCode keyCode) override;
|
std::string GetKeyString(KeyCode keyCode) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
using XcbKeyboardPtr = std::shared_ptr<XcbKeyboard>;
|
using XcbKeyboardUPtr = std::unique_ptr<XcbKeyboard>;
|
||||||
|
|
|
@ -3,48 +3,48 @@
|
||||||
#include "RectangleElement.h"
|
#include "RectangleElement.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
uint32_t XcbLayerInterface::GetColor(ColorPtr color)
|
uint32_t XcbLayerInterface::GetColor(const Color* color)
|
||||||
{
|
{
|
||||||
return XcbLayerInterface::GetColor(color->GetR(),
|
return XcbLayerInterface::GetColor(color->GetR(),
|
||||||
color->GetG(), color->GetB());
|
color->GetG(), color->GetB());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t XcbLayerInterface::GetColor(int r, int g, int b)
|
uint32_t XcbLayerInterface::GetColor(int r, int g, int b)
|
||||||
{
|
{
|
||||||
return b + (g<<8) + (r<<16);
|
return b + (g<<8) + (r<<16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbLayerInterface::ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
void XcbLayerInterface::ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
||||||
ColorPtr color)
|
const Color* color)
|
||||||
{
|
{
|
||||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||||
uint32_t values[2] = {XcbLayerInterface::GetColor(color), 0};
|
uint32_t values[2] = {XcbLayerInterface::GetColor(color), 0};
|
||||||
|
|
||||||
xcb_change_gc(connection, gc, mask, values);
|
xcb_change_gc(connection, gc, mask, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbLayerInterface::AddLayer(xcb_connection_t* connection,
|
void XcbLayerInterface::AddLayer(xcb_connection_t* connection,
|
||||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||||
VisualLayerPtr layer)
|
VisualLayer* layer)
|
||||||
{
|
{
|
||||||
if(layer->HasText())
|
if(layer->HasText())
|
||||||
{
|
{
|
||||||
XcbTextInterface::AddTextElement(connection, screen, window, layer->GetText());
|
XcbTextInterface::AddTextElement(connection, screen, window, layer->GetText());
|
||||||
}
|
}
|
||||||
else if(layer->HasShape())
|
else if(layer->HasShape())
|
||||||
{
|
{
|
||||||
auto shape = layer->GetShape();
|
auto shape = layer->GetShape();
|
||||||
if(shape->GetType() == GeometryElement::Type::Rectangle)
|
if(shape->GetType() == GeometryElement::Type::Rectangle)
|
||||||
{
|
{
|
||||||
auto rectangle = std::dynamic_pointer_cast<RectangleElement>(shape);
|
auto rectangle = dynamic_cast<RectangleElement*>(shape);
|
||||||
Pixel loc = rectangle->GetLocation();
|
Pixel loc = rectangle->GetLocation();
|
||||||
auto width = static_cast<uint16_t>(rectangle->GetWidth());
|
auto width = static_cast<uint16_t>(rectangle->GetWidth());
|
||||||
auto height = static_cast<uint16_t>(rectangle->GetHeight());
|
auto height = static_cast<uint16_t>(rectangle->GetHeight());
|
||||||
xcb_rectangle_t rectangles[] = { { static_cast<int16_t>(loc.GetX()),
|
xcb_rectangle_t rectangles[] = { { static_cast<int16_t>(loc.GetX()),
|
||||||
static_cast<int16_t>(loc.GetY()), width, height} };
|
static_cast<int16_t>(loc.GetY()), width, height} };
|
||||||
XcbLayerInterface::ModifyGcColor(connection, gc, rectangle->GetFillColor());
|
XcbLayerInterface::ModifyGcColor(connection, gc, rectangle->GetFillColor());
|
||||||
xcb_poly_fill_rectangle(connection, window, gc, 1, rectangles);
|
xcb_poly_fill_rectangle(connection, window, gc, 1, rectangles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,15 @@ class XcbLayerInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static uint32_t GetColor(ColorPtr);
|
static uint32_t GetColor(const Color* color);
|
||||||
|
|
||||||
static uint32_t GetColor(int r, int g, int b);
|
static uint32_t GetColor(int r, int g, int b);
|
||||||
|
|
||||||
static void ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
static void ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
||||||
ColorPtr color);
|
const Color* color);
|
||||||
|
|
||||||
static void AddLayer(xcb_connection_t* connection,
|
static void AddLayer(xcb_connection_t* connection,
|
||||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||||
VisualLayerPtr layer);
|
VisualLayer* layer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,38 +2,38 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
|
xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
|
||||||
xcb_screen_t *screen, xcb_window_t window, const char*font_name)
|
xcb_screen_t *screen, xcb_window_t window, const char*font_name)
|
||||||
{
|
{
|
||||||
/* get font */
|
/* get font */
|
||||||
xcb_font_t font = xcb_generate_id(connection);
|
xcb_font_t font = xcb_generate_id(connection);
|
||||||
xcb_open_font(connection, font, strlen(font_name), font_name);
|
xcb_open_font(connection, font, strlen(font_name), font_name);
|
||||||
|
|
||||||
/* create graphics context */
|
/* create graphics context */
|
||||||
xcb_gcontext_t gc = xcb_generate_id(connection);
|
xcb_gcontext_t gc = xcb_generate_id(connection);
|
||||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
||||||
uint32_t value_list[3] = {screen->black_pixel, screen->white_pixel, font };
|
uint32_t value_list[3] = {screen->black_pixel, screen->white_pixel, font };
|
||||||
|
|
||||||
xcb_create_gc(connection, gc, window, mask, value_list);
|
xcb_create_gc(connection, gc, window, mask, value_list);
|
||||||
|
|
||||||
/* close font */
|
/* close font */
|
||||||
xcb_close_font(connection, font);
|
xcb_close_font(connection, font);
|
||||||
return gc;
|
return gc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbTextInterface::AddTextElement(xcb_connection_t* connection,
|
void XcbTextInterface::AddTextElement(xcb_connection_t* connection,
|
||||||
xcb_screen_t* screen, xcb_window_t window,
|
xcb_screen_t* screen, xcb_window_t window,
|
||||||
TextElementPtr textElement)
|
const TextElement* textElement)
|
||||||
{
|
{
|
||||||
/* get graphics context */
|
/* get graphics context */
|
||||||
xcb_gcontext_t gc = XcbTextInterface::GetFontGC(connection, screen, window,
|
xcb_gcontext_t gc = XcbTextInterface::GetFontGC(connection, screen, window,
|
||||||
textElement->GetFontLabel().c_str());
|
textElement->GetFontLabel().c_str());
|
||||||
|
|
||||||
/* draw the text */
|
/* draw the text */
|
||||||
std::string content = textElement->GetContent();
|
std::string content = textElement->GetContent();
|
||||||
Pixel loc = textElement->GetLocation();
|
Pixel loc = textElement->GetLocation();
|
||||||
xcb_image_text_8(connection, content.length(), window, gc,
|
xcb_image_text_8(connection, content.length(), window, gc,
|
||||||
loc.GetX(), loc.GetY(), content.c_str());
|
loc.GetX(), loc.GetY(), content.c_str());
|
||||||
|
|
||||||
/* free the gc */
|
/* free the gc */
|
||||||
xcb_free_gc(connection, gc);
|
xcb_free_gc(connection, gc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
class XcbTextInterface
|
class XcbTextInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static xcb_gcontext_t GetFontGC(xcb_connection_t* connection,
|
static xcb_gcontext_t GetFontGC(xcb_connection_t* connection,
|
||||||
xcb_screen_t*screen, xcb_window_t window, const char*font_name);
|
xcb_screen_t*screen, xcb_window_t window, const char*font_name);
|
||||||
|
|
||||||
static void AddTextElement(xcb_connection_t* connection,
|
static void AddTextElement(xcb_connection_t* connection,
|
||||||
xcb_screen_t* screen, xcb_window_t window,
|
xcb_screen_t* screen, xcb_window_t window,
|
||||||
TextElementPtr textElement);
|
const TextElement* textElement);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue