ladybird/LibGUI/GIcon.h
Andreas Kling be604652ae LibGUI: Add GIcon::default_icon(name).
This is a convenience helper to instantiate a GIcon like so:

    auto icon = GIcon::default_icon("filetype-image");

This will give you the "filetype-image" icon in both 16x16 and 32x32 sizes.
2019-03-25 14:46:37 +01:00

44 lines
1.2 KiB
C++

#pragma once
#include <SharedGraphics/GraphicsBitmap.h>
#include <AK/HashMap.h>
class GIconImpl : public Retainable<GIconImpl> {
public:
static Retained<GIconImpl> create() { return adopt(*new GIconImpl); }
~GIconImpl() { }
const GraphicsBitmap* bitmap_for_size(int) const;
void set_bitmap_for_size(int, RetainPtr<GraphicsBitmap>&&);
private:
GIconImpl() { }
HashMap<int, RetainPtr<GraphicsBitmap>> m_bitmaps;
};
class GIcon {
public:
GIcon();
explicit GIcon(RetainPtr<GraphicsBitmap>&&);
explicit GIcon(RetainPtr<GraphicsBitmap>&&, RetainPtr<GraphicsBitmap>&&);
explicit GIcon(const GIconImpl&);
GIcon(const GIcon&);
~GIcon() { }
static GIcon default_icon(const String&);
GIcon& operator=(const GIcon& other)
{
m_impl = other.m_impl.copy_ref();
return *this;
}
const GraphicsBitmap* bitmap_for_size(int size) const { return m_impl->bitmap_for_size(size); }
void set_bitmap_for_size(int size, RetainPtr<GraphicsBitmap>&& bitmap) { m_impl->set_bitmap_for_size(size, move(bitmap)); }
const GIconImpl& impl() const { return *m_impl; }
private:
Retained<GIconImpl> m_impl;
};