forked from AbleOS/ableos
drag and drop test
This commit is contained in:
parent
d5dfd1d086
commit
1fdef70144
sysdata/programs/render_example/src
|
@ -0,0 +1,43 @@
|
|||
intouch := @use("lib:intouch")
|
||||
render := @use("lib:render")
|
||||
stn := @use("stn")
|
||||
|
||||
example := fn(): void {
|
||||
screen := render.init(true)
|
||||
mouse_pos := stn.math.Vec2(int).(0, 0)
|
||||
image := render.image.from(@bitcast(&@embed("sysdata:assets/mini.qoi")))
|
||||
if image == null {
|
||||
stn.log.error("failed to load images for whatever reason")
|
||||
return
|
||||
}
|
||||
image_pos := stn.math.Vec2(int).(@bitcast(screen.width - image.width) / 2, @bitcast(screen.height - image.height) / 2)
|
||||
image_dim: stn.math.Vec2(int) = .(@bitcast(image.width), @bitcast(image.height))
|
||||
|
||||
loop {
|
||||
mouse := intouch.recieve_mouse_event()
|
||||
if mouse == null {
|
||||
continue
|
||||
}
|
||||
screen.put_surface(image, @bitcast(image_pos), false)
|
||||
|
||||
mouse_pos.x = stn.math.clamp(int, mouse_pos.x + mouse.x_change, 5, @bitcast(screen.width) - 5)
|
||||
mouse_pos.y = stn.math.clamp(int, mouse_pos.y - mouse.y_change, 5, @bitcast(screen.height) - 5)
|
||||
|
||||
// :(
|
||||
if mouse_pos.x >= image_pos.x & mouse_pos.x <= image_pos.x + image_dim.x & mouse_pos.y >= image_pos.y & mouse_pos.y <= image_pos.y + image_dim.y {
|
||||
if mouse.left {
|
||||
screen.put_rect(@bitcast(image_pos), @bitcast(image_dim), render.RED)
|
||||
|
||||
image_pos.x = stn.math.clamp(int, image_pos.x + mouse.x_change, 0, @bitcast(screen.width) - image_dim.x)
|
||||
image_pos.y = stn.math.clamp(int, image_pos.y - mouse.y_change, 0, @bitcast(screen.height) - image_dim.y)
|
||||
} else {
|
||||
screen.put_rect(@bitcast(image_pos), @bitcast(image_dim), render.CYAN)
|
||||
screen.put_filled_circle(@bitcast(mouse_pos), 5, render.GRAY)
|
||||
screen.put_circle(@bitcast(mouse_pos), 5, render.BLACK)
|
||||
}
|
||||
}
|
||||
|
||||
screen.sync()
|
||||
screen.clear(render.BLACK)
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
.{example: main} := @use("./examples/intouch.hb")
|
||||
.{example: main} := @use("./examples/drag-and-drop.hb")
|
Loading…
Reference in a new issue