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

96 lines
2.3 KiB
Plaintext
Raw Normal View History

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-10-15 17:25:11 -05:00
render := @use("../../../libraries/render/src/lib.hb")
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-25 10:37:38 -05:00
x := 0
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
vel_inner := Vec2(int).(1, 1)
2024-10-25 10:37:38 -05:00
pos_inner := Vec2(uint).((window.width - side) / 2, (window.height - side) / 2)
2024-11-01 13:09:12 -05:00
str := "Window Title Bar\0"
font := render.text.font_from_psf2(@bitcast(&psf))
2024-10-15 17:25:11 -05: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-10-15 20:30:24 -05:00
if ret == 0 {
log.info("No messages\0")
2024-11-01 13:09:12 -05:00
} else {
log.info("Handle Messages\0")
2024-10-15 20:30:24 -05:00
}
}
if pos_inner.x == 0 | pos_inner.x == window.width - side {
vel_inner.x = -vel_inner.x
2024-10-25 10:37:38 -05:00
color = random.any(render.Color)
2024-10-15 20:30:24 -05:00
}
2024-10-16 07:34:19 -05:00
if pos_inner.y == 20 | pos_inner.y == window.height - side {
2024-10-15 20:30:24 -05:00
vel_inner.y = -vel_inner.y
2024-10-25 10:37:38 -05:00
color = random.any(render.Color)
2024-10-15 20:30:24 -05:00
}
2024-10-15 17:25:11 -05:00
// TODO: Get windows out of a collection and iter through
2024-10-15 20:30:24 -05:00
window_count := 0
loop {
render.clear(window, render.black)
2024-10-16 07:34:19 -05:00
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
2024-10-15 20:30:24 -05:00
// Draw the decorators
{
render.put_rect(window, .(0, 0), .(window.width - 1, window.height - 1), render.white)
2024-10-16 07:34:19 -05:00
render.put_rect(window, .(0, 0), .(window.width - 1, 20), render.white)
2024-11-01 13:09:12 -05:00
render.put_text(window, font, .(window.width / 2, 1), render.white, str)
2024-10-15 20:30:24 -05:00
}
render.put_filled_rect(window, pos_inner, .(side, side), color)
2024-10-15 17:25:11 -05:00
// Apply the image to the screen
2024-10-25 10:37:38 -05:00
pos := Vec2(uint).(x, 100)
2024-10-15 20:30:24 -05:00
render.put_surface(screen, window, pos, false)
2024-10-15 20:30:24 -05:00
if window_count >= 1 {
2024-10-25 10:37:38 -05:00
x = 0
2024-10-15 20:30:24 -05:00
break
}
window_count += 1
2024-10-25 10:37:38 -05:00
x += screen.width / 2
2024-10-15 17:25:11 -05:00
}
2024-10-25 10:37:38 -05:00
pos_inner += @bitcast(vel_inner)
2024-10-15 17:06:38 -05:00
// Sync the screen
render.sync(screen)
2024-09-13 16:40:05 -05:00
}
return 0
}