blob: b11cbcf42be7854bd3ccd05cee72a20d2a40ad4a (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Julius Heijmen <julius.heijmen@gmail.com>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <LibGfx/Bitmap.h>
namespace GUI {
class IconImpl : public RefCounted<IconImpl> {
public:
static NonnullRefPtr<IconImpl> create() { return adopt_ref(*new IconImpl); }
~IconImpl() = default;
Gfx::Bitmap const* bitmap_for_size(int) const;
void set_bitmap_for_size(int, RefPtr<Gfx::Bitmap>&&);
Vector<int> sizes() const
{
Vector<int> sizes;
for (auto& it : m_bitmaps)
sizes.append(it.key);
return sizes;
}
private:
IconImpl() = default;
HashMap<int, RefPtr<Gfx::Bitmap>> m_bitmaps;
};
class Icon {
public:
Icon();
explicit Icon(RefPtr<Gfx::Bitmap>&&);
explicit Icon(RefPtr<Gfx::Bitmap>&&, RefPtr<Gfx::Bitmap>&&);
explicit Icon(IconImpl const&);
Icon(Icon const&);
~Icon() = default;
static Icon default_icon(StringView);
static ErrorOr<Icon> try_create_default_icon(StringView);
Icon& operator=(Icon const& other)
{
if (this != &other)
m_impl = other.m_impl;
return *this;
}
Gfx::Bitmap const* bitmap_for_size(int size) const { return m_impl->bitmap_for_size(size); }
void set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap) { m_impl->set_bitmap_for_size(size, move(bitmap)); }
IconImpl const& impl() const { return *m_impl; }
Vector<int> sizes() const { return m_impl->sizes(); }
private:
NonnullRefPtr<IconImpl> m_impl;
};
}
|