More cleaning

This commit is contained in:
James Grogan 2022-11-11 11:48:42 +00:00
parent 02ebb9a54b
commit 6adc441e6f
37 changed files with 213 additions and 181 deletions

View file

@ -2,27 +2,13 @@ list(APPEND client_HEADERS
TopBar.h
StatusBar.h
GuiApplication.h
TabbedPanelWidget.h
text_editor/TextEditorView.h
text_editor/TextEditorModel.h
text_editor/TextEditorController.h
text_editor/PlainTextDocument.h
audio_editor/AudioEditorView.h
image_editor/ImageEditorView.h
web_client/WebClientView.h)
TabbedPanelWidget.h)
list(APPEND client_LIB_INCLUDES
TopBar.cpp
StatusBar.cpp
GuiApplication.cpp
TabbedPanelWidget.cpp
text_editor/TextEditorView.cpp
text_editor/TextEditorModel.cpp
text_editor/TextEditorController.cpp
text_editor/PlainTextDocument.cpp
audio_editor/AudioEditorView.cpp
image_editor/ImageEditorView.cpp
web_client/WebClientView.cpp)
TabbedPanelWidget.cpp)
add_library(client SHARED ${client_LIB_INCLUDES} ${client_HEADERS})

View file

@ -1,26 +1,20 @@
#include "GuiApplication.h"
#include "Widget.h"
#include "UiInterfaceFactory.h"
#include "Window.h"
#include "TextElement.h"
#include "WindowManager.h"
#include "TextEditorView.h"
#include "AudioEditorView.h"
#include "ImageEditorView.h"
#include "WebClientView.h"
#include "TabbedPanelWidget.h"
#include "TopBar.h"
#include "StatusBar.h"
#include "HorizontalSpacer.h"
#include "DesktopManager.h"
#include "MainApplication.h"
#include "AbstractUiInterface.h"
#include "FileLogger.h"
GuiApplication::GuiApplication()
GuiApplication::GuiApplication(std::unique_ptr<CommandLineArgs> args)
: AbstractDesktopApp(),
mMainApplication(),
mDesktopManager(DesktopManager::Create())
mMainApplication(MainApplication::Create()),
mDesktopManager(DesktopManager::Create(this))
{
mMainApplication->initialize(args ? std::move(args) : CommandLineArgs::Create());
}
GuiApplication::~GuiApplication()
@ -28,61 +22,37 @@ GuiApplication::~GuiApplication()
}
void GuiApplication::SetMainApplication(MainApplicationPtr app)
AbstractApp* GuiApplication::getMainApplication() const
{
mMainApplication = app;
mDesktopManager->SetMainApp(app);
return mMainApplication.get();
}
void GuiApplication::SetUpWidget()
void GuiApplication::initializeViews()
{
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
mainWindow->SetSize(800, 600);
auto tabbedPanel = TabbedPanelWidget::Create();
auto textEditor = TextEditorView::Create();
auto path = mMainApplication->GetCommandLineArgs()->getLaunchPath();
path /= "out.txt";
textEditor->GetController()->SetSavePath(path);
textEditor->GetController()->SetLoadPath(path);
textEditor->Initialize();
tabbedPanel->AddPanel(std::move(textEditor), "Text Editor");
auto audioEditor = AudioEditorView::Create();
tabbedPanel->AddPanel(std::move(audioEditor), "Audio Editor");
auto imageEditor = ImageEditorView::Create();
tabbedPanel->AddPanel(std::move(imageEditor), "Image Editor");
auto webClient = WebClientView::Create();
tabbedPanel->AddPanel(std::move(webClient), "Web Client");
auto topBar = TopBar::Create();
auto statusBar = StatusBar::Create();
auto horizontalSpace = HorizontalSpacer::Create();
horizontalSpace->AddWidgetWithScale(std::move(topBar), 1);
horizontalSpace->AddWidgetWithScale(std::move(tabbedPanel), 20);
horizontalSpace->AddWidgetWithScale(std::move(statusBar), 1);
mainWindow->AddWidget(std::move(horizontalSpace));
}
void GuiApplication::Run()
void GuiApplication::setUiInterfaceBackend(UiInterfaceFactory::Backend backend)
{
mUiInterfaceBackend = backend;
}
void GuiApplication::run()
{
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
SetUpWidget();
initializeViews();
MLOG_INFO("Creating Window Interface");
auto window_interface = UiInterfaceFactory::create(mDesktopManager.get());
mUiInterface = UiInterfaceFactory::create(mDesktopManager.get(), mUiInterfaceBackend);
window_interface->initialize();
window_interface->addWindow(mainWindow);
window_interface->showWindow(mainWindow);
window_interface->loop();
mUiInterface->initialize();
mUiInterface->addWindow(mainWindow);
mUiInterface->showWindow(mainWindow);
mUiInterface->loop();
window_interface->shutDown();
mUiInterface->shutDown();
MLOG_INFO("Window Interface Shut Down");
mMainApplication->ShutDown();
}

