widget.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import pygame
  2. class Widget:
  3. def __init__(self, x=0, y=0, width=7, height=7, color=pygame.Color(131, 199, 219), bg_color=None):
  4. self._PosX = x
  5. self._PosY = y
  6. self._Width = width
  7. self._Height = height
  8. self._Color = color
  9. self._BG_Color = bg_color
  10. self._Rect = pygame.Rect(self._PosX, self._PosY, self._Width, self._Height)
  11. self._Canvas = None
  12. self._Parent = None
  13. def get_canvas(self):
  14. return self._Canvas
  15. def set_position(self, x, y):
  16. self._PosX = x
  17. self._PosY = y
  18. self._Rect.x = x
  19. self._Rect.y = y
  20. def set_size(self, width, height):
  21. self._Height = height
  22. self._Width = width
  23. self._Rect.height = height
  24. self._Rect.width = width
  25. def set_color(self, color):
  26. self._Color = color
  27. def set_bgcolor(self, color):
  28. self._BG_Color = color
  29. def set_parent(self, parent):
  30. self._Parent = parent
  31. def get_rect(self):
  32. return self._Rect
  33. def Draw(self):
  34. if self._BG_Color is not None and self._Parent is not None:
  35. pygame.draw.rect(self._Parent.get_canvas(), self._BG_Color, self._Rect)
  36. def handle_event(self, evt):
  37. pass
  38. def reload(self):
  39. pass