- '==================== 
- 'RIGHT-CLICK-MENU.BAS 
- '==================== 
- 'Easy to use right click popup menu. 
- 'Coded by Dav JULY/2013 
-   
- 'Here's a single FUNCTION easy to add to your programs to have a right click popup menu. 
- 'Several menu styles to choose from - or set your own custom menu colors (See FUNCTION). 
- 'Menu lets you enable/disble items on the fly and you can also have menu separators. 
- 'Supports many screen sizes, never off screen, and restores original background on exit. 
- 'To use simply add the RightClickMenu% FUNCTION and its defines below to your program. 
- 'Study the demo code below to see how to call and use the function. 
-   
- '======================================================================================== 
- '================== DEFINES FOR RIGHT CLICK MENU - CHANGE TO SUIT ======================= 
- '======================================================================================== 
-   
- DECLARE FUNCTION-  RightClickMenu%  (- menustyle% ) ' (not really needed, but it feels good)
 
-   
- DIM SHARED-  RightClickItems: RightClickItems  = 9 '    <----- Number of items in your menu
 
- DIM SHARED-  RightClickList$ (1 TO-  RightClickItems ) '          (change it to your number)
 
-   
- RightClickList$(1) = "New" '     <------------ List all your menu items here 
- RightClickList$(2) = "Open..." 
- RightClickList$(3) = "-Save" '   <------------ Leading minus makes these Disabled Items (-) 
- RightClickList$(4) = "-Save As..." 
- RightClickList$(5) = "---" '     <------------ This means it's a separator (---) 
- RightClickList$(6) = "Settings..." 
- RightClickList$(7) = "About" 
- RightClickList$(8) = "---" '     <------------ (another separator) 
- RightClickList$(9) = "Exit" 
-   
- ' menustyle% values:      1 = Old Windows style 
- '                         2 = New Windows style 
- '                         3 = Dark grey Linux 
- '                         4 = Blue Glass (semi-transparent) 
- '                         5 = Custom colors (user defined) 
-   
- '======================================================================================== 
- 'NOTE: menustyle% #5 is for user defined colors.  You can set your own custom colors by 
- '      changing the menu variables inside the RightClickMenu% FUNCTION (look in there). 
- '      Then, call RighClickMenu(5) to use your custom colored menu style. 
- '======================================================================================== 
-   
-   
- '======================================================================================== 
- '=============================== START DEMO CODE ======================================== 
- '======================================================================================== 
-   
-   
-   
- '=== draw stuff 
-   
- PRINT "Right Click Anywhere for Popup menu." 
-   
- LOCATE 28, 24- :  PRINT "Press 4 to Enable/Disable: Save As..."
 
-   
- LOCATE 30, 10- :  PRINT "(keep making selections to cycle through different menu styles)"- ; 
 
-   
- style% = 5 'Start with menu style 5 
-   
-   
-     a% = RightClickMenu%(style%) ' <----- Check for rightclick menu 
-   
-     '=== what did you select? 
-         style%  =-  style%  + 1- :  IF-  style%  = 6 THEN-  style%  = 1 'cycle mnu styles
-   
-     '=============================================================================== 
-     'NOTE: You can re-enabled a disabled menu item by removing the leading minus '-' 
-     'from it's name.  And you can disable an item by adding a leading minus. 
-     '=============================================================================== 
-   
-     '=== Here we disable/enable items 3 & 4 on the fly by pressing 3 or 4. 
-   
-         CASE IS = "3" ' Toggle Save menu on off 
-             IF-  RightClickList$ (3) = "-Save" THEN
 
-                 RightClickList$ (3) = "Save"- :  PRINT "ENABLED "- ; 
-                 RightClickList$ (3) = "-Save"- :  PRINT "DISABLED"- ; 
-             IF-  RightClickList$ (4) = "-Save As..." THEN
 
-                 RightClickList$ (4) = "Save As..."- :  PRINT "ENABLED "- ; 
-                 RightClickList$ (4) = "-Save As..."- :  PRINT "DISABLED"- ; 
-   
- LOOP UNTIL-  a%  = 9 'Item 9 (EXIT) exits demo...
 
