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

Libraries: Make CharacterBitmap instances at compile-time

`CharacterBitmap` instances are generated at run-time and put on the
heap, but they can be created in a `constexpr` context and stored in
static memory.

Also, remove additional `width` and `height` `static` values in favor
of using the `constexpr` member functions of `CharacterBitmap`.

These changes also include the removal of some initialization code
which tests if the `CharacterBitmap` is created since it is always
created and removes function-local `static` values which cause
run-time branches to ensure it is initialized each time the function
is called.
This commit is contained in:
Lenny Maiorani 2022-02-28 19:21:12 -07:00 committed by Linus Groh
parent dc518404ce
commit d5fdc6096c
9 changed files with 97 additions and 135 deletions

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020, Till Mayer <till.mayer@web.de> * Copyright (c) 2020, Till Mayer <till.mayer@web.de>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -11,7 +12,7 @@
namespace Cards { namespace Cards {
static const NonnullRefPtr<Gfx::CharacterBitmap> s_diamond = Gfx::CharacterBitmap::create_from_ascii( static constexpr Gfx::CharacterBitmap s_diamond {
" # " " # "
" ### " " ### "
" ##### " " ##### "
@ -21,9 +22,10 @@ static const NonnullRefPtr<Gfx::CharacterBitmap> s_diamond = Gfx::CharacterBitma
" ##### " " ##### "
" ### " " ### "
" # ", " # ",
9, 9); 9, 9
};
static const NonnullRefPtr<Gfx::CharacterBitmap> s_heart = Gfx::CharacterBitmap::create_from_ascii( static constexpr Gfx::CharacterBitmap s_heart {
" # # " " # # "
" ### ### " " ### ### "
"#########" "#########"
@ -33,9 +35,10 @@ static const NonnullRefPtr<Gfx::CharacterBitmap> s_heart = Gfx::CharacterBitmap:
" ##### " " ##### "
" ### " " ### "
" # ", " # ",
9, 9); 9, 9
};
static const NonnullRefPtr<Gfx::CharacterBitmap> s_spade = Gfx::CharacterBitmap::create_from_ascii( static constexpr Gfx::CharacterBitmap s_spade {
" # " " # "
" ### " " ### "
" ##### " " ##### "
@ -45,9 +48,10 @@ static const NonnullRefPtr<Gfx::CharacterBitmap> s_spade = Gfx::CharacterBitmap:
" ## # ## " " ## # ## "
" ### " " ### "
" ### ", " ### ",
9, 9); 9, 9
};
static const NonnullRefPtr<Gfx::CharacterBitmap> s_club = Gfx::CharacterBitmap::create_from_ascii( static constexpr Gfx::CharacterBitmap s_club {
" ### " " ### "
" ##### " " ##### "
" ##### " " ##### "
@ -57,7 +61,8 @@ static const NonnullRefPtr<Gfx::CharacterBitmap> s_club = Gfx::CharacterBitmap::
"#### # ####" "#### # ####"
" ## ### ## " " ## ### ## "
" ### ", " ### ",
11, 9); 11, 9
};
static RefPtr<Gfx::Bitmap> s_background; static RefPtr<Gfx::Bitmap> s_background;
static RefPtr<Gfx::Bitmap> s_background_inverted; static RefPtr<Gfx::Bitmap> s_background_inverted;
@ -105,26 +110,24 @@ Card::Card(Type type, uint8_t value)
auto text_rect = Gfx::IntRect { 4, 6, font.width("10"), font.glyph_height() }; auto text_rect = Gfx::IntRect { 4, 6, font.width("10"), font.glyph_height() };
painter.draw_text(text_rect, label, font, Gfx::TextAlignment::Center, color()); painter.draw_text(text_rect, label, font, Gfx::TextAlignment::Center, color());
NonnullRefPtr<Gfx::CharacterBitmap> symbol = s_diamond; auto const& symbol = [&]() -> Gfx::CharacterBitmap const& {
switch (m_type) { switch (m_type) {
case Diamonds: case Diamonds:
symbol = s_diamond; return s_diamond;
break; case Clubs:
case Clubs: return s_club;
symbol = s_club; break;
break; case Spades:
case Spades: return s_spade;
symbol = s_spade; case Hearts:
break; return s_heart;
case Hearts: default:
symbol = s_heart; VERIFY_NOT_REACHED();
break; }
default: }();
VERIFY_NOT_REACHED();
}
painter.draw_bitmap( painter.draw_bitmap(
{ text_rect.x() + (text_rect.width() - symbol->size().width()) / 2, text_rect.bottom() + 5 }, { text_rect.x() + (text_rect.width() - symbol.size().width()) / 2, text_rect.bottom() + 5 },
symbol, color()); symbol, color());
for (int y = height / 2; y < height; ++y) { for (int y = height / 2; y < height; ++y) {

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org> * Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -13,7 +14,7 @@
namespace GUI { namespace GUI {
static const char* s_arrow_bitmap_data = { static constexpr Gfx::CharacterBitmap s_arrow_bitmap {
" " " "
" # " " # "
" ## " " ## "
@ -22,10 +23,9 @@ static const char* s_arrow_bitmap_data = {
" ### " " ### "
" ## " " ## "
" # " " # "
" " " ",
9, 9
}; };
static const int s_arrow_bitmap_width = 9;
static const int s_arrow_bitmap_height = 9;
ColumnsView::ColumnsView() ColumnsView::ColumnsView()
{ {
@ -128,7 +128,7 @@ void ColumnsView::paint_event(PaintEvent& event)
Gfx::IntRect text_rect = { Gfx::IntRect text_rect = {
icon_rect.right() + 1 + icon_spacing(), row * item_height(), icon_rect.right() + 1 + icon_spacing(), row * item_height(),
column.width - icon_spacing() - icon_size() - icon_spacing() - icon_spacing() - s_arrow_bitmap_width - icon_spacing(), item_height() column.width - icon_spacing() - icon_size() - icon_spacing() - icon_spacing() - static_cast<int>(s_arrow_bitmap.width()) - icon_spacing(), item_height()
}; };
draw_item_text(painter, index, is_selected_row, text_rect, index.data().to_string(), font_for_index(index), Gfx::TextAlignment::CenterLeft, Gfx::TextElision::None); draw_item_text(painter, index, is_selected_row, text_rect, index.data().to_string(), font_for_index(index), Gfx::TextAlignment::CenterLeft, Gfx::TextElision::None);
@ -145,11 +145,10 @@ void ColumnsView::paint_event(PaintEvent& event)
if (expandable) { if (expandable) {
Gfx::IntRect arrow_rect = { Gfx::IntRect arrow_rect = {
text_rect.right() + 1 + icon_spacing(), 0, text_rect.right() + 1 + icon_spacing(), 0,
s_arrow_bitmap_width, s_arrow_bitmap_height s_arrow_bitmap.width(), s_arrow_bitmap.height()
}; };
arrow_rect.center_vertically_within(row_rect); arrow_rect.center_vertically_within(row_rect);
static auto& arrow_bitmap = Gfx::CharacterBitmap::create_from_ascii(s_arrow_bitmap_data, s_arrow_bitmap_width, s_arrow_bitmap_height).leak_ref(); painter.draw_bitmap(arrow_rect.location(), s_arrow_bitmap, text_color);
painter.draw_bitmap(arrow_rect.location(), arrow_bitmap, text_color);
} }
} }
@ -201,7 +200,7 @@ void ColumnsView::update_column_sizes()
ModelIndex index = model()->index(row, m_model_column, column.parent_index); ModelIndex index = model()->index(row, m_model_column, column.parent_index);
VERIFY(index.is_valid()); VERIFY(index.is_valid());
auto text = index.data().to_string(); auto text = index.data().to_string();
int row_width = icon_spacing() + icon_size() + icon_spacing() + font().width(text) + icon_spacing() + s_arrow_bitmap_width + icon_spacing(); int row_width = icon_spacing() + icon_size() + icon_spacing() + font().width(text) + icon_spacing() + s_arrow_bitmap.width() + icon_spacing();
if (row_width > column.width) if (row_width > column.width)
column.width = row_width; column.width = row_width;
} }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -12,7 +13,8 @@
namespace GUI { namespace GUI {
static const char* s_resize_corner_shadows_data = { static constexpr Gfx::CharacterBitmap s_resize_corner_shadows_bitmap {
" " " "
" ## " " ## "
" # " " # "
@ -28,10 +30,11 @@ static const char* s_resize_corner_shadows_data = {
" " " "
" ## ## ## ## ## " " ## ## ## ## ## "
" # # # # # " " # # # # # "
" " " ",
16, 16
}; };
static const char* s_resize_corner_highlights_data = { static constexpr Gfx::CharacterBitmap s_resize_corner_highlights_bitmap {
" " " "
" " " "
" # " " # "
@ -47,14 +50,10 @@ static const char* s_resize_corner_highlights_data = {
" " " "
" " " "
" # # # # # " " # # # # # "
" " " ",
16, 16
}; };
static Gfx::CharacterBitmap* s_resize_corner_shadows_bitmap;
static Gfx::CharacterBitmap* s_resize_corner_highlights_bitmap;
static const int s_resize_corner_bitmap_width = 16;
static const int s_resize_corner_bitmap_height = 16;
ResizeCorner::ResizeCorner() ResizeCorner::ResizeCorner()
{ {
set_override_cursor(Gfx::StandardCursor::ResizeDiagonalTLBR); set_override_cursor(Gfx::StandardCursor::ResizeDiagonalTLBR);
@ -72,13 +71,8 @@ void ResizeCorner::paint_event(PaintEvent& event)
painter.add_clip_rect(event.rect()); painter.add_clip_rect(event.rect());
painter.fill_rect(rect(), palette().color(background_role())); painter.fill_rect(rect(), palette().color(background_role()));
if (!s_resize_corner_shadows_bitmap) painter.draw_bitmap({ 0, 2 }, s_resize_corner_shadows_bitmap, palette().threed_shadow1());
s_resize_corner_shadows_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_resize_corner_shadows_data, s_resize_corner_bitmap_width, s_resize_corner_bitmap_height).leak_ref(); painter.draw_bitmap({ 0, 2 }, s_resize_corner_highlights_bitmap, palette().threed_highlight());
painter.draw_bitmap({ 0, 2 }, *s_resize_corner_shadows_bitmap, palette().threed_shadow1());
if (!s_resize_corner_highlights_bitmap)
s_resize_corner_highlights_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_resize_corner_highlights_data, s_resize_corner_bitmap_width, s_resize_corner_bitmap_height).leak_ref();
painter.draw_bitmap({ 0, 2 }, *s_resize_corner_highlights_bitmap, palette().threed_highlight());
Widget::paint_event(event); Widget::paint_event(event);
} }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -15,7 +16,7 @@ REGISTER_WIDGET(GUI, Scrollbar)
namespace GUI { namespace GUI {
static const char* s_up_arrow_bitmap_data = { static constexpr Gfx::CharacterBitmap s_up_arrow_bitmap {
" " " "
" " " "
" " " "
@ -24,10 +25,11 @@ static const char* s_up_arrow_bitmap_data = {
" ##### " " ##### "
" ####### " " ####### "
" " " "
" " " ",
9, 9
}; };
static const char* s_down_arrow_bitmap_data = { static constexpr Gfx::CharacterBitmap s_down_arrow_bitmap {
" " " "
" " " "
" " " "
@ -36,10 +38,11 @@ static const char* s_down_arrow_bitmap_data = {
" ### " " ### "
" # " " # "
" " " "
" " " ",
9, 9
}; };
static const char* s_left_arrow_bitmap_data = { static constexpr Gfx::CharacterBitmap s_left_arrow_bitmap {
" " " "
" # " " # "
" ## " " ## "
@ -48,10 +51,11 @@ static const char* s_left_arrow_bitmap_data = {
" ### " " ### "
" ## " " ## "
" # " " # "
" " " ",
9, 9
}; };
static const char* s_right_arrow_bitmap_data = { static constexpr Gfx::CharacterBitmap s_right_arrow_bitmap {
" " " "
" # " " # "
" ## " " ## "
@ -60,26 +64,14 @@ static const char* s_right_arrow_bitmap_data = {
" ### " " ### "
" ## " " ## "
" # " " # "
" " " ",
9, 9
}; };
static Gfx::CharacterBitmap* s_up_arrow_bitmap;
static Gfx::CharacterBitmap* s_down_arrow_bitmap;
static Gfx::CharacterBitmap* s_left_arrow_bitmap;
static Gfx::CharacterBitmap* s_right_arrow_bitmap;
Scrollbar::Scrollbar(Orientation orientation) Scrollbar::Scrollbar(Orientation orientation)
: AbstractSlider(orientation) : AbstractSlider(orientation)
{ {
m_automatic_scrolling_timer = add<Core::Timer>(); m_automatic_scrolling_timer = add<Core::Timer>();
if (!s_up_arrow_bitmap)
s_up_arrow_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 9, 9).leak_ref();
if (!s_down_arrow_bitmap)
s_down_arrow_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, 9, 9).leak_ref();
if (!s_left_arrow_bitmap)
s_left_arrow_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_left_arrow_bitmap_data, 9, 9).leak_ref();
if (!s_right_arrow_bitmap)
s_right_arrow_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_right_arrow_bitmap_data, 9, 9).leak_ref();
if (orientation == Orientation::Vertical) { if (orientation == Orientation::Vertical) {
set_fixed_width(16); set_fixed_width(16);
@ -210,15 +202,15 @@ void Scrollbar::paint_event(PaintEvent& event)
if (decrement_pressed) if (decrement_pressed)
decrement_location.translate_by(1, 1); decrement_location.translate_by(1, 1);
if (!has_scrubber() || !is_enabled()) if (!has_scrubber() || !is_enabled())
painter.draw_bitmap(decrement_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, palette().threed_highlight()); painter.draw_bitmap(decrement_location.translated(1, 1), orientation() == Orientation::Vertical ? s_up_arrow_bitmap : s_left_arrow_bitmap, palette().threed_highlight());
painter.draw_bitmap(decrement_location, orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1()); painter.draw_bitmap(decrement_location, orientation() == Orientation::Vertical ? s_up_arrow_bitmap : s_left_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());
auto increment_location = increment_button_rect().location().translated(3, 3); auto increment_location = increment_button_rect().location().translated(3, 3);
if (increment_pressed) if (increment_pressed)
increment_location.translate_by(1, 1); increment_location.translate_by(1, 1);
if (!has_scrubber() || !is_enabled()) if (!has_scrubber() || !is_enabled())
painter.draw_bitmap(increment_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, palette().threed_highlight()); painter.draw_bitmap(increment_location.translated(1, 1), orientation() == Orientation::Vertical ? s_down_arrow_bitmap : s_right_arrow_bitmap, palette().threed_highlight());
painter.draw_bitmap(increment_location, orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1()); painter.draw_bitmap(increment_location, orientation() == Orientation::Vertical ? s_down_arrow_bitmap : s_right_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());
} }
if (has_scrubber() && !scrubber_rect().is_null()) if (has_scrubber() && !scrubber_rect().is_null())

View file

@ -6,7 +6,6 @@ set(SOURCES
BitmapFont.cpp BitmapFont.cpp
BMPLoader.cpp BMPLoader.cpp
BMPWriter.cpp BMPWriter.cpp
CharacterBitmap.cpp
ClassicStylePainter.cpp ClassicStylePainter.cpp
ClassicWindowTheme.cpp ClassicWindowTheme.cpp
Color.cpp Color.cpp

View file

@ -1,26 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CharacterBitmap.h"
namespace Gfx {
CharacterBitmap::CharacterBitmap(const char* ascii_data, unsigned width, unsigned height)
: m_bits(ascii_data)
, m_size(width, height)
{
}
CharacterBitmap::~CharacterBitmap()
{
}
NonnullRefPtr<CharacterBitmap> CharacterBitmap::create_from_ascii(const char* asciiData, unsigned width, unsigned height)
{
return adopt_ref(*new CharacterBitmap(asciiData, width, height));
}
}

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -9,26 +10,31 @@
#include "Size.h" #include "Size.h"
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/StringView.h>
namespace Gfx { namespace Gfx {
class CharacterBitmap : public RefCounted<CharacterBitmap> { class CharacterBitmap {
public: public:
static NonnullRefPtr<CharacterBitmap> create_from_ascii(const char* asciiData, unsigned width, unsigned height); CharacterBitmap() = delete;
~CharacterBitmap(); constexpr CharacterBitmap(StringView ascii_data, unsigned width, unsigned height)
: m_bits(ascii_data)
, m_size(width, height)
{
}
bool bit_at(unsigned x, unsigned y) const { return m_bits[y * width() + x] == '#'; } constexpr ~CharacterBitmap() = default;
const char* bits() const { return m_bits; }
IntSize size() const { return m_size; } constexpr bool bit_at(unsigned x, unsigned y) const { return m_bits[y * width() + x] == '#'; }
unsigned width() const { return m_size.width(); } constexpr StringView bits() const { return m_bits; }
unsigned height() const { return m_size.height(); }
constexpr IntSize size() const { return m_size; }
constexpr unsigned width() const { return m_size.width(); }
constexpr unsigned height() const { return m_size.height(); }
private: private:
CharacterBitmap(const char* b, unsigned w, unsigned h); StringView m_bits {};
IntSize m_size {};
const char* m_bits { nullptr };
IntSize m_size;
}; };
} }

View file

@ -2,6 +2,7 @@
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Sarah Taube <metalflakecobaltpaint@gmail.com> * Copyright (c) 2020, Sarah Taube <metalflakecobaltpaint@gmail.com>
* Copyright (c) 2021, Filiph Sandström <filiph.sandstrom@filfatstudios.com> * Copyright (c) 2021, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -391,7 +392,7 @@ void ClassicStylePainter::paint_radio_button(Painter& painter, IntRect const& re
painter.blit(rect.location(), bitmap, bitmap.rect()); painter.blit(rect.location(), bitmap, bitmap.rect());
} }
static char const* s_checked_bitmap_data = { static constexpr Gfx::CharacterBitmap s_checked_bitmap {
" " " "
" # " " # "
" ## " " ## "
@ -400,13 +401,10 @@ static char const* s_checked_bitmap_data = {
" ##### " " ##### "
" ### " " ### "
" # " " # "
" " " ",
9, 9
}; };
static Gfx::CharacterBitmap* s_checked_bitmap;
static int const s_checked_bitmap_width = 9;
static int const s_checked_bitmap_height = 9;
void ClassicStylePainter::paint_check_box(Painter& painter, IntRect const& rect, Palette const& palette, bool is_enabled, bool is_checked, bool is_being_pressed) void ClassicStylePainter::paint_check_box(Painter& painter, IntRect const& rect, Palette const& palette, bool is_enabled, bool is_checked, bool is_being_pressed)
{ {
painter.fill_rect(rect, is_enabled ? palette.base() : palette.window()); painter.fill_rect(rect, is_enabled ? palette.base() : palette.window());
@ -418,9 +416,7 @@ void ClassicStylePainter::paint_check_box(Painter& painter, IntRect const& rect,
} }
if (is_checked) { if (is_checked) {
if (!s_checked_bitmap) painter.draw_bitmap(rect.shrunken(4, 4).location(), s_checked_bitmap, is_enabled ? palette.base_text() : palette.threed_shadow1());
s_checked_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref();
painter.draw_bitmap(rect.shrunken(4, 4).location(), *s_checked_bitmap, is_enabled ? palette.base_text() : palette.threed_shadow1());
} }
} }

View file

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Shannon Booth <shannon.ml.booth@gmail.com> * Copyright (c) 2020, Shannon Booth <shannon.ml.booth@gmail.com>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -55,7 +56,7 @@ const Gfx::Font& Menu::font() const
return Gfx::FontDatabase::default_font(); return Gfx::FontDatabase::default_font();
} }
static const char* s_submenu_arrow_bitmap_data = { static constexpr Gfx::CharacterBitmap s_submenu_arrow_bitmap {
" " " "
" # " " # "
" ## " " ## "
@ -64,13 +65,12 @@ static const char* s_submenu_arrow_bitmap_data = {
" ### " " ### "
" ## " " ## "
" # " " # "
" " " ",
9, 9
}; };
static const int s_submenu_arrow_bitmap_width = 9; static constexpr int s_item_icon_width = 16;
static const int s_submenu_arrow_bitmap_height = 9; static constexpr int s_stripe_width = 24;
static const int s_item_icon_width = 16;
static const int s_stripe_width = 24;
int Menu::content_width() const int Menu::content_width() const
{ {
@ -269,15 +269,14 @@ void Menu::draw(MenuItem const& item, bool is_drawing_all)
} }
painter.set_font(previous_font); painter.set_font(previous_font);
if (item.is_submenu()) { if (item.is_submenu()) {
static auto& submenu_arrow_bitmap = Gfx::CharacterBitmap::create_from_ascii(s_submenu_arrow_bitmap_data, s_submenu_arrow_bitmap_width, s_submenu_arrow_bitmap_height).leak_ref();
Gfx::IntRect submenu_arrow_rect { Gfx::IntRect submenu_arrow_rect {
item.rect().right() - s_submenu_arrow_bitmap_width - 2, item.rect().right() - static_cast<int>(s_submenu_arrow_bitmap.width()) - 2,
0, 0,
s_submenu_arrow_bitmap_width, s_submenu_arrow_bitmap.width(),
s_submenu_arrow_bitmap_height s_submenu_arrow_bitmap.height()
}; };
submenu_arrow_rect.center_vertically_within(item.rect()); submenu_arrow_rect.center_vertically_within(item.rect());
painter.draw_bitmap(submenu_arrow_rect.location(), submenu_arrow_bitmap, text_color); painter.draw_bitmap(submenu_arrow_rect.location(), s_submenu_arrow_bitmap, text_color);
} }
} else if (item.type() == MenuItem::Separator) { } else if (item.type() == MenuItem::Separator) {
Gfx::IntPoint p1(item.rect().translated(stripe_rect.width() + 4, 0).x(), item.rect().center().y() - 1); Gfx::IntPoint p1(item.rect().translated(stripe_rect.width() + 4, 0).x(), item.rect().center().y() - 1);