内容由用户产出,本次仅代为提交、未做任何语义修改;含 static 修饰符前置迁移等(新增 static 前缀 16 行)。提交消息为中性描述——如需更精确的说明请 amend。
88 lines
2.7 KiB
Plaintext
88 lines
2.7 KiB
Plaintext
from stdint import *
|
||
import drivers.video.vesafb.gfx as gfx
|
||
|
||
|
||
define MAX_SHEETS = 64
|
||
define MAX_UI_COMPONENTS = 256
|
||
|
||
_next_sheet_id: int = 0
|
||
_next_component_id: int = 0
|
||
|
||
class Sheet:
|
||
id: int
|
||
x: int
|
||
y: int
|
||
w: int
|
||
h: int
|
||
visible: int
|
||
_surf_obj: gfx.Surface
|
||
_renderer_obj: gfx.Renderer
|
||
surf: gfx.Surface*
|
||
renderer: gfx.Renderer*
|
||
parent: Sheet*
|
||
bg_color: uint32
|
||
|
||
def __init__(self, fb: UINT32PTR, zb: float*, x: int, y: int, w: int, h: int, parent: Sheet* = None):
|
||
global _next_sheet_id
|
||
self.id = _next_sheet_id
|
||
_next_sheet_id += 1
|
||
self.x = x
|
||
self.y = y
|
||
self.w = w
|
||
self.h = h
|
||
self.visible = 1
|
||
self._surf_obj = gfx.Surface(fb, zb, w, h)
|
||
self.surf = &self._surf_obj
|
||
# gfx.Renderer.__init__(fb, zb, w, h):此前只传 self.surf(Surface*)→
|
||
# fb 被 bitcast 错位、w/h 缺省为 0 → Renderer 的 _w/_h = 0 →
|
||
# Sheet.Clear/Fill/DrawRect(走 renderer)全部空操作。按 Surface 同参构造。
|
||
self._renderer_obj = gfx.Renderer(fb, zb, w, h)
|
||
self.renderer = &self._renderer_obj
|
||
self.parent = parent
|
||
self.bg_color = gfx.COLOR_RGB(20, 20, 30)
|
||
|
||
def MoveTo(self, nx: int, ny: int):
|
||
self.x = nx
|
||
self.y = ny
|
||
|
||
def Resize(self, nw: int, nh: int):
|
||
self.w = nw
|
||
self.h = nh
|
||
|
||
def Show(self):
|
||
self.visible = 1
|
||
|
||
def Hide(self):
|
||
self.visible = 0
|
||
|
||
def Clear(self):
|
||
r: gfx.Renderer = *self.renderer
|
||
r.Clear(self.bg_color)
|
||
|
||
def Fill(self, color: uint32):
|
||
r: gfx.Renderer = *self.renderer
|
||
r.Clear(color)
|
||
|
||
def DrawRect(self, rx: int, ry: int, rw: int, rh: int, color: uint32):
|
||
r: gfx.Renderer = *self.renderer
|
||
r.DrawLine2D(rx, ry, rx + rw - 1, ry, color)
|
||
r.DrawLine2D(rx + rw - 1, ry, rx + rw - 1, ry + rh - 1, color)
|
||
r.DrawLine2D(rx + rw - 1, ry + rh - 1, rx, ry + rh - 1, color)
|
||
r.DrawLine2D(rx, ry + rh - 1, rx, ry, color)
|
||
|
||
def DrawFilledRect(self, rx: int, ry: int, rw: int, rh: int, color: uint32):
|
||
surf: gfx.Surface = *self.surf
|
||
fb: UINT32PTR = surf.fb
|
||
w: int = surf.w
|
||
h: int = surf.h
|
||
for py in range(ry, ry + rh):
|
||
if py < 0 or py >= h: continue
|
||
for px in range(rx, rx + rw):
|
||
if px < 0 or px >= w: continue
|
||
fb[py * w + px] = color
|
||
|
||
def Contains(self, px: int, py: int) -> int:
|
||
if px >= self.x and px < self.x + self.w and py >= self.y and py < self.y + self.h:
|
||
return 1
|
||
return 0
|