More cleaning
This commit is contained in:
parent
02ebb9a54b
commit
6adc441e6f
37 changed files with 213 additions and 181 deletions
|
@ -1,27 +1,42 @@
|
|||
list(APPEND client_HEADERS
|
||||
MediaTool.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)
|
||||
|
||||
|
||||
list(APPEND client_LIB_INCLUDES
|
||||
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
|
||||
MediaTool.cpp)
|
||||
|
||||
if(WIN32)
|
||||
add_executable(sample_gui_win WIN32 gui-main-win.cpp)
|
||||
target_include_directories(sample_gui PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/console"
|
||||
"${PROJECT_SOURCE_DIR}/src/client"
|
||||
)
|
||||
target_link_libraries(sample_gui_win PUBLIC client windows console core
|
||||
network database geometry audio web)
|
||||
set_property(TARGET sample_gui_win PROPERTY FOLDER apps)
|
||||
add_executable(sample_gui WIN32 gui-main-win.cpp ${client_LIB_INCLUDES})
|
||||
else()
|
||||
find_package(X11 QUIET)
|
||||
if(X11_FOUND)
|
||||
add_executable(sample_gui gui-main.cpp)
|
||||
target_include_directories(sample_gui PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/console"
|
||||
"${PROJECT_SOURCE_DIR}/src/client"
|
||||
)
|
||||
target_link_libraries(sample_gui PUBLIC client windows console core
|
||||
network database geometry audio web)
|
||||
set_property(TARGET sample_gui PROPERTY FOLDER apps)
|
||||
add_executable(sample_gui gui-main.cpp ${client_LIB_INCLUDES} ${client_HEADERS})
|
||||
else()
|
||||
message(STATUS "Skipping sample GUI as no X11 dev support")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_include_directories(sample_gui PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/text_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/audio_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/web_client"
|
||||
)
|
||||
target_link_libraries(sample_gui PUBLIC client windows console core network database geometry audio web)
|
||||
set_property(TARGET sample_gui PROPERTY FOLDER apps)
|
||||
|
||||
|
||||
|
|
54
apps/sample-gui/MediaTool.cpp
Normal file
54
apps/sample-gui/MediaTool.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "MediaTool.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"
|
||||
|
||||
MediaTool::MediaTool(std::unique_ptr<CommandLineArgs> args)
|
||||
: GuiApplication(std::move(args))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MediaTool::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));
|
||||
}
|
12
apps/sample-gui/MediaTool.h
Normal file
12
apps/sample-gui/MediaTool.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "GuiApplication.h"
|
||||
|
||||
class MediaTool : public GuiApplication
|
||||
{
|
||||
public:
|
||||
MediaTool(std::unique_ptr<CommandLineArgs> args);
|
||||
|
||||
protected:
|
||||
void initializeViews() override;
|
||||
};
|
18
apps/sample-gui/audio_editor/AudioEditorView.cpp
Normal file
18
apps/sample-gui/audio_editor/AudioEditorView.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#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>();
|
||||
}
|
14
apps/sample-gui/audio_editor/AudioEditorView.h
Normal file
14
apps/sample-gui/audio_editor/AudioEditorView.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class AudioEditorView : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
AudioEditorView();
|
||||
|
||||
static std::unique_ptr<AudioEditorView> Create();
|
||||
};
|
||||
|
||||
using AudioEditorViewUPtr = std::unique_ptr<AudioEditorView>;
|
|
@ -1,6 +1,6 @@
|
|||
#include <memory>
|
||||
|
||||
#include "GuiApplication.h"
|
||||
#include "MediaTool.h"
|
||||
#include "MainApplication.h"
|
||||
#include "CommandLineArgs.h"
|
||||
|
||||
|
@ -10,15 +10,9 @@ int main(int argc, char *argv[])
|
|||
args->process(argc, argv);
|
||||
args->recordLaunchPath();
|
||||
|
||||
// Start the main app
|
||||
auto main_app = MainApplication::Create();
|
||||
main_app->Initialize(std::move(args));
|
||||
|
||||
// Start the gui app
|
||||
auto gui_app = GuiApplication();
|
||||
gui_app.SetMainApplication(main_app);
|
||||
gui_app.Run();
|
||||
auto gui_app = GuiApplication(std::move(args));
|
||||
gui_app.run();
|
||||
|
||||
main_app->ShutDown();
|
||||
return 0;
|
||||
}
|
||||
|
|
18
apps/sample-gui/image_editor/ImageEditorView.cpp
Normal file
18
apps/sample-gui/image_editor/ImageEditorView.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#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>();
|
||||
}
|
14
apps/sample-gui/image_editor/ImageEditorView.h
Normal file
14
apps/sample-gui/image_editor/ImageEditorView.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class ImageEditorView : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
ImageEditorView();
|
||||
|
||||
static std::unique_ptr<ImageEditorView> Create();
|
||||
};
|
||||
|
||||
using ImageEditorViewUPtr = std::unique_ptr<ImageEditorView>;
|
27
apps/sample-gui/text_editor/PlainTextDocument.cpp
Normal file
27
apps/sample-gui/text_editor/PlainTextDocument.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#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 = "";
|
||||
}
|
24
apps/sample-gui/text_editor/PlainTextDocument.h
Normal file
24
apps/sample-gui/text_editor/PlainTextDocument.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#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>;
|
60
apps/sample-gui/text_editor/TextEditorController.cpp
Normal file
60
apps/sample-gui/text_editor/TextEditorController.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#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();
|
||||
}
|
33
apps/sample-gui/text_editor/TextEditorController.h
Normal file
33
apps/sample-gui/text_editor/TextEditorController.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#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>;
|
17
apps/sample-gui/text_editor/TextEditorModel.cpp
Normal file
17
apps/sample-gui/text_editor/TextEditorModel.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#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();
|
||||
}
|
19
apps/sample-gui/text_editor/TextEditorModel.h
Normal file
19
apps/sample-gui/text_editor/TextEditorModel.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#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>;
|
83
apps/sample-gui/text_editor/TextEditorView.cpp
Normal file
83
apps/sample-gui/text_editor/TextEditorView.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#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>();
|
||||
}
|
25
apps/sample-gui/text_editor/TextEditorView.h
Normal file
25
apps/sample-gui/text_editor/TextEditorView.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#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>;
|
18
apps/sample-gui/web_client/WebClientView.cpp
Normal file
18
apps/sample-gui/web_client/WebClientView.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#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>();
|
||||
}
|
14
apps/sample-gui/web_client/WebClientView.h
Normal file
14
apps/sample-gui/web_client/WebClientView.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class WebClientView : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
WebClientView();
|
||||
|
||||
static std::unique_ptr<WebClientView> Create();
|
||||
};
|
||||
|
||||
using WebClientViewUPtr = std::unique_ptr<WebClientView>;
|
Loading…
Add table
Add a link
Reference in a new issue