1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#pragma once
10#include "../../../shared/MessageContent/MenuBar.h"
11#include "../../Components/Elements/Button.h"
12#include "../../Constants/Colors.h"
13#include "../../IPC/Event.h"
14#include <libfoundation/EventReceiver.h>
15#include <libg/Context.h>
16#include <libg/PixelBitmap.h>
17
18namespace WinServer {
19class Compositor;
20}
21
22namespace WinServer::Desktop {
23
24class Window;
25
26class WindowFrame {
27public:
28 explicit WindowFrame(Window& window);
29 WindowFrame(Window& window, std::vector<Button*>&& control_panel_buttons, std::vector<Button*>&& window_control_buttons);
30 ~WindowFrame() = default;
31
32 void draw(LG::Context&);
33 static constexpr size_t std_app_header_size() { return 26; }
34 static constexpr size_t std_top_border_frame_size() { return 4; }
35 static constexpr size_t std_top_border_size() { return std_top_border_frame_size() + std_app_header_size(); }
36 static constexpr size_t std_bottom_border_size() { return 4; }
37 static constexpr size_t std_left_border_size() { return 4; }
38 static constexpr size_t std_right_border_size() { return 4; }
39 inline size_t top_border_size() const { return m_top_border_size; }
40 inline size_t bottom_border_size() const { return std_bottom_border_size(); }
41 inline size_t left_border_size() const { return std_left_border_size(); }
42 inline size_t right_border_size() const { return std_right_border_size(); }
43
44 const LG::Rect bounds() const;
45
46 void receive_tap_event(const LG::Point<int>& tap);
47
48 void on_set_app_title();
49 void add_control(const std::string& title);
50
51 inline std::vector<Button*>& window_control_buttons() { return m_window_control_buttons; }
52 inline const std::vector<Button*>& window_control_buttons() const { return m_window_control_buttons; }
53
54 inline std::vector<Button*>& control_panel_buttons() { return m_control_panel_buttons; }
55 inline const std::vector<Button*>& control_panel_buttons() const { return m_control_panel_buttons; }
56 void handle_control_panel_tap(int button_id);
57
58 inline StatusBarStyle style() const { return m_style; }
59 void set_style(StatusBarStyle ts);
60
61 void set_visible(bool visible)
62 {
63 m_top_border_size = visible ? std_top_border_size() : 0;
64 m_visible = visible;
65 }
66
67 bool visible() const { return m_visible; }
68 void set_active(bool active) { m_active = active; }
69 bool active() const { return m_active; }
70
71 void invalidate(WinServer::Compositor& compositor) const;
72
73 void on_set_icon();
74
75 static constexpr int spacing() { return 8; }
76 static constexpr int icon_width() { return 12; }
77 static constexpr int icon_y_offset() { return 7 + std_top_border_frame_size(); }
78 static constexpr int text_y_offset() { return 9 + std_top_border_frame_size(); }
79 static constexpr int button_y_offset() { return 8 + std_top_border_frame_size(); }
80
81private:
82 Window& m_window;
83 std::vector<Button*> m_window_control_buttons;
84 std::vector<Button*> m_control_panel_buttons;
85 LG::Color m_text_colors[2];
86 LG::Color m_color { LG::Color::LightSystemBackground };
87 size_t m_top_border_size { std_top_border_size() };
88 size_t m_app_title_width { 0 };
89 bool m_visible { true };
90 bool m_active { true };
91
92 StatusBarStyle m_style;
93};
94
95} // namespace WinServer