Просмотр исходного кода

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.
Mustafa Quraish 3 лет назад
Родитель
Сommit
3141d51164

+ 1 - 1
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)

+ 3 - 2
Userland/Applications/PixelPaint/ImageEditor.cpp

@@ -12,6 +12,7 @@
 #include "Layer.h"
 #include "MoveTool.h"
 #include "Tool.h"
+#include <LibConfig/Client.h>
 #include <LibGUI/Command.h>
 #include <LibGUI/Painter.h>
 #include <LibGfx/DisjointRectSet.h>
@@ -29,6 +30,7 @@ ImageEditor::ImageEditor(NonnullRefPtr<Image> image)
     m_undo_stack = make<GUI::UndoStack>();
     m_undo_stack->push(make<ImageUndoCommand>(*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);
 

+ 2 - 0
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;

+ 2 - 0
Userland/Applications/PixelPaint/main.cpp

@@ -6,6 +6,7 @@
  */
 
 #include "MainWidget.h"
+#include <LibConfig/Client.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/File.h>
 #include <LibFileSystemAccessClient/Client.h>
@@ -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;