Skip to content

Commit

Permalink
Move some more classes to the new coding style.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Jan 16, 2019
1 parent a2ec09b commit 7750e69
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 114 deletions.
14 changes: 7 additions & 7 deletions Terminal/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };
Expand Down Expand Up @@ -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;
Expand All @@ -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 == ' ')
Expand Down
2 changes: 1 addition & 1 deletion Widgets/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Widgets/CharacterBitmap.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
}
Expand All @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion Widgets/CharacterBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 4 additions & 4 deletions Widgets/CheckBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
25 changes: 12 additions & 13 deletions Widgets/Font.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "Font.h"
#include "Peanut8x10.h"
#include <AK/RetainPtr.h>

static Font* s_default_font;

Expand All @@ -9,34 +8,34 @@ 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)
{
}

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();
}
18 changes: 9 additions & 9 deletions Widgets/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
2 changes: 1 addition & 1 deletion Widgets/ListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down
32 changes: 16 additions & 16 deletions Widgets/Painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
}
Expand All @@ -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();

Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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())
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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()) {
Expand Down Expand Up @@ -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));
}

Expand Down
8 changes: 4 additions & 4 deletions Widgets/Peanut8x10.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {

Expand Down
8 changes: 4 additions & 4 deletions Widgets/Peanut8x8.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {

Expand Down
10 changes: 5 additions & 5 deletions Widgets/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class Point {
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&);
Expand Down
8 changes: 4 additions & 4 deletions Widgets/Rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7750e69

Please sign in to comment.