Skip to content

Commit

Permalink
Added action listener for allowResize radio buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ipochto committed Dec 9, 2024
1 parent adae0f6 commit 7000567
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/editor/editor_brush_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,29 @@ void CBrushControlsUI::Init(gcn::Container* parrent, const gcn::Rectangle &recta
+ verticalGap / 2);
updateSizeCtrls();

allowResizeRadioListener = std::make_unique<LambdaActionListener>([this](const std::string &) {
const auto brush = Editor.brushes.getCurrentBrush();

if (allowResize["Both"]->isSelected() || allowResize["WidthOnly"]->isSelected()) {
sizeSlider->setScale(brush.getMinSize().x, brush.getMaxSize().x);
sizeSlider->setStepLength(brush.getResizeSteps().x);
sizeSlider->setValue(brush.getWidth());
} else {
sizeSlider->setScale(brush.getMinSize().y, brush.getMaxSize().y);
sizeSlider->setStepLength(brush.getResizeSteps().y);
sizeSlider->setValue(brush.getHeight());
}

});

allowResize["Both"]->addActionListener(allowResizeRadioListener.get());
allowResize["WidthOnly"]->addActionListener(allowResizeRadioListener.get());
allowResize["HeightOnly"]->addActionListener(allowResizeRadioListener.get());

brushSizeSliderListener =
std::make_unique<LambdaActionListener>([this](const std::string&) {

const uint8_t size = sizeSlider->getValue();
DebugPrint("Brush size: %d\n", int(size));

if (allowResize["Both"]->isSelected()) {
Editor.brushes.getCurrentBrush().resize(size, size);
Expand Down
1 change: 1 addition & 0 deletions src/include/editor_brush_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CBrushControlsUI

enum ResizeAllowed { cBoth = 0, cWidthOnly, cHeightOnly };
std::map<std::string, std::unique_ptr<gcn::RadioButton>> allowResize;
std::unique_ptr<LambdaActionListener> allowResizeRadioListener;

std::unique_ptr<gcn::CheckBox> enableRnd;
std::unique_ptr<LambdaActionListener> enableRndListener;
Expand Down

0 comments on commit 7000567

Please sign in to comment.