forked from AbleOS/ableos
106 lines
2.7 KiB
Plaintext
106 lines
2.7 KiB
Plaintext
sunset := @use("lib:sunset_proto")
|
|
render := @use("lib:render")
|
|
intouch := @use("lib:intouch")
|
|
|
|
horizon_api := @use("lib:horizon_api");
|
|
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
|
|
|
stn := @use("stn");
|
|
.{Vec2, clamp} := stn.math
|
|
|
|
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
|
img := @embed("sysdata:assets/wallpaper.qoi")
|
|
|
|
Mouse := struct {
|
|
x: int,
|
|
y: int,
|
|
// 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.(@bitcast(center_x), @bitcast(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)
|
|
}*/
|
|
}
|
|
|
|
main := fn(): int {
|
|
sunset.server.start()
|
|
defer {
|
|
stn.log.info("Sunset Server Exit")
|
|
}
|
|
|
|
screen := render.init(true)
|
|
screen.clear(render.BLACK)
|
|
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false))
|
|
|
|
wallpaper := render.image.from(@bitcast(&img))
|
|
if wallpaper == null {
|
|
// stn.panic("Wallpaper not loaded")
|
|
return 1
|
|
}
|
|
|
|
// mouse_x := 100
|
|
// mouse_y := 100
|
|
|
|
mouse := Mouse.new(screen.width, screen.height)
|
|
//mouse.center()
|
|
|
|
text_label := Label.new_label("", 1024)
|
|
text_label.set_color(sunset.server.DECO_COLOUR, render.BLACK)
|
|
|
|
loop {
|
|
mouse_event := intouch.recieve_mouse_event()
|
|
if mouse_event != null {
|
|
mouse.x = clamp(int, mouse.x + mouse_event.x_change, mouse.cursor_width, @bitcast(screen.width - mouse.cursor_width))
|
|
mouse.y = clamp(int, mouse.y - mouse_event.y_change, mouse.cursor_width, @bitcast(screen.height - mouse.cursor_width))
|
|
|
|
if mouse_event.left {
|
|
text_label.set_label_text("LEFT CLICK")
|
|
} else if mouse_event.middle {
|
|
text_label.set_label_text("MIDDLE CLICK")
|
|
} else if mouse_event.right {
|
|
text_label.set_label_text("RIGHT CLICK")
|
|
}
|
|
}
|
|
{
|
|
screen.put_surface(wallpaper, .(0, 0), false)
|
|
|
|
screen.put_rect(.(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR)
|
|
}
|
|
|
|
_ = sunset.server.incoming()
|
|
sunset.server.collect_frames()
|
|
sunset.server.render_clients(screen)
|
|
|
|
{
|
|
/* Omnibar */
|
|
omnibar_height := 21
|
|
pos := Vec2(uint).(1, screen.height - omnibar_height)
|
|
render_label_to_surface(screen, text_label, font, pos)
|
|
screen.put_rect(.(0, screen.height - 21), .(screen.width - 1, 20), sunset.server.DECO_COLOUR)
|
|
}
|
|
|
|
// Mouse cursor
|
|
{
|
|
p := Vec2(uint).(@bitcast(mouse.x), @bitcast(mouse.y))
|
|
screen.put_filled_circle(p, mouse.cursor_width, sunset.server.DECO_COLOUR_DARKER)
|
|
screen.put_circle(p, mouse.cursor_width, sunset.server.DECO_COLOUR)
|
|
}
|
|
|
|
screen.sync()
|
|
}
|
|
|
|
return 0
|
|
} |