summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-13 13:41:12 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-13 13:43:20 +0200
commit96d03546efb79f33b0bb4bd507825ad847724b02 (patch)
tree6ab36036453bedf2f96f1bd444b79f821198f5ec /Applications
parent8318842c7e5a9ec72cdd7bcb10786749bf773793 (diff)
downloadserenity-96d03546efb79f33b0bb4bd507825ad847724b02.zip
PaintBrush: Make the line, rectangle and ellipsis preview work again
You can now see what you're drawing before committing to it. This works by passing the second_paint_event from the ImageEditor to the tool. We also pass the active layer which makes it easier for the tool to keep his logic in layer-relative coordinates even while drawing preview states directly into the ImageEditor backing bitmap.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/PaintBrush/EllipseTool.cpp3
-rw-r--r--Applications/PaintBrush/EllipseTool.h2
-rw-r--r--Applications/PaintBrush/ImageEditor.cpp6
-rw-r--r--Applications/PaintBrush/ImageEditor.h1
-rw-r--r--Applications/PaintBrush/LineTool.cpp9
-rw-r--r--Applications/PaintBrush/LineTool.h2
-rw-r--r--Applications/PaintBrush/RectangleTool.cpp8
-rw-r--r--Applications/PaintBrush/RectangleTool.h4
-rw-r--r--Applications/PaintBrush/Tool.h2
9 files changed, 20 insertions, 17 deletions
diff --git a/Applications/PaintBrush/EllipseTool.cpp b/Applications/PaintBrush/EllipseTool.cpp
index 462ffb20af..00c90700fd 100644
--- a/Applications/PaintBrush/EllipseTool.cpp
+++ b/Applications/PaintBrush/EllipseTool.cpp
@@ -91,13 +91,14 @@ void EllipseTool::on_mousemove(Layer& layer, GUI::MouseEvent& event, GUI::MouseE
m_editor->update();
}
-void EllipseTool::on_second_paint(GUI::PaintEvent& event)
+void EllipseTool::on_second_paint(const Layer& layer, GUI::PaintEvent& event)
{
if (m_drawing_button == GUI::MouseButton::None)
return;
GUI::Painter painter(*m_editor);
painter.add_clip_rect(event.rect());
+ painter.translate(layer.location());
draw_using(painter);
}
diff --git a/Applications/PaintBrush/EllipseTool.h b/Applications/PaintBrush/EllipseTool.h
index 3223404c91..e3a4a47b96 100644
--- a/Applications/PaintBrush/EllipseTool.h
+++ b/Applications/PaintBrush/EllipseTool.h
@@ -41,7 +41,7 @@ public:
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override;
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override;
virtual void on_contextmenu(GUI::ContextMenuEvent&) override;
- virtual void on_second_paint(GUI::PaintEvent&) override;
+ virtual void on_second_paint(const Layer&, GUI::PaintEvent&) override;
virtual void on_keydown(GUI::KeyEvent&) override;
private:
diff --git a/Applications/PaintBrush/ImageEditor.cpp b/Applications/PaintBrush/ImageEditor.cpp
index b283d73088..4124108a96 100644
--- a/Applications/PaintBrush/ImageEditor.cpp
+++ b/Applications/PaintBrush/ImageEditor.cpp
@@ -62,6 +62,12 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
}
}
+void ImageEditor::second_paint_event(GUI::PaintEvent& event)
+{
+ if (m_active_tool && m_active_layer)
+ m_active_tool->on_second_paint(*m_active_layer, event);
+}
+
static GUI::MouseEvent event_adjusted_for_layer(const GUI::MouseEvent& original_event, const Layer& layer)
{
auto position_in_active_layer_coordinates = original_event.position().translated(-layer.location());
diff --git a/Applications/PaintBrush/ImageEditor.h b/Applications/PaintBrush/ImageEditor.h
index aee01cbfd0..1ce0fd8f13 100644
--- a/Applications/PaintBrush/ImageEditor.h
+++ b/Applications/PaintBrush/ImageEditor.h
@@ -69,6 +69,7 @@ private:
virtual bool accepts_focus() const override { return true; }
virtual void paint_event(GUI::PaintEvent&) override;
+ virtual void second_paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void mouseup_event(GUI::MouseEvent&) override;
diff --git a/Applications/PaintBrush/LineTool.cpp b/Applications/PaintBrush/LineTool.cpp
index 3e7636b459..d098ab3bc0 100644
--- a/Applications/PaintBrush/LineTool.cpp
+++ b/Applications/PaintBrush/LineTool.cpp
@@ -96,18 +96,15 @@ void LineTool::on_mousemove(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
m_editor->update();
}
-void LineTool::on_second_paint(GUI::PaintEvent& event)
+void LineTool::on_second_paint(const Layer& layer, GUI::PaintEvent& event)
{
if (m_drawing_button == GUI::MouseButton::None)
return;
- (void)event;
-
-#if 0
- GUI::Painter painter(*m_widget);
+ 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);
-#endif
}
void LineTool::on_keydown(GUI::KeyEvent& event)
diff --git a/Applications/PaintBrush/LineTool.h b/Applications/PaintBrush/LineTool.h
index ad64e4c1e2..0d5c0a683b 100644
--- a/Applications/PaintBrush/LineTool.h
+++ b/Applications/PaintBrush/LineTool.h
@@ -41,7 +41,7 @@ public:
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override;
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override;
virtual void on_contextmenu(GUI::ContextMenuEvent&) override;
- virtual void on_second_paint(GUI::PaintEvent&) override;
+ virtual void on_second_paint(const Layer&, GUI::PaintEvent&) override;
virtual void on_keydown(GUI::KeyEvent&) override;
virtual void on_keyup(GUI::KeyEvent&) override;
diff --git a/Applications/PaintBrush/RectangleTool.cpp b/Applications/PaintBrush/RectangleTool.cpp
index da6282f51a..171e20896c 100644
--- a/Applications/PaintBrush/RectangleTool.cpp
+++ b/Applications/PaintBrush/RectangleTool.cpp
@@ -97,17 +97,15 @@ void RectangleTool::on_mousemove(Layer&, GUI::MouseEvent& event, GUI::MouseEvent
m_editor->update();
}
-void RectangleTool::on_second_paint(GUI::PaintEvent& event)
+void RectangleTool::on_second_paint(const Layer& layer, GUI::PaintEvent& event)
{
if (m_drawing_button == GUI::MouseButton::None)
return;
- (void)event;
-#if 0
- GUI::Painter painter(*m_widget);
+ GUI::Painter painter(*m_editor);
painter.add_clip_rect(event.rect());
+ painter.translate(layer.location());
draw_using(painter);
-#endif
}
void RectangleTool::on_keydown(GUI::KeyEvent& event)
diff --git a/Applications/PaintBrush/RectangleTool.h b/Applications/PaintBrush/RectangleTool.h
index a34e3386b9..ce0e7039da 100644
--- a/Applications/PaintBrush/RectangleTool.h
+++ b/Applications/PaintBrush/RectangleTool.h
@@ -41,7 +41,7 @@ public:
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override;
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override;
virtual void on_contextmenu(GUI::ContextMenuEvent&) override;
- virtual void on_second_paint(GUI::PaintEvent&) override;
+ virtual void on_second_paint(const Layer&, GUI::PaintEvent&) override;
virtual void on_keydown(GUI::KeyEvent&) override;
private:
@@ -52,7 +52,7 @@ private:
};
virtual const char* class_name() const override { return "RectangleTool"; }
- void draw_using(GUI::Painter& painter);
+ void draw_using(GUI::Painter&);
GUI::MouseButton m_drawing_button { GUI::MouseButton::None };
Gfx::Point m_rectangle_start_position;
diff --git a/Applications/PaintBrush/Tool.h b/Applications/PaintBrush/Tool.h
index ddb4ce5315..e76e825a84 100644
--- a/Applications/PaintBrush/Tool.h
+++ b/Applications/PaintBrush/Tool.h
@@ -43,7 +43,7 @@ public:
virtual void on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) {}
virtual void on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) {}
virtual void on_contextmenu(GUI::ContextMenuEvent&) {}
- virtual void on_second_paint(GUI::PaintEvent&) {}
+ virtual void on_second_paint(const Layer&, GUI::PaintEvent&) {}
virtual void on_keydown(GUI::KeyEvent&) {}
virtual void on_keyup(GUI::KeyEvent&) {}