LUISkin.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import os
  2. from os.path import join
  3. from panda3d.core import Filename
  4. from panda3d.lui import LUIFontPool, LUIAtlasPool
  5. class LUISkin:
  6. """ Abstract class, each skin derives from this class """
  7. skin_location = ""
  8. def __init__(self):
  9. pass
  10. def load(self):
  11. """ Skins should override this. Each skin should at least provide the fonts
  12. 'default' and 'label', and at least one atlas named 'skin' """
  13. raise NotImplementedError()
  14. def get_resource(self, pth):
  15. """ Turns a relative path into an absolute one, using the skin_location """
  16. return Filename.from_os_specific(join(self.skin_location, pth)).get_fullpath()
  17. class LUIDefaultSkin(LUISkin):
  18. """ The default skin which comes with LUI """
  19. skin_location = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../Skins/Default/")
  20. def __init__(self):
  21. pass
  22. def load(self):
  23. LUIFontPool.get_global_ptr().register_font(
  24. "default", loader.loadFont(self.get_resource("font/SourceSansPro-Semibold.ttf")))
  25. labelFont = loader.loadFont(self.get_resource("font/SourceSansPro-Semibold.ttf"))
  26. labelFont.setPixelsPerUnit(32)
  27. LUIFontPool.get_global_ptr().register_font(
  28. "label", labelFont)
  29. headerFont = loader.loadFont(self.get_resource("font/SourceSansPro-Light.ttf"))
  30. headerFont.setPixelsPerUnit(80)
  31. LUIFontPool.get_global_ptr().register_font("header", headerFont)
  32. LUIAtlasPool.get_global_ptr().load_atlas("skin",
  33. self.get_resource("res/atlas.txt"),
  34. self.get_resource("res/atlas.png"))