1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

Update Painter class to the new coding style.

This commit is contained in:
Andreas Kling 2019-01-12 17:02:54 +01:00
parent 959ef2e681
commit bac9aa90dd
11 changed files with 96 additions and 97 deletions

View file

@ -26,45 +26,45 @@ void Button::paintEvent(PaintEvent&)
Painter painter(*this); Painter painter(*this);
painter.drawPixel({ 0, 0 }, backgroundColor()); painter.set_pixel({ 0, 0 }, backgroundColor());
painter.drawPixel({ width() - 1, 0 }, backgroundColor()); painter.set_pixel({ width() - 1, 0 }, backgroundColor());
painter.drawPixel({ 0, height() - 1 }, backgroundColor()); painter.set_pixel({ 0, height() - 1 }, backgroundColor());
painter.drawPixel({ width() - 1, height() - 1 }, backgroundColor()); painter.set_pixel({ width() - 1, height() - 1 }, backgroundColor());
painter.drawLine({ 1, 0 }, { width() - 2, 0 }, Color::Black); painter.draw_line({ 1, 0 }, { width() - 2, 0 }, Color::Black);
painter.drawLine({ 1, height() - 1 }, { width() - 2, height() - 1}, Color::Black); painter.draw_line({ 1, height() - 1 }, { width() - 2, height() - 1}, Color::Black);
painter.drawLine({ 0, 1 }, { 0, height() - 2 }, Color::Black); painter.draw_line({ 0, 1 }, { 0, height() - 2 }, Color::Black);
painter.drawLine({ width() - 1, 1 }, { width() - 1, height() - 2 }, Color::Black); painter.draw_line({ width() - 1, 1 }, { width() - 1, height() - 2 }, Color::Black);
if (m_beingPressed) { if (m_beingPressed) {
// Base // Base
painter.fillRect({ 1, 1, width() - 1, height() - 1 }, buttonColor); painter.fill_rect({ 1, 1, width() - 1, height() - 1 }, buttonColor);
// Sunken shadow // Sunken shadow
painter.drawLine({ 1, 1 }, { width() - 2, 1 }, shadowColor); painter.draw_line({ 1, 1 }, { width() - 2, 1 }, shadowColor);
painter.drawLine({ 1, 2 }, {1, height() - 2 }, shadowColor); painter.draw_line({ 1, 2 }, {1, height() - 2 }, shadowColor);
} else { } else {
// Base // Base
painter.fillRect({ 3, 3, width() - 5, height() - 5 }, buttonColor); painter.fill_rect({ 3, 3, width() - 5, height() - 5 }, buttonColor);
// White highlight // White highlight
painter.drawLine({ 1, 1 }, { width() - 2, 1 }, highlightColor); painter.draw_line({ 1, 1 }, { width() - 2, 1 }, highlightColor);
painter.drawLine({ 1, 2 }, { width() - 3, 2 }, highlightColor); painter.draw_line({ 1, 2 }, { width() - 3, 2 }, highlightColor);
painter.drawLine({ 1, 3 }, { 1, height() - 2 }, highlightColor); painter.draw_line({ 1, 3 }, { 1, height() - 2 }, highlightColor);
painter.drawLine({ 2, 3 }, { 2, height() - 3 }, highlightColor); painter.draw_line({ 2, 3 }, { 2, height() - 3 }, highlightColor);
// Gray shadow // Gray shadow
painter.drawLine({ width() - 2, 1 }, { width() - 2, height() - 4 }, shadowColor); painter.draw_line({ width() - 2, 1 }, { width() - 2, height() - 4 }, shadowColor);
painter.drawLine({ width() - 3, 2 }, { width() - 3, height() - 4 }, shadowColor); painter.draw_line({ width() - 3, 2 }, { width() - 3, height() - 4 }, shadowColor);
painter.drawLine({ 1, height() - 2 }, { width() - 2, height() - 2 }, shadowColor); painter.draw_line({ 1, height() - 2 }, { width() - 2, height() - 2 }, shadowColor);
painter.drawLine({ 2, height() - 3 }, { width() - 2, height() - 3 }, shadowColor); painter.draw_line({ 2, height() - 3 }, { width() - 2, height() - 3 }, shadowColor);
} }
if (!caption().is_empty()) { if (!caption().is_empty()) {
auto textRect = rect(); auto textRect = rect();
if (m_beingPressed) if (m_beingPressed)
textRect.moveBy(1, 1); textRect.moveBy(1, 1);
painter.drawText(textRect, caption(), Painter::TextAlignment::Center, Color::Black); painter.draw_text(textRect, caption(), Painter::TextAlignment::Center, Color::Black);
} }
} }

View file

@ -85,11 +85,11 @@ void CheckBox::paintEvent(PaintEvent&)
bitmapPosition.setX(2); bitmapPosition.setX(2);
bitmapPosition.setY(height() / 2 - bitmap->height() / 2 - 1); bitmapPosition.setY(height() / 2 - bitmap->height() / 2 - 1);
painter.fillRect(rect(), backgroundColor()); painter.fill_rect(rect(), backgroundColor());
painter.drawBitmap(bitmapPosition, *bitmap, foregroundColor()); painter.draw_bitmap(bitmapPosition, *bitmap, foregroundColor());
if (!caption().is_empty()) { if (!caption().is_empty()) {
painter.drawText(textRect, caption(), Painter::TextAlignment::TopLeft, foregroundColor()); painter.draw_text(textRect, caption(), Painter::TextAlignment::TopLeft, foregroundColor());
} }
} }

View file

@ -22,8 +22,8 @@ void ClockWidget::paintEvent(PaintEvent&)
sprintf(timeBuf, "%02u:%02u:%02u ", tm.tm_hour, tm.tm_min, tm.tm_sec); sprintf(timeBuf, "%02u:%02u:%02u ", tm.tm_hour, tm.tm_min, tm.tm_sec);
Painter painter(*this); Painter painter(*this);
painter.fillRect(rect(), Color::MidGray); painter.fill_rect(rect(), Color::MidGray);
painter.drawText(rect(), timeBuf, Painter::TextAlignment::Center, Color::Black); painter.draw_text(rect(), timeBuf, Painter::TextAlignment::Center, Color::Black);
} }
void ClockWidget::timerEvent(TimerEvent&) void ClockWidget::timerEvent(TimerEvent&)

View file

@ -21,9 +21,9 @@ void Label::setText(String&& text)
void Label::paintEvent(PaintEvent&) void Label::paintEvent(PaintEvent&)
{ {
Painter painter(*this); Painter painter(*this);
painter.fillRect({ 0, 0, width(), height() }, backgroundColor()); painter.fill_rect({ 0, 0, width(), height() }, backgroundColor());
if (!text().is_empty()) if (!text().is_empty())
painter.drawText({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor()); painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor());
} }
void Label::mouseMoveEvent(MouseEvent& event) void Label::mouseMoveEvent(MouseEvent& event)

View file

@ -22,11 +22,11 @@ void ListBox::paintEvent(PaintEvent&)
Painter painter(*this); Painter painter(*this);
// FIXME: Reduce overdraw. // FIXME: Reduce overdraw.
painter.fillRect(rect(), Color::White); painter.fill_rect(rect(), Color::White);
painter.drawRect(rect(), Color::Black); painter.draw_rect(rect(), Color::Black);
if (isFocused()) if (isFocused())
painter.drawFocusRect(rect()); painter.draw_focus_rect(rect());
for (unsigned i = m_scrollOffset; i < m_items.size(); ++i) { for (unsigned i = m_scrollOffset; i < m_items.size(); ++i) {
Rect itemRect(2, 2 + (i * itemHeight()), width() - 4, itemHeight()); Rect itemRect(2, 2 + (i * itemHeight()), width() - 4, itemHeight());
@ -35,12 +35,12 @@ void ListBox::paintEvent(PaintEvent&)
Color itemTextColor = foregroundColor(); Color itemTextColor = foregroundColor();
if (m_selectedIndex == i) { if (m_selectedIndex == i) {
if (isFocused()) if (isFocused())
painter.fillRect(itemRect, Color(0, 32, 128)); painter.fill_rect(itemRect, Color(0, 32, 128));
else else
painter.fillRect(itemRect, Color(96, 96, 96)); painter.fill_rect(itemRect, Color(96, 96, 96));
itemTextColor = Color::White; itemTextColor = Color::White;
} }
painter.drawText(textRect, m_items[i], Painter::TextAlignment::TopLeft, itemTextColor); painter.draw_text(textRect, m_items[i], Painter::TextAlignment::TopLeft, itemTextColor);
} }
} }

View file

@ -10,7 +10,7 @@ Painter::Painter(GraphicsBitmap& bitmap)
{ {
m_font = &Font::defaultFont(); m_font = &Font::defaultFont();
m_target = &bitmap; m_target = &bitmap;
m_clipRect = { { 0, 0 }, bitmap.size() }; m_clip_rect = { { 0, 0 }, bitmap.size() };
} }
Painter::Painter(Widget& widget) Painter::Painter(Widget& widget)
@ -20,59 +20,59 @@ Painter::Painter(Widget& widget)
ASSERT(m_target); ASSERT(m_target);
m_window = widget.window(); m_window = widget.window();
m_translation.moveBy(widget.relativePosition()); m_translation.moveBy(widget.relativePosition());
m_clipRect.setWidth(AbstractScreen::the().width()); m_clip_rect.setWidth(AbstractScreen::the().width());
m_clipRect.setHeight(AbstractScreen::the().height()); m_clip_rect.setHeight(AbstractScreen::the().height());
} }
Painter::~Painter() Painter::~Painter()
{ {
} }
void Painter::fillRect(const Rect& rect, Color color) void Painter::fill_rect(const Rect& rect, Color color)
{ {
Rect r = rect; Rect r = rect;
r.moveBy(m_translation); r.moveBy(m_translation);
for (int y = max(r.top(), m_clipRect.top()); y <= min(r.bottom(), m_clipRect.bottom()); ++y) { for (int y = max(r.top(), m_clip_rect.top()); y <= min(r.bottom(), m_clip_rect.bottom()); ++y) {
auto* bits = m_target->scanline(y); auto* bits = m_target->scanline(y);
for (int x = max(r.left(), m_clipRect.left()); x <= min(r.right(), m_clipRect.right()); ++x) { for (int x = max(r.left(), m_clip_rect.left()); x <= min(r.right(), m_clip_rect.right()); ++x) {
bits[x] = color.value(); bits[x] = color.value();
} }
} }
} }
void Painter::drawRect(const Rect& rect, Color color) void Painter::draw_rect(const Rect& rect, Color color)
{ {
Rect r = rect; Rect r = rect;
r.moveBy(m_translation); r.moveBy(m_translation);
for (int y = max(r.top(), m_clipRect.top()); y <= min(r.bottom(), m_clipRect.bottom()); ++y) { for (int y = max(r.top(), m_clip_rect.top()); y <= min(r.bottom(), m_clip_rect.bottom()); ++y) {
auto* bits = m_target->scanline(y); auto* bits = m_target->scanline(y);
if (y == r.top() || y == r.bottom()) { if (y == r.top() || y == r.bottom()) {
for (int x = max(r.left(), m_clipRect.left()); x <= min(r.right(), m_clipRect.right()); ++x) { for (int x = max(r.left(), m_clip_rect.left()); x <= min(r.right(), m_clip_rect.right()); ++x) {
bits[x] = color.value(); bits[x] = color.value();
} }
} else { } else {
if (r.left() >= m_clipRect.left() && r.left() < m_clipRect.right()) if (r.left() >= m_clip_rect.left() && r.left() < m_clip_rect.right())
bits[r.left()] = color.value(); bits[r.left()] = color.value();
if (r.right() >= m_clipRect.left() && r.right() < m_clipRect.right()) if (r.right() >= m_clip_rect.left() && r.right() < m_clip_rect.right())
bits[r.right()] = color.value(); bits[r.right()] = color.value();
} }
} }
} }
void Painter::drawBitmap(const Point& p, const CharacterBitmap& bitmap, Color color) void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color color)
{ {
Point point = p; Point point = p;
point.moveBy(m_translation); point.moveBy(m_translation);
for (unsigned row = 0; row < bitmap.height(); ++row) { for (unsigned row = 0; row < bitmap.height(); ++row) {
int y = point.y() + row; int y = point.y() + row;
if (y < m_clipRect.top() || y >= m_clipRect.bottom()) if (y < m_clip_rect.top() || y >= m_clip_rect.bottom())
break; break;
auto* bits = m_target->scanline(y); auto* bits = m_target->scanline(y);
for (unsigned j = 0; j < bitmap.width(); ++j) { for (unsigned j = 0; j < bitmap.width(); ++j) {
int x = point.x() + j; int x = point.x() + j;
if (x < m_clipRect.left() || x >= m_clipRect.right()) if (x < m_clip_rect.left() || x >= m_clip_rect.right())
break; break;
char fc = bitmap.bits()[row * bitmap.width() + j]; char fc = bitmap.bits()[row * bitmap.width() + j];
if (fc == '#') if (fc == '#')
@ -81,7 +81,7 @@ void Painter::drawBitmap(const Point& p, const CharacterBitmap& bitmap, Color co
} }
} }
void Painter::drawText(const Rect& rect, const String& text, TextAlignment alignment, Color color) void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alignment, Color color)
{ {
Point point; Point point;
@ -108,20 +108,20 @@ void Painter::drawText(const Rect& rect, const String& text, TextAlignment align
} }
int x = point.x() + i * font().glyphWidth(); int x = point.x() + i * font().glyphWidth();
int y = point.y(); int y = point.y();
drawBitmap({ x, y }, *bitmap, color); draw_bitmap({ x, y }, *bitmap, color);
} }
} }
void Painter::drawPixel(const Point& p, Color color) void Painter::set_pixel(const Point& p, Color color)
{ {
auto point = p; auto point = p;
point.moveBy(m_translation); point.moveBy(m_translation);
if (!m_clipRect.contains(point)) if (!m_clip_rect.contains(point))
return; return;
m_target->scanline(point.y())[point.x()] = color.value(); m_target->scanline(point.y())[point.x()] = color.value();
} }
void Painter::set_pixel_with_draw_op(dword& pixel, const Color& color) ALWAYS_INLINE void Painter::set_pixel_with_draw_op(dword& pixel, const Color& color)
{ {
if (m_draw_op == DrawOp::Copy) if (m_draw_op == DrawOp::Copy)
pixel = color.value(); pixel = color.value();
@ -129,7 +129,7 @@ void Painter::set_pixel_with_draw_op(dword& pixel, const Color& color)
pixel ^= color.value(); pixel ^= color.value();
} }
void Painter::drawLine(const Point& p1, const Point& p2, Color color) void Painter::draw_line(const Point& p1, const Point& p2, Color color)
{ {
auto point1 = p1; auto point1 = p1;
point1.moveBy(m_translation); point1.moveBy(m_translation);
@ -140,12 +140,12 @@ void Painter::drawLine(const Point& p1, const Point& p2, Color color)
// Special case: vertical line. // Special case: vertical line.
if (point1.x() == point2.x()) { if (point1.x() == point2.x()) {
const int x = point1.x(); const int x = point1.x();
if (x < m_clipRect.left() || x >= m_clipRect.right()) if (x < m_clip_rect.left() || x >= m_clip_rect.right())
return; return;
if (point1.y() > point2.y()) if (point1.y() > point2.y())
swap(point1, point2); swap(point1, point2);
int min_y = max(point1.y(), m_clipRect.top()); int min_y = max(point1.y(), m_clip_rect.top());
int max_y = min(point2.y(), m_clipRect.bottom()); int max_y = min(point2.y(), m_clip_rect.bottom());
for (int y = min_y; y <= max_y; ++y) for (int y = min_y; y <= max_y; ++y)
set_pixel_with_draw_op(m_target->scanline(y)[x], color); set_pixel_with_draw_op(m_target->scanline(y)[x], color);
return; return;
@ -157,12 +157,12 @@ void Painter::drawLine(const Point& p1, const Point& p2, Color color)
// Special case: horizontal line. // Special case: horizontal line.
if (point1.y() == point2.y()) { if (point1.y() == point2.y()) {
const int y = point1.y(); const int y = point1.y();
if (y < m_clipRect.top() || y >= m_clipRect.bottom()) if (y < m_clip_rect.top() || y >= m_clip_rect.bottom())
return; return;
if (point1.x() > point2.x()) if (point1.x() > point2.x())
swap(point1, point2); swap(point1, point2);
int min_x = max(point1.x(), m_clipRect.left()); int min_x = max(point1.x(), m_clip_rect.left());
int max_x = min(point2.x(), m_clipRect.right()); int max_x = min(point2.x(), m_clip_rect.right());
auto* pixels = m_target->scanline(point1.y()); auto* pixels = m_target->scanline(point1.y());
for (int x = min_x; x <= max_x; ++x) for (int x = min_x; x <= max_x; ++x)
set_pixel_with_draw_op(pixels[x], color); set_pixel_with_draw_op(pixels[x], color);
@ -175,14 +175,14 @@ void Painter::drawLine(const Point& p1, const Point& p2, Color color)
#if 0 #if 0
const double dx = point2.x() - point1.x(); const double dx = point2.x() - point1.x();
const double dy = point2.y() - point1.y(); const double dy = point2.y() - point1.y();
const double deltaError = fabs(dy / dx); const double delta_error = fabs(dy / dx);
double error = 0; double error = 0;
const double yStep = dy == 0 ? 0 : (dy > 0 ? 1 : -1); const double yStep = dy == 0 ? 0 : (dy > 0 ? 1 : -1);
int y = point1.y(); int y = point1.y();
for (int x = point1.x(); x <= point2.x(); ++x) { for (int x = point1.x(); x <= point2.x(); ++x) {
m_target->scanline(y)[x] = color.value(); m_target->scanline(y)[x] = color.value();
error += deltaError; error += delta_error;
if (error >= 0.5) { if (error >= 0.5) {
y = (double)y + yStep; y = (double)y + yStep;
error -= 1.0; error -= 1.0;
@ -191,19 +191,19 @@ void Painter::drawLine(const Point& p1, const Point& p2, Color color)
#endif #endif
} }
void Painter::drawFocusRect(const Rect& rect) void Painter::draw_focus_rect(const Rect& rect)
{ {
Rect focusRect = rect; Rect focus_rect = rect;
focusRect.moveBy(1, 1); focus_rect.moveBy(1, 1);
focusRect.setWidth(focusRect.width() - 2); focus_rect.setWidth(focus_rect.width() - 2);
focusRect.setHeight(focusRect.height() - 2); focus_rect.setHeight(focus_rect.height() - 2);
drawRect(focusRect, Color(96, 96, 192)); draw_rect(focus_rect, Color(96, 96, 192));
} }
void Painter::blit(const Point& position, const GraphicsBitmap& source) void Painter::blit(const Point& position, const GraphicsBitmap& source)
{ {
Rect dst_rect(position, source.size()); Rect dst_rect(position, source.size());
dst_rect.intersect(m_clipRect); dst_rect.intersect(m_clip_rect);
for (int y = 0; y < dst_rect.height(); ++y) { for (int y = 0; y < dst_rect.height(); ++y) {
auto* dst_scanline = m_target->scanline(position.y() + y); auto* dst_scanline = m_target->scanline(position.y() + y);

View file

@ -14,21 +14,20 @@ class Window;
class Painter { class Painter {
public: public:
enum class TextAlignment { TopLeft, CenterLeft, Center };
explicit Painter(Widget&); explicit Painter(Widget&);
explicit Painter(GraphicsBitmap&); explicit Painter(GraphicsBitmap&);
~Painter(); ~Painter();
void fillRect(const Rect&, Color); void fill_rect(const Rect&, Color);
void drawRect(const Rect&, Color); void draw_rect(const Rect&, Color);
void drawText(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, Color = Color()); void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color());
void drawBitmap(const Point&, const CharacterBitmap&, Color = Color()); void set_pixel(const Point&, Color);
void drawPixel(const Point&, Color); void draw_line(const Point&, const Point&, Color);
void drawLine(const Point& p1, const Point& p2, Color); void draw_focus_rect(const Rect&);
void drawFocusRect(const Rect&);
void blit(const Point&, const GraphicsBitmap&); void blit(const Point&, const GraphicsBitmap&);
enum class TextAlignment { TopLeft, CenterLeft, Center };
void draw_text(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, Color = Color());
const Font& font() const { return *m_font; } const Font& font() const { return *m_font; }
enum class DrawOp { Copy, Xor }; enum class DrawOp { Copy, Xor };
@ -40,7 +39,7 @@ private:
const Font* m_font; const Font* m_font;
Point m_translation; Point m_translation;
Rect m_clipRect; Rect m_clip_rect;
RetainPtr<GraphicsBitmap> m_target; RetainPtr<GraphicsBitmap> m_target;
Window* m_window { nullptr }; Window* m_window { nullptr };
DrawOp m_draw_op { DrawOp::Copy }; DrawOp m_draw_op { DrawOp::Copy };

View file

@ -67,7 +67,7 @@ CharacterWithAttributes& TerminalWidget::at(unsigned row, unsigned column)
void TerminalWidget::paintEvent(PaintEvent&) void TerminalWidget::paintEvent(PaintEvent&)
{ {
Painter painter(*this); Painter painter(*this);
painter.fillRect(rect(), Color::Black); painter.fill_rect(rect(), Color::Black);
char buf[2] = { 0, 0 }; char buf[2] = { 0, 0 };
for (unsigned row = 0; row < m_rows; ++row) { for (unsigned row = 0; row < m_rows; ++row) {
@ -75,12 +75,12 @@ void TerminalWidget::paintEvent(PaintEvent&)
for (unsigned column = 0; column < m_columns; ++column) { for (unsigned column = 0; column < m_columns; ++column) {
int x = column * font().glyphWidth(); int x = column * font().glyphWidth();
buf[0] = at(row, column).character; buf[0] = at(row, column).character;
painter.drawText({ x + 2, y + 2, width(), font().glyphHeight() }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0)); painter.draw_text({ x + 2, y + 2, width(), font().glyphHeight() }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0));
} }
} }
if (m_belling) if (m_belling)
painter.drawRect(rect(), Color::Red); painter.draw_rect(rect(), Color::Red);
} }
void TerminalWidget::onReceive(const ByteBuffer& buffer) void TerminalWidget::onReceive(const ByteBuffer& buffer)

View file

@ -26,11 +26,11 @@ void TextBox::paintEvent(PaintEvent&)
Painter painter(*this); Painter painter(*this);
// FIXME: Reduce overdraw. // FIXME: Reduce overdraw.
painter.fillRect(rect(), backgroundColor()); painter.fill_rect(rect(), backgroundColor());
painter.drawRect(rect(), foregroundColor()); painter.draw_rect(rect(), foregroundColor());
if (isFocused()) if (isFocused())
painter.drawFocusRect(rect()); painter.draw_focus_rect(rect());
Rect innerRect = rect(); Rect innerRect = rect();
innerRect.shrink(6, 6); innerRect.shrink(6, 6);
@ -51,13 +51,13 @@ void TextBox::paintEvent(PaintEvent&)
printf("TextBox: glyph missing: %02x\n", ch); printf("TextBox: glyph missing: %02x\n", ch);
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
painter.drawBitmap({x, y}, *bitmap, Color::Black); painter.draw_bitmap({x, y}, *bitmap, Color::Black);
} }
if (isFocused() && m_cursorBlinkState) { if (isFocused() && m_cursorBlinkState) {
unsigned visibleCursorPosition = m_cursorPosition - firstVisibleChar; unsigned visibleCursorPosition = m_cursorPosition - firstVisibleChar;
Rect cursorRect(innerRect.x() + visibleCursorPosition * font().glyphWidth(), innerRect.y(), 1, innerRect.height()); Rect cursorRect(innerRect.x() + visibleCursorPosition * font().glyphWidth(), innerRect.y(), 1, innerRect.height());
painter.fillRect(cursorRect, foregroundColor()); painter.fill_rect(cursorRect, foregroundColor());
} }
} }

View file

@ -73,7 +73,7 @@ void Widget::paintEvent(PaintEvent& event)
//printf("Widget::paintEvent :)\n"); //printf("Widget::paintEvent :)\n");
if (fillWithBackgroundColor()) { if (fillWithBackgroundColor()) {
Painter painter(*this); Painter painter(*this);
painter.fillRect(rect(), backgroundColor()); painter.fill_rect(rect(), backgroundColor());
} }
for (auto* ch : children()) { for (auto* ch : children()) {
auto* child = (Widget*)ch; auto* child = (Widget*)ch;

View file

@ -106,14 +106,14 @@ void WindowManager::paintWindowFrame(Window& window)
auto titleColor = &window == activeWindow() ? m_activeWindowTitleColor : m_inactiveWindowTitleColor; auto titleColor = &window == activeWindow() ? m_activeWindowTitleColor : m_inactiveWindowTitleColor;
auto borderColor = &window == activeWindow() ? m_activeWindowBorderColor : m_inactiveWindowBorderColor; auto borderColor = &window == activeWindow() ? m_activeWindowBorderColor : m_inactiveWindowBorderColor;
p.drawRect(borderRect, Color::MidGray); p.draw_rect(borderRect, Color::MidGray);
p.drawRect(outerRect, borderColor); p.draw_rect(outerRect, borderColor);
p.fillRect(titleBarRect, borderColor); p.fill_rect(titleBarRect, borderColor);
p.drawRect(inner_border_rect, borderColor); p.draw_rect(inner_border_rect, borderColor);
p.drawText(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor); p.draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor);
} }
void WindowManager::addWindow(Window& window) void WindowManager::addWindow(Window& window)
@ -241,7 +241,7 @@ void WindowManager::compose()
if (any_window_contains_rect(r)) if (any_window_contains_rect(r))
continue; continue;
//dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height()); //dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height());
painter.fillRect(r, Color(0, 72, 96)); painter.fill_rect(r, Color(0, 72, 96));
} }
} }
for (auto* window = m_windows_in_order.head(); window; window = window->next()) { for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
@ -265,8 +265,8 @@ void WindowManager::redraw_cursor()
flush(m_last_cursor_rect); flush(m_last_cursor_rect);
flush(cursor_rect); flush(cursor_rect);
auto draw_cross = [&painter] (const Point& p) { auto draw_cross = [&painter] (const Point& p) {
painter.drawLine({ p.x() - 10, p.y() }, { p.x() + 10, p.y() }, Color::Red); painter.draw_line({ p.x() - 10, p.y() }, { p.x() + 10, p.y() }, Color::Red);
painter.drawLine({ p.x(), p.y() - 10 }, { p.x(), p.y() + 10 }, Color::Red); painter.draw_line({ p.x(), p.y() - 10 }, { p.x(), p.y() + 10 }, Color::Red);
}; };
draw_cross(cursor_location); draw_cross(cursor_location);
m_last_cursor_rect = cursor_rect; m_last_cursor_rect = cursor_rect;