AbstractThemePreview.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
  5. * Copyright (c) 2022, the SerenityOS developers.
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <LibGUI/Frame.h>
  11. #include <LibGfx/Bitmap.h>
  12. #include <LibGfx/Palette.h>
  13. #include <LibGfx/WindowTheme.h>
  14. namespace GUI {
  15. class AbstractThemePreview : public GUI::Frame {
  16. C_OBJECT_ABSTRACT(AbstractThemePreview);
  17. public:
  18. virtual ~AbstractThemePreview() override = default;
  19. Gfx::Palette const& preview_palette() const { return m_preview_palette; }
  20. void set_preview_palette(Gfx::Palette const&);
  21. void set_theme_from_file(Core::File&);
  22. void set_theme(Core::AnonymousBuffer const&);
  23. void paint_window(StringView title, Gfx::IntRect const& rect, Gfx::WindowTheme::WindowState, Gfx::Bitmap const& icon, int button_count = 3);
  24. Function<void(String const&)> on_theme_load_from_file;
  25. Function<void()> on_palette_change;
  26. struct Window {
  27. Gfx::IntRect& rect;
  28. };
  29. void center_window_group_within(Span<Window> windows, Gfx::IntRect const& bounds);
  30. protected:
  31. explicit AbstractThemePreview(Gfx::Palette const&);
  32. inline Gfx::Bitmap const& active_window_icon() const
  33. {
  34. VERIFY(m_active_window_icon);
  35. return *m_active_window_icon;
  36. }
  37. inline Gfx::Bitmap const& inactive_window_icon() const
  38. {
  39. VERIFY(m_inactive_window_icon);
  40. return *m_inactive_window_icon;
  41. }
  42. virtual void palette_changed() {};
  43. private:
  44. virtual void paint_preview(GUI::PaintEvent&) = 0;
  45. void load_theme_bitmaps();
  46. virtual void paint_event(GUI::PaintEvent&) override;
  47. Gfx::Palette m_preview_palette;
  48. RefPtr<Gfx::Bitmap> m_active_window_icon;
  49. RefPtr<Gfx::Bitmap> m_inactive_window_icon;
  50. RefPtr<Gfx::Bitmap> m_default_close_bitmap;
  51. RefPtr<Gfx::Bitmap> m_default_maximize_bitmap;
  52. RefPtr<Gfx::Bitmap> m_default_minimize_bitmap;
  53. RefPtr<Gfx::Bitmap> m_close_bitmap;
  54. RefPtr<Gfx::Bitmap> m_maximize_bitmap;
  55. RefPtr<Gfx::Bitmap> m_minimize_bitmap;
  56. String m_last_close_path;
  57. String m_last_maximize_path;
  58. String m_last_minimize_path;
  59. RefPtr<Gfx::Bitmap> m_active_window_shadow;
  60. RefPtr<Gfx::Bitmap> m_inactive_window_shadow;
  61. RefPtr<Gfx::Bitmap> m_menu_shadow;
  62. RefPtr<Gfx::Bitmap> m_taskbar_shadow;
  63. RefPtr<Gfx::Bitmap> m_tooltip_shadow;
  64. String m_last_active_window_shadow_path;
  65. String m_last_inactive_window_shadow_path;
  66. String m_last_menu_shadow_path;
  67. String m_last_taskbar_shadow_path;
  68. String m_last_tooltip_shadow_path;
  69. };
  70. }