Icon.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashMap.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/RefCounted.h>
  10. #include <LibGfx/Bitmap.h>
  11. namespace GUI {
  12. class IconImpl : public RefCounted<IconImpl> {
  13. public:
  14. static NonnullRefPtr<IconImpl> create() { return adopt_ref(*new IconImpl); }
  15. ~IconImpl() { }
  16. const Gfx::Bitmap* bitmap_for_size(int) const;
  17. void set_bitmap_for_size(int, RefPtr<Gfx::Bitmap>&&);
  18. Vector<int> sizes() const
  19. {
  20. Vector<int> sizes;
  21. for (auto& it : m_bitmaps)
  22. sizes.append(it.key);
  23. return sizes;
  24. }
  25. private:
  26. IconImpl() { }
  27. HashMap<int, RefPtr<Gfx::Bitmap>> m_bitmaps;
  28. };
  29. class Icon {
  30. public:
  31. Icon();
  32. explicit Icon(RefPtr<Gfx::Bitmap>&&);
  33. explicit Icon(RefPtr<Gfx::Bitmap>&&, RefPtr<Gfx::Bitmap>&&);
  34. explicit Icon(const IconImpl&);
  35. Icon(const Icon&);
  36. ~Icon() { }
  37. static Icon default_icon(const StringView&);
  38. Icon& operator=(const Icon& other)
  39. {
  40. if (this != &other)
  41. m_impl = other.m_impl;
  42. return *this;
  43. }
  44. const Gfx::Bitmap* bitmap_for_size(int size) const { return m_impl->bitmap_for_size(size); }
  45. void set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap) { m_impl->set_bitmap_for_size(size, move(bitmap)); }
  46. const IconImpl& impl() const { return *m_impl; }
  47. Vector<int> sizes() const { return m_impl->sizes(); }
  48. private:
  49. NonnullRefPtr<IconImpl> m_impl;
  50. };
  51. }