mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
Make better use of geometry class helpers in some places.
This commit is contained in:
parent
952f334de7
commit
f61549ca5f
4 changed files with 27 additions and 40 deletions
|
@ -108,10 +108,7 @@ void GWidget::handle_paint_event(GPaintEvent& event)
|
||||||
if (!child->is_visible())
|
if (!child->is_visible())
|
||||||
continue;
|
continue;
|
||||||
if (child->relative_rect().intersects(event.rect())) {
|
if (child->relative_rect().intersects(event.rect())) {
|
||||||
auto local_rect = event.rect();
|
GPaintEvent local_event(event.rect().intersected(child->relative_rect()).translated(-child->relative_position()));
|
||||||
local_rect.intersect(child->relative_rect());
|
|
||||||
local_rect.move_by(-child->relative_rect().x(), -child->relative_rect().y());
|
|
||||||
GPaintEvent local_event(local_rect);
|
|
||||||
child->event(local_event);
|
child->event(local_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,11 +465,10 @@ bool WSWindowManager::process_ongoing_window_drag(const WSMouseEvent& event, WSW
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (event.type() == WSEvent::MouseMove) {
|
if (event.type() == WSEvent::MouseMove) {
|
||||||
Point pos = m_drag_window_origin;
|
|
||||||
#ifdef DRAG_DEBUG
|
#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());
|
dbgprintf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_drag_origin.x(), m_drag_origin.y(), event.x(), event.y());
|
||||||
#endif
|
#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);
|
m_drag_window->set_position_without_repaint(pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,7 @@ Painter::~Painter()
|
||||||
|
|
||||||
void Painter::fill_rect_with_draw_op(const Rect& a_rect, Color color)
|
void Painter::fill_rect_with_draw_op(const Rect& a_rect, Color color)
|
||||||
{
|
{
|
||||||
auto rect = a_rect;
|
auto rect = a_rect.translated(translation()).intersected(clip_rect());
|
||||||
rect.move_by(state().translation);
|
|
||||||
rect.intersect(clip_rect());
|
|
||||||
|
|
||||||
if (rect.is_empty())
|
if (rect.is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -47,10 +44,7 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rect = a_rect;
|
auto rect = a_rect.translated(translation()).intersected(clip_rect());
|
||||||
rect.move_by(state().translation);
|
|
||||||
rect.intersect(clip_rect());
|
|
||||||
|
|
||||||
if (rect.is_empty())
|
if (rect.is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -70,8 +64,7 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
|
||||||
#ifdef NO_FPU
|
#ifdef NO_FPU
|
||||||
return fill_rect(a_rect, gradient_start);
|
return fill_rect(a_rect, gradient_start);
|
||||||
#endif
|
#endif
|
||||||
auto rect = a_rect;
|
auto rect = a_rect.translated(translation());
|
||||||
rect.move_by(state().translation);
|
|
||||||
auto clipped_rect = Rect::intersection(rect, clip_rect());
|
auto clipped_rect = Rect::intersection(rect, clip_rect());
|
||||||
if (clipped_rect.is_empty())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
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)
|
void Painter::draw_rect(const Rect& a_rect, Color color, bool rough)
|
||||||
{
|
{
|
||||||
Rect rect = a_rect;
|
Rect rect = a_rect.translated(translation());
|
||||||
rect.move_by(state().translation);
|
auto clipped_rect = rect.intersected(clip_rect());
|
||||||
|
|
||||||
auto clipped_rect = Rect::intersection(rect, clip_rect());
|
|
||||||
if (clipped_rect.is_empty())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
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)
|
void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color color)
|
||||||
{
|
{
|
||||||
Rect rect { p, bitmap.size() };
|
auto rect = Rect(p, bitmap.size()).translated(translation());
|
||||||
rect.move_by(state().translation);
|
auto clipped_rect = rect.intersected(clip_rect());
|
||||||
auto clipped_rect = Rect::intersection(rect, clip_rect());
|
|
||||||
if (clipped_rect.is_empty())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
return;
|
||||||
const int first_row = clipped_rect.top() - rect.top();
|
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)
|
void Painter::draw_bitmap(const Point& p, const GlyphBitmap& bitmap, Color color)
|
||||||
{
|
{
|
||||||
Rect dst_rect { p, bitmap.size() };
|
auto dst_rect = Rect(p, bitmap.size()).translated(translation());
|
||||||
dst_rect.move_by(state().translation);
|
auto clipped_rect = dst_rect.intersected(clip_rect());
|
||||||
auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
|
|
||||||
if (clipped_rect.is_empty())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
return;
|
||||||
const int first_row = clipped_rect.top() - dst_rect.top();
|
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)
|
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 safe_src_rect = src_rect.intersected(source.rect());
|
||||||
Rect dst_rect(position, safe_src_rect.size());
|
auto dst_rect = Rect(position, safe_src_rect.size()).translated(translation());
|
||||||
dst_rect.move_by(state().translation);
|
auto clipped_rect = dst_rect.intersected(clip_rect());
|
||||||
auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
|
|
||||||
if (clipped_rect.is_empty())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
return;
|
||||||
const int first_row = clipped_rect.top() - dst_rect.top();
|
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)
|
void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& source, const Rect& src_rect)
|
||||||
{
|
{
|
||||||
ASSERT(source.has_alpha_channel());
|
ASSERT(source.has_alpha_channel());
|
||||||
Rect safe_src_rect = Rect::intersection(src_rect, source.rect());
|
Rect safe_src_rect = src_rect.intersected(source.rect());
|
||||||
Rect dst_rect(position, safe_src_rect.size());
|
auto dst_rect = Rect(position, safe_src_rect.size()).translated(translation());
|
||||||
dst_rect.move_by(state().translation);
|
auto clipped_rect = dst_rect.intersected(clip_rect());
|
||||||
auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
|
|
||||||
if (clipped_rect.is_empty())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
return;
|
||||||
const int first_row = clipped_rect.top() - dst_rect.top();
|
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);
|
return blit_with_opacity(position, source, src_rect, opacity);
|
||||||
if (source.has_alpha_channel())
|
if (source.has_alpha_channel())
|
||||||
return blit_with_alpha(position, source, src_rect);
|
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));
|
ASSERT(source.rect().contains(safe_src_rect));
|
||||||
Rect dst_rect(position, safe_src_rect.size());
|
auto dst_rect = Rect(position, safe_src_rect.size()).translated(translation());
|
||||||
dst_rect.move_by(state().translation);
|
auto clipped_rect = dst_rect.intersected(clip_rect());
|
||||||
auto clipped_rect = Rect::intersection(dst_rect, clip_rect());
|
|
||||||
if (clipped_rect.is_empty())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
return;
|
||||||
const int first_row = clipped_rect.top() - dst_rect.top();
|
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())
|
if (dst_rect.size() == src_rect.size())
|
||||||
return blit(dst_rect.location(), source, src_rect);
|
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));
|
ASSERT(source.rect().contains(safe_src_rect));
|
||||||
dst_rect.move_by(state().translation);
|
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())
|
if (clipped_rect.is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,11 @@ public:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect intersected(const Rect& other) const
|
||||||
|
{
|
||||||
|
return intersection(*this, other);
|
||||||
|
}
|
||||||
|
|
||||||
Rect united(const Rect&) const;
|
Rect united(const Rect&) const;
|
||||||
|
|
||||||
Point top_left() const { return { left(), top() }; }
|
Point top_left() const { return { left(), top() }; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue