1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +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:
Tobias Christiansen 2021-08-31 18:10:27 +02:00 committed by Andreas Kling
parent abcb982485
commit 7e2028a3cd
3 changed files with 31 additions and 22 deletions

View file

@ -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;
}
}