View file

@ -1,28 +1,35 @@
#pragma once
#include "MainApplication.h"
#include "AbstractDesktopApp.h"
#include "DesktopManager.h"
#include "UiInterfaceFactory.h"
#include "CommandLineArgs.h"
#include <memory>
class MainApplication;
class DesktopManager;
class AbstractUiInterface;
class GuiApplication : public AbstractDesktopApp
{
private:
DesktopManagerUPtr mDesktopManager;
MainApplicationPtr mMainApplication;
public:
GuiApplication();
GuiApplication(std::unique_ptr<CommandLineArgs> args = nullptr);
~GuiApplication();
void SetMainApplication(MainApplicationPtr app);
AbstractApp* getMainApplication() const override;
void Run();
void run();
void SetUpWidget();
void setUiInterfaceBackend(UiInterfaceFactory::Backend backend);
protected:
virtual void initializeViews();
std::unique_ptr<DesktopManager> mDesktopManager;
std::unique_ptr<MainApplication> mMainApplication;
private:
UiInterfaceFactory::Backend mUiInterfaceBackend = UiInterfaceFactory::Backend::UNSET;
std::unique_ptr<AbstractUIInterface> mUiInterface;
};

View file

@ -1,18 +0,0 @@
#include "AudioEditorView.h"
#include "Label.h"
#include "Color.h"
AudioEditorView::AudioEditorView()
{
auto label = Label::Create();
label->SetLabel("Audio Editor");
label->SetBackgroundColor(Color::Create(200, 189, 160));
label->SetMargin(1);
AddWidget(std::move(label));
}
std::unique_ptr<AudioEditorView> AudioEditorView::Create()
{
return std::make_unique<AudioEditorView>();
}

View file

@ -1,14 +0,0 @@
#pragma once
#include "Widget.h"
class AudioEditorView : public Widget
{
public:
AudioEditorView();
static std::unique_ptr<AudioEditorView> Create();
};
using AudioEditorViewUPtr = std::unique_ptr<AudioEditorView>;

View file

@ -1,18 +0,0 @@
#include "ImageEditorView.h"
#include "Label.h"
#include "Color.h"
ImageEditorView::ImageEditorView()
{
auto label = Label::Create();
label->SetLabel("Image Editor");
label->SetBackgroundColor(Color::Create(200, 189, 160));
label->SetMargin(1);
AddWidget(std::move(label));
}
std::unique_ptr<ImageEditorView> ImageEditorView::Create()
{
return std::make_unique<ImageEditorView>();
}

View file

@ -1,14 +0,0 @@
#pragma once
#include "Widget.h"
class ImageEditorView : public Widget
{
public:
ImageEditorView();
static std::unique_ptr<ImageEditorView> Create();
};
using ImageEditorViewUPtr = std::unique_ptr<ImageEditorView>;

View file

@ -1,27 +0,0 @@
#include "PlainTextDocument.h"
PlainTextDocument::PlainTextDocument()
: mContent()
{
}
std::unique_ptr<PlainTextDocument> PlainTextDocument::Create()
{
return std::make_unique<PlainTextDocument>();
}
std::string PlainTextDocument::GetContent() const
{
return mContent;
}
void PlainTextDocument::SetContent(const std::string& content)
{
mContent = content;
}
void PlainTextDocument::Clear()
{
mContent = "";
}

View file

@ -1,24 +0,0 @@
#pragma once
#include <string>
#include <memory>
class PlainTextDocument
{
std::string mContent;
public:
PlainTextDocument();
static std::unique_ptr<PlainTextDocument> Create();
std::string GetContent() const;
void SetContent(const std::string& content);
void Clear();
};
using PlainTextDocumentUPtr = std::unique_ptr<PlainTextDocument>;

View file

@ -1,60 +0,0 @@
#include "TextEditorController.h"
#include "File.h"
TextEditorController::TextEditorController()
: mModel(TextEditorModel::Create()),
mSavePath(),
mLoadPath()
{
}
std::unique_ptr<TextEditorController> TextEditorController::Create()
{
return std::make_unique<TextEditorController>();
}
void TextEditorController::SetContent(const std::string& content)
{
mModel->GetDocument()->SetContent(content);
}
std::string TextEditorController::GetContent() const
{
return mModel->GetDocument()->GetContent();
}
void TextEditorController::OnSave()
{
if(mSavePath.empty()) return;
File outfile(mSavePath);
outfile.SetAccessMode(File::AccessMode::Write);
outfile.Open();
outfile.WriteText(mModel->GetDocument()->GetContent());
outfile.Close();
}
void TextEditorController::OnLoad()
{
if(mLoadPath.empty()) return;
File infile(mLoadPath);
infile.SetAccessMode(File::AccessMode::Read);
infile.Open();
mModel->GetDocument()->SetContent(infile.ReadText());
infile.Close();
}
void TextEditorController::SetSavePath(const std::filesystem::path& path)
{
mSavePath = path;
}
void TextEditorController::SetLoadPath(const std::filesystem::path& path)
{
mLoadPath = path;
}
void TextEditorController::OnClear()
{
mModel->GetDocument()->Clear();
}

View file

@ -1,33 +0,0 @@
#pragma once
#include <memory>
#include <filesystem>
#include "TextEditorModel.h"
class TextEditorController
{
TextEditorModelUPtr mModel;
std::filesystem::path mSavePath;
std::filesystem::path mLoadPath;
public:
TextEditorController();
static std::unique_ptr<TextEditorController> Create();
void OnSave();
void OnClear();
void OnLoad();
std::string GetContent() const;
void SetContent(const std::string& content);
void SetSavePath(const std::filesystem::path& path);
void SetLoadPath(const std::filesystem::path& path);
};
using TextEditorControllerUPtr = std::unique_ptr<TextEditorController>;

View file

@ -1,17 +0,0 @@
#include "TextEditorModel.h"
TextEditorModel::TextEditorModel()
: mDocument(PlainTextDocument::Create())
{
}
std::unique_ptr<TextEditorModel> TextEditorModel::Create()
{
return std::make_unique<TextEditorModel>();
}
PlainTextDocument* TextEditorModel::GetDocument() const
{
return mDocument.get();
}

View file

@ -1,19 +0,0 @@
#pragma once
#include "PlainTextDocument.h"
#include <memory>
class TextEditorModel
{
PlainTextDocumentUPtr mDocument;
public:
TextEditorModel();
static std::unique_ptr<TextEditorModel> Create();
PlainTextDocument* GetDocument() const;
};
using TextEditorModelUPtr = std::unique_ptr<TextEditorModel>;

View file

