2024-05-29 16:00:54 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Utils.h"
|
|
|
|
|
|
|
|
#include <BAN/RefPtr.h>
|
2024-06-02 17:27:09 +03:00
|
|
|
#include <BAN/String.h>
|
|
|
|
|
|
|
|
#include <LibFont/Font.h>
|
2024-10-18 03:32:12 +03:00
|
|
|
#include <LibGUI/Window.h>
|
2024-05-29 16:00:54 +03:00
|
|
|
|
|
|
|
class Window : public BAN::RefCounted<Window>
|
|
|
|
{
|
|
|
|
public:
|
2024-06-02 17:27:09 +03:00
|
|
|
Window(int fd, Rectangle area, long smo_key, BAN::StringView title, const LibFont::Font& font);
|
|
|
|
~Window();
|
2024-05-29 16:00:54 +03:00
|
|
|
|
|
|
|
void set_position(Position position)
|
|
|
|
{
|
2024-05-31 03:02:58 +03:00
|
|
|
m_client_area.x = position.x;
|
|
|
|
m_client_area.y = position.y;
|
2024-05-29 16:00:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int client_fd() const { return m_client_fd; }
|
|
|
|
|
2024-05-31 03:02:58 +03:00
|
|
|
int32_t client_x() const { return m_client_area.x; }
|
|
|
|
int32_t client_y() const { return m_client_area.y; }
|
|
|
|
int32_t client_width() const { return m_client_area.width; }
|
|
|
|
int32_t client_height() const { return m_client_area.height; }
|
|
|
|
Rectangle client_size() const { return { 0, 0, client_width(), client_height() }; }
|
|
|
|
Rectangle client_area() const { return m_client_area; }
|
|
|
|
|
|
|
|
int32_t title_bar_x() const { return client_x(); }
|
2024-10-18 03:32:12 +03:00
|
|
|
int32_t title_bar_y() const { return m_attributes.title_bar ? client_y() - title_bar_height() : client_y(); }
|
2024-05-31 03:02:58 +03:00
|
|
|
int32_t title_bar_width() const { return client_width(); }
|
2024-10-18 03:32:12 +03:00
|
|
|
int32_t title_bar_height() const { return m_attributes.title_bar ? m_title_bar_height : 0; }
|
2024-05-31 03:02:58 +03:00
|
|
|
Rectangle title_bar_size() const { return { 0, 0, title_bar_width(), title_bar_height() }; }
|
|
|
|
Rectangle title_bar_area() const { return { title_bar_x(), title_bar_y(), title_bar_width(), title_bar_height() }; }
|
|
|
|
|
|
|
|
int32_t full_x() const { return title_bar_x(); }
|
|
|
|
int32_t full_y() const { return title_bar_y(); }
|
|
|
|
int32_t full_width() const { return client_width(); }
|
|
|
|
int32_t full_height() const { return client_height() + title_bar_height(); }
|
|
|
|
Rectangle full_size() const { return { 0, 0, full_width(), full_height() }; }
|
|
|
|
Rectangle full_area() const { return { full_x(), full_y(), full_width(), full_height() }; }
|
|
|
|
|
2024-10-18 03:32:12 +03:00
|
|
|
LibGUI::Window::Attributes get_attributes() const { return m_attributes; };
|
|
|
|
void set_attributes(LibGUI::Window::Attributes attributes) { m_attributes = attributes; };
|
|
|
|
|
2024-05-29 16:00:54 +03:00
|
|
|
const uint32_t* framebuffer() const { return m_fb_addr; }
|
|
|
|
|
2024-05-31 03:02:58 +03:00
|
|
|
uint32_t title_bar_pixel(int32_t abs_x, int32_t abs_y, Position cursor) const
|
|
|
|
{
|
|
|
|
ASSERT(title_bar_area().contains({ abs_x, abs_y }));
|
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
if (auto close_button = close_button_area(); close_button.contains({ abs_x, abs_y }))
|
2024-09-12 19:35:44 +03:00
|
|
|
return close_button.contains(cursor) ? 0xFFFF0000 : 0xFFD00000;
|
2024-05-31 03:02:58 +03:00
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
int32_t rel_x = abs_x - title_bar_x();
|
|
|
|
int32_t rel_y = abs_y - title_bar_y();
|
|
|
|
return m_title_bar_data[rel_y * title_bar_width() + rel_x];
|
2024-05-31 03:02:58 +03:00
|
|
|
}
|
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
Circle close_button_area() const { return { title_bar_x() + title_bar_width() - title_bar_height() / 2, title_bar_y() + title_bar_height() / 2, title_bar_height() * 3 / 8 }; }
|
|
|
|
Rectangle title_text_area() const { return { title_bar_x(), title_bar_y(), title_bar_width() - title_bar_height(), title_bar_height() }; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void prepare_title_bar(const LibFont::Font& font);
|
|
|
|
|
2024-05-29 16:00:54 +03:00
|
|
|
private:
|
2024-05-31 03:02:58 +03:00
|
|
|
static constexpr int32_t m_title_bar_height { 20 };
|
|
|
|
|
2024-10-18 03:32:12 +03:00
|
|
|
const int m_client_fd { -1 };
|
|
|
|
Rectangle m_client_area { 0, 0, 0, 0 };
|
|
|
|
long m_smo_key { 0 };
|
|
|
|
uint32_t* m_fb_addr { nullptr };
|
|
|
|
uint32_t* m_title_bar_data { nullptr };
|
2024-06-02 17:27:09 +03:00
|
|
|
BAN::String m_title;
|
|
|
|
|
2024-11-08 02:54:27 +02:00
|
|
|
LibGUI::Window::Attributes m_attributes { LibGUI::Window::default_attributes };
|
2024-10-18 03:32:12 +03:00
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
friend class BAN::RefPtr<Window>;
|
2024-05-29 16:00:54 +03:00
|
|
|
};
|