Sample program for creating and using the DRAWMENU command
|
04-11-2015, 04:42 AM
Post: #4
|
|||
|
|||
RE: Sample program for creating and using the DRAWMENU command
In response to a request for a program that loops by (compsystems), here is an update of my prior code. You now have to press the ESC key or by default (no coding required) the ON key to exit the program. Additionally, I have utilized the TEXTOUT_P command to write information to the screen in lieu of using MSGBOX. The program also provides the functionality of returning and displaying the key number from the GETKEY command....
// 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 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 an empty/blank 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; END; END; 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; END; END; END; |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Sample program for creating and using the DRAWMENU command - kharpster - 04-09-2015, 05:00 PM
RE: Sample program for creating and using the DRAWMENU command - compsystems - 04-10-2015, 11:52 AM
RE: Sample program for creating and using the DRAWMENU command - John Colvin - 04-10-2015, 07:10 PM
RE: Sample program for creating and using the DRAWMENU command - kharpster - 04-11-2015 04:42 AM
RE: Sample program for creating and using the DRAWMENU command - Thomas_Sch - 04-11-2015, 09:25 AM
RE: Sample program for creating and using the DRAWMENU command - kharpster - 04-11-2015, 02:41 PM
RE: Sample program for creating and using the DRAWMENU command - Thomas_Sch - 04-11-2015, 03:07 PM
RE: Sample program for creating and using the DRAWMENU command - kharpster - 04-11-2015, 07:26 PM
|
User(s) browsing this thread: 1 Guest(s)