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.
This commit is contained in:
Mustafa Quraish 2021-09-11 13:40:55 -04:00 committed by Andreas Kling
parent 451cba8b47
commit 3141d51164
Notes: sideshowbarker 2024-07-18 04:14:13 +09:00
4 changed files with 8 additions and 3 deletions

View file

@ -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)

View file

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

View file

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

View file

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