99 lines
2.7 KiB
C++
99 lines
2.7 KiB
C++
#include "CanvasView.h"
|
|
|
|
#include "HorizontalSpacer.h"
|
|
#include "VerticalSpacer.h"
|
|
|
|
#include "CanvasController.h"
|
|
#include "CanvasDrawingArea.h"
|
|
#include "CanvasCommandSelectorView.h"
|
|
|
|
#include "TextNode.h"
|
|
#include "GeometryNode.h"
|
|
|
|
#include "Label.h"
|
|
#include "Button.h"
|
|
|
|
#include "ThemeManager.h"
|
|
#include "PaintEvent.h"
|
|
|
|
CanvasView::CanvasView()
|
|
: mController(CanvasController::Create())
|
|
{
|
|
initialize();
|
|
}
|
|
|
|
CanvasView::~CanvasView()
|
|
{
|
|
|
|
}
|
|
|
|
std::unique_ptr<CanvasView> CanvasView::Create()
|
|
{
|
|
return std::make_unique<CanvasView>();
|
|
}
|
|
|
|
void CanvasView::initialize()
|
|
{
|
|
auto label = Label::Create();
|
|
label->setLabel("Canvas");
|
|
label->setBackground(ThemeToken::SystemToken::Secondary);
|
|
label->setMargin(1);
|
|
|
|
auto controls = std::make_unique<CanvasCommandSelectorView>();
|
|
controls->setBackground(ThemeToken::SystemToken::Background);
|
|
controls->setMargin(1);
|
|
|
|
auto on_draw_command_changed = [this](CanvasDrawCommand command){
|
|
onDrawCommandChanged(command);
|
|
};
|
|
controls->setCommandSelectedCallback(on_draw_command_changed);
|
|
|
|
auto drawing_area = std::make_unique<CanvasDrawingArea>();
|
|
drawing_area->setBackground(ThemeToken::SystemToken::Background);
|
|
drawing_area->setMargin(1);
|
|
mDrawingArea = drawing_area.get();
|
|
|
|
auto control_draw_vspacer = VerticalSpacer::Create();
|
|
control_draw_vspacer->addWidgetWithScale(std::move(controls), 1);
|
|
control_draw_vspacer->addWidgetWithScale(std::move(drawing_area), 10);
|
|
|
|
auto hSpacer = HorizontalSpacer::Create();
|
|
hSpacer->addWidgetWithScale(std::move(label), 1);
|
|
|
|
hSpacer->addWidgetWithScale(std::move(control_draw_vspacer), 10);
|
|
|
|
auto cache_button_spacer = initializeCacheButtons();
|
|
hSpacer->addWidgetWithScale(std::move(cache_button_spacer), 1);
|
|
|
|
addWidget(std::move(hSpacer));
|
|
}
|
|
|
|
void CanvasView::onDrawCommandChanged(CanvasDrawCommand command)
|
|
{
|
|
mDrawingArea->setActiveDrawingCommand(command);
|
|
}
|
|
|
|
std::unique_ptr<Widget> CanvasView::initializeCacheButtons()
|
|
{
|
|
auto saveButton = Button::Create();
|
|
saveButton->setLabel("Save");
|
|
saveButton->setBackground(ThemeToken::SystemToken::Primary);
|
|
saveButton->setMargin(2);
|
|
|
|
auto clearButton = Button::Create();
|
|
clearButton->setLabel("Clear");
|
|
clearButton->setBackground(ThemeToken::SystemToken::Primary);
|
|
clearButton->setMargin(2);
|
|
|
|
auto loadButton = Button::Create();
|
|
loadButton->setLabel("Load");
|
|
loadButton->setBackground(ThemeToken::SystemToken::Primary);
|
|
loadButton->setMargin(2);
|
|
|
|
auto buttonSpacer = VerticalSpacer::Create();
|
|
buttonSpacer->addWidgetWithScale(std::move(saveButton), 1);
|
|
buttonSpacer->addWidgetWithScale(std::move(clearButton), 1);
|
|
buttonSpacer->addWidgetWithScale(std::move(loadButton), 1);
|
|
return buttonSpacer;
|
|
}
|
|
|