@ -1,83 +0,0 @@
#include "HorizontalSpacer.h"
#include "TextEditorView.h"
#include "VerticalSpacer.h"
#include <iostream>
TextEditorView::TextEditorView()
: mTextBox(),
mController(TextEditorController::Create())
{
}
TextEditorController* TextEditorView::GetController()
{
return mController.get();
}
void TextEditorView::Initialize()
{
auto label = Label::Create();
label->SetLabel("Text Editor");
label->SetBackgroundColor(Color::Create(181, 189, 200));
label->SetMargin(1);
auto textBox = TextBox::Create();
mTextBox = textBox.get();
auto saveButton = Button::Create();
saveButton->SetLabel("Save");
saveButton->SetBackgroundColor(Color::Create(200, 200, 200));
saveButton->SetMargin(2);
auto onSave = [this](Widget* self){
if(this && mController && mTextBox)
{
mController->SetContent(mTextBox->GetContent());
mController->OnSave();
};
};
saveButton->SetOnClickFunction(onSave);
auto clearButton = Button::Create();
clearButton->SetLabel("Clear");
clearButton->SetBackgroundColor(Color::Create(200, 200, 200));
clearButton->SetMargin(2);
auto onClear = [this](Widget* self){
if(this && mController && mTextBox)
{
mController->OnClear();
mTextBox->SetContent("");
};
};
clearButton->SetOnClickFunction(onClear);
auto loadButton = Button::Create();
loadButton->SetLabel("Load");
loadButton->SetBackgroundColor(Color::Create(200, 200, 200));
loadButton->SetMargin(2);
auto onLoad = [this](Widget* self){
if(this && mController && mTextBox)
{
mController->OnLoad();
mTextBox->SetContent(mController->GetContent());
};
};
loadButton->SetOnClickFunction(onLoad);
auto buttonSpacer = VerticalSpacer::Create();
buttonSpacer->AddWidgetWithScale(std::move(saveButton), 1);
buttonSpacer->AddWidgetWithScale(std::move(clearButton), 1);
buttonSpacer->AddWidgetWithScale(std::move(loadButton), 1);
auto hSpacer = HorizontalSpacer::Create();
hSpacer->AddWidgetWithScale(std::move(label), 1);
hSpacer->AddWidgetWithScale(std::move(textBox), 14);
hSpacer->AddWidgetWithScale(std::move(buttonSpacer), 1);
AddWidget(std::move(hSpacer));
}
std::unique_ptr<TextEditorView> TextEditorView::Create()
{
return std::make_unique<TextEditorView>();
}

View file

@ -1,25 +0,0 @@
#pragma once
#include "Widget.h"
#include "Button.h"
#include "Label.h"
#include "TextBox.h"
#include "TextEditorController.h"
#include <functional>
class TextEditorView : public Widget
{
TextBox* mTextBox;
TextEditorControllerUPtr mController;
public:
TextEditorView();
static std::unique_ptr<TextEditorView> Create();
TextEditorController* GetController();
void Initialize();
};
using TextEditorViewUPtr = std::unique_ptr<TextEditorView>;

View file

@ -1,18 +0,0 @@
#include "WebClientView.h"
#include "Label.h"
#include "Color.h"
WebClientView::WebClientView()
{
auto label = Label::Create();
label->SetLabel("Web Client");
label->SetBackgroundColor(Color::Create(200, 189, 160));
label->SetMargin(1);
AddWidget(std::move(label));
}
std::unique_ptr<WebClientView> WebClientView::Create()
{
return std::make_unique<WebClientView>();
}

View file

@ -1,14 +0,0 @@
#pragma once
#include "Widget.h"
class WebClientView : public Widget
{
public:
WebClientView();
static std::unique_ptr<WebClientView> Create();
};
using WebClientViewUPtr = std::unique_ptr<WebClientView>;

View file

