Add cairo interface.
This commit is contained in:
parent
a03eb9599f
commit
9bcc0ae88e
63 changed files with 1247 additions and 450 deletions
|
@ -1,6 +1,8 @@
|
|||
list(APPEND ui_elements_LIB_INCLUDES
|
||||
desktop_elements/Keyboard.cpp
|
||||
desktop_elements/IPlatformScreen.h
|
||||
desktop_elements/Screen.cpp
|
||||
desktop_elements/IPlatformWindow.h
|
||||
desktop_elements/Window.cpp
|
||||
ui_events/KeyboardEvent.cpp
|
||||
ui_events/MouseEvent.cpp
|
||||
|
@ -13,23 +15,21 @@ list(APPEND ui_elements_LIB_INCLUDES
|
|||
widgets/VerticalSpacer.cpp
|
||||
widgets/StackWidget.cpp
|
||||
widgets/TextBox.cpp
|
||||
widgets/elements/GeometryElement.cpp
|
||||
widgets/elements/RectangleElement.cpp
|
||||
widgets/elements/TextElement.cpp
|
||||
widgets/elements/VisualLayer.cpp)
|
||||
)
|
||||
|
||||
add_library(ui_elements SHARED ${ui_elements_LIB_INCLUDES})
|
||||
|
||||
target_include_directories(ui_elements PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/core/"
|
||||
"${PROJECT_SOURCE_DIR}/src/geometry/"
|
||||
"${PROJECT_SOURCE_DIR}/src/visual_elements"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/widgets"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/widgets/elements"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ui_events"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/desktop_elements"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/desktop_elements"
|
||||
)
|
||||
target_link_libraries(ui_elements PUBLIC core geometry)
|
||||
target_link_libraries(ui_elements PUBLIC core geometry visual_elements)
|
||||
|
||||
set_property(TARGET ui_elements PROPERTY FOLDER src)
|
||||
|
||||
|
|
11
src/ui_elements/desktop_elements/IPlatformScreen.h
Normal file
11
src/ui_elements/desktop_elements/IPlatformScreen.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class IPlatformScreen
|
||||
{
|
||||
public:
|
||||
virtual ~IPlatformScreen() = default;
|
||||
};
|
||||
|
||||
using IPlatformScreenPtr = std::unique_ptr<IPlatformScreen>;
|
11
src/ui_elements/desktop_elements/IPlatformWindow.h
Normal file
11
src/ui_elements/desktop_elements/IPlatformWindow.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class IPlatformWindow
|
||||
{
|
||||
public:
|
||||
virtual ~IPlatformWindow() = default;
|
||||
};
|
||||
|
||||
using IPlatformWindowPtr = std::unique_ptr<IPlatformWindow>;
|
|
@ -1,5 +1,7 @@
|
|||
#include "Screen.h"
|
||||
|
||||
#include "IPlatformScreen.h"
|
||||
|
||||
namespace mt{
|
||||
Screen::Screen()
|
||||
{
|
||||
|
@ -11,8 +13,22 @@ Screen::~Screen()
|
|||
|
||||
}
|
||||
|
||||
std::shared_ptr<Screen> Screen::Create()
|
||||
std::unique_ptr<Screen> Screen::Create()
|
||||
{
|
||||
return std::make_shared<Screen>();
|
||||
return std::make_unique<Screen>();
|
||||
}
|
||||
|
||||
IPlatformScreen* Screen::GetPlatformScreen() const
|
||||
{
|
||||
if (mPlatformScreen)
|
||||
{
|
||||
return mPlatformScreen.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Screen::SetPlatformScreen(IPlatformScreenPtr screen)
|
||||
{
|
||||
mPlatformScreen = std::move(screen);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class IPlatformScreen;
|
||||
using IPlatformScreenPtr = std::unique_ptr<IPlatformScreen>;
|
||||
|
||||
namespace mt{
|
||||
class Screen
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
Screen();
|
||||
Screen();
|
||||
|
||||
~Screen();
|
||||
~Screen();
|
||||
|
||||
static std::shared_ptr<Screen> Create();
|
||||
static std::unique_ptr<Screen> Create();
|
||||
|
||||
IPlatformScreen* GetPlatformScreen() const;
|
||||
|
||||
void SetPlatformScreen(IPlatformScreenPtr screen);
|
||||
|
||||
private:
|
||||
|
||||
IPlatformScreenPtr mPlatformScreen {nullptr};
|
||||
};
|
||||
}
|
||||
using ScreenPtr = std::shared_ptr<mt::Screen>;
|
||||
using ScreenPtr = std::unique_ptr<mt::Screen>;
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
#include "Window.h"
|
||||
|
||||
namespace mt{
|
||||
#include "IPlatformWindow.h"
|
||||
#include "PaintEvent.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "KeyboardEvent.h"
|
||||
|
||||
namespace mt
|
||||
{
|
||||
|
||||
Window::Window()
|
||||
:mWidth(400),
|
||||
mHeight(300),
|
||||
|
@ -21,7 +29,7 @@ std::unique_ptr<Window> Window::Create()
|
|||
|
||||
std::vector<VisualLayer*> Window::GetLayers()
|
||||
{
|
||||
return mLayers;
|
||||
return mWidget->GetLayers();
|
||||
}
|
||||
|
||||
void Window::OnMouseEvent(const MouseEvent* event)
|
||||
|
@ -36,12 +44,8 @@ void Window::OnKeyboardEvent(const KeyboardEvent* event)
|
|||
|
||||
void Window::OnPaint(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
mWidget->SetBounds(mWidth, mHeight);
|
||||
mWidget->OnPaintEvent(event);
|
||||
|
||||
auto layers = mWidget->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
|
||||
void Window::AddWidget(WidgetUPtr widget)
|
||||
|
@ -69,4 +73,19 @@ void Window::SetSize(unsigned width, unsigned height)
|
|||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
IPlatformWindow* Window::GetPlatformWindow() const
|
||||
{
|
||||
if (mPlatformWindow)
|
||||
{
|
||||
return mPlatformWindow.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Window::SetPlatformWindow(IPlatformWindowPtr window)
|
||||
{
|
||||
mPlatformWindow = std::move(window);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "PaintEvent.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "KeyboardEvent.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "Widget.h"
|
||||
class PaintEvent;
|
||||
class MouseEvent;
|
||||
class KeyboardEvent;
|
||||
class VisualLayer;
|
||||
class IPlatformWindow;
|
||||
using IPlatformWindowPtr = std::unique_ptr<IPlatformWindow>;
|
||||
|
||||
namespace mt
|
||||
{
|
||||
|
@ -15,13 +18,6 @@ namespace mt
|
|||
class Window
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
WidgetUPtr mWidget;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
std::vector<VisualLayer*> mLayers;
|
||||
|
||||
public:
|
||||
|
||||
Window();
|
||||
|
@ -47,6 +43,17 @@ public:
|
|||
void OnMouseEvent(const MouseEvent* event);
|
||||
|
||||
void OnKeyboardEvent(const KeyboardEvent* event);
|
||||
|
||||
IPlatformWindow* GetPlatformWindow() const;
|
||||
|
||||
void SetPlatformWindow(IPlatformWindowPtr window);
|
||||
|
||||
private:
|
||||
int mHandle {-1};
|
||||
WidgetUPtr mWidget {nullptr};
|
||||
unsigned mWidth {800};
|
||||
unsigned mHeight {600};
|
||||
IPlatformWindowPtr mPlatformWindow {nullptr};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#include "GeometryElement.h"
|
||||
|
||||
GeometryElement::GeometryElement()
|
||||
: mFillColor(Color::Create(255, 255, 255)),
|
||||
mStrokeColor(Color::Create(0, 0, 0)),
|
||||
mStrokeThickness(1),
|
||||
mType(Type::Path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Color* GeometryElement::GetFillColor() const
|
||||
{
|
||||
return mFillColor.get();
|
||||
}
|
||||
Color* GeometryElement::GetStrokeColor() const
|
||||
{
|
||||
return mStrokeColor.get();
|
||||
}
|
||||
|
||||
unsigned GeometryElement::GetStrokeThickness() const
|
||||
{
|
||||
return mStrokeThickness;
|
||||
}
|
||||
|
||||
void GeometryElement::SetFillColor(ColorUPtr color)
|
||||
{
|
||||
mFillColor = std::move(color);
|
||||
}
|
||||
|
||||
void GeometryElement::SetStrokeColor(ColorUPtr color)
|
||||
{
|
||||
mStrokeColor = std::move(color);
|
||||
}
|
||||
|
||||
void GeometryElement::SetStrokeThickness(unsigned thickness)
|
||||
{
|
||||
mStrokeThickness = thickness;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
class GeometryElement
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
Path,
|
||||
Rectangle,
|
||||
Circle,
|
||||
Arc
|
||||
};
|
||||
|
||||
private:
|
||||
ColorUPtr mFillColor;
|
||||
ColorUPtr mStrokeColor;
|
||||
unsigned mStrokeThickness;
|
||||
Type mType;
|
||||
|
||||
public:
|
||||
|
||||
GeometryElement();
|
||||
virtual ~GeometryElement() = default;
|
||||
|
||||
Color* GetFillColor() const;
|
||||
Color* GetStrokeColor() const;
|
||||
unsigned GetStrokeThickness() const;
|
||||
virtual Type GetType() = 0;
|
||||
|
||||
void SetFillColor(ColorUPtr color);
|
||||
void SetStrokeColor(ColorUPtr color);
|
||||
void SetStrokeThickness(unsigned thickness);
|
||||
};
|
||||
|
||||
using GeometryElementUPtr = std::unique_ptr<GeometryElement>;
|
|
@ -1,36 +0,0 @@
|
|||
#include "RectangleElement.h"
|
||||
|
||||
RectangleElement::RectangleElement(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
: mLocation(loc),
|
||||
mWidth(width),
|
||||
mHeight(height)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
return std::make_unique<RectangleElement>(loc, width, height);
|
||||
}
|
||||
|
||||
GeometryElement::Type RectangleElement::GetType()
|
||||
{
|
||||
return GeometryElement::Type::Rectangle;
|
||||
}
|
||||
|
||||
DiscretePoint RectangleElement::GetLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "GeometryElement.h"
|
||||
#include "DiscretePoint.h"
|
||||
|
||||
class RectangleElement : public GeometryElement
|
||||
{
|
||||
DiscretePoint mLocation;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
|
||||
public:
|
||||
|
||||
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() const;
|
||||
unsigned GetWidth() const;
|
||||
unsigned GetHeight() const;
|
||||
};
|
||||
|
||||
using RectangleElementUPtr = std::unique_ptr<RectangleElement>;
|
||||
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
#include "TextElement.h"
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
TextElement::TextElement(const std::string& content, const DiscretePoint& loc)
|
||||
: mContent(content),
|
||||
mLocation(loc),
|
||||
mFontLabel("fixed"),
|
||||
mFillColor(Color::Create(255, 255, 255)),
|
||||
mStrokeColor(Color::Create(0, 0, 0))
|
||||
{
|
||||
// https://en.wikipedia.org/wiki/Fixed_(typeface)#:~:text=misc%2Dfixed%20is%20a%20collection,to%20a%20single%20font%20family.
|
||||
}
|
||||
|
||||
TextElement::~TextElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<TextElement> TextElement::Create(const std::string& content, const DiscretePoint& loc)
|
||||
{
|
||||
return std::make_unique<TextElement>(content, loc);
|
||||
}
|
||||
|
||||
Color* TextElement::GetFillColor() const
|
||||
{
|
||||
return mFillColor.get();
|
||||
}
|
||||
Color* TextElement::GetStrokeColor() const
|
||||
{
|
||||
return mStrokeColor.get();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void TextElement::SetFillColor(ColorUPtr color)
|
||||
{
|
||||
mFillColor = std::move(color);
|
||||
}
|
||||
|
||||
void TextElement::SetStrokeColor(ColorUPtr color)
|
||||
{
|
||||
mStrokeColor = std::move(color);
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "DiscretePoint.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Color;
|
||||
|
||||
class TextElement
|
||||
{
|
||||
std::string mContent;
|
||||
DiscretePoint mLocation;
|
||||
std::string mFontLabel;
|
||||
std::unique_ptr<Color> mFillColor;
|
||||
std::unique_ptr<Color> mStrokeColor;
|
||||
|
||||
public:
|
||||
|
||||
TextElement(const std::string& content, const DiscretePoint& loc);
|
||||
|
||||
~TextElement();
|
||||
|
||||
static std::unique_ptr<TextElement> Create(const std::string& content, const DiscretePoint& loc);
|
||||
|
||||
Color* GetFillColor() const;
|
||||
Color* GetStrokeColor() const;
|
||||
|
||||
DiscretePoint GetLocation() const;
|
||||
std::string GetContent() const;
|
||||
std::string GetFontLabel() const;
|
||||
void SetContent(const std::string& content);
|
||||
void SetFillColor(std::unique_ptr<Color> color);
|
||||
void SetStrokeColor(std::unique_ptr<Color> color);
|
||||
};
|
||||
|
||||
using TextElementUPtr = std::unique_ptr<TextElement>;
|
|
@ -1,46 +0,0 @@
|
|||
#include "VisualLayer.h"
|
||||
|
||||
#include "GeometryElement.h"
|
||||
#include "TextElement.h"
|
||||
|
||||
VisualLayer::VisualLayer()
|
||||
: mShape(),
|
||||
mText()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<VisualLayer> VisualLayer::Create()
|
||||
{
|
||||
return std::make_unique<VisualLayer>();
|
||||
}
|
||||
|
||||
bool VisualLayer::HasShape() const
|
||||
{
|
||||
return bool(mShape);
|
||||
}
|
||||
|
||||
bool VisualLayer::HasText() const
|
||||
{
|
||||
return bool(mText);
|
||||
}
|
||||
|
||||
GeometryElement* VisualLayer::GetShape() const
|
||||
{
|
||||
return mShape.get();
|
||||
}
|
||||
|
||||
TextElement* VisualLayer::GetText() const
|
||||
{
|
||||
return mText.get();
|
||||
}
|
||||
|
||||
void VisualLayer::SetShape(GeometryElementUPtr shape)
|
||||
{
|
||||
mShape = std::move(shape);
|
||||
}
|
||||
|
||||
void VisualLayer::SetText(TextElementUPtr text)
|
||||
{
|
||||
mText = std::move(text);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
class GeometryElement;
|
||||
class TextElement;
|
||||
|
||||
class VisualLayer
|
||||
{
|
||||
std::unique_ptr<GeometryElement> mShape;
|
||||
std::unique_ptr<TextElement> mText;
|
||||
|
||||
public:
|
||||
|
||||
VisualLayer();
|
||||
|
||||
static std::unique_ptr<VisualLayer> Create();
|
||||
|
||||
GeometryElement* GetShape() const;
|
||||
TextElement* GetText() const;
|
||||
bool HasShape() const;
|
||||
bool HasText() const;
|
||||
void SetShape(std::unique_ptr<GeometryElement> shape);
|
||||
void SetText(std::unique_ptr<TextElement> text);
|
||||
};
|
||||
using VisualLayerUPtr = std::unique_ptr<VisualLayer>;
|
Loading…
Add table
Add a link
Reference in a new issue