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) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -12,7 +13,8 @@
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()
{
set_override_cursor(Gfx::StandardCursor::ResizeDiagonalTLBR);
@ -72,13 +71,8 @@ void ResizeCorner::paint_event(PaintEvent& event)
painter.add_clip_rect(event.rect());
painter.fill_rect(rect(), palette().color(background_role()));
if (!s_resize_corner_shadows_bitmap)
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_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());
painter.draw_bitmap({ 0, 2 }, s_resize_corner_shadows_bitmap, palette().threed_shadow1());
painter.draw_bitmap({ 0, 2 }, s_resize_corner_highlights_bitmap, palette().threed_highlight());
Widget::paint_event(event);
}