mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibGUI+FileManager: Add a GIcon class to support multi-size icons.
A GIcon can contain any number of bitmaps internally, and will give you the best fitting icon when you call bitmap_for_size().
This commit is contained in:
parent
7e54fdce99
commit
86413a6f5a
12 changed files with 165 additions and 23 deletions
41
LibGUI/GIcon.h
Normal file
41
LibGUI/GIcon.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#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() { }
|
||||
|
||||
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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue