Fix more underdraw bugs in Button due to new Rect semantics.

This commit is contained in:
Andreas Kling 2019-01-12 17:17:51 +01:00
parent 0570bbb6cc
commit ecb7e16202
Notes: sideshowbarker 2024-07-19 16:03:57 +09:00
3 changed files with 12 additions and 6 deletions

View file

@ -38,7 +38,7 @@ void Button::paintEvent(PaintEvent&)
if (m_beingPressed) {
// Base
painter.fill_rect({ 1, 1, width() - 1, height() - 1 }, buttonColor);
painter.fill_rect({ 1, 1, width() - 2, height() - 2 }, buttonColor);
// Sunken shadow
painter.draw_line({ 1, 1 }, { width() - 2, 1 }, shadowColor);

View file

@ -5,6 +5,8 @@
#include <AK/Assertions.h>
#include <AK/StdLibExtras.h>
#define DEBUG_WIDGET_UNDERDRAW
Painter::Painter(GraphicsBitmap& bitmap)
{
m_font = &Font::defaultFont();
@ -21,6 +23,10 @@ Painter::Painter(Widget& widget)
m_translation.moveBy(widget.relativePosition());
// NOTE: m_clip_rect is in Window coordinates since we are painting into its backing store.
m_clip_rect = widget.relativeRect();
#ifdef DEBUG_WIDGET_UNDERDRAW
fill_rect(widget.rect(), Color::Red);
#endif
}
Painter::~Painter()
@ -66,12 +72,12 @@ void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color c
point.moveBy(m_translation);
for (unsigned row = 0; row < bitmap.height(); ++row) {
int y = point.y() + row;
if (y < m_clip_rect.top() || y >= m_clip_rect.bottom())
if (y < m_clip_rect.top() || y > m_clip_rect.bottom())
break;
auto* bits = m_target->scanline(y);
for (unsigned j = 0; j < bitmap.width(); ++j) {
int x = point.x() + j;
if (x < m_clip_rect.left() || x >= m_clip_rect.right())
if (x < m_clip_rect.left() || x > m_clip_rect.right())
break;
char fc = bitmap.bits()[row * bitmap.width() + j];
if (fc == '#')
@ -139,7 +145,7 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color)
// Special case: vertical line.
if (point1.x() == point2.x()) {
const int x = point1.x();
if (x < m_clip_rect.left() || x >= m_clip_rect.right())
if (x < m_clip_rect.left() || x > m_clip_rect.right())
return;
if (point1.y() > point2.y())
swap(point1, point2);
@ -156,7 +162,7 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color)
// Special case: horizontal line.
if (point1.y() == point2.y()) {
const int y = point1.y();
if (y < m_clip_rect.top() || y >= m_clip_rect.bottom())
if (y < m_clip_rect.top() || y > m_clip_rect.bottom())
return;
if (point1.x() > point2.x())
swap(point1, point2);

View file

@ -55,7 +55,7 @@ public:
bool contains(int x, int y) const
{
return x >= m_location.x() && x < right() && y >= m_location.y() && y < bottom();
return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom();
}
bool contains(const Point& point) const