Label.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. require "Polycode/Image"
  2. class "Label" (Image)
  3. ANTIALIAS_FULL = 0
  4. ANTIALIAS_NONE = 1
  5. function Label:Label(...)
  6. if type(arg[1]) == "table" and count(arg) == 1 then
  7. if ""..arg[1]:class() == "Image" then
  8. self.__ptr = arg[1].__ptr
  9. return
  10. end
  11. end
  12. for k,v in pairs(arg) do
  13. if type(v) == "table" then
  14. if v.__ptr ~= nil then
  15. arg[k] = v.__ptr
  16. end
  17. end
  18. end
  19. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  20. self.__ptr = Polycore.Label(unpack(arg))
  21. Polycore.__ptr_lookup[self.__ptr] = self
  22. end
  23. end
  24. function Label:setText(text)
  25. local retVal = Polycore.Label_setText(self.__ptr, text)
  26. end
  27. function Label:getText()
  28. local retVal = Polycore.Label_getText(self.__ptr)
  29. return retVal
  30. end
  31. function Label:getTextWidth(font, text, size)
  32. local retVal = Polycore.Label_getTextWidth(self.__ptr, font.__ptr, text, size)
  33. return retVal
  34. end
  35. function Label:getTextHeight(font, text, size)
  36. local retVal = Polycore.Label_getTextHeight(self.__ptr, font.__ptr, text, size)
  37. return retVal
  38. end
  39. function Label:getFont()
  40. local retVal = Polycore.Label_getFont(self.__ptr)
  41. if retVal == nil then return nil end
  42. if Polycore.__ptr_lookup[retVal] ~= nil then
  43. return Polycore.__ptr_lookup[retVal]
  44. else
  45. Polycore.__ptr_lookup[retVal] = Font("__skip_ptr__")
  46. Polycore.__ptr_lookup[retVal].__ptr = retVal
  47. return Polycore.__ptr_lookup[retVal]
  48. end
  49. end
  50. function Label:__delete()
  51. Polycore.__ptr_lookup[self.__ptr] = nil
  52. Polycore.delete_Label(self.__ptr)
  53. end