2024-09-13 16:40:05 -05:00
|
|
|
stn := @use("../../../libraries/stn/src/lib.hb");
|
2024-10-15 20:30:24 -05:00
|
|
|
.{string, memory, buffer, random, log} := stn;
|
2024-10-15 17:25:11 -05:00
|
|
|
.{Vec2} := stn.math
|
2024-09-13 16:40:05 -05:00
|
|
|
|
|
|
|
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb")
|
|
|
|
|
2024-11-06 09:36:17 -06:00
|
|
|
render := @use("../../../libraries/render/src/lib.hb");
|
|
|
|
.{Surface} := render;
|
|
|
|
.{Font} := render.text
|
2024-11-03 19:38:40 -06:00
|
|
|
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
2024-10-15 17:06:38 -05:00
|
|
|
|
2024-11-06 09:36:17 -06:00
|
|
|
Label := struct {is_dirty: bool, surface: Surface, text: ^u8, text_length: uint}
|
|
|
|
set_label_text := fn(label: Label, text: ^u8, text_length: uint): void {
|
|
|
|
label.is_dirty = true
|
|
|
|
label.text = text
|
|
|
|
label.text_length = text_length
|
|
|
|
}
|
|
|
|
|
|
|
|
render_label_to_surface := fn(surface: Surface, label: Label, font: Font): void {
|
|
|
|
if label.is_dirty {
|
|
|
|
render.clear(label.surface, render.blue)
|
|
|
|
render.put_text(label.surface, font, .(0, 0), render.red, "hi\0")
|
|
|
|
}
|
|
|
|
pos := Vec2(uint).(100, 100)
|
|
|
|
render.put_surface(surface, label.surface, pos, false)
|
|
|
|
render.sync(surface)
|
|
|
|
}
|
|
|
|
|
|
|
|
new_label := fn(text: ^u8): Label {
|
|
|
|
text_surface := render.new_surface(100, 16)
|
|
|
|
text_length := string.length(text)
|
|
|
|
label := Label.(true, text_surface, text, text_length)
|
|
|
|
return label
|
|
|
|
}
|
|
|
|
|
2024-10-15 17:06:38 -05:00
|
|
|
Window := struct {
|
|
|
|
// TODO: Replace this with widgets
|
2024-10-15 17:25:11 -05:00
|
|
|
implicit_framebuffer: render.Surface,
|
2024-10-15 17:06:38 -05:00
|
|
|
width: int,
|
|
|
|
height: int,
|
|
|
|
x: int,
|
|
|
|
y: int,
|
|
|
|
}
|
|
|
|
|
2024-11-01 13:09:12 -05:00
|
|
|
psf := @embed("../../../consolefonts/tamsyn/10x20r.psf")
|
|
|
|
|
2024-09-13 16:40:05 -05:00
|
|
|
main := fn(): int {
|
2024-10-15 20:30:24 -05:00
|
|
|
win_buff := buffer.create("XHorizon\0")
|
2024-10-15 17:25:11 -05:00
|
|
|
|
2024-10-15 17:06:38 -05:00
|
|
|
screen := render.init(true)
|
|
|
|
|
2024-10-15 17:25:11 -05:00
|
|
|
// Clear the screen to black.
|
|
|
|
render.clear(screen, render.black)
|
|
|
|
|
|
|
|
window := render.new_surface(screen.width / 3, screen.height / 3)
|
2024-10-15 17:06:38 -05:00
|
|
|
|
2024-10-15 20:30:24 -05:00
|
|
|
mem_buf := memory.request_page(1)
|
2024-10-25 10:37:38 -05:00
|
|
|
color := random.any(render.Color)
|
2024-10-15 20:30:24 -05:00
|
|
|
side := window.width / 8
|
|
|
|
|
2024-11-03 16:31:53 -06:00
|
|
|
// really we should null check but it is a bit broked
|
2024-11-05 19:49:57 -06:00
|
|
|
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false))
|
2024-10-15 17:25:11 -05:00
|
|
|
|
2024-11-03 19:38:40 -06:00
|
|
|
mouse_x := 0
|
|
|
|
mouse_y := 0
|
2024-11-06 09:36:17 -06:00
|
|
|
text_label := new_label("Hi\0")
|
2024-11-03 19:38:40 -06:00
|
|
|
|
2024-09-13 16:40:05 -05:00
|
|
|
loop {
|
2024-10-15 17:06:38 -05:00
|
|
|
// Clear the screen
|
|
|
|
render.clear(screen, render.black)
|
|
|
|
|
2024-10-15 17:25:11 -05:00
|
|
|
// TODO: Read the window buffer here
|
2024-10-15 20:30:24 -05:00
|
|
|
{
|
2024-10-23 15:22:28 -05:00
|
|
|
ret := buffer.recv([u8; 4096], win_buff, mem_buf)
|
2024-11-03 16:31:53 -06:00
|
|
|
// 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")
|
|
|
|
// }
|
2024-10-15 20:30:24 -05:00
|
|
|
}
|
|
|
|
|
2024-11-03 19:38:40 -06:00
|
|
|
{
|
|
|
|
// get input events from drivers via intouch
|
2024-11-05 22:58:52 -06:00
|
|
|
// key_event := intouch.recieve_key_event()
|
2024-11-03 19:38:40 -06:00
|
|
|
mouse_event := intouch.recieve_mouse_event()
|
2024-11-05 22:58:52 -06:00
|
|
|
if mouse_event != null {
|
|
|
|
mouse_x += mouse_event.x_change
|
2024-11-05 23:01:15 -06:00
|
|
|
mouse_y += mouse_event.y_change
|
2024-11-05 22:58:52 -06:00
|
|
|
}
|
2024-11-03 19:38:40 -06:00
|
|
|
// render mouse
|
|
|
|
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white)
|
|
|
|
// Send events to focused window
|
|
|
|
}
|
|
|
|
|
2024-10-15 17:25:11 -05:00
|
|
|
// TODO: Get windows out of a collection and iter through
|
2024-11-05 23:04:29 -06:00
|
|
|
|
2024-11-03 19:38:40 -06:00
|
|
|
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
|
2024-10-15 17:06:38 -05:00
|
|
|
|
2024-11-06 09:36:17 -06:00
|
|
|
render_label_to_surface(screen, text_label, font)
|
|
|
|
|
2024-10-15 17:06:38 -05:00
|
|
|
// Sync the screen
|
|
|
|
render.sync(screen)
|
2024-09-13 16:40:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|