2
0

Label.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if retVal == nil then return nil end
  30. if Polycore.__ptr_lookup[retVal] ~= nil then
  31. return Polycore.__ptr_lookup[retVal]
  32. else
  33. Polycore.__ptr_lookup[retVal] = String("__skip_ptr__")
  34. Polycore.__ptr_lookup[retVal].__ptr = retVal
  35. return Polycore.__ptr_lookup[retVal]
  36. end
  37. end
  38. function Label:getTextWidth(font, text, size)
  39. local retVal = Polycore.Label_getTextWidth(self.__ptr, font.__ptr, text, size)
  40. return retVal
  41. end
  42. function Label:getTextHeight(font, text, size)
  43. local retVal = Polycore.Label_getTextHeight(self.__ptr, font.__ptr, text, size)
  44. return retVal
  45. end
  46. function Label:getFont()
  47. local retVal = Polycore.Label_getFont(self.__ptr)
  48. if retVal == nil then return nil end
  49. if Polycore.__ptr_lookup[retVal] ~= nil then
  50. return Polycore.__ptr_lookup[retVal]
  51. else
  52. Polycore.__ptr_lookup[retVal] = Font("__skip_ptr__")
  53. Polycore.__ptr_lookup[retVal].__ptr = retVal
  54. return Polycore.__ptr_lookup[retVal]
  55. end
  56. end
  57. function Label:__delete()
  58. Polycore.__ptr_lookup[self.__ptr] = nil
  59. Polycore.delete_Label(self.__ptr)
  60. end