-   
-   
- '======================================================================================== 
- '================================= END DEMO CODE ======================================== 
- '======================================================================================== 
-   
-   
- '======================================================================================== 
- '==================================== FUNCTION ========================================== 
- '======================================================================================== 
-   
-     ' 
-     'Creates a popup menu at the current mouse x/y position when right button is clicked. 
-     ' 
-     'This function returns the value of the menu item seleted.  If no selection is made, 
-     'then the function will return a value of 0.  REQUIRES RightClickList$() array defined. 
-     ' 
-     'menustyle% = Number of menu style to use. There are 5, and #5 is a custom color menu. 
-     '             You can set custom menu colors by changing the variables in this FUNCTION. 
-     '             (look lower down in this function to find those variables noted). 
-     ' 
-     'SAMPLE USE:  ClickMe% = RightClickMenu%(3)  '<--- Use menu 3. If any selection is made, 
-     '                                                  the menu item selected is put into 
-     '                                                  the ClickMe% variable. 
-     ' 
-     ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-   
-   
-   
-         '============================================================================ 
-         'Set Custom menu colors for menustyle% #5 here... 
-         '============================================================================ 
-         RCMBorder~&  = _RGB(255, 255, 255) '        <--- Border around menu
-         RCMBack~&  = _RGB(0, 0, 255) '              <--- Basic menu background color
-         'menu item colors 
-         RCMEnText~&  = _RGB(255, 255, 255) '        <--- Enabled menu item color
-         RCMDisText~&  = _RGB(190, 190, 190) '       <--- Disabled menu item color
-         'below is the active row colors 
-         RCMHighBack~&  = _RGB(255, 255, 255) '      <--- Highlight background color
-         RCMHighEnText~&  = _RGB(0, 0, 255) '        <--- Highlight Enabled Text color
-         RCMHighDisText~&  = _RGB(190, 190, 190) '   <----Highlight Disabled text color
-         '============================================================================ 
-   
-         '=== fail safes values for failing memories 
-         IF-  menustyle%  < 1 THEN-  menustyle%  = 1
 
-         IF-  menustyle%  > 5 THEN-  menustyle%  = 5
 
-   
-         'Compute Row & Col for LOCATE, and x & y for drawing 
-         x = Col * 8 - 8: y = Row * 16 - 16 
-   
-         '=== Compute BoxWidth based on longest menu item string length 
-         BoxWidth = 0 
-         FOR-  t  = 1 TO-  RightClickItems 
 
-             temp  = LEN(- RightClickList$ (- t ))
-             IF LEFT$(- RightClickList$ (- t ), 1) = "-" THEN-  temp  =-  temp  - 1
 
-             IF-  temp  >-  BoxWidth  THEN-  BoxWidth  =-  temp 
 
-         NEXT- : BoxWidth  =-  BoxWidth  * 8
 
-   
-         '=== Compute BoxHeight based on num of menu items 
-         BoxHeight = RightClickItems * 16 
-   
-         '===== Make sure Mouse not too close to edge of screen 
-         '===== If it is, Adjust position here, move in closer... 
-             Col = 3: x = Col * 8 - 8: 
-             Col  = FIX(- xm  / 8)- : x  =-  Col  * 8 - 8- : 
-             Row = 2: y = Row * 16 - 16 
-             Row  = FIX(- xy  / 16)- : y  =-  Row  * 16 - 16
-   
-         FirstRow = Row - 1 
-   
-         '=== copy screen using _mem (thanks Steve!) 
-   
-         '=== trap until buttons up 
-   
-                 '=== Draw Box (10 pix padding) 
-                 LINE (- x  - 10,-  y  - 10)-(- x  + 10 +-  BoxWidth ,-  y  + 10 +-  BoxHeight ), _RGB(214, 211, 206),-  BF 
 
-                 LINE (- x  + 10 +-  BoxWidth ,-  y  - 10)-(- x  + 10 +-  BoxWidth ,-  y  + 10 +-  BoxHeight ), _RGB(66, 65, 66),-  B 
 
-                 LINE (- x  - 10,-  y  + 10 +-  BoxHeight )-(- x  + 10 +-  BoxWidth ,-  y  + 10 +-  BoxHeight ), _RGB(66, 65, 66),-  B 
 