@ -28,7 +28,7 @@ MainApplication::~MainApplication()
}
void MainApplication::Initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> applicationContext)
void MainApplication::initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> applicationContext)
{
if (applicationContext)
{
@ -137,7 +137,7 @@ void MainApplication::ShutDown()
FileLogger::GetInstance().Close();
}
std::shared_ptr<MainApplication> MainApplication::Create()
std::unique_ptr<MainApplication> MainApplication::Create()
{
return std::make_shared<MainApplication>();
return std::make_unique<MainApplication>();
}

View file

@ -13,12 +13,11 @@
class MainApplication : public AbstractApp
{
public:
MainApplication();
~MainApplication();
void Initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> applicationContext=nullptr);
void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> applicationContext=nullptr);
void Run();
@ -26,7 +25,7 @@ public:
CommandLineArgs* GetCommandLineArgs() const;
static std::shared_ptr<MainApplication> Create();
static std::unique_ptr<MainApplication> Create();
private:
void RunServer();

View file

@ -10,9 +10,9 @@ namespace mt
{
Window::Window()
:mWidth(400),
mHeight(300),
mWidget()
:mWidth(800),
mHeight(600),
mWidget(Widget::Create())
{
}
@ -50,6 +50,10 @@ void Window::OnPaint(const PaintEvent* event)
void Window::AddWidget(WidgetUPtr widget)
{
if (mWidget)
{
mWidget.reset();
}
mWidget = std::move(widget);
}

View file

@ -2,12 +2,15 @@
#include <memory>
#include "AbstractApp.h"
class AbstractDesktopApp
{
public:
AbstractDesktopApp() = default;
virtual ~AbstractDesktopApp() = default;
virtual AbstractApp* getMainApplication() const = 0;
};
using AbstractDesktopAppPtr = std::shared_ptr<AbstractDesktopApp>;

View file

@ -1,12 +1,14 @@
#include "DesktopManager.h"
#include "AbstractDesktopApp.h"
#include "FileLogger.h"
DesktopManager::DesktopManager()
DesktopManager::DesktopManager(AbstractDesktopApp* application)
: mScreens(),
mWindowManager(WindowManager::Create()),
mKeyboard(Keyboard::Create()),
mMainApplication(),
mUiApplication(application),
mModified(false),
mEventManager(EventManager::Create())
{
@ -18,9 +20,9 @@ DesktopManager::~DesktopManager()
}
std::unique_ptr<DesktopManager> DesktopManager::Create()
std::unique_ptr<DesktopManager> DesktopManager::Create(AbstractDesktopApp* application)
{
return std::make_unique<DesktopManager>();
return std::make_unique<DesktopManager>(application);
}
void DesktopManager::ClearEvents()
@ -100,14 +102,9 @@ void DesktopManager::SetKeyboard(KeyboardUPtr keyboard)
mKeyboard = std::move(keyboard);
}
void DesktopManager::SetMainApp(std::shared_ptr<AbstractApp> mainApp)
AbstractApp* DesktopManager::getMainApp() const
{
mMainApplication = mainApp;
}
AbstractApp* DesktopManager::GetMainApp()
{
return mMainApplication.get();
return mUiApplication->getMainApplication();
}
void DesktopManager::AddScreen(ScreenPtr screen)

View file

@ -13,21 +13,21 @@
#include "AbstractApp.h"
#include "EventManager.h"
class AbstractDesktopApp;
class DesktopManager
{
public:
DesktopManager();
DesktopManager(AbstractDesktopApp* application);
~DesktopManager();
static std::unique_ptr<DesktopManager> Create();
static std::unique_ptr<DesktopManager> Create(AbstractDesktopApp* application);
void SetWindowManager(WindowManagerUPtr windowManager);
void SetMainApp(std::shared_ptr<AbstractApp> mainApp);
AbstractApp* GetMainApp();
AbstractApp* getMainApp() const;
WindowManager* GetWindowManager() const;
@ -58,7 +58,7 @@ private:
WindowManagerUPtr mWindowManager;
KeyboardUPtr mKeyboard;
EventManagerUPtr mEventManager;
std::shared_ptr<AbstractApp> mMainApplication;
AbstractDesktopApp* mUiApplication;
bool mModified;
};

