summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-16 13:58:02 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-16 13:58:02 +0200
commitf61549ca5fdf8101535fbcaea3f830b372416303 (patch)
tree1eb3d4c5472397c43bb0010b013082e8f10fb9b7
parent952f334de75285295cdc16ad683bff0eb9bdf8d9 (diff)
downloadserenity-f61549ca5fdf8101535fbcaea3f830b372416303.zip
Make better use of geometry class helpers in some places.
-rw-r--r--LibGUI/GWidget.cpp5
-rw-r--r--Servers/WindowServer/WSWindowManager.cpp3
-rw-r--r--SharedGraphics/Painter.cpp54
-rw-r--r--SharedGraphics/Rect.h5
4 files changed, 27 insertions, 40 deletions
diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp
index 289a8fe1a6..76f94d8085 100644
--- a/LibGUI/GWidget.cpp
+++ b/LibGUI/GWidget.cpp
@@ -108,10 +108,7 @@ void GWidget::handle_paint_event(GPaintEvent& event)
if (!child->is_visible())
continue;
if (child->relative_rect().intersects(event.rect())) {
- auto local_rect = event.rect();
- local_rect.intersect(child->relative_rect());
- local_rect.move_by(-child->relative_rect().x(), -child->relative_rect().y());
- GPaintEvent local_event(local_rect);
+ GPaintEvent local_event(event.rect().intersected(child->relative_rect()).translated(-child->relative_position()));
child->event(local_event);
}
}
diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp
index 2e54589b0d..426b10c69c 100644
--- a/Servers/WindowServer/WSWindowManager.cpp
+++ b/Servers/WindowServer/WSWindowManager.cpp
@@ -465,11 +465,10 @@ bool WSWindowManager::process_ongoing_window_drag(const WSMouseEvent& event, WSW
return true;
}
if (event.type() == WSEvent::MouseMove) {
- Point pos = m_drag_window_origin;
#ifdef DRAG_DEBUG
dbgprintf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_drag_origin.x(), m_drag_origin.y(), event.x(), event.y());
#endif
- pos.move_by(event.x() - m_drag_origin.x(), event.y() - m_drag_origin.y());
+ Point pos = m_drag_window_origin.translated(event.position() - m_drag_origin);
m_drag_window->set_position_without_repaint(pos);
return true;
}
diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp
index 0b4c0beb45..5463b63033 100644
--- a/SharedGraphics/Painter.cpp
+++ b/SharedGraphics/Painter.cpp
@@ -23,10 +23,7 @@ Painter::~Painter()
void Painter::fill_rect_with_draw_op(const Rect& a_rect, Color color)
{
- auto rect = a_rect;
- rect.move_by(state().translation);
- rect.intersect(clip_rect());
-
+ auto rect = a_rect.translated(translation()).intersected(clip_rect());
if (rect.is_empty())
return;
@@ -47,10 +44,7 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
return;
}
- auto rect = a_rect;
- rect.move_by(state().translation);
- rect.intersect(clip_rect());
-
+ auto rect = a_rect.translated(translation()).intersected(clip_rect());
if (rect.is_empty())
return;
@@ -70,8 +64,7 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
#ifdef NO_FPU
return fill_rect(a_rect, gradient_start);
#endif
- auto rect = a_rect;
- rect.move_by(state().translation);
+ auto rect = a_rect.translated(translation());
auto clipped_rect = Rect::intersection(rect, clip_rect());
if (clipped_rect.is_empty())
return;
@@ -106,10 +99,8 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
void Painter::draw_rect(const Rect& a_rect, Color color, bool rough)
{
- Rect rect = a_rect;
- rect.move_by(state().translation);
-
- auto clipped_rect = Rect::intersection(rect, clip_rect());
+ Rect rect = a_rect.translated(translation());
+ auto clipped_rect = rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
@@ -152,9 +143,8 @@ void Painter::draw_rect(const Rect& a_rect, Color color, bool rough)
void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color color)
{
- Rect rect { p, bitmap.size() };
- rect.move_by(state().translation);
- auto clipped_rect = Rect::intersection(rect, clip_rect());
+ auto rect = Rect(p, bitmap.size()).translated(translation());
+ auto clipped_rect = rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
const int first_row = clipped_rect.top() - rect.top();
@@ -179,9 +169,8 @@ void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color c
void Painter::draw_bitmap(const Point& p, const GlyphBitmap& bitmap, Color color)
{
- Rect dst_rect { p, bitmap.size() };
- dst_rect.move_by(state().translation);
- auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
+ auto dst_rect = Rect(p, bitmap.size()).translated(translation());
+ auto clipped_rect = dst_rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
const int first_row = clipped_rect.top() - dst_rect.top();
@@ -240,10 +229,9 @@ void Painter::blit_with_opacity(const Point& position, const GraphicsBitmap& sou
void Painter::blit_dimmed(const Point& position, const GraphicsBitmap& source, const Rect& src_rect)
{
- Rect safe_src_rect = Rect::intersection(src_rect, source.rect());
- Rect dst_rect(position, safe_src_rect.size());
- dst_rect.move_by(state().translation);
- auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
+ Rect safe_src_rect = src_rect.intersected(source.rect());
+ auto dst_rect = Rect(position, safe_src_rect.size()).translated(translation());
+ auto clipped_rect = dst_rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
const int first_row = clipped_rect.top() - dst_rect.top();
@@ -274,10 +262,9 @@ void Painter::blit_dimmed(const Point& position, const GraphicsBitmap& source, c
void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& source, const Rect& src_rect)
{
ASSERT(source.has_alpha_channel());
- Rect safe_src_rect = Rect::intersection(src_rect, source.rect());
- Rect dst_rect(position, safe_src_rect.size());
- dst_rect.move_by(state().translation);
- auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
+ Rect safe_src_rect = src_rect.intersected(source.rect());
+ auto dst_rect = Rect(position, safe_src_rect.size()).translated(translation());
+ auto clipped_rect = dst_rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
const int first_row = clipped_rect.top() - dst_rect.top();
@@ -310,11 +297,10 @@ void Painter::blit(const Point& position, const GraphicsBitmap& source, const Re
return blit_with_opacity(position, source, src_rect, opacity);
if (source.has_alpha_channel())
return blit_with_alpha(position, source, src_rect);
- auto safe_src_rect = Rect::intersection(src_rect, source.rect());
+ auto safe_src_rect = src_rect.intersected(source.rect());
ASSERT(source.rect().contains(safe_src_rect));
- Rect dst_rect(position, safe_src_rect.size());
- dst_rect.move_by(state().translation);
- auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
+ auto dst_rect = Rect(position, safe_src_rect.size()).translated(translation());
+ auto clipped_rect = dst_rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
const int first_row = clipped_rect.top() - dst_rect.top();
@@ -338,10 +324,10 @@ void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& s
if (dst_rect.size() == src_rect.size())
return blit(dst_rect.location(), source, src_rect);
- auto safe_src_rect = Rect::intersection(src_rect, source.rect());
+ auto safe_src_rect = src_rect.intersected(source.rect());
ASSERT(source.rect().contains(safe_src_rect));
dst_rect.move_by(state().translation);
- auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
+ auto clipped_rect = dst_rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
diff --git a/SharedGraphics/Rect.h b/SharedGraphics/Rect.h
index 6ba9741369..7c7ce72be2 100644
--- a/SharedGraphics/Rect.h
+++ b/SharedGraphics/Rect.h
@@ -195,6 +195,11 @@ public:
return r;
}
+ Rect intersected(const Rect& other) const
+ {
+ return intersection(*this, other);
+ }
+
Rect united(const Rect&) const;
Point top_left() const { return { left(), top() }; }