Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] GUI System (Buttons only) No Sprites

Author
Message
feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 18th Mar 2009 22:59 Edited at: 18th Mar 2009 23:14


A simpler version of the MAIN file if you wanna try this out, though I commented out the picture box so you should be able to run both:



Also note, if you want to display images and get them to work right, you have to manually enter in the Image Width and Image Height in the BMakeButtonPictureBox() function. Image Width() functions don't work that well before the image is loaded...

TUTORIAL!

Copy and paste all the functions and variables into your code!

Before the Main Loop, or anytime you wish to create a button, call BMakeButtonBox() and type in it's x, y, width, height parameters.

Within the Main loop call BReset() before anything to refresh the mouse collisions, otherwise you'll have many highlighted buttons.

mclicked = MouseClick()
highlighted = BCheckMouseInButton()

are two temp variables I added since I called those functions so many times, I just wanted them stored somewhere. You will need to send them to the other functions.

To see which button is being clicked, type

BClicked(highlighted, mclicked)

this will return the number of any button being clicked during that loop. It will return 0 if nothing is being clicked.

So if you had a start button, and it was at 1, you'd type
if BClicked(highlighted, mclicked) = 1 then startGame()

When you want the buttons to show up on screen, which should be before the sync but after everything's tested use:

BDisplay(highlighted)
sync

You send highlighted because BDisplay() would run that test 100 times if you didn't, so it saves processing power.
Also, since most of you aren't noobs, you'll notice I couldn't figure out where to put that to make it work, so it runs a simpler test anyway... but works heh.

Notes:
To make a button inactive, if you don't want it displayed, type BDestroyButton(button_number), and to make it active again use BActivateButton(button_number).

I do not have a BDestroyAll() function, just realized I should add that... but it would need to store which buttons were active before such that you could call 1 function and reactivate your menu, GUI studio does this (and bugs out)...

ENDTUTORIAL

I'll edit my code now to add those and hope you guys enjoy a no-sprite version of this.

Sixty Squares' code is, I think much cleaner but it had syntax in it that didn't load that well on DBP, which is why I reinvented the wheel.

edit: Made the functions!
First add this line to the global dim's at the top!
global dim SButtonStoredActive(BSize) as integer

then add these functions anywhere below main:



I used this in my main loop to test:


and voila!

Here's the full thing, edited:


SButton stands for SimpleButton... if anyone aks
and have fun!

Signed
------
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 18th Mar 2009 23:45
Looks pretty cool . I like how the button has 3 appearances: normal, highlighted, and clicked.

Quote: "Sixty Squares' code is, I think much cleaner but it had syntax in it that didn't load that well on DBP,"


Remind me which?

feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 19th Mar 2009 07:43 Edited at: 19th Mar 2009 07:43
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Mar 2009 18:38
Oh, that . I'm still using that but I've changed it a bit to support different images/colors on different buttons... Anyway, good job on this again .

Login to post a reply

Server time is: 2024-11-25 09:06:29
Your offset time is: 2024-11-25 09:06:29