mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27: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:
parent
dc518404ce
commit
d5fdc6096c
9 changed files with 97 additions and 135 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020, Shannon Booth <shannon.ml.booth@gmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -55,7 +56,7 @@ const Gfx::Font& Menu::font() const
|
|||
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 const int s_submenu_arrow_bitmap_height = 9;
|
||||
static const int s_item_icon_width = 16;
|
||||
static const int s_stripe_width = 24;
|
||||
static constexpr int s_item_icon_width = 16;
|
||||
static constexpr int s_stripe_width = 24;
|
||||
|
||||
int Menu::content_width() const
|
||||
{
|
||||
|
@ -269,15 +269,14 @@ void Menu::draw(MenuItem const& item, bool is_drawing_all)
|
|||
}
|
||||
painter.set_font(previous_font);
|
||||
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 {
|
||||
item.rect().right() - s_submenu_arrow_bitmap_width - 2,
|
||||
item.rect().right() - static_cast<int>(s_submenu_arrow_bitmap.width()) - 2,
|
||||
0,
|
||||
s_submenu_arrow_bitmap_width,
|
||||
s_submenu_arrow_bitmap_height
|
||||
s_submenu_arrow_bitmap.width(),
|
||||
s_submenu_arrow_bitmap.height()
|
||||
};
|
||||
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) {
|
||||
Gfx::IntPoint p1(item.rect().translated(stripe_rect.width() + 4, 0).x(), item.rect().center().y() - 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue