label.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #UI lib
  8. from skin_manager import MySkinManager
  9. from lang_manager import MyLangManager
  10. from widget import Widget
  11. class Label(Widget):
  12. _Text=""
  13. _FontObj=None
  14. _Color = MySkinManager.GiveColor('Text')
  15. _CanvasHWND = None
  16. _TextSurf = None
  17. def __init__(self):
  18. pass
  19. def Init(self, text, font_obj, color=MySkinManager.GiveColor('Text')):
  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 SetColor(self,color):
  27. self._Color = color
  28. def GetText(self):
  29. return self._Text
  30. def SetText(self,text):
  31. self._Text = text
  32. my_text = self._FontObj.render(self._Text,True,self._Color)
  33. self._Width = my_text.get_width()
  34. self._Height = my_text.get_height()
  35. def SetCanvasHWND(self,_canvashwnd):
  36. self._CanvasHWND = _canvashwnd
  37. def DrawCenter(self,bold=False):
  38. self._FontObj.set_bold(bold) ## avoing same font tangling set_bold to others
  39. my_text = self._FontObj.render( self._Text,True,self._Color)
  40. self._CanvasHWND.blit(my_text,midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height))
  41. def Draw(self,bold=False):
  42. self._FontObj.set_bold(bold) ## avoing same font tangling set_bold to others
  43. my_text = self._FontObj.render( self._Text,True,self._Color)
  44. self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))