Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; PROJECT : Another Simple Menu
- ; AUTHOR : PlayBASIC Tutor - Http://PlayBASIC.com
- ; CREATED : 6/03/2022
- ; EDITED : 6/03/2022
- ; ---------------------------------------------------------------------
- https://www.underwaredesign.com/forums/index.php?topic=4528.0
- ; ---------------------------------------------------------------------
- loadfont "Courier new",1, 42
- Dim Menu$(10)
- s$="Load,Save,Delete,End"
- Count=SplittoArray(s$,",",menu$())
- setfps 30
- // -----------------------------------------------------------------
- do // MAIN LOOP
- // -----------------------------------------------------------------
- // Clear the screen to black
- cls
- // Render the menu and process what was clicked (if any)
- Clicked$=Draw_Menu(0,0)
- text 50,270,"Clicked:"+Clicked$
- if len(Clicked$)
- Clicked$=upper$(clicked$)
- CallFunction Clicked$
- endif
- sync
- loop Clicked$="MENU_END"
- cls
- print "Program ended"
- Sync
- waitkey
- // -----------------------------------------------------------------
- Function Menu_Load()
- // -----------------------------------------------------------------
- Text 0,200, "Load was selected"
- EndFunction
- // -----------------------------------------------------------------
- Function Menu_Save()
- // -----------------------------------------------------------------
- Text 0,200, "Save was selected"
- EndFunction
- // -----------------------------------------------------------------
- // -----------------------------------------------------------------
- Function Menu_Delete()
- // -----------------------------------------------------------------
- Text 0,200, "Delete was selected"
- EndFunction
- // -----------------------------------------------------------------
- // -----------------------------------------------------------------
- Function Menu_END()
- EndFunction
- // -----------------------------------------------------------------
- // -----------------------------------------------------------------
- Function Draw_Menu(Xpos,Ypos)
- // -----------------------------------------------------------------
- // -----------------------------------------------------------------
- Clicked_Menu$=""
- mx=mousex()
- my=mousey()
- mb=mousebutton()
- // Compute used slots and Max menu item width
- MaxWidth=0
- MaxCount=0
- for lp=0 to getarrayelements(Menu$())
- m$=Menu$(lp)
- if Len(M$)>0
- MaxWidth=maxval(MaxWidth,GetTextWidth(m$))
- MaxCount=lp
- else
- exit
- endif
- next
- Dim HoverCol(2)
- Dim TextCol(2)
- HoverCol(0) =$665544
- HoverCol(1) =rgbfade(HoverCol(0),50)
- TextCol(0) = -1
- TextCol(1) = $ff00ff
- MaxWidth+=GetTextWidth("__")
- oldink=getink()
- For lp =0 to MaxCount
- // Get Menu item name
- m$=Menu$(lp)
- // Compute the height of this text
- Ypos2=Ypos+gettextheight(m$)
- // If the mouse over this rect ??
- HoverStatus =pointinbox(mx,my,xpos,ypos,xpos+maxwidth,ypos2)
- // check if the mouse is over this button and mouse
- // button is pressed
- if HoverStatus and mb & 1
- Clicked_Menu$="Menu_"+M$
- endif
- // draw box / rectangle for this item
- boxc xpos,ypos,xpos+maxwidth,ypos2,true,HoverCol(HoverStatus)
- // draw our text over the top of it
- ink TextCol(HoverStatus)
- text Xpos,Ypos,m$
- Xpos=Xpos+MaxWidth
- next
- ink OldInk
- EndFunction Clicked_Menu$
Add Comment
Please, Sign In to add comment