1
0
Fork 0
forked from AbleOS/ableos

Halfass sketchpad impl. Input drops occasionally

This commit is contained in:
Able 2025-02-15 07:44:04 -06:00
parent 3d925aa13b
commit 2d4a66598d
2 changed files with 90 additions and 10 deletions
sysdata
programs/sketchpad/src
system_config.toml

View file

@ -1,3 +1,83 @@
main := fn(): int {
return 0
sunset := @use("lib:sunset_proto")
intouch := @use("lib:intouch")
render := @use("lib:render")
stn := @use("stn");
.{log} := stn;
Tools := struct {
pen_size: u8 = 10,
bg_colour: render.Color = render.WHITE,
pen_colour: render.Color = render.BLACK,
}
main := fn(): void {
sunset.client.find_server()
window := sunset.client.new(.(.(600, 400), .(200, 200), "Sketch Pad"))
if window == null {
log.error("got no window")
return
}
mouse_pos := stn.math.Vec2(int).(0, 0)
tools := Tools.{}
loop {
mouse := intouch.recieve_mouse_event()
if mouse != null {
mouse_pos.x = stn.math.clamp(int, mouse_pos.x + mouse.x_change, tools.pen_size, @bitcast(window.surface.width) - tools.pen_size)
mouse_pos.y = stn.math.clamp(int, mouse_pos.y - mouse.y_change, tools.pen_size, @bitcast(window.surface.height) - tools.pen_size)
if mouse.left {
window.surface.put_filled_circle(@bitcast(mouse_pos), tools.pen_size, tools.pen_colour)
} else if mouse.right {
window.surface.put_filled_circle(@bitcast(mouse_pos), tools.pen_size, tools.bg_colour)
} else if mouse.middle {
tools.pen_colour = *window.surface.indexptr(@bitcast(mouse_pos.x), @bitcast(mouse_pos.y))
}
}
kb := intouch.recieve_key_event()
if kb != null {
if kb.just_triggered {
if kb.key == intouch.keycodes.NUMBER1 {
tools.pen_colour = render.WHITE
} else if kb.key == intouch.keycodes.NUMBER2 {
tools.pen_colour = render.BLACK
} else if kb.key == intouch.keycodes.NUMBER3 {
tools.pen_colour = render.RED
} else if kb.key == intouch.keycodes.NUMBER4 {
tools.pen_colour = render.YELLOW
} else if kb.key == intouch.keycodes.NUMBER5 {
tools.pen_colour = render.BLUE
} else if kb.key == intouch.keycodes.NUMBER6 {
tools.pen_colour = render.CYAN
} else if kb.key == intouch.keycodes.NUMBER7 {
tools.pen_colour = render.GREEN
} else if kb.key == intouch.keycodes.NUMBER8 {
tools.pen_colour = render.MAGENTA
} else if kb.key == intouch.keycodes.NUMBER9 {
tools.pen_colour = render.GRAY
} else if kb.key == intouch.keycodes.NUMBER0 {
tools.pen_colour = stn.random.any(render.Color)
} else {
tools.bg_colour = stn.random.any(render.Color)
window.surface.clear(tools.bg_colour)
}
}
}
_ = sunset.client.send_frame(window)
}
}

View file

@ -29,8 +29,8 @@ resolution = "1024x768x24"
[boot.limine.ableos.modules.sunset_server]
path = "boot:///sunset_server.hbf"
# [boot.limine.ableos.modules.ps2_mouse_driver]
# path = "boot:///ps2_mouse_driver.hbf"
[boot.limine.ableos.modules.ps2_mouse_driver]
path = "boot:///ps2_mouse_driver.hbf"
# [boot.limine.ableos.modules.ps2_keyboard_driver]
# path = "boot:///ps2_keyboard_driver.hbf"
@ -38,14 +38,14 @@ path = "boot:///sunset_server.hbf"
# [boot.limine.ableos.modules.ps2_driver]
# path = "boot:///ps2_driver.hbf"
[boot.limine.ableos.modules.sunset_client]
path = "boot:///sunset_client.hbf"
# [boot.limine.ableos.modules.sunset_client]
# path = "boot:///sunset_client.hbf"
[boot.limine.ableos.modules.sdoom]
path = "boot:///sdoom.hbf"
# [boot.limine.ableos.modules.sdoom]
# path = "boot:///sdoom.hbf"
# [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///diskio_driver.hbf"
[boot.limine.ableos.modules.sketchpad]
path = "boot:///sketchpad.hbf"
# [boot.limine.ableos.modules.angels_halo]
# path = "boot:///angels_halo.hbf"