goo.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>Module goo</title>
  6. <link rel="stylesheet" href="../luadoc.css" type="text/css" />
  7. <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>Goo</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li>
  26. <a href="../modules/anim.html">anim</a>
  27. </li>
  28. <li><strong>goo</strong></li>
  29. <li>
  30. <a href="../modules/goo.button.html">goo.button</a>
  31. </li>
  32. <li>
  33. <a href="../modules/goo.checkbox.html">goo.checkbox</a>
  34. </li>
  35. <li>
  36. <a href="../modules/goo.colorpick.html">goo.colorpick</a>
  37. </li>
  38. <li>
  39. <a href="../modules/goo.image.html">goo.image</a>
  40. </li>
  41. <li>
  42. <a href="../modules/goo.null.html">goo.null</a>
  43. </li>
  44. <li>
  45. <a href="../modules/goo.object.html">goo.object</a>
  46. </li>
  47. <li>
  48. <a href="../modules/goo.panel.html">goo.panel</a>
  49. </li>
  50. <li>
  51. <a href="../modules/goo.progressbar.html">goo.progressbar</a>
  52. </li>
  53. <li>
  54. <a href="../modules/goo.text.html">goo.text</a>
  55. </li>
  56. <li>
  57. <a href="../modules/goo.textinput.html">goo.textinput</a>
  58. </li>
  59. </ul>
  60. <!-- File list -->
  61. </div><!-- id="navigation" -->
  62. <div id="content">
  63. <h1>Module <code>goo</code></h1>
  64. <p>GUI Library. <br/>Goo is a gui lib that uses inherited positioning. <br/>What this means is that a object's position is always relative to it's parent's position. <br/>Some of you may recognise this as a scene graph. <br/>Goo also uses skins and styles which means you can easily change and seperate the object look from it's logic. <br/> <br/>To load place the following functions in their respective love function. <pre class="example"> goo = require 'goo/goo'<br/> goo:load()<br/> goo:update(dt)<br/> goo:draw()<br/> goo:mousepressed(x,y,button)<br/> goo:mousereleased(x,y,button)<br/> goo:keypressed(key,unicode)<br/> goo:keyreleased(key,unicode) </pre></p>
  65. <h2>Functions</h2>
  66. <table class="function_list">
  67. <tr>
  68. <td class="name" nowrap><a href="#goo.object:new">goo.object:new</a>&nbsp;(parent)</td>
  69. <td class="summary">Creates a goo object.</td>
  70. </tr>
  71. <tr>
  72. <td class="name" nowrap><a href="#goo:debugdraw">goo:debugdraw</a>&nbsp;()</td>
  73. <td class="summary">Draw a debug interface.</td>
  74. </tr>
  75. <tr>
  76. <td class="name" nowrap><a href="#goo:draw">goo:draw</a>&nbsp;()</td>
  77. <td class="summary">Draws all goo objects.</td>
  78. </tr>
  79. <tr>
  80. <td class="name" nowrap><a href="#goo:keypressed">goo:keypressed</a>&nbsp;(key, unicode)</td>
  81. <td class="summary">Send keypress to goo </td>
  82. </tr>
  83. <tr>
  84. <td class="name" nowrap><a href="#goo:keyreleased">goo:keyreleased</a>&nbsp;(key, unicode)</td>
  85. <td class="summary">Send keyrelease to goo </td>
  86. </tr>
  87. <tr>
  88. <td class="name" nowrap><a href="#goo:load">goo:load</a>&nbsp;()</td>
  89. <td class="summary">Loads the goo library.</td>
  90. </tr>
  91. <tr>
  92. <td class="name" nowrap><a href="#goo:mousepressed">goo:mousepressed</a>&nbsp;(x, y, button)</td>
  93. <td class="summary">Send mousepress to goo </td>
  94. </tr>
  95. <tr>
  96. <td class="name" nowrap><a href="#goo:mouserelease">goo:mouserelease</a>&nbsp;(x, y, button)</td>
  97. <td class="summary">Send mouserelease to goo </td>
  98. </tr>
  99. <tr>
  100. <td class="name" nowrap><a href="#goo:setSkin">goo:setSkin</a>&nbsp;(skin_name)</td>
  101. <td class="summary">Sets the skin of goo, default is 'default'.</td>
  102. </tr>
  103. <tr>
  104. <td class="name" nowrap><a href="#goo:setSkinAllObjects">goo:setSkinAllObjects</a>&nbsp;(skin_name)</td>
  105. <td class="summary">Sets the skin and updates all objects to use that skin.</td>
  106. </tr>
  107. <tr>
  108. <td class="name" nowrap><a href="#goo:update">goo:update</a>&nbsp;(dt)</td>
  109. <td class="summary">Updates all goo objects.</td>
  110. </tr>
  111. </table>
  112. <h2>Tables</h2>
  113. <table class="table_list">
  114. <tr>
  115. <td class="name" nowrap><a href="#goo_object">goo_object</a></td>
  116. <td class="summary">Standard goo object structure.</td>
  117. </tr>
  118. <tr>
  119. <td class="name" nowrap><a href="#style">style</a></td>
  120. <td class="summary">Style table structure.</td>
  121. </tr>
  122. </table>
  123. <h2>Examples</h2>
  124. <table class="table_list">
  125. <tr>
  126. <td class="name" nowrap><a href="#Panel with button.">Panel with button.</a></td>
  127. <td class="summary">Show a panel with a button that prints a message on click.</td>
  128. </tr>
  129. <tr>
  130. <td class="name" nowrap><a href="#Slide in panel.">Slide in panel.</a></td>
  131. <td class="summary">Show a panel that slides in.</td>
  132. </tr>
  133. <tr>
  134. <td class="name" nowrap><a href="#Zoom in panel.">Zoom in panel.</a></td>
  135. <td class="summary">Show a panel that zooms in bouncily with animated opacity too.</td>
  136. </tr>
  137. <tr>
  138. <td class="name" nowrap><a href="#Overriding styles.">Overriding styles.</a></td>
  139. <td class="summary">Show a panel with two buttons, one of which has an overridden style.</td>
  140. </tr>
  141. </table>
  142. <br/>
  143. <br/>
  144. <h2><a name="functions"></a>Functions</h2>
  145. <dl class="function">
  146. <dt><a name="goo.object:new"></a><span>goo.object:</span><strong>new</strong>&nbsp;( parent )</dt>
  147. <dd>
  148. <p class="func_description">Creates a goo object. <br/>This is the main method to create gui objects, replace goo.object with a goo object. <br/>All goo objects inherit methods from <a href='goo.object.html'>goo.object</a></p>
  149. <h3>Parameters</h3>
  150. <ul>
  151. <li>
  152. <b>parent</b> <i><small>:goo_object</small></i><br/>the parent object to use. Position and scale will be inherited from it's parent.
  153. </li>
  154. </ul>
  155. <h3>Usage:</h3>
  156. <pre class="example"> panel = goo.panel:new(); button = goo.button:new( panel ) </pre>
  157. <h3>Return value:</h3>
  158. <p class="func_return">goo_object: A goo object instance. Use links below to see the methods you can call on the table.</p>
  159. <h3>See also:</h3>
  160. <ul>
  161. <li><a href="../modules/goo.html#goo_object">
  162. goo_object
  163. </a>
  164. <li><a href="../modules/goo.object.html">
  165. goo.object
  166. </a>
  167. <li><a href="../modules/goo.panel.html">
  168. goo.panel
  169. </a>
  170. <li><a href="../modules/goo.text.html">
  171. goo.text
  172. </a>
  173. <li><a href="../modules/goo.button.html">
  174. goo.button
  175. </a>
  176. <li><a href="../modules/goo.textinput.html">
  177. goo.textinput
  178. </a>
  179. <li><a href="../modules/goo.colorpick.html">
  180. goo.colorpick
  181. </a>
  182. <li><a href="../modules/goo.null.html">
  183. goo.null
  184. </a>
  185. <li><a href="../modules/goo.progressbar.html">
  186. goo.progressbar
  187. </a>
  188. <li><a href="">
  189. goo.closebutton
  190. </a>
  191. <li><a href="">
  192. goo.bigbutton
  193. </a>
  194. <li><a href="../modules/goo.checkbox.html">
  195. goo.checkbox
  196. </a>
  197. </ul>
  198. </dd>
  199. <dt><a name="goo:debugdraw"></a><span>goo:</span><strong>debugdraw</strong>&nbsp;( )</dt>
  200. <dd>
  201. <p class="func_description">Draw a debug interface. <br/>Will show the mouse position and the name of the goo object the mouse is over.</p>
  202. </dd>
  203. <dt><a name="goo:draw"></a><span>goo:</span><strong>draw</strong>&nbsp;( )</dt>
  204. <dd>
  205. <p class="func_description">Draws all goo objects.</p>
  206. </dd>
  207. <dt><a name="goo:keypressed"></a><span>goo:</span><strong>keypressed</strong>&nbsp;( key, unicode )</dt>
  208. <dd>
  209. <p class="func_description">Send keypress to goo</p>
  210. </dd>
  211. <dt><a name="goo:keyreleased"></a><span>goo:</span><strong>keyreleased</strong>&nbsp;( key, unicode )</dt>
  212. <dd>
  213. <p class="func_description">Send keyrelease to goo</p>
  214. </dd>
  215. <dt><a name="goo:load"></a><span>goo:</span><strong>load</strong>&nbsp;( )</dt>
  216. <dd>
  217. <p class="func_description">Loads the goo library.</p>
  218. </dd>
  219. <dt><a name="goo:mousepressed"></a><span>goo:</span><strong>mousepressed</strong>&nbsp;( x, y, button )</dt>
  220. <dd>
  221. <p class="func_description">Send mousepress to goo</p>
  222. </dd>
  223. <dt><a name="goo:mouserelease"></a><span>goo:</span><strong>mouserelease</strong>&nbsp;( x, y, button )</dt>
  224. <dd>
  225. <p class="func_description">Send mouserelease to goo</p>
  226. </dd>
  227. <dt><a name="goo:setSkin"></a><span>goo:</span><strong>setSkin</strong>&nbsp;( skin_name )</dt>
  228. <dd>
  229. <p class="func_description">Sets the skin of goo, default is 'default'. <br/>Skins are kept in goo/skins/ <br/>If you have already created objects you should use goo:setSkinAllObjects</p>
  230. <h3>Parameters</h3>
  231. <ul>
  232. <li>
  233. <b>skin_name</b> <i><small>:string</small></i><br/>the name of the skin, i.e. 'default', 'dark'.
  234. </li>
  235. </ul>
  236. <h3>See also:</h3>
  237. <ul>
  238. <li><a href="">
  239. goo:setSkinAllObjects
  240. </a>
  241. </ul>
  242. </dd>
  243. <dt><a name="goo:setSkinAllObjects"></a><span>goo:</span><strong>setSkinAllObjects</strong>&nbsp;( skin_name )</dt>
  244. <dd>
  245. <p class="func_description">Sets the skin and updates all objects to use that skin. <br/>any objects with overriden styles will be set to the skin's style.</p>
  246. <h3>Parameters</h3>
  247. <ul>
  248. <li>
  249. <b>skin_name</b> <i><small>:string</small></i><br/>the name of the skin, i.e. 'default', 'dark'.
  250. </li>
  251. </ul>
  252. <h3>See also:</h3>
  253. <ul>
  254. <li><a href="">
  255. goo:setSkin
  256. </a>
  257. </ul>
  258. </dd>
  259. <dt><a name="goo:update"></a><span>goo:</span><strong>update</strong>&nbsp;( dt )</dt>
  260. <dd>
  261. <p class="func_description">Updates all goo objects.</p>
  262. </dd>
  263. </dl>
  264. <h2><a name="tables"></a>Tables</h2>
  265. <dl class="table">
  266. <dt><a name="goo_object"></a><strong>goo_object</strong></dt>
  267. <dd>Standard goo object structure.
  268. <em>Fields</em>
  269. <ul>
  270. <li>
  271. <b>parent</b> The parent instance of the object.
  272. </li>
  273. <li>
  274. <b>super</b> The parent class of the object. To hook an internal function rather than override use super.function(self,...), see usage below.
  275. </li>
  276. <li>
  277. <b>children</b> A list of all children instances.
  278. </li>
  279. <li>
  280. <b>x</b> The x position.
  281. </li>
  282. <li>
  283. <b>y</b> The y position.
  284. </li>
  285. <li>
  286. <b>w</b> The width.
  287. </li>
  288. <li>
  289. <b>h</b> The height.
  290. </li>
  291. <li>
  292. <b>bounds</b> The bounding box. Represented by a table: {x1,y1,x2,y2}. Used for detecting mouse events.
  293. </li>
  294. <li>
  295. <b>xscale</b> The x scale.
  296. </li>
  297. <li>
  298. <b>yscale</b> The y scale.
  299. </li>
  300. <li>
  301. <b>opacity</b> The opacity of the object.
  302. </li>
  303. <li>
  304. <b>visible</b> Boolean representing if the object is being drawn.
  305. </li>
  306. <li>
  307. <b>mouseHover</b> Boolean representing if the mouse is ontop of the object.
  308. </li>
  309. </ul>
  310. <h3>Usage:</h3>
  311. <pre class='example'> button = goo.button:new()<br /> button.draw = function(self)<br /> super.draw(self)<br /> love.graphics.circle( 'line', 0, 0, 20 ) -- we use 0 for x,y because position is always relative to itself.<br /> end<br /> -- will draw a button with a circle ontop, not just a circle.</pre><br />
  312. </dd>
  313. <dt><a name="style"></a><strong>style</strong></dt>
  314. <dd>Style table structure. Possible keys:
  315. <em>Fields</em>
  316. <ul>
  317. <li>
  318. <b>backgroundColor</b>
  319. </li>
  320. <li>
  321. <b>backgroundColorHover</b>
  322. </li>
  323. <li>
  324. <b>borderColor</b>
  325. </li>
  326. <li>
  327. <b>borderColorHover</b>
  328. </li>
  329. <li>
  330. <b>borderWidth</b>
  331. </li>
  332. <li>
  333. <b>textColor</b>
  334. </li>
  335. <li>
  336. <b>textColorHover</b>
  337. </li>
  338. <li>
  339. <b>textFont</b>
  340. </li>
  341. <li>
  342. <b>color</b>
  343. </li>
  344. <li>
  345. <b>colorHover</b>
  346. </li>
  347. <li>
  348. <b>titleColor</b>
  349. </li>
  350. <li>
  351. <b>titleColorHover</b>
  352. </li>
  353. <li>
  354. <b>lineHeight</b>
  355. </li>
  356. </ul>
  357. <h3>Usage:</h3>
  358. excerpt from default/style.lua <pre class="example"> style['goo button'] = {<br /> backgroundColor = {100,100,100},<br /> backgroundColorHover = {131,203,21},<br /> borderColor = {0,0,0,255},<br /> borderColorHover = {0,0,0},<br /> textColor = {255,255,255},<br /> textColorHover = {255,255,255},<br /> textFont = fonts.oldsans12<br /> }<br /> </pre><br />
  359. </dd>
  360. </dl>
  361. <h2><a name="examples"></a>Examples</h2>
  362. <dl class="example">
  363. <dt><a name="Panel with button."></a><strong>Panel with button.</strong></dt>
  364. <dd>
  365. <div class="example">
  366. <pre class="example"> local panel = goo.panel:new()<br /> panel:setPos( 10, 10 )<br /> panel:setSize( 200, 200 )<br /> panel:setTitle( 'I am a panel' )<br /> <br /> local button = goo.button:new( panel )<br /> button:setPos( 10, 20 )<br /> print( button:getAbsolutePos() ) -- 20, 30<br /> button:setText( 'Click me' )<br /> button:sizeToText()<br /> button.onClick = function( self, button )<br /> print( 'I have been clicked' )<br /> end<br /> </pre><br />
  367. </div>
  368. </dd>
  369. <dt><a name="Slide in panel."></a><strong>Slide in panel.</strong></dt>
  370. <dd>
  371. <div class="example">
  372. <pre class="example"> local panel = goo.panel:new()<br /> panel:setPos( -250, 50 )<br /> panel:setSize( 200, 200 )<br /> panel:setTitle( 'I am a panel' )<br /> <br /> local checkbox = goo.checkbox:new( panel )<br /> checkbox:setPos( 10, 20 )<br /> function checkbox:onClick( button )<br /> print( self.class.name .. ' has been clicked' )<br /> end<br /> function checkbox:enterHover()<br /> print( self.class.name .. ' enter hover')<br /> end<br /> <br /> local slideIn = anim:new{<br /> table = panel,<br /> key = 'x',<br /> finish = 350,<br /> time = 2,<br /> style = 'expoOut'<br /> }<br /> slideIn:play()<br /> function slideIn:onFinish()<br /> checkbox:setChecked( true )<br /> end<br /> </pre><br />
  373. </div>
  374. </dd>
  375. <dt><a name="Zoom in panel."></a><strong>Zoom in panel.</strong></dt>
  376. <dd>
  377. <div class="example">
  378. <pre class="example"> local testPanel = goo.panel:new()<br /> testPanel:setPos( 100, 50 )<br /> testPanel:setSize( 370, 500 )<br /> testPanel:setTitle( "This is a Color Panel." )<br /> testPanel:setOpacity( 10 )<br /> <br /> local colorPicker = goo.colorpick:new( testPanel )<br /> colorPicker:setPos(0,20)<br /> <br /> local input = goo.textinput:new( testPanel )<br /> input:setPos(3,486)<br /> input:setSize(360,20)<br /> input:setText('hello!')<br /> <br /> function colorPicker:onClick()<br /> local r,g,b = self:getColor()<br /> local str = string.format( 'Red = %i, Green = %i, Blue = %i', r,g,b)<br /> input:setText( str )<br /> end<br /> <br /> anim:easy( testPanel, 'xscale', 0, 1, 3, 'elastic')<br /> anim:easy( testPanel, 'yscale', 0.9, 1, 3, 'elastic')<br /> anim:easy( testPanel, 'opacity', 0, 255, 0.5, 'quadInOut')<br /> </pre><br />
  379. </div>
  380. </dd>
  381. <dt><a name="Overriding styles."></a><strong>Overriding styles.</strong></dt>
  382. <dd>
  383. <div class="example">
  384. <pre class="example"> local panel = goo.panel:new()<br /> panel:setPos( 10, 10 )<br /> panel:setSize( 200, 200 )<br /> panel:setTitle( 'I am a panel' )<br /> <br /> local button = goo.button:new( panel )<br /> button:setPos( 10, 20 )<br /> print( button:getAbsolutePos() ) -- 20, 30<br /> button:setText( 'Click me' )<br /> button:sizeToText()<br /> button.onClick = function( self, button )<br /> print( 'I have been clicked' )<br /> end<br /> <br /> local redButton = goo.button:new( panel )<br /> redButton:setPos( 10, 100 )<br /> redButton:setText( 'My style has been overridden' )<br /> redButton:sizeToText( 10 )<br /> <br /> local redStyle = {<br /> backgroundColor = {255,0,0},<br /> backgroundColorHover = {125,0,0},<br /> borderColor = {0,0,0,0},<br /> borderColorHover = {0,0,0,0},<br /> }<br /> redButton:setStyle( redStyle )<br /> </pre><br />
  385. </div>
  386. </dd>
  387. </dl>
  388. </div> <!-- id="content" -->
  389. </div> <!-- id="main" -->
  390. <div id="about">
  391. <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
  392. </div> <!-- id="about" -->
  393. </div> <!-- id="container" -->
  394. </body>
  395. </html>