mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
PixelPaint: Move the conversion to pixels into the EditGuideDialog
This seems like the most appropriate location to put this.
This commit is contained in:
parent
abcb982485
commit
7e2028a3cd
3 changed files with 31 additions and 22 deletions
|
@ -62,4 +62,26 @@ EditGuideDialog::EditGuideDialog(GUI::Window* parent_window)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<float> EditGuideDialog::offset_as_pixel(const ImageEditor& editor)
|
||||||
|
{
|
||||||
|
float offset = 0;
|
||||||
|
if (m_offset.ends_with('%')) {
|
||||||
|
auto percentage = m_offset.substring_view(0, m_offset.length() - 1).to_int();
|
||||||
|
if (!percentage.has_value())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (orientation() == PixelPaint::Guide::Orientation::Horizontal)
|
||||||
|
offset = editor.image().size().height() * ((double)percentage.value() / 100.0);
|
||||||
|
else if (orientation() == PixelPaint::Guide::Orientation::Vertical)
|
||||||
|
offset = editor.image().size().width() * ((double)percentage.value() / 100.0);
|
||||||
|
} else {
|
||||||
|
auto parsed_int = m_offset.to_int();
|
||||||
|
if (!parsed_int.has_value())
|
||||||
|
return {};
|
||||||
|
offset = parsed_int.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
String const offset() const { return m_offset; }
|
String const offset() const { return m_offset; }
|
||||||
Guide::Orientation orientation() const { return m_orientation; }
|
Guide::Orientation orientation() const { return m_orientation; }
|
||||||
|
|
||||||
|
Optional<float> offset_as_pixel(ImageEditor const&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EditGuideDialog(GUI::Window* parent_window);
|
EditGuideDialog(GUI::Window* parent_window);
|
||||||
|
|
||||||
|
|
|
@ -372,28 +372,13 @@ int main(int argc, char** argv)
|
||||||
auto add_guide_action = GUI::Action::create(
|
auto add_guide_action = GUI::Action::create(
|
||||||
"Add Guide", [&](auto&) {
|
"Add Guide", [&](auto&) {
|
||||||
auto dialog = PixelPaint::EditGuideDialog::construct(window);
|
auto dialog = PixelPaint::EditGuideDialog::construct(window);
|
||||||
if (dialog->exec() == GUI::Dialog::ExecOK) {
|
if (dialog->exec() != GUI::Dialog::ExecOK)
|
||||||
if (auto* editor = current_image_editor()) {
|
return;
|
||||||
auto specified_offset = dialog->offset();
|
if (auto* editor = current_image_editor()) {
|
||||||
float offset = 0;
|
auto offset = dialog->offset_as_pixel(*editor);
|
||||||
if (specified_offset.ends_with('%')) {
|
if (!offset.has_value())
|
||||||
auto percentage = specified_offset.substring_view(0, specified_offset.length() - 1).to_int();
|
return;
|
||||||
if (!percentage.has_value())
|
editor->add_guide(PixelPaint::Guide::construct(dialog->orientation(), offset.value()));
|
||||||
return;
|
|
||||||
if (dialog->orientation() == PixelPaint::Guide::Orientation::Horizontal)
|
|
||||||
offset = editor->image().size().height() * ((double)percentage.value() / 100.0);
|
|
||||||
else if (dialog->orientation() == PixelPaint::Guide::Orientation::Vertical)
|
|
||||||
offset = editor->image().size().width() * ((double)percentage.value() / 100.0);
|
|
||||||
else
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
} else {
|
|
||||||
auto parsed_int = dialog->offset().to_int();
|
|
||||||
if (!parsed_int.has_value())
|
|
||||||
return;
|
|
||||||
offset = parsed_int.value();
|
|
||||||
}
|
|
||||||
editor->add_guide(PixelPaint::Guide::construct(dialog->orientation(), offset));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
window);
|
window);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue