Add option to reset symmetry to the center (fix #2195)

This commit is contained in:
David Capello 2019-11-11 15:40:01 -03:00
parent 5ac07c0823
commit 8c2a99f952
2 changed files with 33 additions and 6 deletions

View File

@ -1520,3 +1520,5 @@ image_preset_text = Text
toggle = Toggle Symmetry
toggle_horizontal = Toggle Horizontal Symmetry
toggle_vertical = Toggle Vertical Symmetry
show_options = Symmetry Options
reset_position = Reset Symmetry to Center

View File

@ -19,6 +19,7 @@
#include "app/commands/quick_command.h"
#include "app/doc.h"
#include "app/doc_event.h"
#include "app/i18n/strings.h"
#include "app/ini_file.h"
#include "app/match_words.h"
#include "app/modules/editors.h"
@ -1106,16 +1107,18 @@ protected:
class ContextBar::SymmetryField : public ButtonSet {
public:
SymmetryField() : ButtonSet(2) {
SymmetryField() : ButtonSet(3) {
setMultiMode(MultiMode::Set);
SkinTheme* theme = SkinTheme::instance();
addItem(theme->parts.horizontalSymmetry());
addItem(theme->parts.verticalSymmetry());
addItem("...");
}
void setupTooltips(TooltipManager* tooltipManager) {
tooltipManager->addTooltipFor(at(0), "Horizontal Symmetry", BOTTOM);
tooltipManager->addTooltipFor(at(1), "Vertical Symmetry", BOTTOM);
tooltipManager->addTooltipFor(at(0), Strings::symmetry_toggle_horizontal(), BOTTOM);
tooltipManager->addTooltipFor(at(1), Strings::symmetry_toggle_vertical(), BOTTOM);
tooltipManager->addTooltipFor(at(2), Strings::symmetry_show_options(), BOTTOM);
}
void updateWithCurrentDocument() {
@ -1143,11 +1146,33 @@ private:
int mode = 0;
if (at(0)->isSelected()) mode |= int(app::gen::SymmetryMode::HORIZONTAL);
if (at(1)->isSelected()) mode |= int(app::gen::SymmetryMode::VERTICAL);
if (app::gen::SymmetryMode(mode) != docPref.symmetry.mode()) {
docPref.symmetry.mode(app::gen::SymmetryMode(mode));
// Redraw symmetry rules
doc->notifyGeneralUpdate();
}
else if (at(2)->isSelected()) {
auto item = at(2);
gfx::Rect bounds = item->bounds();
item->setSelected(false);
Menu menu;
MenuItem
reset(Strings::symmetry_reset_position());
menu.addChild(&reset);
reset.Click.connect(
[doc, &docPref]{
docPref.symmetry.xAxis(doc->sprite()->width()/2.0);
docPref.symmetry.yAxis(doc->sprite()->height()/2.0);
// Redraw symmetry rules
doc->notifyGeneralUpdate();
});
menu.showPopup(gfx::Point(bounds.x, bounds.y+bounds.h));
}
}
};
class ContextBar::SliceFields : public HBox {