40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include "Window.h"
|
|
#include <luna/Utf8.h>
|
|
#include <os/File.h>
|
|
#include <ui/Font.h>
|
|
|
|
LinkedList<Window> g_windows;
|
|
|
|
void Window::draw(ui::Canvas& screen)
|
|
{
|
|
auto window = screen.subcanvas(surface);
|
|
window.subcanvas(contents).fill(color);
|
|
|
|
wchar_t buffer[4096];
|
|
Utf8StringDecoder decoder(name.chars());
|
|
decoder.decode(buffer, sizeof(buffer)).release_value();
|
|
|
|
auto font = ui::Font::default_font();
|
|
|
|
auto titlebar_canvas = window.subcanvas(titlebar);
|
|
titlebar_canvas.fill(ui::GRAY);
|
|
|
|
auto textarea = titlebar_canvas.subcanvas(ui::Rect { 10, 10, titlebar_canvas.width - 10, titlebar_canvas.height });
|
|
font->render(buffer, ui::BLACK, textarea);
|
|
}
|
|
|
|
void Window::focus()
|
|
{
|
|
// Bring the window to the front of the list.
|
|
g_windows.remove(this);
|
|
g_windows.append(this);
|
|
}
|
|
|
|
Window::Window(ui::Rect r, ui::Color c, StringView n) : surface(r), color(c), name(n)
|
|
{
|
|
auto font = ui::Font::default_font();
|
|
titlebar = ui::Rect { 0, 0, surface.width, font->height() + 20 };
|
|
contents = ui::Rect { 0, font->height() + 20, surface.width, surface.height - (font->height() + 20) };
|
|
g_windows.append(this);
|
|
}
|