from stdint import * import drivers.video.vesafb.gfx as gfx import t, c MAX_SHEETS: t.CDefine = 64 MAX_UI_COMPONENTS: t.CDefine = 256 _next_sheet_id: t.CInt = 0 _next_component_id: t.CInt = 0 @t.Object class Sheet: id: t.CInt x: t.CInt y: t.CInt w: t.CInt h: t.CInt visible: t.CInt _surf_obj: gfx.Surface _renderer_obj: gfx.Renderer surf: gfx.Surface | t.CPtr renderer: gfx.Renderer | t.CPtr parent: 'Sheet | t.CPtr' bg_color: t.CUInt32T def __init__(self, fb: UINT32PTR, zb: float | t.CPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, parent: 'Sheet | t.CPtr' = 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 = c.Addr(self._surf_obj) self._renderer_obj = gfx.Renderer(self.surf) self.renderer = c.Addr(self._renderer_obj) self.parent = parent self.bg_color = gfx.COLOR_RGB(20, 20, 30) def MoveTo(self, nx: t.CInt, ny: t.CInt): self.x = nx self.y = ny def Resize(self, nw: t.CInt, nh: t.CInt): self.w = nw self.h = nh def Show(self): self.visible = 1 def Hide(self): self.visible = 0 def Clear(self): r: gfx.Renderer = c.Deref(self.renderer) r.Clear(self.bg_color) def Fill(self, color: t.CUInt32T): r: gfx.Renderer = c.Deref(self.renderer) r.Clear(color) def DrawRect(self, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T): r: gfx.Renderer = c.Deref(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: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T): surf: gfx.Surface = c.Deref(self.surf) fb: UINT32PTR = surf.fb w: t.CInt = surf.w h: t.CInt = 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: t.CInt, py: t.CInt) -> t.CInt: if px >= self.x and px < self.x + self.w and py >= self.y and py < self.y + self.h: return 1 return 0