ClassicWindowTheme.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGfx/Color.h>
  8. #include <LibGfx/WindowTheme.h>
  9. namespace Gfx {
  10. class ClassicWindowTheme final : public WindowTheme {
  11. public:
  12. ClassicWindowTheme() = default;
  13. virtual ~ClassicWindowTheme() override = default;
  14. virtual void paint_normal_frame(Painter& painter, WindowState window_state, WindowMode window_mode, IntRect const& window_rect, StringView window_title, Bitmap const& icon, Palette const& palette, IntRect const& leftmost_button_rect, int menu_row_count, bool window_modified) const override;
  15. virtual void paint_notification_frame(Painter&, WindowMode, IntRect const& window_rect, Palette const&, IntRect const& close_button_rect) const override;
  16. virtual int titlebar_height(WindowType, WindowMode, Palette const&) const override;
  17. virtual IntRect titlebar_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const override;
  18. virtual IntRect titlebar_icon_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const override;
  19. virtual IntRect titlebar_text_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&) const override;
  20. virtual IntRect menubar_rect(WindowType, WindowMode, IntRect const& window_rect, Palette const&, int menu_row_count) const override;
  21. virtual IntRect frame_rect_for_window(WindowType, WindowMode, IntRect const& window_rect, Palette const&, int menu_row_count) const override;
  22. virtual Vector<IntRect> layout_buttons(WindowType, WindowMode, IntRect const& window_rect, Palette const&, size_t buttons) const override;
  23. virtual bool is_simple_rect_frame() const override { return true; }
  24. virtual bool frame_uses_alpha(WindowState state, Palette const& palette) const override
  25. {
  26. return compute_frame_colors(state, palette).uses_alpha();
  27. }
  28. virtual float frame_alpha_hit_threshold(WindowState) const override { return 1.0f; }
  29. private:
  30. int menubar_height() const;
  31. struct FrameColors {
  32. Color title_color;
  33. Color border_color;
  34. Color border_color2;
  35. Color title_stripes_color;
  36. Color title_shadow_color;
  37. bool uses_alpha() const
  38. {
  39. // We don't care about the title_stripes_color or title_shadow_color alpha channels because they are
  40. // effectively rendered on top of the borders and don't mean whether the frame itself actually has
  41. // any alpha channels that would require the entire frame to be rendered as transparency.
  42. return title_color.alpha() != 0xff || border_color.alpha() != 0xff || border_color2.alpha() != 0xff;
  43. }
  44. };
  45. FrameColors compute_frame_colors(WindowState, Palette const&) const;
  46. };
  47. }