goo.object.luadoc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. --[[ This is the superclass for all goo objects, every object can access it's methods ]]
  2. module 'goo.object'
  3. --[[ Internal function called from goo.object:new()
  4. @param parent:goo_object the parent class to use.
  5. @see goo
  6. ]]
  7. function goo.object:initialize(parent)
  8. --[[ Sets the position of the object.
  9. @param x:number x position
  10. @param y:number y position
  11. ]]
  12. function goo.object:setPos(x,y)
  13. --[[ Sets the size of the position and updates the bounds.
  14. @param w:number width of the object
  15. @param h:number height of the object
  16. ]]
  17. function goo.object:setSize(w,h)
  18. --[[ Sets the scale of the object.
  19. @param x:number x scale (0-1)
  20. @param y:number y scale (0-1)
  21. ]]
  22. function goo.object:setScale(x,y)
  23. --[[ Set whether the object should be drawn.
  24. @param visible:bool Should the object be drawn?
  25. ]]
  26. function goo.object:setVisible(visible)
  27. --[[ is the mouse over the object?
  28. @return bool: returns true if the mouse is over the object. false otherwise.
  29. ]]
  30. function goo.object:isMouseHover()
  31. --[[ Callback function when the mouse enters the bounds of the object. ]]
  32. function goo.object:enterHover()
  33. --[[ Callback function when the mouse exits the bounds of the object. ]]
  34. function goo.object:exitHover()
  35. --[[ Updates the bounds of the object.
  36. <br/>The bounds of the object are 4 points, representing the bounding box.
  37. <br/>This box is used to detect mouse events.
  38. ]]
  39. function goo.object:updateBounds()
  40. --[[ Gets the absolute position of the object.
  41. <br/>This function moves up through the entire instance hierarchy returning it's absolute position.
  42. <br/>If the parent object is at position 10,10 then obj:getRelativePos(5,5) returns 15,15
  43. @param x:number the relative x position. (defaults to objects x position)
  44. @param y:number the relative y position. (defaults to objects y position)
  45. @return number: absolute x position.
  46. @return number: absolute y position.
  47. ]]
  48. function goo.object:getAbsolutePos(x,y)
  49. --[[ Gets the absolute scale of the object.
  50. @param x:number the x scale (0-1) (defaults to objects x scale)
  51. @param y:number the y scale (0-1) (defaults to objects y scale)
  52. @return number: the absolute x scale (0-1)
  53. @return number: the absolute y scale (0-1)
  54. @see goo.object:getAbsolutePos
  55. ]]
  56. function goo.object:getAbsoluteScale(x,y)
  57. --[[ Get the relative position of an object ]]
  58. function goo.object:getRelativePos(x,y)
  59. --[[ Get the relative scale of an object ]]
  60. function goo.object:getRelativeScale(xscale,yscale)
  61. --[[]]
  62. function goo.object:sizeToText()
  63. --[[ Sets the style of the object.
  64. <br/>each object has a style similar to CSS stylesheets.
  65. <br/>You can find these styles in goo/skins/{current skin}/style.lua
  66. <br/>This function's purpose is to override the styles defined in style.lua.
  67. <br/>To override pass a table with the same keys but you're overridden values.
  68. @param style:table the <a href='goo.html#style'>style</a> which will override the style set in style.lua
  69. @see goo.style
  70. ]]
  71. function goo.object:setStyle(style)
  72. --[[ Resets the objects style to the one defined in style.lua
  73. @see goo.object:setStyle
  74. ]]
  75. function goo.object:resetStyle()
  76. --[[ This will remove the object from it's parent, it will not remove it completely.
  77. <br/>This can be used to unhook an object from it's parent preventing it from inheriting position.
  78. <br/>You could also bring an object to the top by calling removeFromParent followed by addToParent but
  79. <br/>there is a convient function <a href='#bringToTop'>bringToTop</a> for that.
  80. @see goo.object:addToParent, goo.object:bringToTop
  81. ]]
  82. function goo.object:removeFromParent()
  83. --[[ This will hook the object onto the given parent
  84. @param parent:goo_object the goo object to hook on to
  85. @see goo.object:removeFromParent
  86. ]]
  87. function goo.object:addToParent(parent)
  88. --[[ Get the current opacity value of the object.
  89. @return number: the opacity of the object (0-255)
  90. ]]
  91. function goo.object:getOpacity()
  92. --[[ Sets the opacity of the object
  93. @param opacity:number the opacity value (0-255)
  94. ]]
  95. function goo.object:setOpacity(opacity)
  96. --[[ Internal function used to set the drawing color, used instead of love.graphics.setColor.
  97. <br/>You should not need to use this unless you're overriding an objects draw method.
  98. <br/>It's much like love.graphics.setColor except it takes a table and respects the objects opacity methods.
  99. @param colorTable:table a table of 3 or 4 color values {r,g,b,a} the values should have no keys. Alpha is optional.
  100. ]]
  101. function goo.object:setColor(colorTable)
  102. --[[ Callback function when the object is clicked.
  103. <br/>If this function exists it will be called when the mousePressed event occurs within the object's bounds.
  104. @param x:number the absolute x position of the mouse.
  105. @param y:number the absolute y position of the mouse.
  106. @param button:string the button pressed. 'l' for left, 'r' for right, 'm' for middle.
  107. @usage <pre class='example'>
  108. local button = goo.button:new()
  109. button.name = 'bob'
  110. function button:onClick(x,y,button)
  111. if button == 'l' then
  112. print(self.name .. ' has been clicked')
  113. end
  114. end
  115. -- when the button is clicked with left mouse button it prints:
  116. -- bob has been clicked</pre>
  117. ]]
  118. function goo.object:onClick(x,y,button)
  119. --[[Internal]]
  120. function goo.object:mousePressed(x,y,button)
  121. --[[Internal]]
  122. function goo.object:mouseReleased(x,y,button)
  123. --[[Internal]]
  124. function goo.object:update(dt)
  125. --[[Internal]]
  126. function goo.object:draw()
  127. --[[ Called after goo.object:setStyle
  128. @see goo.object:setStyle
  129. ]]
  130. function goo.object:styleDidUpdate()