Many thanks for your framework!
I added just a little bit of formatting (indent).
Code:
// Initialize procedures used in project
EVENTHANDLER();
PUTMENU();
GETMENU();
// Initialize variables used globally in project
mSEL;
eTYP;
kP;
m;
m1;
EXPORT MENUTEST()
BEGIN
// Initialize local variables used within this procedure
LOCAL mx,my,mTXT,EXITPGM;
// Set the menu text (this is softcoded and determines if a menu item is valid)
mTXT := {"ITEM1","ITEM2","","","","ITEM6"};
// MAIN CODE - Loop until ESC is pressed, then exit the program
EXITPGM := 0;
RECT();
WHILE EXITPGM == 0 DO
// Draw the menu
PUTMENU(mTXT);
// Flush the mouse buffer
WHILE MOUSE(1) ≥ 0 DO END;
// Loop until we have a keyboard or mouse event
REPEAT
EVENTHANDLER();
UNTIL eTYP <> "";
CASE
// If the event type was a keyboard action then process it
IF eTYP == "K" THEN
// If the ESC key was pressed set the program to end
IF kP == 4 THEN
EXITPGM := 1;
ELSE
// ESC was not pressed do what you want with the keypress,
// we are just going to do a TEXTOUT
RECT_P(0,0,319,219);
TEXTOUT_P("Key "+kP+" was pressed",95,100);
END;
END; // IF eTYP == "K"
// If the event type was mouse action then process it
IF eTYP == "M" THEN
// Convert mouse coordinates to decimal
mx := B→R(m1(1));
my := B→R(m1(2));
// Determine if mouse coordinates are inside of a valid menu
// item otherwise return a zero
GETMENU(mx,my,mTXT);
// If a valid menu item was selected, do something, we are just
// going to do a TEXTOUT
IF mSEL > 0 THEN
RECT_P(0,0,319,219);
TEXTOUT_P("Menu item "+mSEL+" was selected",75,100);
ELSE
// Mouse not in menu, do something if needed
END;
END; // IF eTYP == "M"
END; // CASE
END; // WHILE EXITPGM
END;
// -------------------------------------------------------------------
// Detect keyboard or mouse input (keyboard has priority)
// -------------------------------------------------------------------
EVENTHANDLER()
BEGIN
eTYP := "";
kP := GETKEY;
IF kP <> -1 THEN
eTYP := "K";
ELSE
m := MOUSE;
m1 := m(1);
IF SIZE(m1) > 0 THEN
eTYP := "M";
END;
END;
END;
// ----------------------------------------------
// Draw the menu using the list passed in
// ----------------------------------------------
PUTMENU(mTXT)
BEGIN
DRAWMENU(mTXT(1),mTXT(2),mTXT(3),mTXT(4),mTXT(5),mTXT(6));
END;
// ----------------------------------------------------------------------------
// Get the number of the menu item selected (1-6) by checking mouse position
// Menu items with empty/blank text will return a zero
// ----------------------------------------------------------------------------
GETMENU(mx,my,mTXT)
BEGIN
mSEL := 0;
IF my≥220 AND my≤239 THEN
CASE
IF mx≥0 AND mx≤51 AND mTXT(1)>"" THEN
mSEL := 1;
END;
IF mx≥53 AND mx≤104 AND mTXT(2)>"" THEN
mSEL := 2;
END;
IF mx≥106 AND mx≤157 AND mTXT(3)>"" THEN
mSEL := 3;
END;
IF mx≥159 AND mx≤210AND mTXT(4)>"" THEN
mSEL := 4;
END;
IF mx≥212 AND mx≤263 AND mTXT(5)>"" THEN
mSEL := 5;
END;
IF mx≥265 AND mx≤319 AND mTXT(6)>"" THEN
mSEL := 6;
END; // IF mx
END; // CASE
END; // IF my
END;
edit: changed comment line
// If an empty/blank menu item was selected, do something, we are just going to do a TEXTOUT
to
// If a valid menu item was selected, do something, we are just going to do a TEXTOUT