mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
PixelPaint: Add a Selection class (ImageEditor has a Selection)
This will represent a complex, region-based selection in the future. For now though, it's just a simple rectangle. :^)
This commit is contained in:
parent
96b52f13e4
commit
1b897ec561
6 changed files with 61 additions and 0 deletions
|
@ -21,6 +21,7 @@ set(SOURCES
|
||||||
PixelPaintWindowGML.h
|
PixelPaintWindowGML.h
|
||||||
RectangleTool.cpp
|
RectangleTool.cpp
|
||||||
RectangleSelectTool.cpp
|
RectangleSelectTool.cpp
|
||||||
|
Selection.cpp
|
||||||
SprayTool.cpp
|
SprayTool.cpp
|
||||||
ToolboxWidget.cpp
|
ToolboxWidget.cpp
|
||||||
ToolPropertiesWidget.cpp
|
ToolPropertiesWidget.cpp
|
||||||
|
|
|
@ -95,6 +95,9 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
|
||||||
if (m_active_layer) {
|
if (m_active_layer) {
|
||||||
painter.draw_rect(enclosing_int_rect(image_rect_to_editor_rect(m_active_layer->relative_rect())).inflated(2, 2), Color::Black);
|
painter.draw_rect(enclosing_int_rect(image_rect_to_editor_rect(m_active_layer->relative_rect())).inflated(2, 2), Color::Black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_selection.is_empty())
|
||||||
|
m_selection.paint(painter, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::FloatRect ImageEditor::layer_rect_to_editor_rect(Layer const& layer, Gfx::IntRect const& layer_rect) const
|
Gfx::FloatRect ImageEditor::layer_rect_to_editor_rect(Layer const& layer, Gfx::IntRect const& layer_rect) const
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
#include "Selection.h"
|
||||||
#include <LibGUI/Frame.h>
|
#include <LibGUI/Frame.h>
|
||||||
#include <LibGUI/UndoStack.h>
|
#include <LibGUI/UndoStack.h>
|
||||||
#include <LibGfx/Point.h>
|
#include <LibGfx/Point.h>
|
||||||
|
@ -53,6 +54,9 @@ public:
|
||||||
Color secondary_color() const { return m_secondary_color; }
|
Color secondary_color() const { return m_secondary_color; }
|
||||||
void set_secondary_color(Color);
|
void set_secondary_color(Color);
|
||||||
|
|
||||||
|
Selection& selection() { return m_selection; }
|
||||||
|
Selection const& selection() const { return m_selection; }
|
||||||
|
|
||||||
Color color_for(GUI::MouseEvent const&) const;
|
Color color_for(GUI::MouseEvent const&) const;
|
||||||
Color color_for(GUI::MouseButton) const;
|
Color color_for(GUI::MouseButton) const;
|
||||||
|
|
||||||
|
@ -105,6 +109,8 @@ private:
|
||||||
Gfx::FloatPoint m_pan_origin;
|
Gfx::FloatPoint m_pan_origin;
|
||||||
Gfx::FloatPoint m_saved_pan_origin;
|
Gfx::FloatPoint m_saved_pan_origin;
|
||||||
Gfx::IntPoint m_click_position;
|
Gfx::IntPoint m_click_position;
|
||||||
|
|
||||||
|
Selection m_selection;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,9 @@ void RectangleSelectTool::on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&
|
||||||
|
|
||||||
m_selecting = false;
|
m_selecting = false;
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
|
|
||||||
|
auto rect_in_image = Gfx::IntRect::from_two_points(m_selection_start, m_selection_end);
|
||||||
|
m_editor->selection().set(rect_in_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectangleSelectTool::draw_marching_ants(Gfx::Painter& painter, Gfx::IntRect const& rect) const
|
void RectangleSelectTool::draw_marching_ants(Gfx::Painter& painter, Gfx::IntRect const& rect) const
|
||||||
|
|
18
Userland/Applications/PixelPaint/Selection.cpp
Normal file
18
Userland/Applications/PixelPaint/Selection.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Selection.h"
|
||||||
|
#include "ImageEditor.h"
|
||||||
|
#include <LibGfx/Painter.h>
|
||||||
|
|
||||||
|
namespace PixelPaint {
|
||||||
|
|
||||||
|
void Selection::paint(Gfx::Painter& painter, ImageEditor const& editor)
|
||||||
|
{
|
||||||
|
painter.draw_rect(editor.image_rect_to_editor_rect(m_rect).to_type<int>(), Color::Magenta);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
Userland/Applications/PixelPaint/Selection.h
Normal file
30
Userland/Applications/PixelPaint/Selection.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGfx/Rect.h>
|
||||||
|
|
||||||
|
namespace PixelPaint {
|
||||||
|
|
||||||
|
class ImageEditor;
|
||||||
|
|
||||||
|
// Coordinates are image-relative.
|
||||||
|
class Selection {
|
||||||
|
public:
|
||||||
|
Selection() { }
|
||||||
|
|
||||||
|
bool is_empty() const { return m_rect.is_empty(); }
|
||||||
|
void clear() { m_rect = {}; }
|
||||||
|
void set(Gfx::IntRect const& rect) { m_rect = rect; }
|
||||||
|
|
||||||
|
void paint(Gfx::Painter&, ImageEditor const&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Gfx::IntRect m_rect;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue