1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/programs/sunset_server/src/main.hb

130 lines
3 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-26 07:39:16 -06:00
.{set_color, render_label_to_surface, Label} := 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")
2024-12-16 07:58:04 -06:00
Mouse := struct {
x: uint,
y: uint,
// TODO: Make this configurable via wm config
cursor_width: u8,
max_x: uint,
max_y: uint,
new := fn(max_x: uint, max_y: uint): Self {
center_x := max_x / 2
center_y := max_y / 2
return Self.(center_x, center_y, 3, max_x, max_y)
}
/*
center := fn(self: Self){
center_x := max_x / 2
center_y := max_y / 2
return Self.(center_x, center_y, 3, max_x, max_y)
}*/
}
2024-11-14 18:33:29 -06:00
main := fn(): int {
sunset.server.start()
2024-11-24 23:51:37 -06:00
defer {
stn.log.info("Sunset Server Exit\0")
}
2024-11-14 18:33:29 -06:00
screen := render.init(true)
2024-12-14 10:39:45 -06:00
screen.clear(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
}
2024-12-16 07:58:04 -06:00
// mouse_x := 100
// mouse_y := 100
mouse := Mouse.new(screen.width, screen.height)
//mouse.center()
2024-11-14 18:33:29 -06:00
2024-12-03 12:31:33 -06:00
text_label := Label.new_label("\0", 1024)
2024-12-14 10:39:45 -06:00
text_label.set_color(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
2024-12-16 07:58:04 -06:00
mouse.x += change_x
if mouse.x <= 0 {
mouse.x = 0
2024-11-14 18:09:54 -06:00
}
2024-12-16 07:58:04 -06:00
if mouse.x >= screen.width - 20 {
mouse.x = @intcast(screen.width - 21)
2024-11-14 18:09:54 -06:00
}
change_y := @as(i16, mouse_event.y_change)
change_y = change_y << 8
change_y = change_y >> 8
2024-12-16 07:58:04 -06:00
mouse.y -= change_y
if mouse.y < 0 {
mouse.y = 1
2024-11-14 18:09:54 -06:00
}
2024-12-16 07:58:04 -06:00
if mouse.y >= screen.height - 20 {
mouse.y = @intcast(screen.height - 21)
2024-11-14 18:09:54 -06:00
}
if mouse_event.left {
2024-11-26 07:39:16 -06:00
text_label.set_label_text("LEFT CLICK\0")
2024-11-14 18:09:54 -06:00
}
if mouse_event.middle {
2024-11-26 07:39:16 -06:00
text_label.set_label_text("MIDDLE CLICK\0")
2024-11-14 18:09:54 -06:00
}
if mouse_event.right {
2024-11-26 07:39:16 -06:00
text_label.set_label_text("RIGHT CLICK\0")
2024-11-14 18:09:54 -06:00
}
}
{
2024-12-14 10:39:45 -06:00
screen.clear(render.BLACK)
screen.put_surface(wallpaper, .(0, 0), false)
2024-11-14 18:33:29 -06:00
2024-12-14 10:39:45 -06:00
screen.put_rect(.(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
{
2024-12-05 11:04:28 -06:00
/* Omnibar */
omnibar_height := 21
pos := Vec2(uint).(1, screen.height - omnibar_height)
2024-11-14 18:33:29 -06:00
render_label_to_surface(screen, text_label, font, pos)
2024-12-14 10:39:45 -06:00
screen.put_rect(.(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-12-14 10:39:45 -06:00
screen.put_filled_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER)
screen.put_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR)
2024-11-14 18:09:54 -06:00
}
2024-12-14 10:39:45 -06:00
screen.sync()
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
}