mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
PixelPaint: Make the LineTool previews work while zoomed in
This commit is contained in:
parent
53b859c5ad
commit
f57df29724
4 changed files with 31 additions and 15 deletions
|
@ -65,6 +65,11 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
Gfx::FloatRect ImageEditor::layer_rect_to_editor_rect(const Layer& layer, const Gfx::Rect& layer_rect) const
|
||||
{
|
||||
return image_rect_to_editor_rect(layer_rect.translated(layer.location()));
|
||||
}
|
||||
|
||||
Gfx::FloatRect ImageEditor::image_rect_to_editor_rect(const Gfx::Rect& image_rect) const
|
||||
{
|
||||
Gfx::FloatRect editor_rect;
|
||||
|
@ -83,6 +88,11 @@ Gfx::FloatRect ImageEditor::editor_rect_to_image_rect(const Gfx::Rect& editor_re
|
|||
return image_rect;
|
||||
}
|
||||
|
||||
Gfx::FloatPoint ImageEditor::layer_position_to_editor_position(const Layer& layer, const Gfx::Point& layer_position) const
|
||||
{
|
||||
return image_position_to_editor_position(layer_position.translated(layer.location()));
|
||||
}
|
||||
|
||||
Gfx::FloatPoint ImageEditor::image_position_to_editor_position(const Gfx::Point& image_position) const
|
||||
{
|
||||
Gfx::FloatPoint editor_position;
|
||||
|
|
|
@ -68,6 +68,13 @@ public:
|
|||
|
||||
Function<void(const GUI::ModelIndex&)> on_active_layer_change;
|
||||
|
||||
Gfx::FloatRect layer_rect_to_editor_rect(const Layer&, const Gfx::Rect&) const;
|
||||
Gfx::FloatRect image_rect_to_editor_rect(const Gfx::Rect&) const;
|
||||
Gfx::FloatRect editor_rect_to_image_rect(const Gfx::Rect&) const;
|
||||
Gfx::FloatPoint layer_position_to_editor_position(const Layer&, const Gfx::Point&) const;
|
||||
Gfx::FloatPoint image_position_to_editor_position(const Gfx::Point&) const;
|
||||
Gfx::FloatPoint editor_position_to_image_position(const Gfx::Point&) const;
|
||||
|
||||
private:
|
||||
ImageEditor();
|
||||
|
||||
|
@ -84,11 +91,6 @@ private:
|
|||
virtual void context_menu_event(GUI::ContextMenuEvent&) override;
|
||||
virtual void resize_event(GUI::ResizeEvent&) override;
|
||||
|
||||
Gfx::FloatRect image_rect_to_editor_rect(const Gfx::Rect&) const;
|
||||
Gfx::FloatRect editor_rect_to_image_rect(const Gfx::Rect&) const;
|
||||
Gfx::FloatPoint image_position_to_editor_position(const Gfx::Point&) const;
|
||||
Gfx::FloatPoint editor_position_to_image_position(const Gfx::Point&) const;
|
||||
|
||||
GUI::MouseEvent event_adjusted_for_layer(const GUI::MouseEvent&, const Layer&) const;
|
||||
GUI::MouseEvent event_with_pan_and_scale_applied(const GUI::MouseEvent&) const;
|
||||
|
||||
|
|
|
@ -55,17 +55,19 @@ LineTool::~LineTool()
|
|||
{
|
||||
}
|
||||
|
||||
void LineTool::on_mousedown(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
|
||||
void LineTool::on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent&)
|
||||
{
|
||||
if (event.button() != GUI::MouseButton::Left && event.button() != GUI::MouseButton::Right)
|
||||
if (layer_event.button() != GUI::MouseButton::Left && layer_event.button() != GUI::MouseButton::Right)
|
||||
return;
|
||||
|
||||
if (m_drawing_button != GUI::MouseButton::None)
|
||||
return;
|
||||
|
||||
m_drawing_button = event.button();
|
||||
m_line_start_position = event.position();
|
||||
m_line_end_position = event.position();
|
||||
m_drawing_button = layer_event.button();
|
||||
|
||||
m_line_start_position = layer_event.position();
|
||||
m_line_end_position = layer_event.position();
|
||||
|
||||
m_editor->update();
|
||||
}
|
||||
|
||||
|
@ -79,16 +81,16 @@ void LineTool::on_mouseup(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent&
|
|||
}
|
||||
}
|
||||
|
||||
void LineTool::on_mousemove(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
|
||||
void LineTool::on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent&)
|
||||
{
|
||||
if (m_drawing_button == GUI::MouseButton::None)
|
||||
return;
|
||||
|
||||
if (!m_constrain_angle) {
|
||||
m_line_end_position = event.position();
|
||||
m_line_end_position = layer_event.position();
|
||||
} else {
|
||||
const float ANGLE_STEP = M_PI / 8.0f;
|
||||
m_line_end_position = constrain_line_angle(m_line_start_position, event.position(), ANGLE_STEP);
|
||||
m_line_end_position = constrain_line_angle(m_line_start_position, layer_event.position(), ANGLE_STEP);
|
||||
}
|
||||
m_editor->update();
|
||||
}
|
||||
|
@ -100,8 +102,9 @@ void LineTool::on_second_paint(const Layer& layer, GUI::PaintEvent& event)
|
|||
|
||||
GUI::Painter painter(*m_editor);
|
||||
painter.add_clip_rect(event.rect());
|
||||
painter.translate(layer.location());
|
||||
painter.draw_line(m_line_start_position, m_line_end_position, m_editor->color_for(m_drawing_button), m_thickness);
|
||||
auto preview_start = m_editor->layer_position_to_editor_position(layer, m_line_start_position).to_int_point();
|
||||
auto preview_end = m_editor->layer_position_to_editor_position(layer, m_line_end_position).to_int_point();
|
||||
painter.draw_line(preview_start, preview_end, m_editor->color_for(m_drawing_button), m_thickness);
|
||||
}
|
||||
|
||||
void LineTool::on_keydown(GUI::KeyEvent& event)
|
||||
|
|
|
@ -51,6 +51,7 @@ private:
|
|||
GUI::MouseButton m_drawing_button { GUI::MouseButton::None };
|
||||
Gfx::Point m_line_start_position;
|
||||
Gfx::Point m_line_end_position;
|
||||
|
||||
RefPtr<GUI::Menu> m_context_menu;
|
||||
GUI::ActionGroup m_thickness_actions;
|
||||
int m_thickness { 1 };
|
||||
|
|
Loading…
Add table
Reference in a new issue