-                 LINE (- x  - 9,-  y  - 9)-(- x  + 9 +-  BoxWidth ,-  y  + 9 +-  BoxHeight ), _RGB(255, 255, 255),-  B 
 
-                 LINE (- x  - 9,-  y  - 9)-(- x  + 9 +-  BoxWidth ,-  y  + 9 +-  BoxHeight ), _RGB(255, 255, 255),-  B 
 
-                 LINE (- x  + 9 +-  BoxWidth ,-  y  - 9)-(- x  + 9 +-  BoxWidth ,-  y  + 9 +-  BoxHeight ), _RGB(127, 127, 127),-  B 
 
-                 LINE (- x  - 9,-  y  + 9 +-  BoxHeight )-(- x  + 9 +-  BoxWidth ,-  y  + 9 +-  BoxHeight ), _RGB(127, 127, 127),-  B 
 
-                 '=== Draw Box (10 pix padding) 
-                 LINE (- x  - 10,-  y  - 10)-(- x  + 9 +-  BoxWidth ,-  y  + 10 +-  BoxHeight ), _RGB(151, 151, 151),-  B 
 
-                 LINE (- x  - 9,-  y  - 9)-(- x  + 8 +-  BoxWidth ,-  y  + 9 +-  BoxHeight ), _RGB(245, 245, 245),-  B 
 
-                 LINE (- x  - 8,-  y  - 8)-(- x  + 7 +-  BoxWidth ,-  y  + 8 +-  BoxHeight ), _RGB(241, 241, 241),-  BF 
 
-             CASE 3- :  'Dark Grey Linux style
 
-                 '=== Draw Box (10 pix padding) 
-                 LINE (- x  - 11,-  y  - 10)-(- x  + 10 +-  BoxWidth ,-  y  + 10 +-  BoxHeight ), _RGB(85, 85, 85),-  BF 
 
-                 LINE (- x  - 9,-  y  - 8)-(- x  + 8 +-  BoxWidth ,-  y  + 8 +-  BoxHeight ), _RGB(55, 55, 55),-  BF 
 
-             CASE 4- :  'Transparent style
 
-                 '=== Draw Box (10 pix padding) 
-                 LINE (- x  - 11,-  y  - 10)-(- x  + 10 +-  BoxWidth ,-  y  + 10 +-  BoxHeight ), _RGBA32(0, 0, 0, 150),-  BF 
 
-                 LINE (- x  - 9,-  y  - 8)-(- x  + 8 +-  BoxWidth ,-  y  + 8 +-  BoxHeight ), _RGBA32(100, 200, 255, 100),-  BF 
 
-                 '=== save original printmode 
-                 LINE (- x  - 11,-  y  - 10)-(- x  + 10 +-  BoxWidth ,-  y  + 10 +-  BoxHeight ),-  RCMBorder~& ,-  BF 
 
-                 LINE (- x  - 9,-  y  - 8)-(- x  + 8 +-  BoxWidth ,-  y  + 8 +-  BoxHeight ),-  RCMBack~& ,-  BF 
 
-   
-         'draw right drop shadow edge 
-         LINE (- x  + 11 +-  BoxWidth ,-  y  - 4)-(- x  + 11 +-  BoxWidth ,-  y  + 11 +-  BoxHeight ), _RGBA32(0, 0, 0, 90),-  B 
 
-         LINE (- x  + 12 +-  BoxWidth ,-  y  - 3)-(- x  + 12 +-  BoxWidth ,-  y  + 12 +-  BoxHeight ), _RGBA32(0, 0, 0, 60),-  B 
 
-         LINE (- x  + 13 +-  BoxWidth ,-  y  - 2)-(- x  + 13 +-  BoxWidth ,-  y  + 13 +-  BoxHeight ), _RGBA32(0, 0, 0, 40),-  B 
 
-         LINE (- x  + 14 +-  BoxWidth ,-  y  - 1)-(- x  + 14 +-  BoxWidth ,-  y  + 14 +-  BoxHeight ), _RGBA32(0, 0, 0, 25),-  B 
 
-         LINE (- x  + 15 +-  BoxWidth ,-  y )-(- x  + 15 +-  BoxWidth ,-  y  + 15 +-  BoxHeight ), _RGBA32(0, 0, 0, 10),-  B 
 
