1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:25:08 +00:00
serenity/Userland/Libraries/LibGUI/Painter.cpp
Mart G 157cd7c819 LibGUI: Prevent a Painter's clip_rect from being outside of its target
Previously a Painter's m_clip_origin field was initialized to a
widget's window_relative_rect, which is not ensured to be within
the target rect.
m_clip_origin is normally not used for clipping, but after calling
clear_clip_rect the clip rect that IS used for clipping gets reset
to m_clip_origin (so an invalid state is entered).
Now the window_relative_rect will be clipped by the target rect
first, and will only then be used to initialize both the active
clip_rect and m_clip_origin.
2021-04-24 15:57:20 +02:00

28 lines
645 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGUI/Painter.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h>
namespace GUI {
Painter::Painter(Gfx::Bitmap& bitmap)
: Gfx::Painter(bitmap)
{
}
Painter::Painter(Widget& widget)
: Painter(*widget.window()->back_bitmap())
{
state().font = &widget.font();
auto origin_rect = widget.window_relative_rect();
state().translation = origin_rect.location();
state().clip_rect = origin_rect.intersected(m_target->rect());
m_clip_origin = state().clip_rect;
}
}