label.py 1.8 KB

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