summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Christiansen <tobi@tobyase.de>2021-08-01 15:55:44 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-08-07 02:52:47 +0430
commitd4cf4b74c1738f55e39bfcd37f4592a545a71af3 (patch)
tree5e80c5e95d226301a8fbd90f2fa65c3fc22221a8
parent515bbd0b833f8fb9abbcc5e50d3d4318f25c2168 (diff)
downloadserenity-d4cf4b74c1738f55e39bfcd37f4592a545a71af3.zip
PixelPaint: Allow creation of Guides via the View-Menu
You can specify the offset in percent, and it's getting parsed and calculated appropriately.
-rw-r--r--Userland/Applications/PixelPaint/main.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp
index fae1dc4f30..7752df39a0 100644
--- a/Userland/Applications/PixelPaint/main.cpp
+++ b/Userland/Applications/PixelPaint/main.cpp
@@ -4,9 +4,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include "CreateNewGuideDialog.h"
#include "CreateNewImageDialog.h"
#include "CreateNewLayerDialog.h"
#include "FilterParams.h"
+#include "Guide.h"
#include "Image.h"
#include "ImageEditor.h"
#include "Layer.h"
@@ -316,9 +318,40 @@ int main(int argc, char** argv)
},
window);
+ auto add_guide_action = GUI::Action::create(
+ "Add Guide", [&](auto&) {
+ auto dialog = PixelPaint::CreateNewGuideDialog::construct(window);
+ if (dialog->exec() == GUI::Dialog::ExecOK) {
+ if (auto* editor = current_image_editor()) {
+ auto specified_offset = dialog->offset();
+ float offset = 0;
+ if (specified_offset.ends_with('%')) {
+ auto percentage = specified_offset.substring_view(0, specified_offset.length() - 1).to_int();
+ if (!percentage.has_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);
+
view_menu.add_action(zoom_in_action);
view_menu.add_action(zoom_out_action);
view_menu.add_action(reset_zoom_action);
+ view_menu.add_separator();
+ view_menu.add_action(add_guide_action);
auto& tool_menu = window->add_menu("&Tool");
toolbox.for_each_tool([&](auto& tool) {