Compare commits
4 Commits
2dff2c9934
...
4cbdea954a
Author | SHA1 | Date | |
---|---|---|---|
4cbdea954a | |||
ec256e058d | |||
6388672d00 | |||
36c1374c16 |
@ -21,6 +21,15 @@ namespace ui
|
||||
*/
|
||||
bool contains(Point point);
|
||||
|
||||
/**
|
||||
* @brief Check if another rectangle is contained in this one.
|
||||
*
|
||||
* @param point The rectangle to check.
|
||||
* @return true The other rectangle is contained inside this one.
|
||||
* @return false The other rectangle is not contained inside this one.
|
||||
*/
|
||||
bool contains(Rect rect);
|
||||
|
||||
/**
|
||||
* @brief Normalize a point to fit inside this rectangle.
|
||||
*
|
||||
|
@ -101,7 +101,7 @@ namespace ui
|
||||
{
|
||||
u32 line = offset;
|
||||
int mask = 1 << (m_psf_header.width - 1);
|
||||
for (int x = 0; x < m_psf_header.width; x++)
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
if (*((u32*)glyph) & mask) *(u32*)(canvas.ptr + line) = color.raw;
|
||||
mask >>= 1;
|
||||
|
@ -8,6 +8,15 @@ namespace ui
|
||||
(point.y <= (pos.y + height));
|
||||
}
|
||||
|
||||
bool Rect::contains(Rect rect)
|
||||
{
|
||||
if (!contains(rect.pos)) return false;
|
||||
Point rel = relative(rect.pos);
|
||||
if ((rel.x + rect.width) > width) return false;
|
||||
if ((rel.y + rect.height) > height) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Point Rect::normalize(Point point)
|
||||
{
|
||||
if (point.x < pos.x) point.x = pos.x;
|
||||
|
@ -42,6 +42,8 @@ void Window::focus()
|
||||
Window::Window(ui::Rect r, ui::Color c, StringView n) : surface(r), color(c), name(n)
|
||||
{
|
||||
auto font = ui::Font::default_font();
|
||||
if (surface.width < 36) surface.width = 36;
|
||||
if (surface.height < (font->height() + 20)) surface.height = font->height() + 20;
|
||||
titlebar = ui::Rect { 0, 0, surface.width, font->height() + 20 };
|
||||
close_button = ui::Rect { surface.width - 26, 10, 16, 16 };
|
||||
contents = ui::Rect { 0, font->height() + 20, surface.width, surface.height - (font->height() + 20) };
|
||||
|
@ -11,10 +11,13 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/poll.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
Result<int> luna_main(int argc, char** argv)
|
||||
{
|
||||
srand((unsigned)time(NULL));
|
||||
|
||||
StringView socket_path = "/tmp/wind.sock";
|
||||
StringView user;
|
||||
|
||||
@ -105,7 +108,14 @@ Result<int> luna_main(int argc, char** argv)
|
||||
{
|
||||
moon::KeyboardPacket packet;
|
||||
TRY(keyboard->read_typed(packet));
|
||||
background = ui::Color::from_rgb(0x00, 0x00, packet.key * 2);
|
||||
if (!packet.released)
|
||||
{
|
||||
TRY(make<Window>(ui::Rect { rand() % screen.canvas().width, rand() % screen.canvas().height,
|
||||
rand() % screen.canvas().width, rand() % screen.canvas().height },
|
||||
ui::Color::from_rgb(static_cast<u8>(rand() % 256), static_cast<u8>(rand() % 256),
|
||||
static_cast<u8>(rand() % 256)),
|
||||
strerror(packet.key)));
|
||||
}
|
||||
}
|
||||
if (fds[2].revents & POLLIN)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user