Guest User

Another Simple Menu For PlayBASIC

a guest
Mar 5th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. ; PROJECT : Another Simple Menu
  2. ; AUTHOR : PlayBASIC Tutor - Http://PlayBASIC.com
  3. ; CREATED : 6/03/2022
  4. ; EDITED : 6/03/2022
  5. ; ---------------------------------------------------------------------
  6. https://www.underwaredesign.com/forums/index.php?topic=4528.0
  7. ; ---------------------------------------------------------------------
  8.  
  9.  
  10. loadfont "Courier new",1, 42
  11. Dim Menu$(10)
  12. s$="Load,Save,Delete,End"
  13. Count=SplittoArray(s$,",",menu$())
  14.  
  15. setfps 30
  16.  
  17. // -----------------------------------------------------------------
  18. do // MAIN LOOP
  19. // -----------------------------------------------------------------
  20.  
  21. // Clear the screen to black
  22. cls
  23.  
  24. // Render the menu and process what was clicked (if any)
  25. Clicked$=Draw_Menu(0,0)
  26.  
  27. text 50,270,"Clicked:"+Clicked$
  28. if len(Clicked$)
  29. Clicked$=upper$(clicked$)
  30. CallFunction Clicked$
  31. endif
  32.  
  33. sync
  34. loop Clicked$="MENU_END"
  35.  
  36.  
  37. cls
  38. print "Program ended"
  39. Sync
  40. waitkey
  41.  
  42.  
  43.  
  44.  
  45. // -----------------------------------------------------------------
  46. Function Menu_Load()
  47. // -----------------------------------------------------------------
  48. Text 0,200, "Load was selected"
  49. EndFunction
  50.  
  51.  
  52.  
  53. // -----------------------------------------------------------------
  54. Function Menu_Save()
  55. // -----------------------------------------------------------------
  56. Text 0,200, "Save was selected"
  57.  
  58. EndFunction
  59.  
  60. // -----------------------------------------------------------------
  61. // -----------------------------------------------------------------
  62. Function Menu_Delete()
  63. // -----------------------------------------------------------------
  64. Text 0,200, "Delete was selected"
  65.  
  66. EndFunction
  67.  
  68. // -----------------------------------------------------------------
  69. // -----------------------------------------------------------------
  70. Function Menu_END()
  71. EndFunction
  72.  
  73.  
  74. // -----------------------------------------------------------------
  75. // -----------------------------------------------------------------
  76. Function Draw_Menu(Xpos,Ypos)
  77. // -----------------------------------------------------------------
  78. // -----------------------------------------------------------------
  79.  
  80. Clicked_Menu$=""
  81.  
  82. mx=mousex()
  83. my=mousey()
  84. mb=mousebutton()
  85.  
  86. // Compute used slots and Max menu item width
  87. MaxWidth=0
  88. MaxCount=0
  89. for lp=0 to getarrayelements(Menu$())
  90. m$=Menu$(lp)
  91. if Len(M$)>0
  92. MaxWidth=maxval(MaxWidth,GetTextWidth(m$))
  93. MaxCount=lp
  94. else
  95. exit
  96. endif
  97. next
  98.  
  99. Dim HoverCol(2)
  100. Dim TextCol(2)
  101. HoverCol(0) =$665544
  102. HoverCol(1) =rgbfade(HoverCol(0),50)
  103. TextCol(0) = -1
  104. TextCol(1) = $ff00ff
  105.  
  106. MaxWidth+=GetTextWidth("__")
  107. oldink=getink()
  108. For lp =0 to MaxCount
  109.  
  110. // Get Menu item name
  111. m$=Menu$(lp)
  112.  
  113. // Compute the height of this text
  114. Ypos2=Ypos+gettextheight(m$)
  115.  
  116. // If the mouse over this rect ??
  117. HoverStatus =pointinbox(mx,my,xpos,ypos,xpos+maxwidth,ypos2)
  118.  
  119. // check if the mouse is over this button and mouse
  120. // button is pressed
  121. if HoverStatus and mb & 1
  122. Clicked_Menu$="Menu_"+M$
  123. endif
  124.  
  125. // draw box / rectangle for this item
  126. boxc xpos,ypos,xpos+maxwidth,ypos2,true,HoverCol(HoverStatus)
  127.  
  128. // draw our text over the top of it
  129. ink TextCol(HoverStatus)
  130. text Xpos,Ypos,m$
  131.  
  132. Xpos=Xpos+MaxWidth
  133. next
  134.  
  135. ink OldInk
  136. EndFunction Clicked_Menu$
  137.  
  138.  
  139.  
  140.  
Add Comment
Please, Sign In to add comment