summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GIcon.h
blob: d849929a50af114aeb217ab5e310173a57ba10d2 (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
#pragma once

#include <AK/HashMap.h>
#include <LibDraw/GraphicsBitmap.h>

class GIconImpl : public RefCounted<GIconImpl> {
public:
    static NonnullRefPtr<GIconImpl> create() { return adopt(*new GIconImpl); }
    ~GIconImpl() {}

    const GraphicsBitmap* bitmap_for_size(int) const;
    void set_bitmap_for_size(int, RefPtr<GraphicsBitmap>&&);

private:
    GIconImpl() {}
    HashMap<int, RefPtr<GraphicsBitmap>> m_bitmaps;
};

class GIcon {
public:
    GIcon();
    explicit GIcon(RefPtr<GraphicsBitmap>&&);
    explicit GIcon(RefPtr<GraphicsBitmap>&&, RefPtr<GraphicsBitmap>&&);
    explicit GIcon(const GIconImpl&);
    GIcon(const GIcon&);
    ~GIcon() {}

    static GIcon default_icon(const StringView&);

    GIcon& operator=(const GIcon& other)
    {
        if (this != &other)
            m_impl = other.m_impl;
        return *this;
    }

    const GraphicsBitmap* bitmap_for_size(int size) const { return m_impl->bitmap_for_size(size); }
    void set_bitmap_for_size(int size, RefPtr<GraphicsBitmap>&& bitmap) { m_impl->set_bitmap_for_size(size, move(bitmap)); }

    const GIconImpl& impl() const { return *m_impl; }

private:
    NonnullRefPtr<GIconImpl> m_impl;
};