Well, I've been pretty busy with real life stuff, but i had a couple late night programming sessions, and started working on something I've been wanting to work on for a while.. a button system to allow for easy creation of menus.
The long term plan is to set up a system that allows both images and buttons to be assigned to different groups which can then be activated and deactivated. This would allow you to assign buttons and images for a 'mainmenu' group as well as images(that can be altered in realtime) to be displayed in another group such as a 'ingamehud' group. However, that is the long term goal, and I still have a ways to go before I get to that point.
What I have so far, however, is a fairly robust(yet very dirty
) button system that uses images for the default button graphic as well as hover and clicked graphics. I also have fairly simplified methods for setting buttons as spinners or as single click style buttons.
It also features a spiffy justification method as long as cUpdateRes()(edit: cUpdateRes() is called during cInit()) is called prior to positioning buttons.
I do not have much time to document all of the functions yet, however I will attach a demo that is fairly readable... I dont claim the same readability for the 'cButton.dba' include file however.
Screenshot:
And a current list of useable functions:
cInit()
cMakeButton(cButtonNum,dimg,himg,cimg)
cPositionButton(cButtonNum,x,y,justification)
cPasteImage(img,x,y,justification)
cUpdateButton(cButtonNum)
cUpdateButtonRange(int1, int2)
cUpdateRes()
isButtonClicked(cButtonNum)
isButtonHovered(cButtonNum)
cCloneButton(cButtonNum,cDest)
cSetButtonFontExtended(cButtonNum, font$,drgb,dsize,hrgb,hsize,crgb,csize)
cSetButtonFontSize(cButtonNum, size)
cSetButtonDefaultFontSize(cButtonNum, size)
cSetButtonHoverFontSize(cButtonNum, size)
cSetButtonLabel(cButtonNum, label$)
cSetButtonClickFontSize(cButtonNum, size)
cSetButtonFontColor(cButtonNum, color)
cSetButtonDefaultFontColor(cButtonNum, color)
cSetButtonHoverFontColor(cButtonNum, color)
cSetButtonClickFontColor(cButtonNum, color)
cSetButtonFont(cButtonNum, font$)
cSetButtonDefaultFont(cButtonNum, font$)
cSetButtonHoverFont(cButtonNum, font$)
cSetButtonClickFont(cButtonNum, font$)
To use the demo, open the 'gui.dbpro' and compile.
Even in this simple state, I have noticed a simple bug that if you are already clicking down off a button and then hover over a button it still registers as being clicked.
Also in the demo, I have text labels set up for the buttons. This uses DBP font commands and drastically drops the frame rate. For a comparison, The demo with text labels runs at ~57 frames per second while the demo without runs at ~5,500 frames per second. This is most likely due to me constantly changing the font multiple times per frame. I have heard the DBP fonts are slow though...
Anyways, without further rambling, the first demo:
Edit:
Source for demo to show its simplicity:
#include "./cButton.dba"
set display mode 800,600,32,0
sync on
sync rate 0
set window off
cInit()
load image "default.png",1
load image "hovered.png",2
load image "clicked.png",3
cMakeButton(1,1,2,3)
cSetButtonFontExtended(1,"arial",rgb(64,64,64),14,rgb(0,0,0),14,rgb(0,0,0),14)
cCloneButton(1,2)
cCloneButton(1,3)
cCloneButton(1,4)
cPositionButton(1,0,0,UPPERRIGHT)
cPositionButton(2,0,32,UPPERRIGHT)
cPositionButton(3,0,32*2,UPPERRIGHT)
cPositionButton(4,0,32*3,UPPERRIGHT)
cSetButtonLabel(1,"Spin Left")
cSetButtonLabel(2,"Rotate 5 Degrees Left")
cSetButtonLabel(3,"Rotate 5 Degrees Right")
cSetButtonLabel(4,"Spin Right")
make object cube 1,1
yrot#=0
do
if isButtonClicked(1)
inc yrot#,1.0
yrot#=wrapvalue(yrot#)
yrotate object 1,yrot#
endif
if isButtonClicked(2)
repeat
Main()
until isButtonClicked(2)=0
if isButtonHovered(2)
inc yrot#,5.0
yrot#=wrapvalue(yrot#)
yrotate object 1,yrot#
endif
endif
if isButtonClicked(3)
repeat
Main()
until isButtonClicked(3)=0
if isButtonHovered(3)
inc yrot#,-5.0
yrot#=wrapvalue(yrot#)
yrotate object 1,yrot#
endif
endif
if isButtonClicked(4)
inc yrot#,-1.0
yrot#=wrapvalue(yrot#)
yrotate object 1,yrot#
endif
Main()
loop
end
function Main()
cUpdateButtonRange(1,4)
set cursor 0,0
print screen fps()
sync
endfunction