将 .py 和 .pyi 后缀名改为了 .vp 和 .vpi 后缀名
This commit is contained in:
80
Libs/VPUI64/vpui64.vp
Normal file
80
Libs/VPUI64/vpui64.vp
Normal file
@@ -0,0 +1,80 @@
|
||||
import t
|
||||
import vpsdk.syscall as syscall
|
||||
|
||||
UINT32PTR: t.CTypedef = t.CUInt32T | t.CPtr
|
||||
|
||||
def color_rgb(r: t.CUInt8T, g: t.CUInt8T, b: t.CUInt8T) -> t.CUInt32T:
|
||||
return t.CUInt32T(r) | (t.CUInt32T(g) << 8) | (t.CUInt32T(b) << 16)
|
||||
|
||||
def get_winbuf(win_id: t.CInt) -> UINT32PTR:
|
||||
return t.CVoid(syscall._syscall2(t.CUInt64T(syscall.GET_WINBUF), t.CUInt64T(win_id), 0), t.CPtr)
|
||||
|
||||
def win_flush(win_id: t.CInt) -> t.CVoid:
|
||||
syscall._syscall2(t.CUInt64T(syscall.WIN_FLUSH), t.CUInt64T(win_id), 0)
|
||||
|
||||
def draw_pixel(buf: UINT32PTR, bw: t.CInt, x: t.CInt, y: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
|
||||
if x < 0 or y < 0: return
|
||||
buf[y * bw + x] = color
|
||||
|
||||
def draw_line(buf: UINT32PTR, bw: t.CInt, x0: t.CInt, y0: t.CInt, x1: t.CInt, y1: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
|
||||
dx: t.CInt = x1 - x0
|
||||
dy: t.CInt = y1 - y0
|
||||
sx: t.CInt = 1
|
||||
sy: t.CInt = 1
|
||||
if dx < 0:
|
||||
dx = -dx
|
||||
sx = -1
|
||||
if dy < 0:
|
||||
dy = -dy
|
||||
sy = -1
|
||||
err: t.CInt = dx - dy
|
||||
while True:
|
||||
if x0 >= 0 and y0 >= 0:
|
||||
buf[y0 * bw + x0] = color
|
||||
if x0 == x1 and y0 == y1:
|
||||
break
|
||||
e2: t.CInt = 2 * err
|
||||
if e2 > -dy:
|
||||
err -= dy
|
||||
x0 += sx
|
||||
if e2 < dx:
|
||||
err += dx
|
||||
y0 += sy
|
||||
|
||||
def draw_rect(buf: UINT32PTR, bw: t.CInt, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
|
||||
draw_line(buf, bw, rx, ry, rx + rw - 1, ry, color)
|
||||
draw_line(buf, bw, rx + rw - 1, ry, rx + rw - 1, ry + rh - 1, color)
|
||||
draw_line(buf, bw, rx + rw - 1, ry + rh - 1, rx, ry + rh - 1, color)
|
||||
draw_line(buf, bw, rx, ry + rh - 1, rx, ry, color)
|
||||
|
||||
def fill_rect(buf: UINT32PTR, bw: t.CInt, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
|
||||
if rx < 0: rw += rx; rx = 0
|
||||
if ry < 0: rh += ry; ry = 0
|
||||
if rw <= 0 or rh <= 0: return
|
||||
py: t.CInt = ry
|
||||
while py < ry + rh:
|
||||
px: t.CInt = rx
|
||||
while px < rx + rw:
|
||||
buf[py * bw + px] = color
|
||||
px += 1
|
||||
py += 1
|
||||
|
||||
def draw_circle(buf: UINT32PTR, bw: t.CInt, cx: t.CInt, cy: t.CInt, r: t.CInt, color: t.CUInt32T) -> t.CVoid | t.CExport:
|
||||
x: t.CInt = r
|
||||
y: t.CInt = 0
|
||||
d: t.CInt = 1 - r
|
||||
while x >= y:
|
||||
if cx + x >= 0: buf[(cy + y) * bw + cx + x] = color
|
||||
if cx + y >= 0: buf[(cy + x) * bw + cx + y] = color
|
||||
if cx - y >= 0: buf[(cy + x) * bw + cx - y] = color
|
||||
if cx - x >= 0: buf[(cy + y) * bw + cx - x] = color
|
||||
if cx - x >= 0: buf[(cy - y) * bw + cx - x] = color
|
||||
if cx - y >= 0: buf[(cy - x) * bw + cx - y] = color
|
||||
if cx + y >= 0: buf[(cy - x) * bw + cx + y] = color
|
||||
if cx + x >= 0: buf[(cy - y) * bw + cx + x] = color
|
||||
y += 1
|
||||
if d <= 0:
|
||||
d += 2 * y + 1
|
||||
else:
|
||||
x -= 1
|
||||
d += 2 * (y - x) + 1
|
||||
Reference in New Issue
Block a user