Post Reply 
Code snippet: drawmenu with catching user action
03-03-2014, 10:08 PM
Post: #3
RE: Code snippet: drawmenu with catching user action
Thank you Han! That works much better and is even simpler now. Here is my reworked code:

Code:

EXPORT DrawMenuSelect(buttonlabellist)
// Parameters: menustringlist is a list which should contain at most 6 strings for the button labels
// Returns: The ID (1 to 6) of the button that was pressed
BEGIN
 LOCAL selection, mouselist;
 DRAWMENU(buttonlabellist);
 mouselist:=WAIT(-1); // Wait until screen is touched
 selection := -1; //preinitialize with -1 which is returned if none of the buttons is pressed
 // Check whether one of the on-screen buttons was pressed:
 IF (mouselist(1)==3 AND mouselist(3) >= #DD:-16h) THEN
  selection:=CEILING((mouselist(2)+1)*6/320); // Screen is 320px wide. There are six buttons. hence divide
// mouse value by 320/6. To avoid getting a value of zero when the user presses exactly at the left 
//border a 1 is added to the mouse value
 END;

 RETURN selection;
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Code snippet: drawmenu with catching user action - Stefan - 03-03-2014 10:08 PM



User(s) browsing this thread: 1 Guest(s)