mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 10:05:08 +00:00
PixelPaint: Allow creation of Guides via the View-Menu
You can specify the offset in percent, and it's getting parsed and calculated appropriately.
This commit is contained in:
parent
515bbd0b83
commit
d4cf4b74c1
1 changed files with 33 additions and 0 deletions
|
@ -4,9 +4,11 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "CreateNewGuideDialog.h"
|
||||||
#include "CreateNewImageDialog.h"
|
#include "CreateNewImageDialog.h"
|
||||||
#include "CreateNewLayerDialog.h"
|
#include "CreateNewLayerDialog.h"
|
||||||
#include "FilterParams.h"
|
#include "FilterParams.h"
|
||||||
|
#include "Guide.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "ImageEditor.h"
|
#include "ImageEditor.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
@ -316,9 +318,40 @@ int main(int argc, char** argv)
|
||||||
},
|
},
|
||||||
window);
|
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_in_action);
|
||||||
view_menu.add_action(zoom_out_action);
|
view_menu.add_action(zoom_out_action);
|
||||||
view_menu.add_action(reset_zoom_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");
|
auto& tool_menu = window->add_menu("&Tool");
|
||||||
toolbox.for_each_tool([&](auto& tool) {
|
toolbox.for_each_tool([&](auto& tool) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue