Move some more classes to the new coding style.

This commit is contained in:
Andreas Kling 2019-01-16 17:54:06 +01:00
parent a2ec09bc20
commit 7750e6952b
Notes: sideshowbarker 2024-07-19 16:01:22 +09:00
20 changed files with 113 additions and 114 deletions

View file

@ -11,10 +11,10 @@
void Terminal::create_window()
{
auto& font = Font::defaultFont();
auto& font = Font::default_font();
m_pixel_width = m_columns * font.glyphWidth() + m_inset * 2;
m_pixel_height = (m_rows * (font.glyphHeight() + m_line_spacing)) + (m_inset * 2) - m_line_spacing;
m_pixel_width = m_columns * font.glyph_width() + m_inset * 2;
m_pixel_height = (m_rows * (font.glyph_height() + m_line_spacing)) + (m_inset * 2) - m_line_spacing;
GUI_CreateWindowParameters params;
params.rect = { { 300, 300 }, { m_pixel_width, m_pixel_height } };
@ -398,9 +398,9 @@ void Terminal::set_size(word columns, word rows)
void Terminal::paint()
{
Rect rect { 0, 0, m_pixel_width, m_pixel_height };
Font& font = Font::defaultFont();
Font& font = Font::default_font();
Painter painter(*m_backing);
int line_height = Font::defaultFont().glyphHeight() + m_line_spacing;
int line_height = Font::default_font().glyph_height() + m_line_spacing;
#ifdef FAST_SCROLL
if (m_rows_to_scroll_backing_store && m_rows_to_scroll_backing_store < m_rows) {
int first_scanline = m_inset;
@ -424,8 +424,8 @@ void Terminal::paint()
continue;
attribute.dirty = false;
char ch = m_buffer[(row * m_columns) + (column)];
int x = column * font.glyphWidth();
Rect glyph_rect { x + m_inset, y + m_inset, font.glyphWidth(), line_height };
int x = column * font.glyph_width();
Rect glyph_rect { x + m_inset, y + m_inset, font.glyph_width(), line_height };
auto glyph_background = ansi_color(attribute.background_color);
painter.fill_rect(glyph_rect, glyph_background);
if (ch == ' ')

View file

@ -59,7 +59,7 @@ void Button::paintEvent(PaintEvent&)
if (!caption().is_empty()) {
auto textRect = rect();
if (m_beingPressed)
textRect.moveBy(1, 1);
textRect.move_by(1, 1);
painter.draw_text(textRect, caption(), Painter::TextAlignment::Center, Color::Black);
}
}

View file

@ -1,7 +1,7 @@
#include "CharacterBitmap.h"
CharacterBitmap::CharacterBitmap(const char* asciiData, unsigned width, unsigned height)
: m_bits(asciiData)
CharacterBitmap::CharacterBitmap(const char* ascii_data, unsigned width, unsigned height)
: m_bits(ascii_data)
, m_size(width, height)
{
}
@ -10,7 +10,7 @@ CharacterBitmap::~CharacterBitmap()
{
}
RetainPtr<CharacterBitmap> CharacterBitmap::createFromASCII(const char* asciiData, unsigned width, unsigned height)
RetainPtr<CharacterBitmap> CharacterBitmap::create_from_ascii(const char* asciiData, unsigned width, unsigned height)
{
return adopt(*new CharacterBitmap(asciiData, width, height));
}

View file

@ -6,7 +6,7 @@
class CharacterBitmap : public Retainable<CharacterBitmap> {
public:
static RetainPtr<CharacterBitmap> createFromASCII(const char* asciiData, unsigned width, unsigned height);
static RetainPtr<CharacterBitmap> create_from_ascii(const char* asciiData, unsigned width, unsigned height);
~CharacterBitmap();
const char* bits() const { return m_bits; }

View file

@ -75,15 +75,15 @@ static const char* checkedBitmap = {
void CheckBox::paintEvent(PaintEvent&)
{
Painter painter(*this);
auto bitmap = CharacterBitmap::createFromASCII(isChecked() ? checkedBitmap : uncheckedBitmap, 11, 11);
auto bitmap = CharacterBitmap::create_from_ascii(isChecked() ? checkedBitmap : uncheckedBitmap, 11, 11);
auto textRect = rect();
textRect.set_left(bitmap->width() + 4);
textRect.set_top(height() / 2 - font().glyphHeight() / 2);
textRect.set_top(height() / 2 - font().glyph_height() / 2);
Point bitmapPosition;
bitmapPosition.setX(2);
bitmapPosition.setY(height() / 2 - bitmap->height() / 2 - 1);
bitmapPosition.set_x(2);
bitmapPosition.set_y(height() / 2 - bitmap->height() / 2 - 1);
painter.fill_rect(rect(), backgroundColor());
painter.draw_bitmap(bitmapPosition, *bitmap, foregroundColor());

View file

@ -1,6 +1,5 @@
#include "Font.h"
#include "Peanut8x10.h"
#include <AK/RetainPtr.h>
static Font* s_default_font;
@ -9,19 +8,19 @@ void Font::initialize()
s_default_font = nullptr;
}
Font& Font::defaultFont()
Font& Font::default_font()
{
if (!s_default_font)
s_default_font = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
s_default_font = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyph_width, Peanut8x10::glyph_height, Peanut8x10::first_glyph, Peanut8x10::last_glyph)).leakRef();
return *s_default_font;
}
Font::Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph)
Font::Font(const char* const* glyphs, byte glyph_width, byte glyph_height, byte first_glyph, byte last_glyph)
: m_glyphs(glyphs)
, m_glyphWidth(glyphWidth)
, m_glyphHeight(glyphHeight)
, m_firstGlyph(firstGlyph)
, m_lastGlyph(lastGlyph)
, m_glyph_width(glyph_width)
, m_glyph_height(glyph_height)
, m_first_glyph(first_glyph)
, m_last_glyph(last_glyph)
{
}
@ -29,14 +28,14 @@ Font::~Font()
{
}
const CharacterBitmap* Font::glyphBitmap(byte ch) const
const CharacterBitmap* Font::glyph_bitmap(byte ch) const
{
if (!m_bitmaps[ch]) {
if (ch < m_firstGlyph || ch > m_lastGlyph)
if (ch < m_first_glyph || ch > m_last_glyph)
return nullptr;
const char* data = m_glyphs[(unsigned)ch - m_firstGlyph];
m_bitmaps[ch] = CharacterBitmap::createFromASCII(data, m_glyphWidth, m_glyphHeight);
const char* data = m_glyphs[(unsigned)ch - m_first_glyph];
m_bitmaps[ch] = CharacterBitmap::create_from_ascii(data, m_glyph_width, m_glyph_height);
}
ASSERT(ch >= m_firstGlyph && ch <= m_lastGlyph);
ASSERT(ch >= m_first_glyph && ch <= m_last_glyph);
return m_bitmaps[ch].ptr();
}

View file

@ -7,26 +7,26 @@
class Font : public Retainable<Font> {
public:
static Font& defaultFont();
static Font& default_font();
~Font();
const CharacterBitmap* glyphBitmap(byte) const;
const CharacterBitmap* glyph_bitmap(byte) const;
byte glyphWidth() const { return m_glyphWidth; }
byte glyphHeight() const { return m_glyphHeight; }
byte glyph_width() const { return m_glyph_width; }
byte glyph_height() const { return m_glyph_height; }
static void initialize();
private:
Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph);
Font(const char* const* glyphs, byte glyph_width, byte glyph_height, byte firstGlyph, byte lastGlyph);
const char* const* m_glyphs { nullptr };
mutable RetainPtr<CharacterBitmap> m_bitmaps[256];
byte m_glyphWidth { 0 };
byte m_glyphHeight { 0 };
byte m_glyph_width { 0 };
byte m_glyph_height { 0 };
byte m_firstGlyph { 0 };
byte m_lastGlyph { 0 };
byte m_first_glyph { 0 };
byte m_last_glyph { 0 };
};

View file

@ -14,7 +14,7 @@ ListBox::~ListBox()
Rect ListBox::item_rect(int index) const
{
int item_height = font().glyphHeight() + 2;
int item_height = font().glyph_height() + 2;
return Rect { 2, 2 + (index * item_height), width() - 4, item_height };
}

View file

@ -9,7 +9,7 @@
Painter::Painter(GraphicsBitmap& bitmap)
{
m_font = &Font::defaultFont();
m_font = &Font::default_font();
m_target = &bitmap;
m_clip_rect = { { 0, 0 }, bitmap.size() };
}
@ -20,7 +20,7 @@ Painter::Painter(Widget& widget)
m_target = widget.backing();
ASSERT(m_target);
m_window = widget.window();
m_translation.moveBy(widget.relativePosition());
m_translation.move_by(widget.relativePosition());
// NOTE: m_clip_rect is in Window coordinates since we are painting into its backing store.
m_clip_rect = widget.relativeRect();
@ -38,7 +38,7 @@ Painter::~Painter()
void Painter::fill_rect(const Rect& rect, Color color)
{
Rect r = rect;
r.moveBy(m_translation);
r.move_by(m_translation);
int min_y = max(r.top(), m_clip_rect.top());
int max_y = min(r.bottom(), m_clip_rect.bottom());
@ -53,7 +53,7 @@ void Painter::fill_rect(const Rect& rect, Color color)
void Painter::draw_rect(const Rect& rect, Color color)
{
Rect r = rect;
r.moveBy(m_translation);
r.move_by(m_translation);
int min_y = max(r.top(), m_clip_rect.top());
int max_y = min(r.bottom(), m_clip_rect.bottom());
@ -76,7 +76,7 @@ void Painter::draw_rect(const Rect& rect, Color color)
void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color color)
{
Point point = p;
point.moveBy(m_translation);
point.move_by(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())
@ -95,7 +95,7 @@ void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color c
void Painter::draw_glyph(const Point& point, char ch, Color color)
{
auto* bitmap = font().glyphBitmap(ch);
auto* bitmap = font().glyph_bitmap(ch);
if (!bitmap) {
dbgprintf("Font doesn't have 0x%b ('%c')\n", (byte)ch, ch);
ASSERT_NOT_REACHED();
@ -112,16 +112,16 @@ void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alig
if (alignment == TextAlignment::TopLeft) {
point = rect.location();
} else if (alignment == TextAlignment::CenterLeft) {
point = { rect.x(), rect.center().y() - (font().glyphHeight() / 2) };
point = { rect.x(), rect.center().y() - (font().glyph_height() / 2) };
} else if (alignment == TextAlignment::Center) {
int textWidth = text.length() * font().glyphWidth();
int textWidth = text.length() * font().glyph_width();
point = rect.center();
point.moveBy(-(textWidth / 2), -(font().glyphHeight() / 2));
point.move_by(-(textWidth / 2), -(font().glyph_height() / 2));
} else {
ASSERT_NOT_REACHED();
}
for (unsigned i = 0; i < text.length(); ++i, point.moveBy(font().glyphWidth(), 0)) {
for (unsigned i = 0; i < text.length(); ++i, point.move_by(font().glyph_width(), 0)) {
byte ch = text[i];
if (ch == ' ')
continue;
@ -132,7 +132,7 @@ void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alig
void Painter::set_pixel(const Point& p, Color color)
{
auto point = p;
point.moveBy(m_translation);
point.move_by(m_translation);
if (!m_clip_rect.contains(point))
return;
m_target->scanline(point.y())[point.x()] = color.value();
@ -149,10 +149,10 @@ ALWAYS_INLINE void Painter::set_pixel_with_draw_op(dword& pixel, const Color& co
void Painter::draw_line(const Point& p1, const Point& p2, Color color)
{
auto point1 = p1;
point1.moveBy(m_translation);
point1.move_by(m_translation);
auto point2 = p2;
point2.moveBy(m_translation);
point2.move_by(m_translation);
// Special case: vertical line.
if (point1.x() == point2.x()) {
@ -215,9 +215,9 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color)
void Painter::draw_focus_rect(const Rect& rect)
{
Rect focus_rect = rect;
focus_rect.moveBy(1, 1);
focus_rect.setWidth(focus_rect.width() - 2);
focus_rect.setHeight(focus_rect.height() - 2);
focus_rect.move_by(1, 1);
focus_rect.set_width(focus_rect.width() - 2);
focus_rect.set_height(focus_rect.height() - 2);
draw_rect(focus_rect, Color(96, 96, 192));
}

View file

@ -2,10 +2,10 @@
namespace Peanut8x10 {
static constexpr char firstGlyph = '!';
static constexpr char lastGlyph = '~';
static constexpr byte glyphWidth = 8;
static constexpr byte glyphHeight = 10;
static constexpr char first_glyph = '!';
static constexpr char last_glyph = '~';
static constexpr byte glyph_width = 8;
static constexpr byte glyph_height = 10;
static constexpr const char* glyphs[] {

View file

@ -2,10 +2,10 @@
namespace Peanut8x8 {
static constexpr char firstCharacter = '!';
static constexpr char lastCharacter = '~';
static constexpr byte fontWidth = 8;
static constexpr byte fontHeight = 8;
static constexpr char first_character = '!';
static constexpr char last_character = '~';
static constexpr byte font_width = 8;
static constexpr byte font_height = 8;
static constexpr const char* font[] {

View file

@ -12,18 +12,18 @@ public:
int x() const { return m_x; }
int y() const { return m_y; }
void setX(int x) { m_x = x; }
void setY(int y) { m_y = y; }
void set_x(int x) { m_x = x; }
void set_y(int y) { m_y = y; }
void moveBy(int dx, int dy)
void move_by(int dx, int dy)
{
m_x += dx;
m_y += dy;
}
void moveBy(const Point& delta)
void move_by(const Point& delta)
{
moveBy(delta.x(), delta.y());
move_by(delta.x(), delta.y());
}
void constrain(const Rect&);

View file

@ -15,10 +15,10 @@ void Rect::intersect(const Rect& other)
return;
}
m_location.setX(l);
m_location.setY(t);
m_size.setWidth((r - l) + 1);
m_size.setHeight((b - t) + 1);
m_location.set_x(l);
m_location.set_y(t);
m_size.set_width((r - l) + 1);
m_size.set_height((b - t) + 1);
}
Rect Rect::united(const Rect& other) const

View file

@ -25,14 +25,14 @@ public:
return width() == 0 || height() == 0;
}
void moveBy(int dx, int dy)
void move_by(int dx, int dy)
{
m_location.moveBy(dx, dy);
m_location.move_by(dx, dy);
}
void moveBy(const Point& delta)
void move_by(const Point& delta)
{
m_location.moveBy(delta);
m_location.move_by(delta);
}
Point center() const
@ -42,18 +42,18 @@ public:
void inflate(int w, int h)
{
setX(x() - w / 2);
setWidth(width() + w);
setY(y() - h / 2);
setHeight(height() + h);
set_x(x() - w / 2);
set_width(width() + w);
set_y(y() - h / 2);
set_height(height() + h);
}
void shrink(int w, int h)
{
setX(x() + w / 2);
setWidth(width() - w);
setY(y() + h / 2);
setHeight(height() - h);
set_x(x() + w / 2);
set_width(width() - w);
set_y(y() + h / 2);
set_height(height() - h);
}
bool contains(int x, int y) const
@ -81,22 +81,22 @@ public:
void set_left(int left)
{
setX(left);
set_x(left);
}
void set_top(int top)
{
setY(top);
set_y(top);
}
void set_right(int right)
{
setWidth(right - x() + 1);
set_width(right - x() + 1);
}
void set_bottom(int bottom)
{
setHeight(bottom - y() + 1);
set_height(bottom - y() + 1);
}
bool intersects(const Rect& other) const
@ -112,10 +112,10 @@ public:
int width() const { return m_size.width(); }
int height() const { return m_size.height(); }
void setX(int x) { m_location.setX(x); }
void setY(int y) { m_location.setY(y); }
void setWidth(int width) { m_size.setWidth(width); }
void setHeight(int height) { m_size.setHeight(height); }
void set_x(int x) { m_location.set_x(x); }
void set_y(int y) { m_location.set_y(y); }
void set_width(int width) { m_size.set_width(width); }
void set_height(int height) { m_size.set_height(height); }
Point location() const { return m_location; }
Size size() const { return m_size; }
@ -147,11 +147,11 @@ private:
inline void Point::constrain(const Rect& rect)
{
if (x() < rect.left())
setX(rect.left());
set_x(rect.left());
else if (x() > rect.right())
setX(rect.right());
set_x(rect.right());
if (y() < rect.top())
setY(rect.top());
set_y(rect.top());
else if (y() > rect.bottom())
setY(rect.bottom());
set_y(rect.bottom());
}

View file

@ -13,8 +13,8 @@ public:
int width() const { return m_width; }
int height() const { return m_height; }
void setWidth(int w) { m_width = w; }
void setHeight(int h) { m_height = h; }
void set_width(int w) { m_width = w; }
void set_height(int h) { m_height = h; }
bool operator==(const Size& other) const
{

View file

@ -14,7 +14,7 @@ TerminalWidget::TerminalWidget(Widget* parent)
{
g_tw = this;
setWindowRelativeRect({ 0, 0, int(columns() * font().glyphWidth()) + 4, int(rows() * font().glyphHeight()) + 4 });
setWindowRelativeRect({ 0, 0, int(columns() * font().glyph_width()) + 4, int(rows() * font().glyph_height()) + 4 });
printf("rekt: %d x %d\n", width(), height());
m_screen = new CharacterWithAttributes[rows() * columns()];
@ -71,11 +71,11 @@ void TerminalWidget::paintEvent(PaintEvent&)
char buf[2] = { 0, 0 };
for (unsigned row = 0; row < m_rows; ++row) {
int y = row * font().glyphHeight();
int y = row * font().glyph_height();
for (unsigned column = 0; column < m_columns; ++column) {
int x = column * font().glyphWidth();
int x = column * font().glyph_width();
buf[0] = at(row, column).character;
painter.draw_text({ x + 2, y + 2, width(), font().glyphHeight() }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0));
painter.draw_text({ x + 2, y + 2, width(), font().glyph_height() }, buf, Painter::TextAlignment::TopLeft, Color(0xa0, 0xa0, 0xa0));
}
}

View file

@ -35,18 +35,18 @@ void TextBox::paintEvent(PaintEvent&)
Rect innerRect = rect();
innerRect.shrink(6, 6);
size_t maxCharsToPaint = innerRect.width() / font().glyphWidth();
size_t maxCharsToPaint = innerRect.width() / font().glyph_width();
int firstVisibleChar = max((int)m_cursorPosition - (int)maxCharsToPaint, 0);
size_t charsToPaint = min(m_text.length() - firstVisibleChar, maxCharsToPaint);
int y = innerRect.center().y() - font().glyphHeight() / 2;
int y = innerRect.center().y() - font().glyph_height() / 2;
for (size_t i = 0; i < charsToPaint; ++i) {
char ch = m_text[firstVisibleChar + i];
if (ch == ' ')
continue;
int x = innerRect.x() + (i * font().glyphWidth());
auto* bitmap = font().glyphBitmap(ch);
int x = innerRect.x() + (i * font().glyph_width());
auto* bitmap = font().glyph_bitmap(ch);
if (!bitmap) {
printf("TextBox: glyph missing: %02x\n", ch);
ASSERT_NOT_REACHED();
@ -56,7 +56,7 @@ void TextBox::paintEvent(PaintEvent&)
if (isFocused() && m_cursorBlinkState) {
unsigned visibleCursorPosition = m_cursorPosition - firstVisibleChar;
Rect cursorRect(innerRect.x() + visibleCursorPosition * font().glyphWidth(), innerRect.y(), 1, innerRect.height());
Rect cursorRect(innerRect.x() + visibleCursorPosition * font().glyph_width(), innerRect.y(), 1, innerRect.height());
painter.fill_rect(cursorRect, foregroundColor());
}
}

View file

@ -151,7 +151,7 @@ void Widget::setFocus(bool focus)
void Widget::setFont(RetainPtr<Font>&& font)
{
if (!font)
m_font = Font::defaultFont();
m_font = Font::default_font();
else
m_font = move(font);
}

View file

@ -34,12 +34,12 @@ WSScreen::~WSScreen()
void WSScreen::on_receive_mouse_data(int dx, int dy, bool left_button, bool right_button)
{
auto prev_location = m_cursor_location;
m_cursor_location.moveBy(dx, dy);
m_cursor_location.move_by(dx, dy);
m_cursor_location.constrain(rect());
if (m_cursor_location.x() >= width())
m_cursor_location.setX(width() - 1);
m_cursor_location.set_x(width() - 1);
if (m_cursor_location.y() >= height())
m_cursor_location.setY(height() - 1);
m_cursor_location.set_y(height() - 1);
if (m_cursor_location != prev_location) {
auto event = make<MouseEvent>(WSEvent::MouseMove, m_cursor_location.x(), m_cursor_location.y());
WSEventLoop::the().post_event(&WSWindowManager::the(), move(event));

View file

@ -128,8 +128,8 @@ WSWindowManager::WSWindowManager()
m_inactiveWindowBorderColor = Color(64, 64, 64);
m_inactiveWindowTitleColor = Color::White;
m_cursor_bitmap_inner = CharacterBitmap::createFromASCII(cursor_bitmap_inner_ascii, 12, 17);
m_cursor_bitmap_outer = CharacterBitmap::createFromASCII(cursor_bitmap_outer_ascii, 12, 17);
m_cursor_bitmap_inner = CharacterBitmap::create_from_ascii(cursor_bitmap_inner_ascii, 12, 17);
m_cursor_bitmap_outer = CharacterBitmap::create_from_ascii(cursor_bitmap_outer_ascii, 12, 17);
invalidate();
compose();
@ -237,7 +237,7 @@ void WSWindowManager::processMouseEvent(MouseEvent& event)
auto old_window_rect = m_dragWindow->rect();
Point pos = m_dragWindowOrigin;
printf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_dragOrigin.x(), m_dragOrigin.y(), event.x(), event.y());
pos.moveBy(event.x() - m_dragOrigin.x(), event.y() - m_dragOrigin.y());
pos.move_by(event.x() - m_dragOrigin.x(), event.y() - m_dragOrigin.y());
m_dragWindow->set_position_without_repaint(pos);
invalidate(outerRectForWindow(old_window_rect));
invalidate(outerRectForWindow(m_dragWindow->rect()));