1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +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:
Andreas Kling 2019-03-09 16:54:41 +01:00
parent 3c2139b824
commit 88f6ce152f
3 changed files with 22 additions and 7 deletions

View file

@ -80,3 +80,20 @@ private:
Retained<GraphicsBitmap> m_target; Retained<GraphicsBitmap> m_target;
Vector<State> m_state_stack; 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;
};

View file

@ -48,6 +48,8 @@ public:
return !(*this == other); return !(*this == other);
} }
Point operator-() const { return { -m_x, -m_y }; }
operator WSAPI_Point() const; operator WSAPI_Point() const;
String to_string() const { return String::format("[%d,%d]", x(), y()); } String to_string() const { return String::format("[%d,%d]", x(), y()); }

View file

@ -876,24 +876,20 @@ void WSWindowManager::compose()
if (!any_dirty_rect_intersects_window(window)) if (!any_dirty_rect_intersects_window(window))
return; return;
for (auto& dirty_rect : dirty_rects.rects()) { for (auto& dirty_rect : dirty_rects.rects()) {
PainterStateSaver saver(*m_back_painter);
m_back_painter->set_clip_rect(dirty_rect); m_back_painter->set_clip_rect(dirty_rect);
paint_window_frame(window); paint_window_frame(window);
Rect dirty_rect_in_window_coordinates = Rect::intersection(dirty_rect, window.rect()); Rect dirty_rect_in_window_coordinates = Rect::intersection(dirty_rect, window.rect());
if (dirty_rect_in_window_coordinates.is_empty()) { if (dirty_rect_in_window_coordinates.is_empty())
m_back_painter->clear_clip_rect();
continue; continue;
} dirty_rect_in_window_coordinates.move_by(-window.position());
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());
auto dst = window.position(); auto dst = window.position();
dst.move_by(dirty_rect_in_window_coordinates.location()); dst.move_by(dirty_rect_in_window_coordinates.location());
if (window.opacity() == 1.0f) if (window.opacity() == 1.0f)
m_back_painter->blit(dst, *backing_store, dirty_rect_in_window_coordinates); m_back_painter->blit(dst, *backing_store, dirty_rect_in_window_coordinates);
else else
m_back_painter->blit_with_opacity(dst, *backing_store, dirty_rect_in_window_coordinates, window.opacity()); 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) { for_each_visible_window_from_back_to_front([&] (WSWindow& window) {