forked from AbleOS/ableos
130 lines
3 KiB
Plaintext
130 lines
3 KiB
Plaintext
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
|
render := @use("../../../libraries/render/src/lib.hb")
|
|
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
|
|
|
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
|
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
|
|
|
stn := @use("../../../libraries/stn/src/lib.hb");
|
|
.{Vec2} := stn.math
|
|
|
|
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
|
img := @embed("../../../assets/wallpaper.qoi")
|
|
|
|
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)
|
|
}*/
|
|
}
|
|
|
|
main := fn(): int {
|
|
sunset.server.start()
|
|
defer {
|
|
stn.log.info("Sunset Server Exit\0")
|
|
}
|
|
|
|
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\0")
|
|
return 1
|
|
}
|
|
|
|
// mouse_x := 100
|
|
// mouse_y := 100
|
|
|
|
mouse := Mouse.new(screen.width, screen.height)
|
|
//mouse.center()
|
|
|
|
text_label := Label.new_label("\0", 1024)
|
|
text_label.set_color(sunset.server.DECO_COLOUR, render.BLACK)
|
|
|
|
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
|
|
if mouse.x <= 0 {
|
|
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
|
|
|
|
mouse.y -= change_y
|
|
if mouse.y < 0 {
|
|
mouse.y = 1
|
|
}
|
|
if mouse.y >= screen.height - 20 {
|
|
mouse.y = @intcast(screen.height - 21)
|
|
}
|
|
|
|
if mouse_event.left {
|
|
text_label.set_label_text("LEFT CLICK\0")
|
|
}
|
|
if mouse_event.middle {
|
|
text_label.set_label_text("MIDDLE CLICK\0")
|
|
}
|
|
if mouse_event.right {
|
|
text_label.set_label_text("RIGHT CLICK\0")
|
|
}
|
|
}
|
|
{
|
|
screen.clear(render.BLACK)
|
|
screen.put_surface(wallpaper, .(0, 0), false)
|
|
|
|
screen.put_rect(.(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR)
|
|
}
|
|
|
|
if 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
|
|
{
|
|
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)
|
|
}
|
|
|
|
screen.sync()
|
|
}
|
|
|
|
return 0
|
|
} |