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

99 lines
2.5 KiB
Plaintext
Raw Normal View History

2024-11-10 19:03:01 -06:00
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
2024-11-13 11:03:31 -06:00
render := @use("../../../libraries/render/src/lib.hb")
2024-11-14 18:09:54 -06:00
intouch := @use("../../../libraries/intouch/src/lib.hb")
2024-11-10 12:57:48 -06:00
2024-11-14 18:33:29 -06:00
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
2024-11-18 09:19:04 -06:00
.{new_label, render_label_to_surface, set_label_text, set_color} := horizon_api.widgets.label
2024-11-14 18:33:29 -06:00
stn := @use("../../../libraries/stn/src/lib.hb");
.{Vec2} := stn.math
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
img := @embed("../../../assets/wallpaper.qoi")
main := fn(): int {
sunset.server.start()
2024-11-14 18:33:29 -06:00
screen := render.init(true)
2024-11-14 18:09:54 -06:00
render.clear(screen, render.black)
2024-11-14 18:33:29 -06:00
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false))
wallpaper := render.image.from(@bitcast(&img))
if wallpaper == null {
// stn.panic("Wallpaper not loaded\0")
return 1
}
mouse_x := 100
mouse_y := 100
text_label := new_label("Hi\0")
2024-11-18 09:19:04 -06:00
set_color(text_label, sunset.server.DECO_COLOUR, render.black)
2024-11-14 18:09:54 -06:00
loop {
mouse_event := intouch.recieve_mouse_event()
if mouse_event != null {
change_x := @as(i16, mouse_event.x_change)
change_x = change_x << 8
change_x = change_x >> 8
mouse_x += change_x
2024-11-18 09:19:04 -06:00
if mouse_x <= 0 {
2024-11-14 18:09:54 -06:00
mouse_x = 0
}
if mouse_x >= screen.width - 20 {
mouse_x = @intcast(screen.width - 21)
}
change_y := @as(i16, mouse_event.y_change)
change_y = change_y << 8
change_y = change_y >> 8
2024-11-18 09:19:04 -06:00
mouse_y -= change_y
2024-11-14 18:09:54 -06:00
if mouse_y < 0 {
2024-11-18 09:19:04 -06:00
mouse_y = 1
2024-11-14 18:09:54 -06:00
}
if mouse_y >= screen.height - 20 {
mouse_y = @intcast(screen.height - 21)
}
if mouse_event.left {
2024-11-14 18:33:29 -06:00
set_label_text(text_label, "LEFT CLICK\0")
2024-11-14 18:09:54 -06:00
}
if mouse_event.middle {
2024-11-14 18:33:29 -06:00
set_label_text(text_label, "MIDDLE CLICK\0")
2024-11-14 18:09:54 -06:00
}
if mouse_event.right {
2024-11-14 18:33:29 -06:00
set_label_text(text_label, "RIGHT CLICK\0")
2024-11-14 18:09:54 -06:00
}
}
{
2024-11-14 18:33:29 -06:00
render.clear(screen, render.black)
render.put_surface(screen, wallpaper, .(0, 0), false)
2024-11-14 18:40:44 -06:00
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR)
2024-11-14 18:09:54 -06:00
}
if sunset.server.incoming() {
sunset.server.collect_frames()
sunset.server.render_clients(screen)
}
2024-11-14 18:33:29 -06:00
{
pos := Vec2(uint).(1, screen.height - 21)
render_label_to_surface(screen, text_label, font, pos)
2024-11-14 18:40:44 -06:00
render.put_rect(screen, .(0, screen.height - 21), .(screen.width - 1, 20), sunset.server.DECO_COLOUR)
2024-11-14 18:33:29 -06:00
}
2024-11-14 18:09:54 -06:00
// Mouse cursor
{
2024-11-14 18:40:44 -06:00
render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR_DARKER)
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR)
2024-11-14 18:09:54 -06:00
}
render.sync(screen)
2024-11-10 12:57:48 -06:00
}
2024-11-14 18:33:29 -06:00
return 0
2024-11-10 12:57:48 -06:00
}