Something ive just knocked up in half hour
// Project: GUI
// Created: 2016-12-23
// show all errors
SetErrorMode(2)
#constant width=1024
#constant height=768
// set window properties
SetWindowTitle( "GUI" )
SetWindowSize( width, height, 0 )
// set display properties
SetVirtualResolution( width, height )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.20 we can use nicer default fonts
// Change this value if you want more buttons on screen at any one time
global maxbuttons as integer
global clicked as integer
type _buttons
id as integer // For the text ID
clicked as integer
str$ as string
x# as float
y# as float
size as integer
color as integer
endtype
global buttons as _buttons[100] // A set of buttons that can use within your app
text = createtext("")
SetTextColor(text, 0,0,0,0)
setupbuttons()
do
drawdisplay()
clicked=drawbuttons()
print (clicked)
if clicked=>0
print ("Button '" + buttons[clicked].str$ + "' was pressed")
select clicked
case 0 : // Do something
endcase
case 1 : // Do something
endcase
case 2 : // Do something
endcase
case 3 : // Do something
endcase
// etc
// etc
// etc
endselect
endif
Print( ScreenFPS() )
Render2DFront()
Sync()
loop
function setupbuttons()
for maxbuttons=0 to 100
// if buttons[maxbuttons].str$="" then exit
buttons[maxbuttons].str$="Button " + str(maxbuttons)
buttons[maxbuttons].id = createtext ( buttons[maxbuttons].str$)
buttons[maxbuttons].x# = random(0,width)
buttons[maxbuttons].y# = random(0,height)
buttons[maxbuttons].size = random(10,50)
buttons[maxbuttons].color = makecolor(random(0,255),random(0,255),random(0,255))
buttons[maxbuttons].clicked = 0
SetTextSize(buttons[maxbuttons].id, buttons[0].size)
SetTextColor(buttons[maxbuttons].id,255,0,0,255)
next
clicked=-1
endfunction
function drawdisplay()
backgroundcol=MakeColor(100,100,100)
DrawBox(0,0,width,height,backgroundcol,backgroundcol,backgroundcol,backgroundcol,1)
endfunction
function drawbuttons()
for a=0 to maxbuttons-1
drawbox(buttons[a].x#, buttons[a].y#, buttons[a].x# + GetTextTotalWidth(buttons[a].id), buttons[a].y# + GetTextTotalHeight(buttons[a].id), buttons[a].color, buttons[a].color, buttons[a].color<<2, buttons[a].color<<2, 1)
SetTextPosition( buttons[a].id, buttons[a].x#, buttons[a].y#)
//check collision
mx=getpointerx()
my=getpointery()
if (mx>buttons[a].x# and my> buttons[a].y# and mx< buttons[a].x# + GetTextTotalWidth(buttons[a].id) and my< buttons[a].y# + GetTextTotalHeight(buttons[a].id))
if GetRawMouseLeftPressed()
buttons[a].clicked = 1
clicked=a
endif
endif
next
endfunction clicked
Try it, it can be all tweakable and indeed look more professional but it can be achievable.
To be honest, I'm going to carry on with this, will look like a good development learning experience and will send on some library in the near future
Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it