2023-08-15 08:23:37 +00:00
|
|
|
/**
|
|
|
|
* @file Window.h
|
|
|
|
* @author apio (cloudapio.eu)
|
|
|
|
* @brief UI windows.
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2023, the Luna authors.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <luna/OwnedPtr.h>
|
|
|
|
#include <luna/StringView.h>
|
|
|
|
#include <ui/Canvas.h>
|
2023-08-15 13:10:13 +00:00
|
|
|
#include <ui/Mouse.h>
|
2023-08-15 08:23:37 +00:00
|
|
|
#include <ui/Rect.h>
|
2023-08-15 10:28:47 +00:00
|
|
|
#include <ui/Widget.h>
|
2023-08-15 08:23:37 +00:00
|
|
|
|
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
class Window
|
|
|
|
{
|
|
|
|
public:
|
2023-08-15 10:56:55 +00:00
|
|
|
static Result<Window*> create(Rect rect, bool decorated = true);
|
2023-08-15 08:23:37 +00:00
|
|
|
|
|
|
|
void set_title(StringView title);
|
|
|
|
|
2023-08-15 10:28:47 +00:00
|
|
|
void set_background(Color color)
|
|
|
|
{
|
|
|
|
m_background = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_main_widget(Widget& widget)
|
|
|
|
{
|
|
|
|
check(!m_main_widget);
|
|
|
|
widget.set_window(this, m_canvas.rect(), {});
|
|
|
|
m_main_widget = &widget;
|
|
|
|
}
|
|
|
|
|
2023-08-15 08:23:37 +00:00
|
|
|
Canvas& canvas()
|
|
|
|
{
|
|
|
|
return m_canvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update();
|
|
|
|
|
2023-08-15 09:20:17 +00:00
|
|
|
void close();
|
|
|
|
|
2023-08-15 10:28:47 +00:00
|
|
|
Result<void> draw();
|
2023-09-11 17:38:29 +00:00
|
|
|
Result<ui::EventResult> handle_mouse_leave();
|
|
|
|
Result<ui::EventResult> handle_mouse_move(ui::Point position);
|
|
|
|
Result<ui::EventResult> handle_mouse_buttons(ui::Point position, int buttons);
|
2023-08-15 10:28:47 +00:00
|
|
|
|
2023-08-15 09:20:17 +00:00
|
|
|
int id() const
|
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
2023-08-15 08:23:37 +00:00
|
|
|
~Window();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_id;
|
|
|
|
Canvas m_canvas;
|
2023-08-15 10:28:47 +00:00
|
|
|
Widget* m_main_widget { nullptr };
|
|
|
|
Color m_background { ui::BLACK };
|
2023-08-15 13:10:13 +00:00
|
|
|
Option<int> m_old_mouse_buttons;
|
2023-08-15 08:23:37 +00:00
|
|
|
};
|
|
|
|
}
|