stuff-from-scratch/apps/notes_tk/canvas/CanvasView.cpp

94 lines
2.3 KiB
C++
Raw Normal View History

2022-11-18 15:11:54 +00:00
#include "CanvasView.h"
#include "HorizontalSpacer.h"
#include "VerticalSpacer.h"
#include "CanvasController.h"
2022-12-05 10:59:45 +00:00
#include "CanvasDrawingArea.h"
#include "CanvasCommandSelectorView.h"
2022-11-18 15:11:54 +00:00
#include "TextNode.h"
2022-12-05 10:59:45 +00:00
#include "GeometryNode.h"
2022-11-18 15:11:54 +00:00
#include "Label.h"
#include "Button.h"
2023-01-17 13:01:59 +00:00
#include "ThemeManager.h"
#include "PaintEvent.h"
2022-11-18 15:11:54 +00:00
CanvasView::CanvasView()
: mController(CanvasController::Create())
{
initialize();
}
CanvasView::~CanvasView()
{
}
2023-12-21 09:18:44 +00:00
Ptr<CanvasView> CanvasView::Create()
2022-11-18 15:11:54 +00:00
{
return std::make_unique<CanvasView>();
}
void CanvasView::initialize()
{
auto label = Label::Create();
label->setLabel("Canvas");
label->setMargin(1);
2022-12-05 10:59:45 +00:00
auto controls = std::make_unique<CanvasCommandSelectorView>();
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->setMargin(1);
mDrawingArea = drawing_area.get();
2022-11-18 15:11:54 +00:00
2022-12-05 10:59:45 +00:00
auto control_draw_vspacer = VerticalSpacer::Create();
control_draw_vspacer->addWidgetWithScale(std::move(controls), 1);
control_draw_vspacer->addWidgetWithScale(std::move(drawing_area), 10);
2022-11-18 15:11:54 +00:00
auto hSpacer = HorizontalSpacer::Create();
hSpacer->addWidgetWithScale(std::move(label), 1);
2022-12-05 10:59:45 +00:00
hSpacer->addWidgetWithScale(std::move(control_draw_vspacer), 10);
2022-11-18 15:11:54 +00:00
auto cache_button_spacer = initializeCacheButtons();
hSpacer->addWidgetWithScale(std::move(cache_button_spacer), 1);
addWidget(std::move(hSpacer));
}
2022-12-05 10:59:45 +00:00
void CanvasView::onDrawCommandChanged(CanvasDrawCommand command)
{
mDrawingArea->setActiveDrawingCommand(command);
}
2023-12-21 09:18:44 +00:00
Ptr<Widget> CanvasView::initializeCacheButtons()
2022-11-18 15:11:54 +00:00
{
auto saveButton = Button::Create();
saveButton->setLabel("Save");
saveButton->setMargin(2);
auto clearButton = Button::Create();
clearButton->setLabel("Clear");
clearButton->setMargin(2);
auto loadButton = Button::Create();
loadButton->setLabel("Load");
loadButton->setMargin(2);
auto buttonSpacer = VerticalSpacer::Create();
2022-12-05 10:59:45 +00:00
buttonSpacer->addWidgetWithScale(std::move(saveButton), 1);
buttonSpacer->addWidgetWithScale(std::move(clearButton), 1);
buttonSpacer->addWidgetWithScale(std::move(loadButton), 1);
2022-11-18 15:11:54 +00:00
return buttonSpacer;
}