ClassicWindowTheme.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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();
  13. virtual ~ClassicWindowTheme() override;
  14. virtual void paint_normal_frame(Painter& painter, WindowState window_state, const IntRect& window_rect, const StringView& window_title, const Bitmap& icon, const Palette& palette, const IntRect& leftmost_button_rect, int menu_row_count, bool window_modified) const override;
  15. virtual void paint_tool_window_frame(Painter&, WindowState, const IntRect& window_rect, const StringView& title, const Palette&, const IntRect& leftmost_button_rect) const override;
  16. virtual void paint_notification_frame(Painter&, const IntRect& window_rect, const Palette&, const IntRect& close_button_rect) const override;
  17. virtual int titlebar_height(WindowType, const Palette&) const override;
  18. virtual IntRect titlebar_rect(WindowType, const IntRect& window_rect, const Palette&) const override;
  19. virtual IntRect titlebar_icon_rect(WindowType, const IntRect& window_rect, const Palette&) const override;
  20. virtual IntRect titlebar_text_rect(WindowType, const IntRect& window_rect, const Palette&) const override;
  21. virtual IntRect menubar_rect(WindowType, const IntRect& window_rect, const Palette&, int menu_row_count) const override;
  22. virtual IntRect frame_rect_for_window(WindowType, const IntRect& window_rect, const Palette&, int menu_row_count) const override;
  23. virtual Vector<IntRect> layout_buttons(WindowType, const IntRect& window_rect, const Palette&, size_t buttons) const override;
  24. virtual bool is_simple_rect_frame() const override { return true; }
  25. virtual bool frame_uses_alpha(WindowState state, const Palette& palette) const override
  26. {
  27. return compute_frame_colors(state, palette).uses_alpha();
  28. }
  29. virtual float frame_alpha_hit_threshold(WindowState) const override { return 1.0f; }
  30. private:
  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 atually 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, const Palette&) const;
  46. };
  47. }