-   
-         'draw bottom drop shadow edge 
-         LINE (- x  - 4,-  y  + 11 +-  BoxHeight )-(- x  + 10 +-  BoxWidth ,-  y  + 11 +-  BoxHeight ), _RGBA32(0, 0, 0, 90),-  B 
 
-         LINE (- x  - 3,-  y  + 12 +-  BoxHeight )-(- x  + 11 +-  BoxWidth ,-  y  + 12 +-  BoxHeight ), _RGBA32(0, 0, 0, 60),-  B 
 
-         LINE (- x  - 2,-  y  + 13 +-  BoxHeight )-(- x  + 12 +-  BoxWidth ,-  y  + 13 +-  BoxHeight ), _RGBA32(0, 0, 0, 40),-  B 
 
-         LINE (- x  - 1,-  y  + 14 +-  BoxHeight )-(- x  + 13 +-  BoxWidth ,-  y  + 14 +-  BoxHeight ), _RGBA32(0, 0, 0, 25),-  B 
 
-         LINE (- x ,-  y  + 15 +-  BoxHeight )-(- x  + 14 +-  BoxWidth ,-  y  + 15 +-  BoxHeight ), _RGBA32(0, 0, 0, 10),-  B 
 
-   
-   
-   
-             '=== if in bounds of menu space 
-   
-                 '=== Draw items 
-                     FOR-  t  = 0 TO-  RightClickItems  - 1
 
-                             'If highlighted row, draw highlight colors... 
-                                     COLOR-  RCMHighEnText~& ,-  RCMHighBack~&  'custom
 
-                                     IF LEFT$(- RightClickList$ (- t  + 1), 1) = "-" THEN COLOR-  RCMHighDisText~& ,-  RCMHighBack~& 
 
-   
-                         padme  =-  BoxWidth  / 8 - LEN(- RightClickList$ (- t  + 1))
-                         IF LEFT$(- RightClickList$ (- t  + 1), 1) = "-" THEN-  padme  =-  padme  + 1
 
-                         IF-  RightClickList$ (- t  + 1) = "---" THEN
 
-                                 PRINT " "- ;  RIGHT$(- RightClickList$ (- t  + 1), LEN(- RightClickList$ (- t  + 1)) - 1)- ; pad$;  " "- ; 
 
-                                 PRINT " "- ; RightClickList$ (- t  + 1)- ; pad$;  " "- ; 
 
-                                 CASE 2- :  'win7 box around highlight area
 
-                                     '=== Draw box around highlighted 
-                                         LINE (- x  - 8,-  by  + 16)-(- x  +-  BoxWidth  + 7,-  by  + 31), _RGB(174, 207, 247),-  B 
 
-                                     '=== Draw box around highlighted 
-                                         LINE (- x  - 8,-  by  + 16)-(- x  +-  BoxWidth  + 7,-  by  + 31), _RGB(240, 240, 240),-  B 
 
-   
-                 '=== left click makes a selection 
-                     'only select if not a seperator and not disabled 
-                     IF-  RightClickList$ (- sel ) <> "---" THEN
 
-                             RightClickMenu%  =-  sel:  EXIT DO
-   
-                 '=== right click closes menu 
-   
-   
-                 '=== Draw items 
-                     FOR-  t  = 0 TO-  RightClickItems  - 1
 
-                         padme  =-  BoxWidth  / 8 - LEN(- RightClickList$ (- t  + 1))
-                         IF LEFT$(- RightClickList$ (- t  + 1), 1) = "-" THEN-  padme  =-  padme  + 1
 
-                         IF-  RightClickList$ (- t  + 1) = "---" THEN
 
-   
-                                 PRINT " "- ;  RIGHT$(- RightClickList$ (- t  + 1), LEN(- RightClickList$ (- t  + 1)) - 1)- ; pad$;  " "- ; 
 
-                                 PRINT " "- ; RightClickList$ (- t  + 1)- ; pad$;  " "- ; 
 
-   
-   
-   
-   
-             '=== Mark current row mouse is in 
-   
-   
-         '=== restore screen 
-   
-         '=== restore original printmode 
-   
-   
- '================================================================================ 
- '================================================================================ 
-