forked from AbleOS/ableos
multi-drag
This commit is contained in:
parent
abaac886ef
commit
19715ef6fd
rust-toolchain.toml
sysdata
|
@ -3,5 +3,6 @@
|
|||
# channel = "nightly-2024-07-27"
|
||||
# last stable
|
||||
# channel = "nightly-2024-11-20"
|
||||
channel = "nightly"
|
||||
# locking here to prevent compile error in holey-bytes crate
|
||||
channel = "nightly-2025-01-25"
|
||||
components = ["rust-src", "llvm-tools"]
|
||||
|
|
|
@ -2,42 +2,72 @@ intouch := @use("lib:intouch")
|
|||
render := @use("lib:render")
|
||||
stn := @use("stn")
|
||||
|
||||
mouse_pos := stn.math.Vec2(int).(0, 0)
|
||||
mouse_event := @as(?intouch.MouseEvent, null)
|
||||
global_lock := false
|
||||
|
||||
DraggableSurface := struct {
|
||||
pos: stn.math.Vec2(int),
|
||||
surface: render.Surface,
|
||||
lock: bool,
|
||||
process := fn(self: ^Self, screen: ^render.Surface): void {
|
||||
screen.put_surface(self.surface, @bitcast(self.pos), false)
|
||||
// funny hblang bug means need to check for boolean equality
|
||||
if global_lock | @unwrap(mouse_event).left {
|
||||
if self.lock == true return
|
||||
}
|
||||
if mouse_pos.x >= self.pos.x & mouse_pos.x <= self.pos.x + @bitcast(self.surface.width) & mouse_pos.y >= self.pos.y & mouse_pos.y <= self.pos.y + @bitcast(self.surface.height) {
|
||||
global_lock = true
|
||||
self.lock = false
|
||||
if @unwrap(mouse_event).left {
|
||||
self.pos = .(
|
||||
stn.math.clamp(int, self.pos.x + @unwrap(mouse_event).x_change, 1, @bitcast(screen.width) - @bitcast(self.surface.width) - 1),
|
||||
stn.math.clamp(int, self.pos.y - @unwrap(mouse_event).y_change, 1, @bitcast(screen.height) - @bitcast(self.surface.height) - 1),
|
||||
)
|
||||
screen.put_rect(@bitcast(self.pos), .(self.surface.width, self.surface.height), render.RED)
|
||||
} else {
|
||||
screen.put_rect(@bitcast(self.pos), .(self.surface.width, self.surface.height), render.CYAN)
|
||||
}
|
||||
} else {
|
||||
global_lock = false
|
||||
self.lock = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
image2 := render.image.from(@bitcast(&@embed("sysdata:assets/able.bmp")))
|
||||
if image == null | image2 == 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))
|
||||
|
||||
thing := DraggableSurface.(
|
||||
.(400, 400),
|
||||
image,
|
||||
false,
|
||||
)
|
||||
|
||||
thing2 := DraggableSurface.(
|
||||
.(0, 0),
|
||||
image2,
|
||||
false,
|
||||
)
|
||||
|
||||
loop {
|
||||
mouse := intouch.recieve_mouse_event()
|
||||
if mouse == null {
|
||||
continue
|
||||
}
|
||||
screen.put_surface(image, @bitcast(image_pos), false)
|
||||
mouse_event = intouch.recieve_mouse_event()
|
||||
if mouse_event == null continue
|
||||
mouse_pos.x = stn.math.clamp(int, mouse_pos.x + mouse_event.x_change, 6, @bitcast(screen.width) - 6)
|
||||
mouse_pos.y = stn.math.clamp(int, mouse_pos.y - @unwrap(mouse_event).y_change, 6, @bitcast(screen.height) - 6)
|
||||
|
||||
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)
|
||||
thing.process(&screen)
|
||||
thing2.process(&screen)
|
||||
|
||||
// :(
|
||||
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.put_filled_circle(@bitcast(mouse_pos), 5, render.BLACK)
|
||||
|
||||
screen.sync()
|
||||
screen.clear(render.BLACK)
|
||||
screen.clear(render.GRAY)
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
.{example: main} := @use("./examples/intouch.hb")
|
||||
.{example: main} := @use("./examples/drag-and-drop.hb")
|
|
@ -29,8 +29,8 @@ path = "boot:///render_example.hbf"
|
|||
# [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"
|
||||
|
|
Loading…
Reference in a new issue