AbstractThemePreview.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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& preview_palette() { return m_preview_palette; }
  20. void set_preview_palette(Gfx::Palette&);
  21. ErrorOr<void> set_theme_from_file(StringView path, NonnullOwnPtr<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()> on_palette_change;
  25. struct Window {
  26. Gfx::IntRect& rect;
  27. };
  28. void center_window_group_within(Span<Window> windows, Gfx::IntRect const& bounds);
  29. protected:
  30. explicit AbstractThemePreview(Gfx::Palette const&);
  31. inline Gfx::Bitmap const& active_window_icon() const
  32. {
  33. VERIFY(m_active_window_icon);
  34. return *m_active_window_icon;
  35. }
  36. inline Gfx::Bitmap const& inactive_window_icon() const
  37. {
  38. VERIFY(m_inactive_window_icon);
  39. return *m_inactive_window_icon;
  40. }
  41. virtual void palette_changed() {};
  42. private:
  43. virtual void paint_preview(GUI::PaintEvent&) = 0;
  44. void load_theme_bitmaps();
  45. virtual void paint_event(GUI::PaintEvent&) override;
  46. Gfx::Palette m_preview_palette;
  47. RefPtr<Gfx::Bitmap> m_active_window_icon;
  48. RefPtr<Gfx::Bitmap> m_inactive_window_icon;
  49. RefPtr<Gfx::Bitmap> m_default_close_bitmap;
  50. RefPtr<Gfx::Bitmap> m_default_maximize_bitmap;
  51. RefPtr<Gfx::Bitmap> m_default_minimize_bitmap;
  52. RefPtr<Gfx::Bitmap> m_close_bitmap;
  53. RefPtr<Gfx::Bitmap> m_maximize_bitmap;
  54. RefPtr<Gfx::Bitmap> m_minimize_bitmap;
  55. DeprecatedString m_last_close_path;
  56. DeprecatedString m_last_maximize_path;
  57. DeprecatedString m_last_minimize_path;
  58. RefPtr<Gfx::Bitmap> m_active_window_shadow;
  59. RefPtr<Gfx::Bitmap> m_inactive_window_shadow;
  60. RefPtr<Gfx::Bitmap> m_menu_shadow;
  61. RefPtr<Gfx::Bitmap> m_taskbar_shadow;
  62. RefPtr<Gfx::Bitmap> m_tooltip_shadow;
  63. DeprecatedString m_last_active_window_shadow_path;
  64. DeprecatedString m_last_inactive_window_shadow_path;
  65. DeprecatedString m_last_menu_shadow_path;
  66. DeprecatedString m_last_taskbar_shadow_path;
  67. DeprecatedString m_last_tooltip_shadow_path;
  68. };
  69. }