mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
SharedGraphics: Make Painter clipping work with translated clip origin.
This commit is contained in:
parent
8eefdbdce8
commit
fd428d6ed3
6 changed files with 20 additions and 9 deletions
|
@ -181,9 +181,10 @@ Rect GScrollBar::scrubber_rect() const
|
||||||
return { (int)x_or_y, 0, button_size(), button_size() };
|
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 painter(*this);
|
||||||
|
painter.set_clip_rect(event.rect());
|
||||||
|
|
||||||
painter.fill_rect(rect(), Color(164, 164, 164));
|
painter.fill_rect(rect(), Color(164, 164, 164));
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,10 @@ String GStatusBar::text() const
|
||||||
return m_label->text();
|
return m_label->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GStatusBar::paint_event(GPaintEvent&)
|
void GStatusBar::paint_event(GPaintEvent& event)
|
||||||
{
|
{
|
||||||
Painter painter(*this);
|
Painter painter(*this);
|
||||||
|
painter.set_clip_rect(event.rect());
|
||||||
painter.fill_rect({ 0, 1, width(), height() - 1 }, Color::LightGray);
|
painter.fill_rect({ 0, 1, width(), height() - 1 }, Color::LightGray);
|
||||||
painter.draw_line({ 0, 0 }, { width() - 1, 0 }, Color::DarkGray);
|
painter.draw_line({ 0, 0 }, { width() - 1, 0 }, Color::DarkGray);
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,9 +92,10 @@ void GTableView::mousedown_event(GMouseEvent& event)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTableView::paint_event(GPaintEvent&)
|
void GTableView::paint_event(GPaintEvent& event)
|
||||||
{
|
{
|
||||||
Painter painter(*this);
|
Painter painter(*this);
|
||||||
|
painter.set_clip_rect(event.rect());
|
||||||
painter.translate(-m_horizontal_scrollbar->value(), -m_vertical_scrollbar->value());
|
painter.translate(-m_horizontal_scrollbar->value(), -m_vertical_scrollbar->value());
|
||||||
|
|
||||||
int exposed_width = max(content_width(), width());
|
int exposed_width = max(content_width(), width());
|
||||||
|
|
|
@ -14,11 +14,14 @@
|
||||||
#include <LibC/string.h>
|
#include <LibC/string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
Painter::Painter(GraphicsBitmap& bitmap)
|
Painter::Painter(GraphicsBitmap& bitmap)
|
||||||
: m_target(bitmap)
|
: m_target(bitmap)
|
||||||
{
|
{
|
||||||
m_font = &Font::default_font();
|
m_font = &Font::default_font();
|
||||||
m_clip_rect = { { 0, 0 }, bitmap.size() };
|
m_clip_rect = { { 0, 0 }, bitmap.size() };
|
||||||
|
m_clip_origin = m_clip_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LIBGUI
|
#ifdef LIBGUI
|
||||||
|
@ -27,9 +30,10 @@ Painter::Painter(GWidget& widget)
|
||||||
, m_window(widget.window())
|
, m_window(widget.window())
|
||||||
, m_target(*m_window->backing())
|
, m_target(*m_window->backing())
|
||||||
{
|
{
|
||||||
m_translation.move_by(widget.window_relative_rect().location());
|
auto origin_rect = widget.window_relative_rect();
|
||||||
// NOTE: m_clip_rect is in Window coordinates since we are painting into its backing store.
|
m_translation.move_by(origin_rect.location());
|
||||||
m_clip_rect = widget.window_relative_rect();
|
m_clip_rect = origin_rect;
|
||||||
|
m_clip_origin = origin_rect;
|
||||||
m_clip_rect.intersect(m_target->rect());
|
m_clip_rect.intersect(m_target->rect());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -446,10 +450,11 @@ void Painter::draw_focus_rect(const Rect& rect)
|
||||||
|
|
||||||
void Painter::set_clip_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()
|
void Painter::clear_clip_rect()
|
||||||
{
|
{
|
||||||
m_clip_rect = m_target->rect();
|
m_clip_rect = m_clip_origin;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ private:
|
||||||
const Font* m_font;
|
const Font* m_font;
|
||||||
Point m_translation;
|
Point m_translation;
|
||||||
Rect m_clip_rect;
|
Rect m_clip_rect;
|
||||||
|
Rect m_clip_origin;
|
||||||
GWindow* m_window { nullptr };
|
GWindow* m_window { nullptr };
|
||||||
Retained<GraphicsBitmap> m_target;
|
Retained<GraphicsBitmap> m_target;
|
||||||
DrawOp m_draw_op { DrawOp::Copy };
|
DrawOp m_draw_op { DrawOp::Copy };
|
||||||
|
|
|
@ -865,8 +865,10 @@ void WSWindowManager::compose()
|
||||||
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.set_x(dirty_rect_in_window_coordinates.x() - window.x());
|
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.set_y(dirty_rect_in_window_coordinates.y() - window.y());
|
||||||
auto dst = window.position();
|
auto dst = window.position();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue