summaryrefslogtreecommitdiff
path: root/Userland/Services/WindowServer/MultiScaleBitmaps.h
blob: 47789bd28470f7df467c857ce7ce88773eda6597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * 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 };
};

}