/* * Copyright (c) 2018-2023, Andreas Kling * Copyright (c) 2021, Julius Heijmen * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace GUI { class IconImpl : public RefCounted { public: static NonnullRefPtr create() { return adopt_ref(*new IconImpl); } ~IconImpl() = default; Gfx::Bitmap const* bitmap_for_size(int) const; void set_bitmap_for_size(int, RefPtr&&); Vector sizes() const { Vector sizes; for (auto& it : m_bitmaps) sizes.append(it.key); return sizes; } private: IconImpl() = default; HashMap> m_bitmaps; }; class Icon { public: Icon(); explicit Icon(RefPtr&&); explicit Icon(RefPtr&&, RefPtr&&); explicit Icon(IconImpl const&); Icon(Icon const&); ~Icon() = default; static Icon default_icon(StringView); static ErrorOr 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&& bitmap) { m_impl->set_bitmap_for_size(size, move(bitmap)); } IconImpl const& impl() const { return *m_impl; } Vector sizes() const { return m_impl->sizes(); } private: NonnullRefPtr m_impl; }; }