|
#1
|
|||
|
|||
|
I promised it earlier but finally got around to working on it. What this is, is a module you include in your application to allow event driven GUI code.
For example: Code:
--[[ Small application to demonstrate the Apeopex module. Displays two buttons, one 3D and one flat. --]] --Clear cached package package.loaded.Apeopex = nil; --Load Apoepex module require "Apeopex"; --Set Exit variable DoExit = false; --Our button event functions. Simply sets our Exit variable to true. function ExitApp() DoExit = true; end; function DisplayText() screen.clear(); text.color(Apeopex.clRed); text.size(10); text.draw(10,150,"You pressed the second button!"); screen.update(); end; function TouchEvent(x,y) screen.clear(); screen.fillrect(200,10,100,50,Apeopex.clBlack); text.color(Apeopex.clWhite); text.size(15); text.draw(200,10,"X: " .. x); text.draw(200,30,"Y: " .. y); screen.update(); end; --Demonstrates screen wrapper and module color usage Apeopex.FillScreen(Apeopex.clBlack); --CreateButton(X,Y,Width,Height,IsFlat,MainColor,TextColor,ButtonCaption,ButtonClickEvent) Apeopex.CreateButton(10,10,100,30,true,Apeopex.clLightGray,Apeopex.clBlack,"Exit",ExitApp); Apeopex.CreateButton(10,50,100,30,false,Apeopex.clLightGray,Apeopex.clBlack,"Display Text",DisplayText); --Demonstrate event usage Apeopex.OnHomeHold = ExitApp; Apeopex.OnTouchClick = TouchEvent; Apeopex.OnTouchMove = TouchEvent; --Our application loop repeat --Call the module event loop to process button clicks Apeopex.EventLoop(); --Exit when button is pressed, which calls the event ExitApp, which sets DoExit to true. until (DoExit == true); . If I had a camera I'd attempt to get a picture of the buttons, but they are slightly 3Dish and are push/rollover buttons that utilize the touch.down() and touch.up() events.v0.1 - Release! v0.2 - Fully event driven. Allowed to add user events for all control events. Works without sleep or wait. Last edited by ThievingSix; 01-15-2010 at 12:44 PM. |
|
|
|||
|
|
|
#2
|
||||
|
||||
|
Nice, I'm playing with it as you can see :-)
![]() But I have a slight problem if I pass parms. to the function from the line below. function Drawplanet(refx,refy) code end; Apeopex.CreateButton(10,90,100,30,false,Apeopex.cl LightGray,Apeopex.clBlack,"Draw planet ",Drawplanet(200,120)); It draws the planet before drawing the button or touching the button, and the button never work again. If I use: function Drawplanet() refx=200;refy=120; code end; Apeopex.CreateButton(10,90,100,30,false,Apeopex.cl LightGray,Apeopex.clBlack,"Draw planet ",Drawplanet ); And put the parms in the function then everything is fine, is this behaviour intended ? EDIT: the complete code http://www.exras.netne.net/Apeopex_MAIN.LUA Jan_DK |
|
#3
|
|||
|
|||
|
In a sense, yes, it's intended.
When passing a function with just the function name(eg "DrawPlanet") you are passing the actual function address. When passing a function with parameters(eg "Drawplanet(200,120)") you are telling lua to call that function before CreateButton and pass the result of the function to CreateButton. It's evaluating it as a function you want to pass the result of instead of passing the actual function itself. What you could do is add another parameter to the end of CreateButton() that will take the parameters you want to pass to the event but since LUA deals with global variable access equally or better than function parameter passing overhead I decided to go this route. BTW, nice planet draw =D. |
|
#4
|
|||
|
|||
|
Updated, sample works without a sleep or wait. Might have to do with the way I'm handling events.
|
|
#5
|
|||
|
|||
|
I believe that Apeopex needs a slight edit (not being critical in any way).
FillScreen (and anywhere else they are used) requires width and height to both have '-1' appended. 0 to 239=240 etc. |
|
#6
|
|||
|
|||
|
I have been experimenting to learn how this package works.
Can you please explain why the function ExitApp() cannot be placed in Apeopex itself. I have tried to do that and it does not work. My expectancy was that the package would have been declared? as it is loaded and therefore the function will have been pre-declared. I have obviously not understood packages correctly. Thank you. |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 12:51 PM.










. If I had a camera I'd attempt to get a picture of the buttons, but they are slightly 3Dish and are push/rollover buttons that utilize the touch.down() and touch.up() events.

Linear Mode