View file

@ -5,9 +5,18 @@ namespace mt
class Window;
}
class DesktopManager;
class AbstractUIInterface
{
public:
AbstractUIInterface(DesktopManager* desktopManager, bool useHardware = false)
: mDesktopManager(desktopManager),
mUseHardwareRendering(useHardware)
{
}
virtual ~AbstractUIInterface() = default;
virtual void initialize() = 0;
@ -26,5 +35,6 @@ public:
}
protected:
DesktopManager* mDesktopManager{nullptr};
bool mUseHardwareRendering{false};
};

View file

@ -10,13 +10,15 @@
std::unique_ptr<AbstractUIInterface> UiInterfaceFactory::create(DesktopManager* desktopManager, Backend backend)
{
#ifdef __linux__
if (backend == Backend::UNSET || backend == Backend::X11)
if (backend == Backend::UNSET || backend == Backend::X11 || backend == Backend::X11_RASTER)
{
return std::make_unique<XcbInterface>(desktopManager);
const bool use_hardware = (backend != Backend::X11_RASTER);
return std::make_unique<XcbInterface>(desktopManager, use_hardware);
}
else
{
return std::make_unique<WaylandInterface>(desktopManager);
const bool use_hardware = (backend != Backend::WAYLAND_RASTER);
return std::make_unique<WaylandInterface>(desktopManager, use_hardware);
}
#else
return std::make_unique<Win32UiInterface>();

View file

@ -12,7 +12,9 @@ public:
enum class Backend
{
UNSET,
X11_RASTER,
X11,
WAYLAND_RASTER,
WAYLAND
};

View file

@ -41,9 +41,8 @@ void WaylandInterface::registryHandleGlobalRemoveEvent(void *data, struct wl_reg
}
WaylandInterface::WaylandInterface(DesktopManager* desktopManager)
: mDesktopManager(desktopManager),
WaylandInterface::WaylandInterface(DesktopManager* desktopManager, bool useHardware)
: AbstractUIInterface(desktopManager, useHardware),
mBuffer(std::make_shared<WaylandBuffer>())
{
mRegistryListener.global = registryHandleGlobalEvent;

View file

@ -14,13 +14,12 @@ class WaylandSurface;
class WaylandBuffer;
class WaylandSeatInterface;
class WaylandEglInterface;
class DesktopManager;
class WaylandInterface : public AbstractUIInterface
{
public:
WaylandInterface(DesktopManager* desktopManager);
WaylandInterface(DesktopManager* desktopManager, bool useHardware = true);
~WaylandInterface();
@ -48,8 +47,6 @@ private:
void setXdgBase(xdg_wm_base* xdg_base);
DesktopManager* mDesktopManager{nullptr};
wl_display* mDisplay{nullptr};
wl_compositor* mCompositor{nullptr};
wl_registry_listener mRegistryListener;

View file

@ -20,8 +20,8 @@
#include "FileLogger.h"
XcbInterface::XcbInterface(DesktopManager* desktopManager)
: mDesktopManager(desktopManager),
XcbInterface::XcbInterface(DesktopManager* desktopManager, bool useHardware)
: AbstractUIInterface(desktopManager, useHardware),
mConnection(nullptr),
mX11Display(),
mGlxInterface(),

View file

@ -4,7 +4,6 @@
#include <memory>
class DesktopManager;
class GlxInterface;
using GlxInterfacePtr = std::unique_ptr<GlxInterface>;
@ -26,7 +25,7 @@ namespace mt
class XcbInterface : public AbstractUIInterface
{
public:
XcbInterface(DesktopManager* desktopManager);
XcbInterface(DesktopManager* desktopManager, bool useHardware = true);
~XcbInterface();
@ -57,7 +56,6 @@ private:
uint32_t getEventMask();
private:
DesktopManager* mDesktopManager{nullptr};
xcb_connection_t* mConnection;
_XDisplay* mX11Display;
GlxInterfacePtr mGlxInterface;