forked from AbleOS/ableos
Merge branch 'master' of ssh://git.ablecorp.us:20/AbleOS/ableos
This commit is contained in:
commit
3d925aa13b
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ example := fn(): void {
|
|||
} else if mouse.right {
|
||||
screen.put_filled_circle(@bitcast(mouse_pos), 10, bg_colour)
|
||||
} else if mouse.middle {
|
||||
pen_colour = stn.random.any(render.Color)
|
||||
pen_colour = *screen.indexptr(@bitcast(mouse_pos.x), @bitcast(mouse_pos.y))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,8 @@ example := fn(): void {
|
|||
pen_colour = render.MAGENTA
|
||||
} else if kb.key == intouch.keycodes.NUMBER9 {
|
||||
pen_colour = render.GRAY
|
||||
} else if kb.key == intouch.keycodes.NUMBER0 {
|
||||
pen_colour = stn.random.any(render.Color)
|
||||
} else {
|
||||
bg_colour = stn.random.any(render.Color)
|
||||
screen.clear(bg_colour)
|
||||
|
|
Loading…
Reference in a new issue