ableos/sysdata/programs/horizon/src/main.hb

98 lines
2.6 KiB
Plaintext

stn := @use("../../../libraries/stn/src/lib.hb");
.{string, memory, buffer, random, log} := stn;
.{Vec2} := stn.math
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label;
.{sexpr_parser, render_ui} := horizon_api.ui
render := @use("../../../libraries/render/src/lib.hb");
.{Surface} := render;
.{Font} := render.text
intouch := @use("../../../libraries/intouch/src/lib.hb")
Window := struct {
// TODO: Replace this with widgets
implicit_framebuffer: render.Surface,
width: int,
height: int,
x: int,
y: int,
}
psf := @embed("../../../consolefonts/tamsyn/10x20r.psf")
main := fn(): int {
win_buff := buffer.create("XHorizon\0")
screen := render.init(true)
// Clear the screen to black.
render.clear(screen, render.black)
window := render.new_surface(screen.width / 3, screen.height / 3)
mem_buf := memory.request_page(1)
color := random.any(render.Color)
side := window.width / 8
// really we should null check but it is a bit broked
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false))
mouse_x := 0
mouse_y := 0
text_label := new_label("Hi\0")
widgets := "()\0"
ui := sexpr_parser(widgets)
loop {
// Clear the screen
render.clear(screen, render.black)
// TODO: Read the window buffer here
{
ret := buffer.recv([u8; 4096], win_buff, mem_buf)
// for some reason this null check causes the compiler to spin forever
// if ret == null {
// log.info("No messages\0")
// } else {
// log.info("Handle Messages\0")
// }
}
{
// get input events from drivers via intouch
// key_event := intouch.recieve_key_event()
mouse_event := intouch.recieve_mouse_event()
if mouse_event != null {
mouse_x += mouse_event.x_change
mouse_y += mouse_event.y_change
set_label_text(text_label, "Mouse Moved\0")
}
// render mouse
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white)
// Send events to focused window
}
// TODO: Get windows out of a collection and iter through
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
{
// Scroll bar :ThumbsUp:
render.put_rect(screen, .(100, 100), .(100, 10), render.white)
render.put_filled_rect(screen, .(110, 100), .(20, 10), render.white)
render.put_rect(screen, .(90, 110), .(10, 100), render.white)
render.put_filled_rect(screen, .(90, 120), .(10, 20), render.white)
}
{
pos := Vec2(uint).(1, screen.height - 21)
render_label_to_surface(screen, text_label, font, pos)
}
// Sync the screen
render.sync(screen)
}
return 0
}