1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +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

@ -2,6 +2,7 @@
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Sarah Taube <metalflakecobaltpaint@gmail.com>
* Copyright (c) 2021, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
* Copyright (c) 2022, the SerenityOS developers.
*
* 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());
}
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)
{
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 (!s_checked_bitmap)
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());
painter.draw_bitmap(rect.shrunken(4, 4).location(), s_checked_bitmap, is_enabled ? palette.base_text() : palette.threed_shadow1());
}
}