label.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. #import base64
  4. #from beeprint import pp
  5. class Label:
  6. _PosX=0
  7. _PosY=0
  8. _Width=0
  9. _Height=0
  10. _Text=""
  11. _FontObj=None
  12. _Color = pygame.Color(83,83,83)
  13. _CanvasHWND = None
  14. _TextSurf = None
  15. def __init__(self):
  16. pass
  17. def Init(self,text,font_obj,color=pygame.Color(83,83,83)):
  18. self._Color = color
  19. self._FontObj = font_obj
  20. self._Text = text
  21. my_text = self._FontObj.render(self._Text,True,self._Color)
  22. self._Width = my_text.get_width()
  23. self._Height = my_text.get_height()
  24. def NewCoord(self,x,y):
  25. self._PosX = x
  26. self._PosY = y
  27. def SetColor(self,color):
  28. self._Color = color
  29. def GetText(self):
  30. return self._Text
  31. def SetText(self,text):
  32. self._Text = text
  33. my_text = self._FontObj.render(self._Text,True,self._Color)
  34. self._Width = my_text.get_width()
  35. self._Height = my_text.get_height()
  36. def Width(self):
  37. return self._Width
  38. def SetCanvasHWND(self,_canvashwnd):
  39. self._CanvasHWND = _canvashwnd
  40. def Draw(self):
  41. self._FontObj.set_bold(False) ## avoing same font tangling set_bold to others
  42. my_text = self._FontObj.render( self._Text,True,self._Color)
  43. self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))