AbstractThemePreview.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 paint_window(StringView title, Gfx::IntRect const& rect, Gfx::WindowTheme::WindowState, Gfx::Bitmap const& icon, int button_count = 3);
  23. Function<void(String const&)> on_theme_load_from_file;
  24. Function<void()> on_palette_change;
  25. protected:
  26. explicit AbstractThemePreview(Gfx::Palette const&);
  27. inline Gfx::Bitmap const& active_window_icon() const
  28. {
  29. VERIFY(m_active_window_icon);
  30. return *m_active_window_icon;
  31. }
  32. inline Gfx::Bitmap const& inactive_window_icon() const
  33. {
  34. VERIFY(m_inactive_window_icon);
  35. return *m_inactive_window_icon;
  36. }
  37. virtual void palette_changed() {};
  38. private:
  39. virtual void paint_preview(GUI::PaintEvent&) = 0;
  40. void load_theme_bitmaps();
  41. virtual void paint_event(GUI::PaintEvent&) override;
  42. Gfx::Palette m_preview_palette;
  43. RefPtr<Gfx::Bitmap> m_active_window_icon;
  44. RefPtr<Gfx::Bitmap> m_inactive_window_icon;
  45. RefPtr<Gfx::Bitmap> m_default_close_bitmap;
  46. RefPtr<Gfx::Bitmap> m_default_maximize_bitmap;
  47. RefPtr<Gfx::Bitmap> m_default_minimize_bitmap;
  48. RefPtr<Gfx::Bitmap> m_close_bitmap;
  49. RefPtr<Gfx::Bitmap> m_maximize_bitmap;
  50. RefPtr<Gfx::Bitmap> m_minimize_bitmap;
  51. String m_last_close_path;
  52. String m_last_maximize_path;
  53. String m_last_minimize_path;
  54. RefPtr<Gfx::Bitmap> m_active_window_shadow;
  55. RefPtr<Gfx::Bitmap> m_inactive_window_shadow;
  56. RefPtr<Gfx::Bitmap> m_menu_shadow;
  57. RefPtr<Gfx::Bitmap> m_taskbar_shadow;
  58. RefPtr<Gfx::Bitmap> m_tooltip_shadow;
  59. String m_last_active_window_shadow_path;
  60. String m_last_inactive_window_shadow_path;
  61. String m_last_menu_shadow_path;
  62. String m_last_taskbar_shadow_path;
  63. String m_last_tooltip_shadow_path;
  64. };
  65. }