1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

Make better use of geometry class helpers in some places.

This commit is contained in:
Andreas Kling 2019-04-16 13:58:02 +02:00
parent 952f334de7
commit f61549ca5f
4 changed files with 27 additions and 40 deletions

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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() }; }