From 9566f6c8b3362c1b8d8594119b1bfa7fd195be35 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 12 May 2020 23:49:52 +0200 Subject: [PATCH] PaintBrush: Let's have Layer::rect() and Layer::relative_rect() These two have the same semantics as GUI::Widget. The rect() is always at location { 0, 0 }, while the relative_rect()'s location is relative to the "parent", which in this case is the Layer's Image. --- Applications/PaintBrush/ImageEditor.cpp | 3 +-- Applications/PaintBrush/Layer.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Applications/PaintBrush/ImageEditor.cpp b/Applications/PaintBrush/ImageEditor.cpp index e49016a2d7..99b5f3f91d 100644 --- a/Applications/PaintBrush/ImageEditor.cpp +++ b/Applications/PaintBrush/ImageEditor.cpp @@ -58,14 +58,13 @@ void ImageEditor::paint_event(GUI::PaintEvent& event) } if (m_active_layer) { - painter.draw_rect(m_active_layer->rect().inflated(2, 2), Color::Black); + painter.draw_rect(m_active_layer->relative_rect().inflated(2, 2), Color::Black); } } 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()); - dbg() << "adjusted: " << position_in_active_layer_coordinates; return { static_cast(original_event.type()), position_in_active_layer_coordinates, original_event.buttons(), diff --git a/Applications/PaintBrush/Layer.h b/Applications/PaintBrush/Layer.h index b0fe8a142d..ab7d5e2b1f 100644 --- a/Applications/PaintBrush/Layer.h +++ b/Applications/PaintBrush/Layer.h @@ -49,7 +49,8 @@ public: Gfx::Bitmap& bitmap() { return *m_bitmap; } Gfx::Size size() const { return bitmap().size(); } - Gfx::Rect rect() const { return { location(), size() }; } + Gfx::Rect relative_rect() const { return { location(), size() }; } + Gfx::Rect rect() const { return { {}, size() }; } const String& name() const { return m_name; } void set_name(const String& name) { m_name = name; }