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 (Light Multi-Media Tool) is a low-dependency C++ library for working with a range of digital media.
|
||||
limmto (Light Multi-Media Tool) is a free, low-dependency C++ library for working with digital media.
|
||||
|
||||
```bash
|
||||
mkdir build
|
||||
|
|
|
@ -6,18 +6,18 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
auto command_line_args = CommandLineArgs::CreateUnique();
|
||||
command_line_args->Process(argc, argv);
|
||||
command_line_args->RecordLaunchPath();
|
||||
auto args = CommandLineArgs::CreateUnique();
|
||||
args->Process(argc, argv);
|
||||
args->RecordLaunchPath();
|
||||
|
||||
// Start the main app
|
||||
auto main_app = MainApplication::Create();
|
||||
main_app->Initialize(std::move(command_line_args));
|
||||
main_app->Initialize(std::move(args));
|
||||
|
||||
// Start the gui app
|
||||
auto gui_app = std::make_shared<GuiApplication>();
|
||||
gui_app->SetMainApplication(main_app);
|
||||
gui_app->Run();
|
||||
auto gui_app = GuiApplication();
|
||||
gui_app.SetMainApplication(main_app);
|
||||
gui_app.Run();
|
||||
|
||||
main_app->ShutDown();
|
||||
return 0;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "GuiApplication.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "Widget.h"
|
||||
#include "HorizontalSpacer.h"
|
||||
#include "TextBox.h"
|
||||
#include "Button.h"
|
||||
#include "Label.h"
|
||||
#include "XcbInterface.h"
|
||||
|
@ -14,9 +14,9 @@
|
|||
GuiApplication::GuiApplication()
|
||||
: AbstractDesktopApp(),
|
||||
mMainApplication(),
|
||||
mDesktopManager()
|
||||
mDesktopManager(DesktopManager::Create())
|
||||
{
|
||||
mDesktopManager = DesktopManager::Create();
|
||||
|
||||
}
|
||||
|
||||
GuiApplication::~GuiApplication()
|
||||
|
@ -27,7 +27,6 @@ GuiApplication::~GuiApplication()
|
|||
void GuiApplication::SetMainApplication(MainApplicationPtr app)
|
||||
{
|
||||
mMainApplication = app;
|
||||
//mDesktopManager->SetMainApp(shared_from_this());
|
||||
}
|
||||
|
||||
void GuiApplication::Run()
|
||||
|
@ -37,19 +36,21 @@ void GuiApplication::Run()
|
|||
mainWindow->SetSize(800, 600);
|
||||
|
||||
auto label = Label::Create();
|
||||
label->SetLabel("Click the button!!");
|
||||
label->SetLabel("Type text!!");
|
||||
label->SetBackgroundColor(Color::Create(0, 200, 200));
|
||||
|
||||
auto textBox = TextBox::Create();
|
||||
|
||||
auto button = Button::Create();
|
||||
button->SetLabel("Ok");
|
||||
button->SetLabel("Save");
|
||||
button->SetBackgroundColor(Color::Create(0, 0, 200));
|
||||
|
||||
auto spacer = HorizontalSpacer::Create();
|
||||
spacer->AddWidget(label);
|
||||
spacer->AddWidget(button);
|
||||
|
||||
mainWindow->AddWidget(spacer);
|
||||
spacer->AddWidget(std::move(label));
|
||||
spacer->AddWidget(std::move(textBox));
|
||||
spacer->AddWidget(std::move(button));
|
||||
|
||||
mainWindow->AddWidget(std::move(spacer));
|
||||
mDesktopManager->SetKeyboard(XcbKeyboard::Create());
|
||||
|
||||
bool useOpenGl = false;
|
||||
|
@ -63,7 +64,7 @@ void GuiApplication::Run()
|
|||
window_interface.CreateOpenGlDrawable(mainWindow);
|
||||
}
|
||||
|
||||
window_interface.Loop(mDesktopManager);
|
||||
window_interface.Loop(mDesktopManager.get());
|
||||
|
||||
window_interface.ShutDown();
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
#include "AbstractDesktopApp.h"
|
||||
#include "DesktopManager.h"
|
||||
|
||||
class GuiApplication : public AbstractDesktopApp, std::enable_shared_from_this<GuiApplication>
|
||||
class GuiApplication : public AbstractDesktopApp
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
DesktopManagerPtr mDesktopManager;
|
||||
DesktopManagerUPtr mDesktopManager;
|
||||
MainApplicationPtr mMainApplication;
|
||||
|
||||
public:
|
||||
|
|
|
@ -9,28 +9,39 @@ Color::Color(unsigned r, unsigned g, unsigned b, double 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 )
|
||||
{
|
||||
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 std::make_unique<Color>(r, g, b, a);
|
||||
}
|
||||
|
||||
std::unique_ptr<Color> Color::Create(const Color& color)
|
||||
{
|
||||
return std::make_unique<Color>(color);
|
||||
}
|
||||
|
||||
unsigned Color::GetR() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
unsigned Color::GetG()
|
||||
unsigned Color::GetG() const
|
||||
{
|
||||
return mG;
|
||||
}
|
||||
|
||||
unsigned Color::GetB()
|
||||
unsigned Color::GetB() const
|
||||
{
|
||||
return mB;
|
||||
}
|
||||
|
||||
double Color::GetAlpha()
|
||||
double Color::GetAlpha() const
|
||||
{
|
||||
return mAlpha;
|
||||
}
|
||||
|
|
|
@ -9,15 +9,17 @@ class Color
|
|||
double mAlpha;
|
||||
|
||||
public:
|
||||
|
||||
Color(unsigned r, unsigned g, unsigned b, double a = 1.0);
|
||||
|
||||
static std::shared_ptr<Color> Create(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);
|
||||
|
||||
unsigned GetR();
|
||||
unsigned GetG();
|
||||
unsigned GetB();
|
||||
double GetAlpha();
|
||||
unsigned GetR() const;
|
||||
unsigned GetG() const;
|
||||
unsigned GetB() const;
|
||||
double GetAlpha() const;
|
||||
};
|
||||
|
||||
using ColorPtr = std::shared_ptr<Color>;
|
||||
using ColorUPtr = std::unique_ptr<Color>;
|
||||
|
|
|
@ -10,6 +10,7 @@ list(APPEND ui_elements_LIB_INCLUDES
|
|||
widgets/Button.cpp
|
||||
widgets/Label.cpp
|
||||
widgets/HorizontalSpacer.cpp
|
||||
widgets/TextBox.cpp
|
||||
widgets/elements/GeometryElement.cpp
|
||||
widgets/elements/RectangleElement.cpp
|
||||
widgets/elements/TextElement.cpp
|
||||
|
|
|
@ -6,8 +6,8 @@ Keyboard::Keyboard()
|
|||
|
||||
}
|
||||
|
||||
std::shared_ptr<Keyboard> Keyboard::Create()
|
||||
std::unique_ptr<Keyboard> Keyboard::Create()
|
||||
{
|
||||
return std::make_shared<Keyboard>();
|
||||
return std::make_unique<Keyboard>();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,10 @@ protected:
|
|||
|
||||
public:
|
||||
Keyboard();
|
||||
|
||||
virtual ~Keyboard() = default;
|
||||
|
||||
static std::shared_ptr<Keyboard> Create();
|
||||
static std::unique_ptr<Keyboard> Create();
|
||||
|
||||
virtual std::string GetKeyString(KeyCode code)
|
||||
{
|
||||
|
@ -23,4 +24,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
using KeyboardPtr = std::shared_ptr<Keyboard>;
|
||||
using KeyboardUPtr = std::unique_ptr<Keyboard>;
|
||||
|
|
|
@ -14,17 +14,27 @@ Window::~Window()
|
|||
|
||||
}
|
||||
|
||||
std::vector<VisualLayerPtr> Window::GetLayers()
|
||||
std::unique_ptr<Window> Window::Create()
|
||||
{
|
||||
return std::make_unique<Window>();
|
||||
}
|
||||
|
||||
std::vector<VisualLayer*> Window::GetLayers()
|
||||
{
|
||||
return mLayers;
|
||||
}
|
||||
|
||||
void Window::OnMouseEvent(MouseEventPtr event)
|
||||
void Window::OnMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
mWidget->OnMouseEvent(event);
|
||||
}
|
||||
|
||||
void Window::OnPaint(PaintEventPtr event)
|
||||
void Window::OnKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
mWidget->OnKeyboardEvent(event);
|
||||
}
|
||||
|
||||
void Window::OnPaint(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
mWidget->SetSize(mWidth, mHeight);
|
||||
|
@ -34,27 +44,22 @@ void Window::OnPaint(PaintEventPtr event)
|
|||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
|
||||
std::shared_ptr<Window> Window::Create()
|
||||
void Window::AddWidget(WidgetUPtr widget)
|
||||
{
|
||||
return std::make_shared<Window>();
|
||||
mWidget = std::move(widget);
|
||||
}
|
||||
|
||||
void Window::AddWidget(WidgetPtr widget)
|
||||
Widget* Window::GetWidget() const
|
||||
{
|
||||
mWidget = widget;
|
||||
return mWidget.get();
|
||||
}
|
||||
|
||||
WidgetPtr Window::GetWidget()
|
||||
{
|
||||
return mWidget;
|
||||
}
|
||||
|
||||
unsigned Window::GetWidth()
|
||||
unsigned Window::GetWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned Window::GetHeight()
|
||||
unsigned Window::GetHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "PaintEvent.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "KeyboardEvent.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "Widget.h"
|
||||
|
||||
|
@ -16,10 +17,10 @@ class Window
|
|||
|
||||
private:
|
||||
|
||||
WidgetPtr mWidget;
|
||||
WidgetUPtr mWidget;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
std::vector<VisualLayerPtr> mLayers;
|
||||
std::vector<VisualLayer*> mLayers;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -27,24 +28,26 @@ public:
|
|||
|
||||
~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 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>;
|
||||
|
|
|
@ -13,9 +13,9 @@ 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)
|
||||
|
@ -23,7 +23,7 @@ void KeyboardEvent::SetKeyString(const std::string& key)
|
|||
mKeyString = key;
|
||||
}
|
||||
|
||||
std::string KeyboardEvent::GetKeyString()
|
||||
std::string KeyboardEvent::GetKeyString() const
|
||||
{
|
||||
return mKeyString;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ void KeyboardEvent::SetAction(Action action)
|
|||
mAction = action;
|
||||
}
|
||||
|
||||
KeyboardEvent::Action KeyboardEvent::GetAction()
|
||||
KeyboardEvent::Action KeyboardEvent::GetAction() const
|
||||
{
|
||||
return mAction;
|
||||
}
|
||||
|
|
|
@ -25,15 +25,15 @@ public:
|
|||
|
||||
~KeyboardEvent();
|
||||
|
||||
static std::shared_ptr<KeyboardEvent> Create();
|
||||
static std::unique_ptr<KeyboardEvent> Create();
|
||||
|
||||
void SetKeyString(const std::string& key);
|
||||
|
||||
std::string GetKeyString();
|
||||
std::string GetKeyString() const;
|
||||
|
||||
void SetAction(Action action);
|
||||
|
||||
Action GetAction();
|
||||
Action GetAction() const;
|
||||
|
||||
};
|
||||
using KeyboardEventPtr = std::shared_ptr<KeyboardEvent>;
|
||||
using KeyboardEventUPtr = std::unique_ptr<KeyboardEvent>;
|
||||
|
|
|
@ -14,9 +14,9 @@ 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)
|
||||
|
@ -34,17 +34,17 @@ void MouseEvent::SetAction(MouseEvent::Action action)
|
|||
mAction = action;
|
||||
}
|
||||
|
||||
Pixel MouseEvent::GetClientLocation()
|
||||
Pixel MouseEvent::GetClientLocation() const
|
||||
{
|
||||
return mClientLocation;
|
||||
}
|
||||
|
||||
Pixel MouseEvent::GetScreenLocation()
|
||||
Pixel MouseEvent::GetScreenLocation() const
|
||||
{
|
||||
return mScreenLocation;
|
||||
}
|
||||
|
||||
MouseEvent::Action MouseEvent::GetAction()
|
||||
MouseEvent::Action MouseEvent::GetAction() const
|
||||
{
|
||||
return mAction;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
~MouseEvent();
|
||||
|
||||
static std::shared_ptr<MouseEvent> Create();
|
||||
static std::unique_ptr<MouseEvent> Create();
|
||||
|
||||
void SetClientLocation(Pixel location);
|
||||
|
||||
|
@ -33,10 +33,10 @@ public:
|
|||
|
||||
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>;
|
||||
|
|
|
@ -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>();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,6 @@ public:
|
|||
|
||||
~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>;
|
||||
|
|
|
@ -11,12 +11,12 @@ 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;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ public:
|
|||
|
||||
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>;
|
||||
|
|
|
@ -8,9 +8,9 @@ Button::Button()
|
|||
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -18,7 +18,7 @@ void Button::SetLabel(const std::string& text)
|
|||
mLabel = text;
|
||||
}
|
||||
|
||||
void Button::OnMyMouseEvent(MouseEventPtr event)
|
||||
void Button::OnMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
|
@ -27,18 +27,17 @@ void Button::OnMyMouseEvent(MouseEventPtr event)
|
|||
}
|
||||
}
|
||||
|
||||
void Button::OnPaintEvent(PaintEventPtr event)
|
||||
void Button::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||
mLocation.GetY() + mHeight/2);
|
||||
auto text = TextElement::Create(mLabel, middle);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(text);
|
||||
mLayers.push_back(textLayer);
|
||||
textLayer->SetText(TextElement::Create(mLabel, middle));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
CopyMyLayers();
|
||||
}
|
||||
|
|
|
@ -10,15 +10,15 @@ private:
|
|||
public:
|
||||
Button();
|
||||
|
||||
static std::unique_ptr<Button> Create();
|
||||
|
||||
void SetLabel(const std::string& text);
|
||||
|
||||
static std::shared_ptr<Button> Create();
|
||||
|
||||
void OnPaintEvent(PaintEventPtr event);
|
||||
void OnPaintEvent(const PaintEvent* event) override;
|
||||
|
||||
protected:
|
||||
|
||||
void OnMyMouseEvent(MouseEventPtr event);
|
||||
void OnMyMouseEvent(const MouseEvent* event) override;
|
||||
};
|
||||
|
||||
using ButtonPtr = std::shared_ptr<Button>;
|
||||
using ButtonUPtr = std::unique_ptr<Button>;
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
#include "HorizontalSpacer.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
HorizontalSpacer::HorizontalSpacer()
|
||||
: 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)
|
||||
{
|
||||
mLayers.clear();
|
||||
unsigned delta = mHeight / mChildren.size();
|
||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||
{
|
||||
auto child = mChildren[idx];
|
||||
auto& child = mChildren[idx];
|
||||
child->SetSize(mWidth, delta);
|
||||
child->SetLocation(DiscretePoint(mLocation.GetX(), mLocation.GetY() + delta*idx));
|
||||
child->OnPaintEvent(event);
|
||||
|
@ -25,9 +28,7 @@ void HorizontalSpacer::AddChildLayers(PaintEventPtr event)
|
|||
}
|
||||
}
|
||||
|
||||
void HorizontalSpacer::OnPaintEvent(PaintEventPtr event)
|
||||
void HorizontalSpacer::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
|
||||
AddChildLayers(event);
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ class HorizontalSpacer : public Widget
|
|||
public:
|
||||
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>;
|
||||
|
|
|
@ -8,9 +8,9 @@ Label::Label()
|
|||
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -18,18 +18,18 @@ void Label::SetLabel(const std::string& text)
|
|||
mLabel = text;
|
||||
}
|
||||
|
||||
void Label::OnPaintEvent(PaintEventPtr event)
|
||||
void Label::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||
mLocation.GetY() + mHeight/2);
|
||||
auto text = TextElement::Create(mLabel, middle);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(text);
|
||||
mLayers.push_back(textLayer);
|
||||
textLayer->SetText(TextElement::Create(mLabel, middle));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
CopyMyLayers();
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ public:
|
|||
|
||||
Label();
|
||||
|
||||
static std::unique_ptr<Label> Create();
|
||||
|
||||
void SetLabel(const std::string& text);
|
||||
|
||||
static std::shared_ptr<Label> Create();
|
||||
|
||||
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,10 +1,13 @@
|
|||
#include "RectangleElement.h"
|
||||
#include "Widget.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
Widget::Widget()
|
||||
: mLocation(DiscretePoint(0, 0)),
|
||||
mWidth(100),
|
||||
mHeight(100),
|
||||
mMyLayers(),
|
||||
mLayers(),
|
||||
mChildren(),
|
||||
mBackgroundColor(Color::Create(200, 0, 0))
|
||||
|
@ -17,54 +20,65 @@ 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;
|
||||
mHeight = height;
|
||||
mChildren.push_back(std::move(widget));
|
||||
}
|
||||
|
||||
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 mHeight;
|
||||
}
|
||||
|
||||
DiscretePoint Widget::GetLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
std::vector<VisualLayerPtr> Widget::GetLayers()
|
||||
std::vector<VisualLayer*> Widget::GetLayers() const
|
||||
{
|
||||
return mLayers;
|
||||
}
|
||||
|
||||
void Widget::AddChildLayers(PaintEventPtr event)
|
||||
void Widget::CopyMyLayers()
|
||||
{
|
||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||
mLayers.clear();
|
||||
mLayers.reserve(mMyLayers.size());
|
||||
auto getRaw = [](const VisualLayerUPtr& uptr){return uptr.get();};
|
||||
std::transform(mMyLayers.begin(), mMyLayers.end(), std::back_inserter(mLayers), getRaw);
|
||||
}
|
||||
|
||||
void Widget::AddChildLayers(const PaintEvent* event)
|
||||
{
|
||||
for(auto& child: mChildren)
|
||||
{
|
||||
auto child = mChildren[idx];
|
||||
child->SetSize(mWidth, mHeight);
|
||||
child->SetLocation(mLocation);
|
||||
child->OnPaintEvent(event);
|
||||
auto layers = child->GetLayers();
|
||||
const auto layers = child->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::OnPaintEvent(PaintEventPtr event)
|
||||
void Widget::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
CopyMyLayers();
|
||||
AddChildLayers(event);
|
||||
}
|
||||
|
||||
bool Widget::Contains(const DiscretePoint& loc)
|
||||
bool Widget::Contains(const DiscretePoint& loc) const
|
||||
{
|
||||
if(loc.GetX() < mLocation.GetX()) return false;
|
||||
if(loc.GetX() > mLocation.GetX() + mWidth) return false;
|
||||
|
@ -73,7 +87,30 @@ bool Widget::Contains(const DiscretePoint& loc)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Widget::OnMouseEvent(MouseEventPtr event)
|
||||
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)
|
||||
|
@ -99,23 +136,23 @@ bool Widget::OnMouseEvent(MouseEventPtr event)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Widget::OnMyMouseEvent(MouseEventPtr event)
|
||||
void Widget::OnMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Widget::AddBackground(PaintEventPtr event)
|
||||
void Widget::AddBackground(const PaintEvent* event)
|
||||
{
|
||||
auto shape = RectangleElement::Create(mLocation, mWidth, mHeight);
|
||||
shape->SetFillColor(mBackgroundColor);
|
||||
shape->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
auto shapeLayer = VisualLayer::Create();
|
||||
shapeLayer->SetShape(shape);
|
||||
mLayers.push_back(shapeLayer);
|
||||
shapeLayer->SetShape(std::move(shape));
|
||||
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)
|
||||
|
@ -123,12 +160,8 @@ void Widget::SetLocation(const DiscretePoint& loc)
|
|||
mLocation = loc;
|
||||
}
|
||||
|
||||
unsigned Widget::GetWidth()
|
||||
void Widget::SetSize(unsigned width, unsigned height)
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned Widget::GetHeight()
|
||||
{
|
||||
return mHeight;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "PaintEvent.h"
|
||||
#include "Color.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "KeyboardEvent.h"
|
||||
|
||||
class Widget
|
||||
{
|
||||
|
@ -16,9 +17,10 @@ protected:
|
|||
DiscretePoint mLocation;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
std::vector<VisualLayerPtr> mLayers;
|
||||
std::vector<std::shared_ptr<Widget> > mChildren;
|
||||
ColorPtr mBackgroundColor;
|
||||
std::vector<VisualLayerUPtr> mMyLayers;
|
||||
std::vector<VisualLayer*> mLayers;
|
||||
std::vector<std::unique_ptr<Widget> > mChildren;
|
||||
ColorUPtr mBackgroundColor;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -26,37 +28,43 @@ public:
|
|||
|
||||
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);
|
||||
|
||||
unsigned GetWidth() const;
|
||||
|
||||
unsigned GetHeight() const;
|
||||
|
||||
std::vector<VisualLayer*> GetLayers() const;
|
||||
|
||||
DiscretePoint GetLocation() const;
|
||||
|
||||
virtual void OnPaintEvent(const PaintEvent* event);
|
||||
|
||||
virtual bool OnMouseEvent(const MouseEvent* event);
|
||||
|
||||
virtual bool OnKeyboardEvent(const KeyboardEvent* event);
|
||||
|
||||
bool Contains(const DiscretePoint& loc) const;
|
||||
|
||||
void SetBackgroundColor(ColorUPtr color);
|
||||
|
||||
void SetSize(unsigned mWidth, unsigned mHeight);
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
|
||||
void SetLocation(const DiscretePoint& loc);
|
||||
|
||||
unsigned GetWidth();
|
||||
|
||||
unsigned GetHeight();
|
||||
|
||||
std::vector<VisualLayerPtr> GetLayers();
|
||||
|
||||
static std::shared_ptr<Widget> Create();
|
||||
|
||||
virtual void OnPaintEvent(PaintEventPtr event);
|
||||
|
||||
virtual bool OnMouseEvent(MouseEventPtr event);
|
||||
|
||||
bool Contains(const DiscretePoint& loc);
|
||||
|
||||
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>;
|
||||
|
|
|
@ -9,27 +9,30 @@ GeometryElement::GeometryElement()
|
|||
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
unsigned GeometryElement::GetStrokeThickness() const
|
||||
{
|
||||
return mStrokeThickness;
|
||||
}
|
||||
|
||||
void GeometryElement::SetFillColor(ColorPtr color)
|
||||
void GeometryElement::SetFillColor(ColorUPtr color)
|
||||
{
|
||||
mFillColor = color;
|
||||
mFillColor = std::move(color);
|
||||
}
|
||||
void GeometryElement::SetStrokeColor(ColorPtr color)
|
||||
|
||||
void GeometryElement::SetStrokeColor(ColorUPtr color)
|
||||
{
|
||||
mStrokeColor = color;
|
||||
mStrokeColor = std::move(color);
|
||||
}
|
||||
|
||||
void GeometryElement::SetStrokeThickness(unsigned thickness)
|
||||
{
|
||||
mStrokeThickness = thickness;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
class GeometryElement
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Type
|
||||
{
|
||||
Path,
|
||||
|
@ -15,9 +14,8 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
|
||||
ColorPtr mFillColor;
|
||||
ColorPtr mStrokeColor;
|
||||
ColorUPtr mFillColor;
|
||||
ColorUPtr mStrokeColor;
|
||||
unsigned mStrokeThickness;
|
||||
Type mType;
|
||||
|
||||
|
@ -26,14 +24,14 @@ public:
|
|||
GeometryElement();
|
||||
virtual ~GeometryElement() = default;
|
||||
|
||||
ColorPtr GetFillColor();
|
||||
ColorPtr GetStrokeColor();
|
||||
unsigned GetStrokeThickness();
|
||||
Color* GetFillColor() const;
|
||||
Color* GetStrokeColor() const;
|
||||
unsigned GetStrokeThickness() const;
|
||||
virtual Type GetType() = 0;
|
||||
|
||||
void SetFillColor(ColorPtr color);
|
||||
void SetStrokeColor(ColorPtr color);
|
||||
void SetFillColor(ColorUPtr color);
|
||||
void SetStrokeColor(ColorUPtr color);
|
||||
void SetStrokeThickness(unsigned thickness);
|
||||
};
|
||||
|
||||
using GeometryElementPtr = std::shared_ptr<GeometryElement>;
|
||||
using GeometryElementUPtr = std::unique_ptr<GeometryElement>;
|
||||
|
|
|
@ -9,10 +9,10 @@ RectangleElement::RectangleElement(const DiscretePoint& loc,
|
|||
|
||||
}
|
||||
|
||||
std::shared_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
||||
std::unique_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
return std::make_shared<RectangleElement>(loc, width, height);
|
||||
return std::make_unique<RectangleElement>(loc, width, height);
|
||||
}
|
||||
|
||||
GeometryElement::Type RectangleElement::GetType()
|
||||
|
@ -20,17 +20,17 @@ GeometryElement::Type RectangleElement::GetType()
|
|||
return GeometryElement::Type::Rectangle;
|
||||
}
|
||||
|
||||
DiscretePoint RectangleElement::GetLocation()
|
||||
DiscretePoint RectangleElement::GetLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetWidth()
|
||||
unsigned RectangleElement::GetWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetHeight()
|
||||
unsigned RectangleElement::GetHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
|
|
@ -13,17 +13,16 @@ class RectangleElement : public GeometryElement
|
|||
|
||||
public:
|
||||
|
||||
RectangleElement(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height);
|
||||
static std::shared_ptr<RectangleElement> Create(const DiscretePoint& loc,
|
||||
RectangleElement(const DiscretePoint& loc, unsigned width, unsigned height);
|
||||
static std::unique_ptr<RectangleElement> Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height);
|
||||
GeometryElement::Type GetType() override;
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
unsigned GetWidth();
|
||||
unsigned GetHeight();
|
||||
DiscretePoint GetLocation() const;
|
||||
unsigned GetWidth() const;
|
||||
unsigned GetHeight() const;
|
||||
};
|
||||
|
||||
using RectangleElementPtr = std::shared_ptr<RectangleElement>;
|
||||
using RectangleElementUPtr = std::unique_ptr<RectangleElement>;
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
std::string TextElement::GetFontLabel() const
|
||||
{
|
||||
return mFontLabel;
|
||||
}
|
||||
|
||||
std::string TextElement::GetContent() const
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
||||
void TextElement::SetContent(const std::string& content)
|
||||
{
|
||||
mContent = content;
|
||||
}
|
||||
|
||||
std::string TextElement::GetFontLabel()
|
||||
{
|
||||
return mFontLabel;
|
||||
}
|
||||
|
||||
std::string TextElement::GetContent()
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
|
|
@ -17,15 +17,15 @@ public:
|
|||
|
||||
~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;
|
||||
|
||||
std::string GetFontLabel() const;
|
||||
|
||||
void SetContent(const std::string& content);
|
||||
|
||||
std::string GetFontLabel();
|
||||
};
|
||||
|
||||
using TextElementPtr = std::shared_ptr<TextElement>;
|
||||
using TextElementUPtr = std::unique_ptr<TextElement>;
|
||||
|
|
|
@ -7,32 +7,37 @@ VisualLayer::VisualLayer()
|
|||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
mShape = shape;
|
||||
}
|
||||
void VisualLayer::SetText(TextElementPtr text)
|
||||
{
|
||||
mText = text;
|
||||
}
|
||||
bool VisualLayer::HasShape()
|
||||
bool VisualLayer::HasShape() const
|
||||
{
|
||||
return bool(mShape);
|
||||
}
|
||||
bool VisualLayer::HasText()
|
||||
|
||||
bool VisualLayer::HasText() const
|
||||
{
|
||||
return bool(mText);
|
||||
}
|
||||
GeometryElementPtr VisualLayer::GetShape()
|
||||
|
||||
GeometryElement* VisualLayer::GetShape() const
|
||||
{
|
||||
return mShape;
|
||||
return mShape.get();
|
||||
}
|
||||
TextElementPtr VisualLayer::GetText()
|
||||
|
||||
TextElement* VisualLayer::GetText() const
|
||||
{
|
||||
return mText;
|
||||
return mText.get();
|
||||
}
|
||||
|
||||
void VisualLayer::SetShape(GeometryElementUPtr shape)
|
||||
{
|
||||
mShape = std::move(shape);
|
||||
}
|
||||
|
||||
void VisualLayer::SetText(TextElementUPtr text)
|
||||
{
|
||||
mText = std::move(text);
|
||||
}
|
||||
|
|
|
@ -6,21 +6,20 @@
|
|||
|
||||
class VisualLayer
|
||||
{
|
||||
GeometryElementPtr mShape;
|
||||
TextElementPtr mText;
|
||||
GeometryElementUPtr mShape;
|
||||
TextElementUPtr mText;
|
||||
|
||||
public:
|
||||
|
||||
VisualLayer();
|
||||
|
||||
static std::shared_ptr<VisualLayer> Create();
|
||||
|
||||
void SetShape(GeometryElementPtr shape);
|
||||
void SetText(TextElementPtr text);
|
||||
bool HasShape();
|
||||
bool HasText();
|
||||
GeometryElementPtr GetShape();
|
||||
TextElementPtr GetText();
|
||||
static std::unique_ptr<VisualLayer> Create();
|
||||
|
||||
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>;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
list(APPEND windows_LIB_INCLUDES
|
||||
managers/WindowManager.cpp
|
||||
managers/DesktopManager.cpp
|
||||
managers/EventManager.cpp
|
||||
ui_interfaces/x11/XcbInterface.cpp
|
||||
ui_interfaces/x11/XcbLayerInterface.cpp
|
||||
ui_interfaces/x11/XcbTextInterface.cpp
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
DesktopManager::DesktopManager()
|
||||
: mScreens(),
|
||||
mWindowManager(),
|
||||
mKeyboard(),
|
||||
mWindowManager(WindowManager::Create()),
|
||||
mKeyboard(Keyboard::Create()),
|
||||
mMainApplication(),
|
||||
mModified(false)
|
||||
mModified(false),
|
||||
mEventManager(EventManager::Create())
|
||||
{
|
||||
mWindowManager = WindowManager::Create();
|
||||
mKeyboard = Keyboard::Create();
|
||||
|
||||
}
|
||||
|
||||
DesktopManager::~DesktopManager()
|
||||
|
@ -18,51 +18,56 @@ 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)
|
||||
{
|
||||
GetWindowManager()->OnMouseEvent(event);
|
||||
}
|
||||
|
||||
bool DesktopManager::IsModified() const
|
||||
{
|
||||
return mModified;
|
||||
}
|
||||
|
||||
void DesktopManager::OnUiEvent(UiEventPtr event)
|
||||
void DesktopManager::OnUiEvent(UiEventUPtr eventUPtr)
|
||||
{
|
||||
mModified = false;
|
||||
const auto event = mEventManager->AddEvent(std::move(eventUPtr));
|
||||
switch (event->GetType())
|
||||
{
|
||||
case (UiEvent::Type::Paint):
|
||||
{
|
||||
OnPaintEvent(std::dynamic_pointer_cast<PaintEvent>(event));
|
||||
OnPaintEvent(dynamic_cast<const PaintEvent*>(event));
|
||||
break;
|
||||
}
|
||||
case (UiEvent::Type::Keyboard):
|
||||
{
|
||||
OnKeyboardEvent(std::dynamic_pointer_cast<KeyboardEvent>(event));
|
||||
//mModified = true;
|
||||
OnKeyboardEvent(dynamic_cast<const KeyboardEvent*>(event));
|
||||
mModified = true;
|
||||
break;
|
||||
}
|
||||
case (UiEvent::Type::Mouse):
|
||||
{
|
||||
auto mouseEvent = std::dynamic_pointer_cast<MouseEvent>(event);
|
||||
|
||||
auto mouseEvent = dynamic_cast<const MouseEvent*>(event);
|
||||
OnMouseEvent(mouseEvent);
|
||||
if(mouseEvent->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
|
@ -81,14 +86,14 @@ void DesktopManager::SetIsModified(bool 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)
|
||||
|
@ -101,12 +106,12 @@ AbstractDesktopAppPtr DesktopManager::GetMainApp()
|
|||
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,12 +11,14 @@
|
|||
#include "WindowManager.h"
|
||||
#include "UiEvent.h"
|
||||
#include "AbstractDesktopApp.h"
|
||||
#include "EventManager.h"
|
||||
|
||||
class DesktopManager
|
||||
{
|
||||
std::vector<ScreenPtr> mScreens;
|
||||
WindowManagerPtr mWindowManager;
|
||||
KeyboardPtr mKeyboard;
|
||||
WindowManagerUPtr mWindowManager;
|
||||
KeyboardUPtr mKeyboard;
|
||||
EventManagerUPtr mEventManager;
|
||||
AbstractDesktopAppPtr mMainApplication;
|
||||
bool mModified;
|
||||
|
||||
|
@ -26,33 +28,33 @@ public:
|
|||
|
||||
~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);
|
||||
|
||||
AbstractDesktopAppPtr GetMainApp();
|
||||
|
||||
WindowManagerPtr GetWindowManager();
|
||||
WindowManager* GetWindowManager() const;
|
||||
|
||||
KeyboardPtr GetKeyboard();
|
||||
Keyboard* GetKeyboard() const;
|
||||
|
||||
bool IsModified();
|
||||
bool IsModified() const;
|
||||
|
||||
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 OnPaintEvent(PaintEventPtr paintEvent);
|
||||
void OnMouseEvent(const MouseEvent* mouseEvent);
|
||||
|
||||
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>;
|
|
@ -11,27 +11,39 @@ WindowManager::~WindowManager()
|
|||
|
||||
}
|
||||
|
||||
void WindowManager::OnPaintEvent(PaintEventPtr event)
|
||||
std::unique_ptr<WindowManager> WindowManager::Create()
|
||||
{
|
||||
return std::make_unique<WindowManager>();
|
||||
}
|
||||
|
||||
void WindowManager::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
GetMainWindow()->OnPaint(event);
|
||||
}
|
||||
|
||||
void WindowManager::OnMouseEvent(MouseEventPtr event)
|
||||
void WindowManager::OnMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
GetMainWindow()->OnMouseEvent(event);
|
||||
}
|
||||
|
||||
void WindowManager::AddWindow(WindowPtr window)
|
||||
void WindowManager::OnKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
mWindows.push_back(window);
|
||||
GetMainWindow()->OnKeyboardEvent(event);
|
||||
}
|
||||
|
||||
std::shared_ptr<WindowManager> WindowManager::Create()
|
||||
void WindowManager::AddWindow(WindowUPtr window)
|
||||
{
|
||||
return std::make_shared<WindowManager>();
|
||||
mWindows.push_back(std::move(window));
|
||||
}
|
||||
|
||||
WindowPtr WindowManager::GetMainWindow()
|
||||
mt::Window* WindowManager::GetMainWindow() const
|
||||
{
|
||||
return mWindows[0];
|
||||
if(mWindows.size()>0)
|
||||
{
|
||||
return mWindows[0].get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
#include "Window.h"
|
||||
#include "PaintEvent.h"
|
||||
#include "MouseEvent.h"
|
||||
|
||||
#include "KeyboardEvent.h"
|
||||
|
||||
class WindowManager
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
std::vector<WindowPtr> mWindows;
|
||||
std::vector<WindowUPtr> mWindows;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -21,16 +21,18 @@ public:
|
|||
|
||||
~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>;
|
||||
|
|
|
@ -109,9 +109,9 @@ void XcbInterface::InitializeOpenGl()
|
|||
mGlxInterface->SetupContext(mX11Display, default_screen);
|
||||
}
|
||||
|
||||
void XcbInterface::CreateOpenGlDrawable(WindowPtr window)
|
||||
void XcbInterface::CreateOpenGlDrawable(mt::Window* window)
|
||||
{
|
||||
if(!mUseOpenGl)
|
||||
if(!mUseOpenGl or !window)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -134,14 +134,14 @@ void XcbInterface::CreateGraphicsContext()
|
|||
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_flush(mConnection);
|
||||
}
|
||||
|
||||
void XcbInterface::ShowWindow(WindowPtr window)
|
||||
void XcbInterface::ShowWindow(mt::Window* window)
|
||||
{
|
||||
MapWindow(window);
|
||||
}
|
||||
|
@ -152,9 +152,9 @@ uint32_t XcbInterface::GetEventMask()
|
|||
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);
|
||||
|
||||
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||
|
@ -175,16 +175,16 @@ void XcbInterface::AddWindow(WindowPtr window)
|
|||
mDefaultWindow = hwnd;
|
||||
}
|
||||
|
||||
void XcbInterface::onPaint(DesktopManagerPtr desktopManager)
|
||||
void XcbInterface::onPaint(DesktopManager* desktopManager)
|
||||
{
|
||||
auto ui_event = PaintEvent::Create();
|
||||
desktopManager->OnUiEvent(ui_event);
|
||||
|
||||
desktopManager->OnUiEvent(PaintEvent::Create());
|
||||
PaintWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
||||
}
|
||||
|
||||
void XcbInterface::PaintWindow(WindowPtr window)
|
||||
void XcbInterface::PaintWindow(mt::Window* window)
|
||||
{
|
||||
if(!window) return;
|
||||
|
||||
const auto hwnd = mHandles[window];
|
||||
for(const auto& layer : window->GetLayers())
|
||||
{
|
||||
|
@ -193,25 +193,25 @@ void XcbInterface::PaintWindow(WindowPtr window)
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Pressed);
|
||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||
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();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Released);
|
||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||
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 x = static_cast<unsigned>(event->event_x);
|
||||
|
@ -223,10 +223,10 @@ void XcbInterface::OnButtonPress(xcb_button_press_event_t* event, DesktopManager
|
|||
ui_event->SetScreenLocation(DiscretePoint(x, y));
|
||||
|
||||
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;
|
||||
while(running)
|
||||
|
@ -271,14 +271,15 @@ void XcbInterface::LoopOpenGl(std::shared_ptr<DesktopManager> desktopManager)
|
|||
return;
|
||||
}
|
||||
|
||||
void XcbInterface::ClearWindow(WindowPtr window)
|
||||
void XcbInterface::ClearWindow(mt::Window* window)
|
||||
{
|
||||
if(!window) return;
|
||||
xcb_clear_area(mConnection, 1, mHandles[window], 0, 0,
|
||||
window->GetWidth(), window->GetHeight());
|
||||
xcb_flush(mConnection);
|
||||
}
|
||||
|
||||
void XcbInterface::Loop(DesktopManagerPtr desktopManager)
|
||||
void XcbInterface::Loop(DesktopManager* desktopManager)
|
||||
{
|
||||
if(!mConnection) return;
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ class XcbInterface
|
|||
private:
|
||||
|
||||
bool mUseOpenGl;
|
||||
std::map<unsigned, WindowPtr> mWindows;
|
||||
std::map<WindowPtr, unsigned> mHandles;
|
||||
std::map<unsigned, mt::Window*> mWindows;
|
||||
std::map<mt::Window*, unsigned> mHandles;
|
||||
unsigned mDefaultWindow;
|
||||
xcb_connection_t* mConnection;
|
||||
xcb_screen_t* mScreen;
|
||||
|
@ -40,27 +40,27 @@ public:
|
|||
~XcbInterface();
|
||||
|
||||
void SetUseOpenGl(bool use);
|
||||
void onPaint(std::shared_ptr<DesktopManager> desktopManager);
|
||||
void onPaint(DesktopManager* desktopManager);
|
||||
|
||||
void Initialize();
|
||||
|
||||
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 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:
|
||||
|
||||
|
@ -70,13 +70,13 @@ private:
|
|||
|
||||
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();
|
||||
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
#include "XcbKeyboard.h"
|
||||
|
||||
|
||||
XcbKeyboard::XcbKeyboard()
|
||||
: Keyboard()
|
||||
{
|
||||
mKeyMap = {{24, "q"}, {25, "w"},
|
||||
{26, "e"}, {27, "r"},
|
||||
{28, "t"}, {29, "y"}, {30, "u"}, {31, "i"}, {32, "o"},
|
||||
{33, "p"}, {38, "a"}, {39, "s"}, {40, "d"}, {41, "f"},
|
||||
{42, "g"}, {43, "h"}, {44, "j"}, {45, "k"}, {46, "l"},
|
||||
mKeyMap = {{10, "1"}, {11, "2"}, {12, "3"}, {13, "4"}, {14, "5"}, {15, "6"},
|
||||
{16, "7"}, {17, "8"}, {18, "9"}, {19, "0"}, {20, "-"}, {21, "+"}, {22, "KEY_BACK"},
|
||||
{24, "q"}, {25, "w"}, {26, "e"}, {27, "r"}, {28, "t"}, {29, "y"},
|
||||
{30, "u"}, {31, "i"}, {32, "o"}, {33, "p"}, {34, "["}, {35, "]"}, {36, "KEY_RETURN"},
|
||||
{38, "a"}, {39, "s"}, {40, "d"}, {41, "f"}, {42, "g"}, {43, "h"},
|
||||
{44, "j"}, {45, "k"}, {46, "l"}, {47, ":"}, {48, "'"}, {49, "#"},
|
||||
{52, "z"}, {53, "x"}, {54, "c"}, {55, "v"}, {56, "b"},
|
||||
{57, "n"}, {58, "m"}};
|
||||
{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)
|
||||
|
|
|
@ -6,9 +6,9 @@ class XcbKeyboard : public Keyboard
|
|||
public:
|
||||
XcbKeyboard();
|
||||
|
||||
static std::shared_ptr<XcbKeyboard> Create();
|
||||
static std::unique_ptr<XcbKeyboard> Create();
|
||||
|
||||
std::string GetKeyString(KeyCode keyCode) override;
|
||||
};
|
||||
|
||||
using XcbKeyboardPtr = std::shared_ptr<XcbKeyboard>;
|
||||
using XcbKeyboardUPtr = std::unique_ptr<XcbKeyboard>;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "RectangleElement.h"
|
||||
#include <memory>
|
||||
|
||||
uint32_t XcbLayerInterface::GetColor(ColorPtr color)
|
||||
uint32_t XcbLayerInterface::GetColor(const Color* color)
|
||||
{
|
||||
return XcbLayerInterface::GetColor(color->GetR(),
|
||||
color->GetG(), color->GetB());
|
||||
|
@ -15,7 +15,7 @@ uint32_t XcbLayerInterface::GetColor(int r, int g, int b)
|
|||
}
|
||||
|
||||
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 values[2] = {XcbLayerInterface::GetColor(color), 0};
|
||||
|
@ -25,7 +25,7 @@ void XcbLayerInterface::ModifyGcColor(xcb_connection_t* connection, xcb_gcontext
|
|||
|
||||
void XcbLayerInterface::AddLayer(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||
VisualLayerPtr layer)
|
||||
VisualLayer* layer)
|
||||
{
|
||||
if(layer->HasText())
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ void XcbLayerInterface::AddLayer(xcb_connection_t* connection,
|
|||
auto shape = layer->GetShape();
|
||||
if(shape->GetType() == GeometryElement::Type::Rectangle)
|
||||
{
|
||||
auto rectangle = std::dynamic_pointer_cast<RectangleElement>(shape);
|
||||
auto rectangle = dynamic_cast<RectangleElement*>(shape);
|
||||
Pixel loc = rectangle->GetLocation();
|
||||
auto width = static_cast<uint16_t>(rectangle->GetWidth());
|
||||
auto height = static_cast<uint16_t>(rectangle->GetHeight());
|
||||
|
|
|
@ -8,15 +8,15 @@ class XcbLayerInterface
|
|||
{
|
||||
public:
|
||||
|
||||
static uint32_t GetColor(ColorPtr);
|
||||
static uint32_t GetColor(const Color* color);
|
||||
|
||||
static uint32_t GetColor(int r, int g, int b);
|
||||
|
||||
static void ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
||||
ColorPtr color);
|
||||
const Color* color);
|
||||
|
||||
static void AddLayer(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||
VisualLayerPtr layer);
|
||||
VisualLayer* layer);
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
|
|||
|
||||
void XcbTextInterface::AddTextElement(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
TextElementPtr textElement)
|
||||
const TextElement* textElement)
|
||||
{
|
||||
/* get graphics context */
|
||||
xcb_gcontext_t gc = XcbTextInterface::GetFontGC(connection, screen, window,
|
||||
|
|
|
@ -10,7 +10,7 @@ public:
|
|||
|
||||
static void AddTextElement(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
TextElementPtr textElement);
|
||||
const TextElement* textElement);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue