mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
SharedGraphics: Add PainterStateSaver RAII helper and Point::operator-().
Two little things to help tidy up a bit in WSWindowManager.
This commit is contained in:
parent
3c2139b824
commit
88f6ce152f
3 changed files with 22 additions and 7 deletions
|
@ -80,3 +80,20 @@ private:
|
|||
Retained<GraphicsBitmap> m_target;
|
||||
Vector<State> m_state_stack;
|
||||
};
|
||||
|
||||
class PainterStateSaver {
|
||||
public:
|
||||
PainterStateSaver(Painter& painter)
|
||||
: m_painter(painter)
|
||||
{
|
||||
m_painter.save();
|
||||
}
|
||||
|
||||
~PainterStateSaver()
|
||||
{
|
||||
m_painter.restore();
|
||||
}
|
||||
|
||||
private:
|
||||
Painter& m_painter;
|
||||
};
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
return !(*this == other);
|
||||
}
|
||||
|
||||
Point operator-() const { return { -m_x, -m_y }; }
|
||||
|
||||
operator WSAPI_Point() const;
|
||||
String to_string() const { return String::format("[%d,%d]", x(), y()); }
|
||||
|
||||
|
|
|
@ -876,24 +876,20 @@ void WSWindowManager::compose()
|
|||
if (!any_dirty_rect_intersects_window(window))
|
||||
return;
|
||||
for (auto& dirty_rect : dirty_rects.rects()) {
|
||||
PainterStateSaver saver(*m_back_painter);
|
||||
m_back_painter->set_clip_rect(dirty_rect);
|
||||
paint_window_frame(window);
|
||||
Rect dirty_rect_in_window_coordinates = Rect::intersection(dirty_rect, window.rect());
|
||||
if (dirty_rect_in_window_coordinates.is_empty()) {
|
||||
m_back_painter->clear_clip_rect();
|
||||
if (dirty_rect_in_window_coordinates.is_empty())
|
||||
continue;
|
||||
}
|
||||
dirty_rect_in_window_coordinates.set_x(dirty_rect_in_window_coordinates.x() - window.x());
|
||||
dirty_rect_in_window_coordinates.set_y(dirty_rect_in_window_coordinates.y() - window.y());
|
||||
dirty_rect_in_window_coordinates.move_by(-window.position());
|
||||
auto dst = window.position();
|
||||
dst.move_by(dirty_rect_in_window_coordinates.location());
|
||||
if (window.opacity() == 1.0f)
|
||||
m_back_painter->blit(dst, *backing_store, dirty_rect_in_window_coordinates);
|
||||
else
|
||||
m_back_painter->blit_with_opacity(dst, *backing_store, dirty_rect_in_window_coordinates, window.opacity());
|
||||
m_back_painter->clear_clip_rect();
|
||||
}
|
||||
m_back_painter->clear_clip_rect();
|
||||
};
|
||||
|
||||
for_each_visible_window_from_back_to_front([&] (WSWindow& window) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue