blob: fbe01f66dad1e8425e96af87d4f99e0faa6c1970 (
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
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* 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() { }
const Gfx::Bitmap* 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() { }
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(const IconImpl&);
Icon(const Icon&);
~Icon() { }
static Icon default_icon(StringView);
Icon& operator=(const Icon& other)
{
if (this != &other)
m_impl = other.m_impl;
return *this;
}
const Gfx::Bitmap* 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)); }
const IconImpl& impl() const { return *m_impl; }
Vector<int> sizes() const { return m_impl->sizes(); }
private:
NonnullRefPtr<IconImpl> m_impl;
};
}
|