summaryrefslogtreecommitdiff
path: root/Applications/PixelPaint
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-22 14:45:14 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-22 14:45:14 +0200
commitf57df29724ffbba9a97de1cca902c0b52dc5e5cb (patch)
tree21861a08f1ab722b37a39af278097582ef74bbb3 /Applications/PixelPaint
parent53b859c5ad7567d7eb7240c71fc75c26961586ca (diff)
downloadserenity-f57df29724ffbba9a97de1cca902c0b52dc5e5cb.zip
PixelPaint: Make the LineTool previews work while zoomed in
Diffstat (limited to 'Applications/PixelPaint')
-rw-r--r--Applications/PixelPaint/ImageEditor.cpp10
-rw-r--r--Applications/PixelPaint/ImageEditor.h12
-rw-r--r--Applications/PixelPaint/LineTool.cpp23
-rw-r--r--Applications/PixelPaint/LineTool.h1
4 files changed, 31 insertions, 15 deletions
diff --git a/Applications/PixelPaint/ImageEditor.cpp b/Applications/PixelPaint/ImageEditor.cpp
index 9c27fc438f..4d82ad0015 100644
--- a/Applications/PixelPaint/ImageEditor.cpp
+++ b/Applications/PixelPaint/ImageEditor.cpp
@@ -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;
diff --git a/Applications/PixelPaint/ImageEditor.h b/Applications/PixelPaint/ImageEditor.h
index fbd6050983..e9f9b9c182 100644
--- a/Applications/PixelPaint/ImageEditor.h
+++ b/Applications/PixelPaint/ImageEditor.h
@@ -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;
diff --git a/Applications/PixelPaint/LineTool.cpp b/Applications/PixelPaint/LineTool.cpp
index 2d1d34387a..04b14b8a46 100644
--- a/Applications/PixelPaint/LineTool.cpp
+++ b/Applications/PixelPaint/LineTool.cpp
@@ -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)
diff --git a/Applications/PixelPaint/LineTool.h b/Applications/PixelPaint/LineTool.h
index 306e3e1e5c..df165ecb93 100644
--- a/Applications/PixelPaint/LineTool.h
+++ b/Applications/PixelPaint/LineTool.h
@@ -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 };