From 3141d51164464db499553e89fd71c60b77f82f0c Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 11 Sep 2021 13:40:55 -0400 Subject: [PATCH] PixelPaint: Use LibConfig to allow custom pixel grid threshold Depending on the size / scaling of the UI, someone might want to change what the threshold is to show the pixel grid. For instance if you are working on a 50x50 image, and want to see the grid while still fitting the whole image in the editor. Since there's no UI for settings in PixelPaint right now, this commit just uses LibConfig to read the following entry: ("PixelPaint", "PixelGrid", "Threshold") which is then used when drawing the grid. --- Userland/Applications/PixelPaint/CMakeLists.txt | 2 +- Userland/Applications/PixelPaint/ImageEditor.cpp | 5 +++-- Userland/Applications/PixelPaint/ImageEditor.h | 2 ++ Userland/Applications/PixelPaint/main.cpp | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/PixelPaint/CMakeLists.txt b/Userland/Applications/PixelPaint/CMakeLists.txt index 7c87a29487..27618d1ed0 100644 --- a/Userland/Applications/PixelPaint/CMakeLists.txt +++ b/Userland/Applications/PixelPaint/CMakeLists.txt @@ -44,4 +44,4 @@ set(SOURCES ) serenity_app(PixelPaint ICON app-pixel-paint) -target_link_libraries(PixelPaint LibImageDecoderClient LibGUI LibGfx LibFileSystemAccessClient) +target_link_libraries(PixelPaint LibImageDecoderClient LibGUI LibGfx LibFileSystemAccessClient LibConfig) diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index ce8f2a4fcd..9c23d4f065 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -12,6 +12,7 @@ #include "Layer.h" #include "MoveTool.h" #include "Tool.h" +#include #include #include #include @@ -29,6 +30,7 @@ ImageEditor::ImageEditor(NonnullRefPtr image) m_undo_stack = make(); m_undo_stack->push(make(*m_image)); m_image->add_client(*this); + m_pixel_grid_threshold = (float)Config::read_i32("PixelPaint", "PixelGrid", "Threshold", 15); } ImageEditor::~ImageEditor() @@ -86,8 +88,7 @@ void ImageEditor::paint_event(GUI::PaintEvent& event) painter.draw_rect(enclosing_int_rect(image_rect_to_editor_rect(m_active_layer->relative_rect())).inflated(2, 2), Color::Black); } - const float pixel_grid_threshold = 15.0f; - if (m_show_pixel_grid && m_scale > pixel_grid_threshold) { + if (m_show_pixel_grid && m_scale > m_pixel_grid_threshold) { auto event_image_rect = enclosing_int_rect(editor_rect_to_image_rect(event.rect())).inflated(1, 1); auto image_rect = m_image->rect().inflated(1, 1).intersected(event_image_rect); diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index e42df9035f..051d03dd25 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -157,6 +157,8 @@ private: int m_ruler_thickness { 20 }; int m_mouse_indicator_triangle_size { 5 }; + float m_pixel_grid_threshold { 15.0f }; + Gfx::StandardCursor m_active_cursor { Gfx::StandardCursor::None }; Selection m_selection; diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index c2ecb89fda..bad0004826 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -6,6 +6,7 @@ */ #include "MainWidget.h" +#include #include #include #include @@ -26,6 +27,7 @@ int main(int argc, char** argv) } auto app = GUI::Application::construct(argc, argv); + Config::pledge_domains("PixelPaint"); const char* image_file = nullptr; Core::ArgsParser args_parser;