I developed several GUI objects over the course of several months as their presence became necessary.
You will need:
IanM's Utility and Array Plugin
Debug
Notes: This is here for the same reason as 'system' and 'gamestate'. It is used to display messages on the screen that can be useful when debugging an application.
type __debug
_name as string
_value as string
_length as integer
endtype
function debug_init()
dim debug_All() as __debug
empty array debug_All()
endfunction 1
function debug_update()
if system()._debug=0 then exitfunction -1
for i=0 to array count(debug_All())
text 5,5+i*(system()._textheight+5),debug_All(i)._name+" : "+debug_All(i)._value
if debug_All(i)._length<=timer() and debug_All(i)._length<>-1 then debug_delete(debug_All(i)._name)
next i
endfunction 1
function debug_add(name as string,value as string,length as integer)
r as integer
array insert at bottom debug_All()
debug_All()._name=name
debug_All()._value=value
if length>0
debug_All()._length=timer()+length
debug_All()._name=debug_All()._name+"_("+generate string$(5)+")"
else
debug_All()._length=length
endif
r=get array index(debug_All())
endfunction r
function debug_set(name as string,value as string)
id as integer
id=debug_nameToID(name)
if id=-1 then exitfunction -1
debug_All(id)._value=value
endfunction 1
function debug_delete(name as string)
id as integer
id=debug_nameToID(name)
if id=-1 then exitfunction -1
array delete element debug_All(),id
endfunction 1
function debug_count()
r as integer
r=array count(debug_All())
endfunction r
function debug_nameToID(name as string)
for i=0 to array count(debug_All())
if debug_All(i)._name=name
exitfunction i
endif
next i
endfunction -1
function debug_idToName(id as integer)
r as string
r=gamestate_All(id)._name
endfunction r
System
Notes: This is here for the same reason as 'gamestate'. All of the following things depend on it. There is various useful functions in this.
type __system
rem initialation, etc.
_screenwidth as integer
_screenheight as integer
_screendepth as integer
_screensyncrate as integer
rem media path
_systempath as string
rem max amount of each type of object allowed
_maxobjects as integer
rem timing
_fps as integer
_dt as float
_lastFrame as integer
rem related to text
_textheight as float
rem related to mouse
_mousex as integer
_mousey as integer
_mousez as integer
_mousexspeed as integer
_mouseyspeed as integer
_mousezspeed as integer
_mousexspeed2 as integer
_mouseyspeed2 as integer
_mousebutton as integer
_mouseleftpressed as integer
_mouserightpressed as integer
rem utility object used for various purposes
_utilityID as integer
rem debugging enabled (0-false,1-true)
_debug as integer
rem ai enabled
_ai as integer
endtype
function system_init(width as integer,height as integer,depth as integer,syncrate as integer,systempath as string,maxobjects as integer,debug as integer)
dim system() as __system
empty array system()
array insert at bottom system()
system()._screenwidth=width
system()._screenheight=height
system()._screendepth=depth
system()._screensyncrate=syncrate
system()._systempath=systempath
system()._maxobjects=maxobjects
system()._debug=debug
set display mode system()._screenwidth,system()._screenheight,system()._screendepth
sync on
sync rate system()._screensyncrate
autocam off
randomize timer()
random seed timer()
draw sprites last
set image colorkey 255,0,255
ink rgb(255,255,255),rgb(0,0,0)
set text font "verdana"
set text size 14
system()._textheight=text height("I")
system()._utilityID=system_freeObject(1,system()._maxObjects)
make object plain system()._utilityID,1,1
exclude object on system()._utilityID
endfunction 1
function system_beginStep()
system()._fps=screen fps()
system()._dt=timer()-system()._lastFrame
system()._lastFrame=timer()
`if dt doesnt work use something like system()._dt=white rabbit get force
precheck as integer:precheck=system()._mousebutton
system()._mousebutton=mouseclick()
if precheck=0 and (system()._mousebutton=1 or system()._mousebutton=3)
system()._mouseleftpressed=1
else
system()._mouseleftpressed=0
endif
if precheck=0 and (system()._mousebutton=2 or system()._mousebutton=3)
system()._mouserightpressed=1
else
system()._mouserightpressed=0
endif
system()._mousex=mousex()
system()._mousey=mousey()
system()._mousez=mousez()
system()._mousexspeed=mousemovex()
system()._mouseyspeed=mousemovey()
system()._mousezspeed=mousemovez()
endfunction 1
function system_updateMouseSpeed2()
system()._mousexspeed2=system()._mousex-system()._screenwidth/2
system()._mouseyspeed2=system()._mousey-system()._screenheight/2
position mouse system()._screenwidth/2,system()._screenheight/2
endfunction 1
function system_endStep()
if system()._ai=1 then ai update
clear entry buffer
fastsync
endfunction 1
function system_setDebug(debug as integer)
system()._debug=debug
endfunction 1
function system_setSystemPath(systempath as string)
system()._systempath=systempath
endfunction 1
function system_distance3d(x1 as float,y1 as float,z1 as float,x2 as float,y2 as float,z2 as float)
r as float
r=sqrt( (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 )
endfunction r
function system_distance2d(x1 as float,y1 as float,x2 as float,y2 as float)
r as float
r=sqrt( (x2-x1)^2 + (y2-y1)^2 )
endfunction r
function system_clipImage(id as integer,x as integer,y as integer,width as integer,height as integer)
r as integer
r=system_freeImage(1,system()._maxobjects)
paste image id,0,0
get image r,x,y,x+width,y+width,3
endfunction r
function system_imageWidth(id as integer)
r as integer
remstart
temp=find free sprite()
sprite temp,0,0,id
r=sprite width(temp)
delete sprite temp
remend
r=image width(id)
endfunction r
function system_imageHeight(id as integer)
r as integer
remstart
temp=find free sprite()
sprite temp,0,0,id
r=sprite height(temp)
delete sprite temp
remend
r=image height(id)
endfunction r
function system_clampValue(a as float,b as float,c as float)
mn as float:mn=system_min(b,c)
mx as float:mx=system_max(b,c)
if a<mn then a=mn
if a>mx then a=mx
endfunction a
function system_min(a as float,b as float)
if a>b then a=b
endfunction a
function system_max(a as float,b as float)
if a<b then a=b
endfunction a
function system_wrapValue(a as float,mn as float,mx as float)
If a<mn
a=mx-Abs(mn-a)
Else
if a>mx
a=mn+Abs(mx-a)
endif
EndIf
if a<mn or a>mx Then a=system_wrapValue(a,mn,mx)
endfunction a
function system_polarity(a as float)
r as integer
if a=0
r=0
else
if a>0
r=1
else
r=-1
endif
endif
endfunction r
function system_circleCollision(x1 as float,y1 as float,r1 as float,x2 as float,y2 as float,r2 as float)
r as integer
if system_distance2d(x1,y1,x2,y2)>=r1+r2 then r=1
endfunction r
function system_makeQuad(x1 as float,y1 as float,x2 as float,y2 as float,x3 as float,y3 as float,x4 as float,y4 as float)
id=system_freeObject(1,system()._maxobjects)
make object box id,1,1,1
lock vertexdata for limb id,0
for i=0 to get vertexdata vertex count()-1
if get vertexdata position x(i)<=0
if get vertexdata position y(i)>=0
rem top left
set vertexdata position i,x1,y1,get vertexdata position z(i)
else
rem bottom left
set vertexdata position i,x4,y4,get vertexdata position z(i)
endif
else
if get vertexdata position y(i)>=0
rem top right
set vertexdata position i,x2,y2,get vertexdata position z(i)
else
rem bottom right
set vertexdata position i,x3,y3,get vertexdata position z(i)
endif
endif
next i
unlock vertexdata
endfunction id
function system_percentToX(percent as float)
r as float
r=(system()._screenwidth/100.0)*percent
endfunction r
function system_xToPercent(x as float)
r as float
r=(x/system()._screenwidth)*100.0
endfunction r
function system_percentToY(percent as float)
r as float
r=(system()._screenheight/100.0)*percent
endfunction r
function system_yToPercent(y as float)
r as float
r=(y/system()._screenheight)*100.0
endfunction r
function system_drawRect(x1 as float,y1 as float,x2 as float,y2 as float)
line x1,y1,x1,y2
line x1,y2,x2,y2
line x2,y2,x2,y1
line x2,y1,x1,y1
endfunction 1
function system_3Dto2D_x(x as float,y as float,z as float)
position object system()._utilityID,x,y,z
r as integer:r=object screen x(system()._utilityID)
endfunction r
function system_3Dto2D_y(x as float,y as float,z as float)
position object system()._utilityID,x,y,z
r as integer:r=object screen y(system()._utilityID)
endfunction r
function system_getAngle(x1 as float,y1 as float,x2 as float,y2 as float)
r as float
position object system()._utilityID,x1,0,y1
point object system()._utilityID,x2,0,y2
r=object angle y(system()._utilityID)
endfunction r
function system_freeObject(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if object exist(id)=1 then id=system_freeObject(id+1,maxid)
endfunction id
function system_freeFile(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if file open(id)=1 then id=system_freeFile(id+1,maxid)
endfunction id
function system_freeTerrain(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if terrain exist(id)=1 or object exist(id)=1 then id=system_freeTerrain(id+1,maxid)
endfunction id
function system_freeMatrix(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if matrix exist(id)=1 then id=system_freeMatrix(id+1,maxid)
endfunction id
function system_freeImage(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if image exist(id)=1 then id=system_freeImage(id+1,maxid)
endfunction id
function system_freeSprite(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if sprite exist(id)=1 then id=system_freeSprite(id+1,maxid)
endfunction id
function system_freeMemblock(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if memblock exist(id)=1 then id=system_freeMemblock(id+1,maxid)
endfunction id
function system_freeSound(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if audio exist(id)=1 then id=system_freeSound(id+1,maxid)
endfunction id
function system_freeAnimation(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if animation exist(id)=1 then id=system_freeAnimation(id+1,maxid)
endfunction id
function system_freeLight(id as integer,maxid as integer)
if id>maxid then exitfunction -1
if light exist(id)=1 then id=system_freeLight(id+1,maxid)
endfunction id
Gamestate
Notes: This might be useful to some people, but the reason I put it here is because a lot of the following items depend on this. For the following objects, there is typically a function such as 'button_setGamestate' that will cause the item to automatically show the item only if the gamestate is equal to it.
type __gamestate
_name as string
_active as integer
endtype
function gamestate_init()
dim gamestate_All() as __gamestate
empty array gamestate_All()
endfunction 1
function gamestate_add(name as string)
r as integer
array insert at bottom gamestate_All()
gamestate_All()._name=name
gamestate_All()._active=0
r=get array index(gamestate_All())
endfunction r
function gamestate_delete(name as string)
id as integer
id=gamestate_nameToID(name)
if id=-1 then exitfunction -1
array delete element gamestate_All(),id
endfunction 1
function gamestate_set(name as string)
for i=0 to array count(gamestate_All())
if gamestate_All(i)._name=name
gamestate_All(i)._active=1
else
gamestate_All(i)._active=0
endif
next i
endfunction 1
function gamestate_check()
r as string
r="none"
for i=0 to array count(gamestate_All())
if gamestate_All(i)._active=1
r=gamestate_All(i)._name
exitfunction r
endif
next i
endfunction r
rem returns the number of gamestates
function gamestate_count()
r as integer
r=array count(gamestate_All())
endfunction r
rem returns the id of the button with the name
function gamestate_nameToID(name as string)
for i=0 to array count(gamestate_All())
if gamestate_All(i)._name=name
exitfunction i
endif
next i
endfunction -1
rem returns the name of the gamestate with the given id
function gamestate_idToName(id as integer)
r as string
r=gamestate_All(id)._name
endfunction r
Button
Notes: The picture should be 4 equally sized graphics. From left to right, they should be: regular, over, down, disabled.
type __button
_name as string
_group as string
_gamestate as string
_status as integer
_baseimage as integer
_buttonsprite as integer
_x as integer
_y as integer
_width as integer
_height as integer
_canrelease as integer
_active as integer
_visible as integer
endtype
function button_init()
#constant BUTTON_DISABLED 0
#constant BUTTON_UP 1
#constant BUTTON_OVER 2
#constant BUTTON_PRESSED 3
#constant BUTTON_RELEASED 4
dim button_All() as __button
empty array button_All()
endfunction 1
function button_add(name as string,path as string)
r as integer
array insert at bottom button_All()
button_All()._name=name
button_All()._group="none"
button_All()._gamestate="none"
button_All()._active=1
button_All()._canrelease=0
button_All()._visible=1
button_All()._baseimage=system_freeImage(1,system()._maxobjects)
button_All()._buttonsprite=system_freeImage(1,system()._maxobjects)
create animated sprite button_All()._buttonsprite,path,4,1,button_All()._baseimage
`set sprite button_All()._buttonsprite,0,1
button_All()._width=system_imageWidth(button_All()._baseimage)/4
button_All()._height=system_imageHeight(button_All()._baseimage)
r=get array index(button_All())
endfunction r
function button_updateAll()
for i=0 to array count(button_All())
button_update(button_All(i)._name)
next i
endfunction
function button_updateGroup(group as string)
for i=0 to array count(button_All())
if button_All(i)._group=group then button_update(button_All(i)._name)
next i
endfunction
function button_update(name as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if gamestate_check()<>button_All(id)._gamestate and button_All(id)._gamestate<>"none"
hide sprite button_All(id)._buttonsprite
exitfunction -1
else
show sprite button_All(id)._buttonsprite
endif
if button_All(id)._visible=1
if button_All(id)._active=0
button_All(id)._status=BUTTON_DISABLED
else
button_All(id)._status=BUTTON_UP
if button_mouseOver(name)
if button_All(id)._canrelease>=0
button_All(id)._status=BUTTON_OVER
if system()._mousebutton=1
button_All(id)._status=BUTTON_PRESSED
button_All(id)._canrelease=1
else
if button_All(id)._canrelease=1
button_All(id)._status=BUTTON_RELEASED
endif
button_All(id)._canrelease=0
endif
endif
else
if button_All(id)._canrelease=0 or system()._mousebutton=0 then button_All(id)._canrelease=-1
endif
if system()._mousebutton=0 and button_All(id)._canrelease=-1 then button_All(id)._canrelease=0
endif
select button_All(id)._status
case BUTTON_DISABLED
set sprite frame button_All(id)._buttonsprite,4
sprite button_All(id)._buttonsprite,button_All(id)._x,button_All(id)._y,button_All(id)._baseimage
endcase
case BUTTON_UP
set sprite frame button_All(id)._buttonsprite,1
sprite button_All(id)._buttonsprite,button_All(id)._x,button_All(id)._y,button_All(id)._baseimage
endcase
case BUTTON_OVER
set sprite frame button_All(id)._buttonsprite,2
sprite button_All(id)._buttonsprite,button_All(id)._x,button_All(id)._y,button_All(id)._baseimage
endcase
case BUTTON_PRESSED
set sprite frame button_All(id)._buttonsprite,3
sprite button_All(id)._buttonsprite,button_All(id)._x,button_All(id)._y,button_All(id)._baseimage
endcase
case BUTTON_RELEASED
set sprite frame button_All(id)._buttonsprite,2
sprite button_All(id)._buttonsprite,button_All(id)._x,button_All(id)._y,button_All(id)._baseimage
endcase
endselect
show sprite button_All(id)._buttonsprite
else
hide sprite button_All(id)._buttonsprite
endif
endfunction 1
function button_getStatus(name as string)
r as integer
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if button_All(id)._visible=0 then exitfunction -1
r=button_All(id)._status
endfunction r
function button_getPressed(name as string)
r as integer
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if button_All(id)._visible=0 then exitfunction -1
if button_All(id)._status=BUTTON_PRESSED then r=1
endfunction r
function button_getReleased(name as string)
r as integer
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if button_All(id)._visible=0 then exitfunction -1
if button_All(id)._status=BUTTON_RELEASED then r=1
endfunction r
function button_getOver(name as string)
r as integer
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if button_All(id)._visible=0 then exitfunction -1
if button_All(id)._status=BUTTON_OVER then r=1
endfunction r
function button_getUp(name as string)
r as integer
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if button_All(id)._visible=0 then exitfunction -1
if button_All(id)._status=BUTTON_UP then r=1
endfunction r
function button_getDisabled(name as string)
r as integer
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if button_All(id)._visible=0 then exitfunction -1
if button_All(id)._status=BUTTON_DISABLED then r=1
endfunction r
function button_set(name as string,x as integer,y as integer,centered as integer)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if centered=0
button_All(id)._x=x
button_All(id)._y=y
else
button_All(id)._x=x-button_All(id)._width/2.0
button_All(id)._y=y-button_All(id)._height/2.0
endif
endfunction 1
function button_setGroup(name as string,group as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
button_All(id)._group=group
endfunction 1
function button_setGamestate(name as string,gamestate as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
button_All(id)._gamestate=gamestate
endfunction 1
function button_deactivate(name as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
button_All(id)._active=0
endfunction 1
function button_activate(name as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
button_All(id)._active=1
endfunction 1
function button_show(name as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
button_All(id)._visible=1
endfunction 1
function button_hide(name as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
button_All(id)._visible=0
endfunction 1
function button_deactivateGroup(group as string)
for i=0 to array count(button_All())
if button_All(i)._group=group then button_All(i)._active=0
next i
endfunction 1
function button_activateGroup(group as string)
for i=0 to array count(button_All())
if button_All(i)._group=group then button_All(i)._active=1
next i
endfunction 1
function button_hideGroup(group as string)
for i=0 to array count(button_All())
if button_All(i)._group=group then button_All(i)._visible=0
next i
endfunction 1
function button_showGroup(group as string)
for i=0 to array count(button_All())
if button_All(i)._group=group then button_All(i)._visible=1
next i
endfunction 1
function button_delete(name as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
delete sprite button_All(id)._buttonsprite
delete image button_All(id)._baseimage
array delete element button_All(),id
endfunction 1
rem returns the number of buttons
function button_count()
r as integer
r=array count(button_All())
endfunction r
rem returns the id of the button with the name
function button_nameToID(name as string)
for i=0 to array count(button_All())
if button_All(i)._name=name
exitfunction i
endif
next i
endfunction -1
rem returns the name of the button with the given id
function button_idToName(id as integer)
r as string
r=button_All(id)._name
endfunction r
rem returns 1 if the mouse is over the given button,0 if not
function button_mouseOver(name as string)
id as integer
id=button_nameToID(name)
if id=-1 then exitfunction -1
if system()._mou > _All(id)._x and system()._mou < _All(id)._x+button_All(id)._width
if system()._mousey>button_All(id)._y and system()._mousey<button_All(id)._y+button_All(id)._height
exitfunction 1
endif
endif
endfunction 0
Example:
[...]
button_init()
button_add("mybutton","mediabutton.png")
[...]
do
button_updateAll()
if button_getPressed("mybutton")
text 5,5,"that tickles!"
endif
sync
loop
Meter (Slider)
Notes: This one uses 2 separate images. The second one is the part that moves. The first is the part that the second image moves along horizontally.
type __meter
_name as string
_group as string
_gamestate as string
_lowval as float
_highval as float
_currentval as float
_meterimageid as integer
_meterspriteid as integer
_sliderimageid as integer
_sliderspriteid as integer
_x as integer
_y as integer
_width as integer
_height as integer
_visible as integer
_active as integer
endtype
function meter_init()
dim meter_All() as __meter
empty array meter_All()
endfunction 1
function meter_add(name as string,path1 as string,path2 as string,lowval as float,highval as float)
r as integer
array insert at bottom meter_All()
meter_All()._name=name
meter_All()._group="none"
meter_All()._gamestate="none"
meter_All()._lowval=system_min(lowval,highval)
meter_All()._highval=system_max(lowval,highval)
meter_All()._currentval=(meter_All()._lowval+meter_All()._highval)/2
meter_All()._visible=1
meter_All()._meterimageid=system_freeImage(1,system()._maxobjects)
load image path1,meter_All()._meterimageid,1
meter_All()._sliderimageid=system_freeImage(1,system()._maxobjects)
load image path2,meter_All()._sliderimageid,1
meter_All()._meterspriteid=system_freeSprite(1,system()._maxobjects)
sprite meter_All()._meterspriteid,0,0,meter_All()._meterimageid
meter_All()._sliderspriteid=system_freeSprite(1,system()._maxobjects)
sprite meter_All()._sliderspriteid,0,0,meter_All()._sliderimageid
meter_All()._x=0
meter_All()._y=0
meter_All()._width=system_imageWidth(meter_All()._meterimageid)
meter_All()._height=system_imageHeight(meter_All()._meterimageid)
offset sprite meter_All()._meterspriteid,meter_All()._width/2,meter_All()._height/2
offset sprite meter_All()._sliderspriteid,sprite width(meter_All()._sliderspriteid)/2,sprite height(meter_All()._sliderspriteid)/2
r=get array index(meter_All())
endfunction r
function meter_set(name as string,x as float,y as float)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
meter_All(id)._x=x
meter_All(id)._y=y
endfunction 1
function meter_setValues(name as string,lowval as float,highval as float)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
meter_All(id)._lowval=lowval
meter_All(id)._highval=highval
endfunction 1
function meter_setCurrentValue(name as string,value as float)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
meter_All(id)._currentval=system_clampValue(value,meter_All(id)._lowval,meter_All(id)._highval)
endfunction 1
function meter_getCurrentValue(name as string)
r as float
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1.0
r=meter_All(id)._currentval
endfunction r
function meter_setGamestate(name as string,gamestate as string)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
meter_All(id)._gamestate=gamestate
endfunction 1
function meter_setGroup(name as string,group as string)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
meter_All(id)._group=group
endfunction 1
function meter_show(name as string)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
meter_All(id)._visible=1
endfunction 1
function meter_hide(name as string)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
meter_All(id)._visible=0
endfunction 1
function meter_showGroup(group as string)
for i=0 to array count(meter_All())
if meter_All(i)._group=group
meter_All(i)._visible=1
endif
next i
endfunction 1
function meter_hideGroup(group as string)
for i=0 to array count(meter_All())
if meter_All(i)._group=group
meter_All(i)._visible=0
endif
next i
endfunction 1
function meter_delete(name as string)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
delete sprite meter_All(id)._meterspriteid
delete sprite meter_All(id)._sliderspriteid
delete image meter_All(id)._meterimageid
delete image meter_All(id)._sliderimageid
array delete element meter_All(),id
endfunction 1
function meter_updateAll()
for i=0 to array count(meter_All())
meter_update(meter_All(i)._name)
next i
endfunction 1
function meter_updateGroup(group as string)
for i=0 to array count(meter_All())
if meter_All(i)._group=group then meter_update(meter_All(i)._name)
next i
endfunction 1
function meter_update(name as string)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
if gamestate_check()<>meter_All(id)._gamestate and meter_All(id)._gamestate<>"none"
hide sprite meter_All(id)._meterspriteid
hide sprite meter_All(id)._sliderspriteid
exitfunction -1
else
show sprite meter_All(id)._meterspriteid
show sprite meter_All(id)._sliderspriteid
endif
if meter_All(id)._visible=1
if system()._mousebutton=1
if meter_mouseOver(meter_All(id)._name)=1
meter_All(id)._active=1
endif
else
meter_All(id)._active=0
endif
if meter_All(id)._active=1
temp1 as float:temp1=abs((meter_All(id)._x+meter_All(id)._width/2.0)-(meter_All(id)._x-meter_All(id)._width/2.0))
temp2 as float:temp2=system()._mousex-(meter_All(id)._x-meter_All(id)._width/2.0)
`-
pct as float:pct=temp2/temp1
temp1=meter_All(id)._highval-meter_All(id)._lowval
temp2=temp1*pct
meter_All(id)._currentval=meter_All(id)._lowval+temp2
endif
rem limit currentval,and convert to integer
meter_All(id)._currentval=system_clampValue(meter_All(id)._currentval,meter_All(id)._lowval,meter_All(id)._highval)
rem place meter sprite at location
sprite meter_All(id)._meterspriteid,meter_All(id)._x,meter_All(id)._y,meter_All(id)._meterimageid
rem calculate location of slider
temp1 as float:temp1=meter_All(id)._highval-meter_All(id)._lowval
temp2 as float:temp2=meter_All(id)._currentval-meter_All(id)._lowval
pct as float:pct=temp2/temp1
temp1=(meter_All(id)._x+meter_All(id)._width/2.0)-(meter_All(id)._x-meter_All(id)._width/2.0)
temp2=temp1*pct
temp1=meter_All(id)._x-meter_All(id)._width/2.0+temp2
sprite meter_All(id)._sliderspriteid,temp1,meter_All(id)._y,meter_All(id)._sliderimageid
show sprite meter_All(id)._meterspriteid
show sprite meter_All(id)._sliderspriteid
else
hide sprite meter_All(id)._meterspriteid
hide sprite meter_All(id)._sliderspriteid
endif
endfunction 1
function meter_nameToID(name as string)
for i=0 to array count(meter_All())
if meter_All(i)._name=name
exitfunction i
endif
next i
endfunction -1
function meter_idToName(id as integer)
r as string
r=meter_All(id)._name
endfunction r
function meter_count()
r as integer
r=array count(meter_All())
endfunction r
function meter_mouseOver(name as string)
id as integer
id=meter_nameToID(name)
if id=-1 then exitfunction -1
if system()._mousex>meter_All(id)._x-meter_All(id)._width/2 and system()._mousex<meter_All(id)._x+meter_All(id)._width/2
if system()._mousey>meter_All(id)._y-meter_All(id)._height/2 and system()._mousey<meter_All(id)._y+meter_All(id)._height/2
exitfunction 1
endif
endif
endfunction 0
Example:
[...]
meter_init()
meter_add("mymeter","mediaslider1.png","mediaslider2.png",0,100)
[...]
do
meter_updateAll()
sync
loop
Checkbox
Notes: The graphic is setup very similar to the button.
type __checkbox
_name as string
_group as string
_gamestate as string
_status as integer
_baseimage as integer
_checkboxsprite as integer
_x as integer
_y as integer
_width as integer
_height as integer
_canrelease as integer
_visible as integer
endtype
function checkbox_init()
#constant CHECKBOX_DISABLED 0
#constant CHECKBOX_DISABLEDDOWN 1
#constant CHECKBOX_ENABLED 2
#constant CHECKBOX_ENABLEDDOWN 3
dim checkbox_All() as __checkbox
empty array checkbox_All()
endfunction 1
function checkbox_add(name as string,path as string)
r as integer
array insert at bottom checkbox_All()
checkbox_All()._name=name
checkbox_All()._group="none"
checkbox_All()._gamestate="none"
checkbox_All()._canrelease=0
checkbox_All()._visible=1
checkbox_All()._status=CHECKBOX_DISABLED
checkbox_All()._baseimage=system_freeImage(1,system()._maxobjects)
checkbox_All()._checkboxsprite=system_freeSprite(1,system()._maxobjects)
create animated sprite checkbox_All()._checkboxsprite,path,4,1,checkbox_All()._baseimage
`set sprite checkbox_All()._checkboxsprite,0,1
checkbox_All()._width=system_imageWidth(checkbox_All()._baseimage)/4
checkbox_All()._height=system_imageHeight(checkbox_All()._baseimage)
r=get array index(checkbox_All())
endfunction r
function checkbox_updateAll()
for i=0 to array count(checkbox_All())
checkbox_update(checkbox_All(i)._name)
next i
endfunction
function checkbox_updateGroup(group as string)
for i=0 to array count(checkbox_All())
if checkbox_All(i)._group=group then checkbox_update(checkbox_All(i)._name)
next i
endfunction
function checkbox_update(name as string)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
if gamestate_check()<>checkbox_All(id)._gamestate and checkbox_All(id)._gamestate<>"none"
hide sprite checkbox_All(id)._checkboxsprite
exitfunction -1
else
show sprite checkbox_All(id)._checkboxsprite
endif
if checkbox_All(id)._visible=1
if checkbox_mouseOver(name)
if checkbox_All(id)._canrelease>=0
if system()._mousebutton=1
if checkbox_All(id)._status=CHECKBOX_DISABLED then checkbox_All(id)._status=CHECKBOX_DISABLEDDOWN
if checkbox_All(id)._status=CHECKBOX_ENABLED then checkbox_All(id)._status=CHECKBOX_ENABLEDDOWN
checkbox_All(id)._canrelease=1
else
if checkbox_All(id)._canrelease=1
if checkbox_All(id)._status=CHECKBOX_DISABLEDDOWN then checkbox_All(id)._status=CHECKBOX_ENABLED
if checkbox_All(id)._status=CHECKBOX_ENABLEDDOWN then checkbox_All(id)._status=CHECKBOX_DISABLED
endif
checkbox_All(id)._canrelease=0
endif
endif
else
if checkbox_All(id)._status=CHECKBOX_DISABLEDDOWN then checkbox_All(id)._status=CHECKBOX_DISABLED
if checkbox_All(id)._status=CHECKBOX_ENABLEDDOWN then checkbox_All(id)._status=CHECKBOX_ENABLED
if checkbox_All(id)._canrelease=0 or system()._mousebutton=0 then checkbox_All(id)._canrelease=-1
endif
if system()._mousebutton=0 and checkbox_All(id)._canrelease=-1 then checkbox_All(id)._canrelease=0
select checkbox_All(id)._status
case CHECKBOX_DISABLED
set sprite frame checkbox_All(id)._checkboxsprite,1
sprite checkbox_All(id)._checkboxsprite,checkbox_All(id)._x,checkbox_All(id)._y,checkbox_All(id)._baseimage
endcase
case CHECKBOX_DISABLEDDOWN
set sprite frame checkbox_All(id)._checkboxsprite,2
sprite checkbox_All(id)._checkboxsprite,checkbox_All(id)._x,checkbox_All(id)._y,checkbox_All(id)._baseimage
endcase
case CHECKBOX_ENABLED
set sprite frame checkbox_All(id)._checkboxsprite,3
sprite checkbox_All(id)._checkboxsprite,checkbox_All(id)._x,checkbox_All(id)._y,checkbox_All(id)._baseimage
endcase
case CHECKBOX_ENABLEDDOWN
set sprite frame checkbox_All(id)._checkboxsprite,4
sprite checkbox_All(id)._checkboxsprite,checkbox_All(id)._x,checkbox_All(id)._y,checkbox_All(id)._baseimage
endcase
endselect
show sprite checkbox_All(id)._checkboxsprite
else
hide sprite checkbox_All(id)._checkboxsprite
endif
endfunction 1
function checkbox_getStatus(name as string)
r as integer
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
if checkbox_All(id)._visible=0 then exitfunction -1
r=checkbox_All(id)._status
endfunction r
function checkbox_getEnabled(name as string)
r as integer
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
if checkbox_All(id)._visible=0 then exitfunction -1
if checkbox_All(id)._status=CHECKBOX_ENABLED then r=1
endfunction r
function checkbox_getDisabled(name as string)
r as integer
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
if checkbox_All(id)._visible=0 then exitfunction -1
if checkbox_All(id)._status=CHECKBOX_DISABLED then r=1
endfunction r
function checkbox_set(name as string,x as integer,y as integer)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
checkbox_All(id)._x=x
checkbox_All(id)._y=y
endfunction 1
function checkbox_setGroup(name as string,group as string)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
checkbox_All(id)._group=group
endfunction 1
function checkbox_setGamestate(name as string,gamestate as string)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
checkbox_All(id)._gamestate=gamestate
endfunction 1
function checkbox_show(name as string)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
checkbox_All(id)._visible=1
endfunction 1
function checkbox_hide(name as string)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
checkbox_All(id)._visible=0
endfunction 1
function checkbox_hideGroup(group as string)
for i=0 to array count(checkbox_All())
if checkbox_All(i)._group=group then checkbox_All(i)._visible=0
next i
endfunction 1
function checkbox_showGroup(group as string)
for i=0 to array count(checkbox_All())
if checkbox_All(i)._group=group then checkbox_All(i)._visible=1
next i
endfunction 1
function checkbox_delete(name as string)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
delete sprite checkbox_All(id)._checkboxsprite
delete image checkbox_All(id)._baseimage
array delete element checkbox_All(),id
endfunction 1
rem returns the number of checkboxs
function checkbox_count()
r as integer
r=array count(checkbox_All())
endfunction r
rem returns the id of the checkbox with the name
function checkbox_nameToID(name as string)
for i=0 to array count(checkbox_All())
if checkbox_All(i)._name=name
exitfunction i
endif
next i
endfunction -1
rem returns the name of the checkbox with the given id
function checkbox_idToName(id as integer)
r as string
r=checkbox_All(id)._name
endfunction r
rem returns 1 if the mouse is over the given checkbox,0 if not
function checkbox_mouseOver(name as string)
id as integer
id=checkbox_nameToID(name)
if id=-1 then exitfunction -1
if system()._mousex>checkbox_All(id)._x and system()._mousex<checkbox_All(id)._x+checkbox_All(id)._width
if system()._mousey>checkbox_All(id)._y and system()._mousey<checkbox_All(id)._y+checkbox_All(id)._height
exitfunction 1
endif
endif
endfunction 0
Example:
[...]
checkbox_init()
checkbox_add("mycheckbox","mediacheckbox.png")
[...]
do
checkbox_updateAll()
if checkbox_getEnabled("mycheckbox")
text 400,300,"That tickles."
endif
sync
loop
Textbox
Notes: No graphic is required. Wraps lines correctly. Has scrolling (use a button to increase and decrease scroll value). 'redrawfreq' is how often to redraw it (It only redraws when you change the text though). In other words, if it is being updated constantly, and 'redrawfreq' is set to 100-300, it will only redraw it twice a second. Usually 500 is fine. The 'lines' value will automatically set the height of the textbox to fit that many lines nicely. Use 'n' to create a new line, regardless of whether or not it is at the edge of the box (example: "line 1nline 2").
type __textbox
_name as string
_group as string
_gamestate as string
_imageid as integer
_spriteid as integer
_contents as string
_x as integer
_y as integer
_width as float
_lines as float
_maxlines as integer
_scroll as integer
_textcolor as dword
_primarycolor as dword
_secondarycolor as dword
_visible as integer
_lastredraw as integer
_redrawfreq as integer
endtype
function textbox_init()
dim textbox_All() as __textbox
empty array textbox_All()
endfunction 1
function textbox_add(name as string,contents as string,x as float,y as float,width as float,lines as float,redrawfreq as integer)
r as integer
array insert at bottom textbox_All()
textbox_All()._name=name
textbox_All()._group="none"
textbox_All()._gamestate="none"
textbox_All()._contents=contents
textbox_All()._x=x
textbox_All()._y=y
textbox_All()._width=width
textbox_All()._lines=lines
textbox_All()._visible=1
textbox_All()._textcolor=rgb(255,255,255)
textbox_All()._primarycolor=rgb(0,0,0)
textbox_All()._secondarycolor=rgb(255,255,255)
textbox_All()._redrawfreq=redrawfreq
textbox_All()._imageid=system_freeImage(1,system()._maxobjects)
textbox_redraw(textbox_All()._name)
textbox_All()._spriteid=system_freeSprite(1,system()._maxobjects)
sprite textbox_All()._spriteid,x,y,textbox_All()._imageid
r=get array index(textbox_All())
endfunction r
function textbox_updateAll()
for i=0 to array count(textbox_All())
textbox_update(textbox_All(i)._name)
next i
endfunction 1
function textbox_updateGroup(group as string)
for i=0 to array count(textbox_All())
if textbox_All(i)._group=group then textbox_update(textbox_All(i)._name)
next i
endfunction 1
function textbox_update(name as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
if gamestate_check()<>textbox_All(id)._gamestate and textbox_All(id)._gamestate<>"none"
hide sprite textbox_All(id)._spriteid
exitfunction -1
else
show sprite textbox_All(id)._spriteid
endif
if textbox_All(id)._visible=1
show sprite textbox_All(id)._spriteid
`paste image textbox_All(id)._imageid,textbox_All(id)._x,textbox_All(id)._y
else
hide sprite textbox_All(id)._spriteid
endif
endfunction 1
function textbox_redraw(name as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
if textbox_All(id)._lastredraw>timer() then exitfunction -1
box textbox_All(id)._x,textbox_All(id)._y,textbox_All(id)._x+textbox_All(id)._width,textbox_All(id)._y+textbox_All(id)._lines*(5+system()._textheight)+5,textbox_All(id)._secondarycolor,textbox_All(id)._secondarycolor,textbox_All(id)._secondarycolor,textbox_All(id)._secondarycolor
box textbox_All(id)._x+1,textbox_All(id)._y+1,textbox_All(id)._x+textbox_All(id)._width-1,textbox_All(id)._y+textbox_All(id)._lines*(5+system()._textheight)+5-1,textbox_All(id)._primarycolor,textbox_All(id)._primarycolor,textbox_All(id)._primarycolor,textbox_All(id)._primarycolor
ink textbox_All(id)._textcolor,rgb(0,0,0)
textbox_All(id)._contents=replace$(textbox_All(id)._contents,"n"," n ")
split string textbox_All(id)._contents," "
dim contents() as string
array insert at bottom contents()
for i=1 to split count()
if text width(contents()+" "+get split word$(i))>textbox_All(id)._width-10 or get split word$(i)="n"
array insert at bottom contents()
if get split word$(i)<>"n" then contents()=contents()+" "+get split word$(i)
else
contents()=contents()+" "+get split word$(i)
endif
next i
textbox_All(id)._maxlines=array count(contents())
for i=0 to textbox_All(id)._scroll-1
array delete element contents(),0
next i
for i=0 to array count(contents())
if 5+(i)*system()._textheight<5+textbox_All(id)._lines*system()._textheight then text textbox_All(id)._x+5,textbox_All(id)._y+5+((system()._textheight+5)*i),contents(i)
next i
get image textbox_All(id)._imageid,textbox_All(id)._x,textbox_All(id)._y,textbox_All(id)._x+textbox_All(id)._width,textbox_All(id)._y+textbox_All(id)._lines*(5+system()._textheight)+5,1
ink rgb(255,255,255),rgb(0,0,0)
textbox_All(id)._lastredraw=timer()+textbox_All(id)._redrawfreq
endfunction 1
function textbox_set(name as string,x as float,y as float)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
textbox_All(id)._x=x
textbox_All(id)._y=y
endfunction 1
function textbox_setContents(name as string,contents as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
textbox_All(id)._contents=contents
textbox_redraw(name)
endfunction 1
function textbox_getContents(name as string)
r as string
id as integer
id=textbox_nameToId(name)
if id=-1 then exitfunction ""
r=textbox_All(id)._contents
endfunction r
function textbox_setColor(name as string,textcolor as dword,primarycolor as dword,secondarycolor as dword)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
textbox_All(id)._textcolor=textcolor
textbox_All(id)._primarycolor=primarycolor
textbox_All(id)._secondarycolor=secondarycolor
textbox_redraw(name)
endfunction 1
function textbox_setGroupColor(group as string,textcolor as dword,primarycolor as dword,secondarycolor as dword)
for i=0 to array count(textbox_All())
if textbox_All(i)._group=group
textbox_All(i)._textcolor=textcolor
textbox_All(i)._primarycolor=primarycolor
textbox_All(i)._secondarycolor=secondarycolor
textbox_redraw(textbox_All(i)._name)
endif
next i
endfunction 1
function textbox_setGroup(name as string,group as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
textbox_All(id)._group=group
endfunction 1
function textbox_setGamestate(name as string,gamestate as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
textbox_All(id)._gamestate=gamestate
endfunction 1
function textbox_scroll(name as string,amount as integer,relative as integer)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
if relative=0
textbox_All(id)._scroll=amount
else
inc textbox_All(id)._scroll,amount
endif
textbox_All(id)._scroll=min(max(textbox_All(id)._scroll,0),textbox_All(id)._maxlines)
textbox_redraw(textbox_All()._name)
endfunction 1
function textbox_scrollGroup(group as string,amount as integer,relative as integer)
for i=0 to array count(textbox_All())
if textbox_All(i)._group=group
if relative=0
textbox_All(i)._scroll=amount
else
inc textbox_All(id)._scroll,amount
endif
endif
next i
textbox_All(id)._scroll=min(max(textbox_All(id)._scroll,0),textbox_All(id)._maxlines)
textbox_redraw(textbox_All()._name)
endfunction 1
function textbox_hide(name as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
textbox_All(id)._visible=0
endfunction 1
function textbox_hideGroup(group as string)
for i=0 to array count(textbox_All())
if textbox_All(i)._group=group then textbox_All(id)._visible=0
next i
endfunction 1
function textbox_show(name as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
textbox_All(id)._visible=1
endfunction 1
function textbox_showGroup(group as string)
for i=0 to array count(textbox_All())
if textbox_All(i)._group=group then textbox_All(id)._visible=1
next i
endfunction 1
function textbox_delete(name as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1
delete image textbox_All(id)._imageid
delete sprite textbox_All(id)._spriteid
array delete element textbox_All(),id
endfunction 1
function textbox_getWidth(name as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1.0
r as float
r=textbox_All(id)._width
endfunction r
function textbox_getHeight(name as string)
id as integer
id=textbox_nameToID(name)
if id=-1 then exitfunction -1.0
r as float
r=textbox_All(id)._lines*(5+system()._textheight)
endfunction r
rem returns the number of textboxs
function textbox_count()
r as integer
r=array count(textbox_All())
endfunction r
rem returns the id of the textbox with the name
function textbox_nameToID(name as string)
for i=0 to array count(textbox_All())
if textbox_All(i)._name=name
exitfunction i
endif
next i
endfunction -1
rem returns the name of the textbox with the given id
function textbox_idToName(id as integer)
r as string
r=textbox_All(id)._name
endfunction r
Example
[...]
textbox_init()
textbox_add("mytextbox","this can be as long as you want...",5,5,100,100,6,500)
[...]
do
textbox_updateAll()
sync
loop
Input Box
Notes: No graphic necessary.
type __inputbox
_name as string
_group as string
_gamestate as string
_imageid as integer
_spriteid as integer
_contents as string
_x as integer
_y as integer
_width as float
_textcolor as dword
_primarycolor as dword
_secondarycolor as dword
_visible as integer
_active as integer
_canbackspace as integer
endtype
function inputbox_init()
dim inputbox_All() as __inputbox
empty array inputbox_All()
endfunction 1
function inputbox_add(name as string,contents as string,x as float,y as float,width as float)
r as integer
array insert at bottom inputbox_All()
inputbox_All()._name=name
inputbox_All()._group="none"
inputbox_All()._gamestate="none"
inputbox_All()._contents=contents
inputbox_All()._x=x
inputbox_All()._y=y
inputbox_All()._width=width
inputbox_All()._visible=1
inputbox_All()._textcolor=rgb(0,0,0)
inputbox_All()._primarycolor=rgb(255,255,255)
inputbox_All()._secondarycolor=rgb(0,0,0)
inputbox_All()._active=0
inputbox_All()._imageid=system_freeSprite(1,system()._maxobjects)
inputbox_redraw(inputbox_All()._name)
inputbox_All()._spriteid=system_freeSprite(1,system()._maxobjects)
sprite inputbox_All()._spriteid,x,y,inputbox_All()._imageid
r=get array index(inputbox_All())
endfunction r
function inputbox_updateAll()
for i=0 to array count(inputbox_All())
inputbox_update(inputbox_All(i)._name)
next i
endfunction 1
function inputbox_updateGroup(group as string)
for i=0 to array count(inputbox_All())
if inputbox_All(i)._group=group then inputbox_update(inputbox_All(i)._name)
next i
endfunction 1
function inputbox_update(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
if gamestate_check()<>inputbox_All(id)._gamestate and inputbox_All(id)._gamestate<>"none"
hide sprite inputbox_All(id)._spriteid
exitfunction -1
else
show sprite inputbox_All(id)._spriteid
endif
if inputbox_All(id)._visible=1
if inputbox_mouseOver(name)
if system()._mousebutton=1
inputbox_All(id)._active=1
inputbox_redraw(name)
endif
else
if system()._mousebutton<>0
inputbox_All(id)._active=0
inputbox_redraw(name)
endif
endif
oldcontents as string:oldcontents=inputbox_All(id)._contents
if inputbox_All(id)._active=1
if text width(inputbox_All(id)._contents)<inputbox_All(id)._width-10
inputbox_All(id)._contents=inputbox_All(id)._contents+entry$(1)
endif
if keystate(14)
if inputbox_All(id)._canbackspace=1
inputbox_All(id)._canbackspace=0
inputbox_All(id)._contents=left$(inputbox_All(id)._contents,len(inputbox_All(id)._contents)-1)
endif
else
inputbox_All(id)._canbackspace=1
endif
if oldcontents<>inputbox_All(id)._contents then inputbox_redraw(name)
endif
show sprite inputbox_All(id)._spriteid
`paste image inputbox_All(id)._imageid,inputbox_All(id)._x,inputbox_All(id)._y
else
hide sprite inputbox_All(id)._spriteid
endif
endfunction 1
function inputbox_redraw(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
rem outline
box inputbox_All(id)._x,inputbox_All(id)._y,inputbox_All(id)._x+inputbox_All(id)._width,inputbox_All(id)._y+(5+system()._textheight)+5,inputbox_All(id)._secondarycolor,inputbox_All(id)._secondarycolor,inputbox_All(id)._secondarycolor,inputbox_All(id)._secondarycolor
rem inside color
if inputbox_All(id)._active=1
box inputbox_All(id)._x+1,inputbox_All(id)._y+1,inputbox_All(id)._x+inputbox_All(id)._width-1,inputbox_All(id)._y+(5+system()._textheight)+5-1,inputbox_All(id)._primarycolor,inputbox_All(id)._primarycolor,inputbox_All(id)._primarycolor,inputbox_All(id)._primarycolor
else
tempcolor as dword
tempcolor=inputbox_All(id)._primarycolor
tempcolor=rgb((rgbr(tempcolor)+128)/2,(rgbg(tempcolor)+128)/2,(rgbb(tempcolor)+128)/2)
box inputbox_All(id)._x+1,inputbox_All(id)._y+1,inputbox_All(id)._x+inputbox_All(id)._width-1,inputbox_All(id)._y+(5+system()._textheight)+5-1,tempcolor,tempcolor,tempcolor,tempcolor
endif
ink inputbox_All(id)._textcolor,rgb(0,0,0)
contents as string
contents=inputbox_All(id)._contents
text inputbox_All(id)._x+5,inputbox_All(id)._y+5+((system()._textheight+5)*i),contents
get image inputbox_All(id)._imageid,inputbox_All(id)._x,inputbox_All(id)._y,inputbox_All(id)._x+inputbox_All(id)._width,inputbox_All(id)._y+(5+system()._textheight)+5,1
ink rgb(255,255,255),rgb(0,0,0)
endfunction 1
function inputbox_set(name as string,x as float,y as float)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
inputbox_All(id)._x=x
inputbox_All(id)._y=y
endfunction 1
function inputbox_setContents(name as string,contents as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
inputbox_All(id)._contents=contents
inputbox_redraw(name)
endfunction 1
function inputbox_getContents(name as string)
r as string
id as integer
id=inputbox_nameToId(name)
if id=-1 then exitfunction ""
r=inputbox_All(id)._contents
endfunction r
function inputbox_setColor(name as string,textcolor as dword,primarycolor as dword,secondarycolor as dword)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
inputbox_All(id)._textcolor=textcolor
inputbox_All(id)._primarycolor=primarycolor
inputbox_All(id)._secondarycolor=secondarycolor
inputbox_redraw(name)
endfunction 1
function inputbox_setGroupColor(group as string,textcolor as dword,primarycolor as dword,secondarycolor as dword)
for i=0 to array count(inputbox_All())
if inputbox_All(i)._group=group
inputbox_All(i)._textcolor=textcolor
inputbox_All(i)._primarycolor=primarycolor
inputbox_All(i)._secondarycolor=secondarycolor
inputbox_redraw(inputbox_All(i)._name)
endif
next i
endfunction 1
function inputbox_setGroup(name as string,group as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
inputbox_All(id)._group=group
endfunction 1
function inputbox_setGamestate(name as string,gamestate as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
inputbox_All(id)._gamestate=gamestate
endfunction 1
function inputbox_hide(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
inputbox_All(id)._visible=0
endfunction 1
function inputbox_hideGroup(group as string)
for i=0 to array count(inputbox_All())
if inputbox_All(i)._group=group then inputbox_All(id)._visible=0
next i
endfunction 1
function inputbox_show(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
inputbox_All(id)._visible=1
endfunction 1
function inputbox_showGroup(group as string)
for i=0 to array count(inputbox_All())
if inputbox_All(i)._group=group then inputbox_All(id)._visible=1
next i
endfunction 1
function inputbox_delete(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
delete image inputbox_All(id)._imageid
delete sprite inputbox_All(id)._spriteid
array delete element inputbox_All(),id
endfunction 1
function inputbox_getWidth(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1.0
r as float
r=inputbox_All(id)._width
endfunction r
function inputbox_getHeight(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1.0
r as float
r=5+system()._textheight
endfunction r
rem returns the number of inputboxs
function inputbox_count()
r as integer
r=array count(inputbox_All())
endfunction r
rem returns the id of the inputbox with the name
function inputbox_nameToID(name as string)
for i=0 to array count(inputbox_All())
if inputbox_All(i)._name=name
exitfunction i
endif
next i
endfunction -1
rem returns the name of the inputbox with the given id
function inputbox_idToName(id as integer)
r as string
r=inputbox_All(id)._name
endfunction r
rem returns 1 if the mouse is over the given button,0 if not
function inputbox_mouseOver(name as string)
id as integer
id=inputbox_nameToID(name)
if id=-1 then exitfunction -1
if system()._mousex>inputbox_All(id)._x and system()._mousex<(inputbox_All(id)._x+inputbox_All(id)._width)
if system()._mousey>inputbox_All(id)._y and system()._mousey<inputbox_All(id)._y+sprite height(inputbox_All(id)._spriteid)
exitfunction 1
endif
endif
endfunction 0
Example:
[...]
inputbox_init()
inputbox_add("myinput","",5,5,120)
[...]
do
inputbox_updateAll()
if lower$(inputbox_getContents("myinput"))="quit" then end
sync
loop
If you have trouble getting something to work, let me know. I will work to make sure you get it working.