Could use the text character:
≡
Or use my nifty code I wrote tonight
The 200 lines might be more than I planned on it being, but I got carried away with modular design. And the reason I made the array of menuItems a separate UDT is so it can be expanded to support more than just text, such as icons. Also, it should theoretically handle multiple burger menus at the same time, though I haven't tested that yet.
// Project: burger
// Created: 2016-12-25
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "burger" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.20 we can use nicer default fonts
Type MenuItem
id as integer
Endtype
Type BurgerMenu
x as integer
y as integer
size as integer
open as integer
toggle as integer
items as MenuItem[0]
menuWidth as integer
menuHeight as integer
toggleTime as integer
menuTotalHeight as integer
padding as integer
speed as integer
triggeredItem as integer
Endtype
burger as BurgerMenu
burger.x = 100
burger.y = 100
burger.size = 48
burger.padding = 8
burger.speed = 9
burger = addMenuItem(burger, "blue")
burger = addMenuItem(burger, "green")
burger = addMenuItem(burger, "red")
burger = addMenuItem(burger, "orange")
burger = addMenuItem(burger, "yellow")
// Menu items can be of different sizes.
// Any time an item size is changed, the menu must be refactored.
// Refactoring is automatically called whenever an item is added.
setTextSize(burger.items[3].id, 48)
burger = refactorItems(burger)
do
// Handles drawing and UI
burger = handleBurger(burger)
// When a menu item is selected, this returns the index, otherwise 0.
if burger.triggeredItem > 0 then a = burger.triggeredItem
// Display last menu item clicked
print("Selected Item: "+str(a))
// Called to draw menu background behind the item text
Render2DFront()
Sync()
loop
function addMenuItem(b as BurgerMenu, name$)
m as MenuItem
m.id = createText(name$)
b.items.insert(m)
id = b.items.length
setTextSize(b.items[id].id, 24)
setTextScissor(b.items[id].id,0,0,1,1)
b = refactorItems(b)
endfunction b
function drawBurger(b as BurgerMenu)
x = b.x
y = b.y
s = b.size
h = s/5
c = 4294967295
drawBox(x, y, x+s, y+h, c,c,c,c,1)
drawBox(x, y+h*2+1, x+s, y+h*3+1, c,c,c,c,1)
drawBox(x, y+h*4+2, x+s, y+h*5+2, c,c,c,c,1)
c1 = makeColor(92,92,92)
drawBox(b.x, b.y+b.size+2, b.x+b.menuWidth, b.y+b.size+2+b.menuHeight, c1,c1,c1,c1,1)
endfunction
function handleBurger(b as BurgerMenu)
x = getRawMouseX()
y = getRawMouseY()
if getRawMouseLeftPressed()
if x > b.x and x < b.x+b.size and y > b.y and y < b.y+b.size
b.open = 1 - b.open
b.toggle = 1
endif
endif
b.triggeredItem = 0
if b.toggle = 1
t = getMilliseconds()
if b.toggleTime + 10 <= t
if b.open = 1
b.menuHeight = b.menuHeight + b.speed
clipMenuItems(b)
if b.menuHeight >= b.menuTotalHeight
b.menuHeight = b.menuTotalHeight
b.toggle = 0
endif
else
b.menuHeight = b.menuHeight - b.speed
clipMenuItems(b)
if b.menuHeight <= 0
b.menuHeight = 0
b.toggle = 0
endif
endif
b.toggleTime = t
endif
endif
drawBurger(b)
if getRawMouseLeftPressed() = 1 then d = 1
c = makeColor(48,48,48)
if b.open = 1 and b.toggle = 0
mx = getRawMouseX()
my = getRawMouseY()
if mx > b.x and mx < b.x+b.menuWidth
for i = 1 to b.items.length
y = getTextY(b.items[i].id)
h = getTextSize(b.items[i].id)
if my > y and my < y+h
drawBox(b.x, y, b.x+b.menuWidth, y+h, c,c,c,c,1)
if d = 1
b.triggeredItem = i
b.open = 0
b.toggle = 1
endif
exit
endif
next i
endif
endif
endfunction b
function clipMenuItems(b as BurgerMenu)
for i = 1 to b.items.length
setTextScissor(b.items[i].id, b.x, b.y+b.size, b.x+b.menuWidth, b.y+b.size+b.menuHeight)
next i
endfunction
function refactorItems(b as BurgerMenu)
y = b.y+b.size+b.padding
b.menuWidth = 0
b.menuTotalHeight = 0
b.menuTotalHeight = 0
for i = 1 to b.items.length
setTextPosition(b.items[i].id, b.x+b.padding, y)
y = y + getTextSize(b.items[i].id)
b.menuTotalHeight = b.menuTotalHeight + getTextSize(b.items[i].id)
w = getTextTotalWidth(b.items[i].id)
if w > b.menuWidth then b.menuWidth = w
next i
b.menuWidth = b.menuWidth+b.padding*2
b.menuTotalHeight = b.menuTotalHeight + b.padding*2
endfunction b
"I like offending people, because I think people who get offended should be offended." - Linus Torvalds