SharedGraphics: Make Painter clipping work with translated clip origin.

This commit is contained in:
Andreas Kling 2019-02-28 18:57:36 +01:00
parent 8eefdbdce8
commit fd428d6ed3
Notes: sideshowbarker 2024-07-19 15:29:12 +09:00
6 changed files with 20 additions and 9 deletions

View file

@ -181,9 +181,10 @@ Rect GScrollBar::scrubber_rect() const
return { (int)x_or_y, 0, button_size(), button_size() };
}
void GScrollBar::paint_event(GPaintEvent&)
void GScrollBar::paint_event(GPaintEvent& event)
{
Painter painter(*this);
painter.set_clip_rect(event.rect());
painter.fill_rect(rect(), Color(164, 164, 164));

View file

@ -28,9 +28,10 @@ String GStatusBar::text() const
return m_label->text();
}
void GStatusBar::paint_event(GPaintEvent&)
void GStatusBar::paint_event(GPaintEvent& event)
{
Painter painter(*this);
painter.set_clip_rect(event.rect());
painter.fill_rect({ 0, 1, width(), height() - 1 }, Color::LightGray);
painter.draw_line({ 0, 0 }, { width() - 1, 0 }, Color::DarkGray);
}

View file

@ -92,9 +92,10 @@ void GTableView::mousedown_event(GMouseEvent& event)
update();
}
void GTableView::paint_event(GPaintEvent&)
void GTableView::paint_event(GPaintEvent& event)
{
Painter painter(*this);
painter.set_clip_rect(event.rect());
painter.translate(-m_horizontal_scrollbar->value(), -m_vertical_scrollbar->value());
int exposed_width = max(content_width(), width());

View file

@ -14,11 +14,14 @@
#include <LibC/string.h>
#endif
#include <unistd.h>
Painter::Painter(GraphicsBitmap& bitmap)
: m_target(bitmap)
{
m_font = &Font::default_font();
m_clip_rect = { { 0, 0 }, bitmap.size() };
m_clip_origin = m_clip_rect;
}
#ifdef LIBGUI
@ -27,9 +30,10 @@ Painter::Painter(GWidget& widget)
, m_window(widget.window())
, m_target(*m_window->backing())
{
m_translation.move_by(widget.window_relative_rect().location());
// NOTE: m_clip_rect is in Window coordinates since we are painting into its backing store.
m_clip_rect = widget.window_relative_rect();
auto origin_rect = widget.window_relative_rect();
m_translation.move_by(origin_rect.location());
m_clip_rect = origin_rect;
m_clip_origin = origin_rect;
m_clip_rect.intersect(m_target->rect());
}
#endif
@ -446,10 +450,11 @@ void Painter::draw_focus_rect(const Rect& rect)
void Painter::set_clip_rect(const Rect& rect)
{
m_clip_rect = Rect::intersection(rect, m_target->rect());
m_clip_rect.intersect(rect.translated(m_clip_origin.location()));
m_clip_rect.intersect(m_target->rect());
}
void Painter::clear_clip_rect()
{
m_clip_rect = m_target->rect();
m_clip_rect = m_clip_origin;
}

View file

@ -62,6 +62,7 @@ private:
const Font* m_font;
Point m_translation;
Rect m_clip_rect;
Rect m_clip_origin;
GWindow* m_window { nullptr };
Retained<GraphicsBitmap> m_target;
DrawOp m_draw_op { DrawOp::Copy };

View file

@ -865,8 +865,10 @@ void WSWindowManager::compose()
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())
if (dirty_rect_in_window_coordinates.is_empty()) {
m_back_painter->clear_clip_rect();
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());
auto dst = window.position();