ladybird/Userland/Services/WindowServer/MultiScaleBitmaps.h
MacDue 857a767ab4 WindowServer: Fix crash when hovering over title buttons
This fixes a crash where if you switched to a theme that has hover
icons for title buttons, then back to a theme that does not. Then
when you next hover over the title buttons the window server would
crash.

This was due to the hover_bitmap multi-scale bitmap pointer being
non-null, but not containing any bitmaps, so hitting an assertion
when painting.
2022-05-18 19:05:18 +02:00

37 lines
1.1 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <LibGfx/Bitmap.h>
namespace WindowServer {
class MultiScaleBitmaps : public RefCounted<MultiScaleBitmaps> {
public:
static RefPtr<MultiScaleBitmaps> create_empty();
static RefPtr<MultiScaleBitmaps> create(StringView filename, StringView default_filename = {});
Gfx::Bitmap const& default_bitmap() const { return bitmap(1); }
Gfx::Bitmap const& bitmap(int scale_factor) const;
Gfx::Bitmap const* find_bitmap(int scale_factor) const;
Gfx::BitmapFormat format() const { return m_format; }
bool load(StringView filename, StringView default_filename = {});
void add_bitmap(int scale_factor, NonnullRefPtr<Gfx::Bitmap>&&);
bool is_empty() const { return m_bitmaps.is_empty(); }
private:
MultiScaleBitmaps() = default;
HashMap<int, NonnullRefPtr<Gfx::Bitmap>> m_bitmaps;
Gfx::BitmapFormat m_format { Gfx::BitmapFormat::Invalid };
};
}