mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
PixelPaint: Include Guides in the ImageEditor
The ImageEditor knows about its Guides, how to draw them and exposes ways to manipulate them.
This commit is contained in:
parent
7e01d06226
commit
a717caa4b7
2 changed files with 21 additions and 1 deletions
|
@ -83,6 +83,16 @@ 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);
|
painter.draw_rect(enclosing_int_rect(image_rect_to_editor_rect(m_active_layer->relative_rect())).inflated(2, 2), Color::Black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& guide : m_guides) {
|
||||||
|
if (guide.orientation() == Guide::Orientation::Horizontal) {
|
||||||
|
int y_coordinate = (int)image_position_to_editor_position({ 0.0f, guide.offset() }).y();
|
||||||
|
painter.draw_line({ 0, y_coordinate }, { rect().width(), y_coordinate }, Color::Cyan, 1, Gfx::Painter::LineStyle::Dashed, Color::LightGray);
|
||||||
|
} else if (guide.orientation() == Guide::Orientation::Vertical) {
|
||||||
|
int x_coordinate = (int)image_position_to_editor_position({ guide.offset(), 0.0f }).x();
|
||||||
|
painter.draw_line({ x_coordinate, 0 }, { x_coordinate, rect().height() }, Color::Cyan, 1, Gfx::Painter::LineStyle::Dashed, Color::LightGray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_selection.is_empty())
|
if (!m_selection.is_empty())
|
||||||
m_selection.paint(painter);
|
m_selection.paint(painter);
|
||||||
}
|
}
|
||||||
|
@ -424,5 +434,4 @@ void ImageEditor::image_select_layer(Layer* layer)
|
||||||
{
|
{
|
||||||
set_active_layer(layer);
|
set_active_layer(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Guide.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "Selection.h"
|
#include "Selection.h"
|
||||||
#include <LibGUI/Frame.h>
|
#include <LibGUI/Frame.h>
|
||||||
|
@ -38,6 +39,12 @@ public:
|
||||||
bool undo();
|
bool undo();
|
||||||
bool redo();
|
bool redo();
|
||||||
|
|
||||||
|
void add_guide(NonnullRefPtr<Guide> guide) { m_guides.append(guide); }
|
||||||
|
void remove_guide(Guide const& guide)
|
||||||
|
{
|
||||||
|
m_guides.remove_first_matching([&](auto& entry) { return &guide == entry.ptr(); });
|
||||||
|
}
|
||||||
|
|
||||||
void layers_did_change();
|
void layers_did_change();
|
||||||
|
|
||||||
Layer* layer_at_editor_position(Gfx::IntPoint const&);
|
Layer* layer_at_editor_position(Gfx::IntPoint const&);
|
||||||
|
@ -77,6 +84,8 @@ public:
|
||||||
Gfx::FloatPoint image_position_to_editor_position(Gfx::IntPoint const&) const;
|
Gfx::FloatPoint image_position_to_editor_position(Gfx::IntPoint const&) const;
|
||||||
Gfx::FloatPoint editor_position_to_image_position(Gfx::IntPoint const&) const;
|
Gfx::FloatPoint editor_position_to_image_position(Gfx::IntPoint const&) const;
|
||||||
|
|
||||||
|
NonnullRefPtrVector<Guide> const& guides() const { return m_guides; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ImageEditor(NonnullRefPtr<Image>);
|
explicit ImageEditor(NonnullRefPtr<Image>);
|
||||||
|
|
||||||
|
@ -106,6 +115,8 @@ private:
|
||||||
RefPtr<Layer> m_active_layer;
|
RefPtr<Layer> m_active_layer;
|
||||||
OwnPtr<GUI::UndoStack> m_undo_stack;
|
OwnPtr<GUI::UndoStack> m_undo_stack;
|
||||||
|
|
||||||
|
NonnullRefPtrVector<Guide> m_guides;
|
||||||
|
|
||||||
Tool* m_active_tool { nullptr };
|
Tool* m_active_tool { nullptr };
|
||||||
|
|
||||||
Color m_primary_color { Color::Black };
|
Color m_primary_color { Color::Black };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue