android
  #1  
Old 01-14-2010, 12:26 AM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default Apeopex GUI/Event Module

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);
Right now there is only support for simple buttons, but I wanted to get it out there to see what you think . 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.
Attached Files
File Type: zip Apeopex(Module + Sample).zip (3.5 KB, 22 views)
File Type: zip Apeopex(Module + Sample)v0.2.zip (4.2 KB, 49 views)

Last edited by ThievingSix; 01-15-2010 at 01:44 PM.
Reply With Quote

Advertisement [Remove Advertisement]

  #2  
Old 01-14-2010, 04:33 AM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

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
Reply With Quote

  #3  
Old 01-14-2010, 11:45 AM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

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.
Reply With Quote

  #4  
Old 01-15-2010, 01:35 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

Updated, sample works without a sleep or wait. Might have to do with the way I'm handling events.
Reply With Quote

  #5  
Old 05-08-2010, 10:16 AM
Donone Donone is offline
Junior Member
 
Join Date: May 2010
Posts: 59
Default Slight edit needed

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.
Reply With Quote

  #6  
Old 05-10-2010, 07:24 AM
Donone Donone is offline
Junior Member
 
Join Date: May 2010
Posts: 59
Default

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.
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:12 PM.