Computer Science Canada Simple Button Class |
Author: | Degensquared [ Mon Dec 17, 2007 5:28 pm ] |
Post subject: | Simple Button Class |
I have just learned how to use classes and objects, so I decided to use my new found knowledge to save myself some time in the future ![]() This simple button class allows you to create button objects quickly, and check if they are pressed with a few easy commands. Command List button -> initialize: initializes the position, color and toggle depression animation. button -> newlabel: allows you to put text onto the button. (for now only one font, in one size, but that will change. ![]() button -> clicked: checks if the button was clicked this frame and returns if it was clicked last frame. button -> draw: draws the button, the depression animation, and the label for each button Enjoy! ![]() |
Author: | SNIPERDUDE [ Thu Dec 20, 2007 6:45 pm ] |
Post subject: | RE:Simple Button Class |
wow, Button/GUI classes seem to be growing popular in subject. Good work! ![]() |
Author: | Degensquared [ Thu Dec 20, 2007 7:11 pm ] |
Post subject: | RE:Simple Button Class |
Thanks ![]() ![]() |
Author: | Lawlly [ Thu Dec 20, 2007 7:15 pm ] |
Post subject: | Re: Simple Button Class |
It looks useful to me but I don't understand how I can use it. I'm thinking of creating 3 buttons for a game I'm making. When you click it it selects a map. How can I use this for that? Of course if I were to use it, I'd note it as borrowed code. |
Author: | Degensquared [ Thu Dec 20, 2007 9:19 pm ] | ||
Post subject: | Re: Simple Button Class | ||
Well, if you look at the example program, it should be kind of clear, but if not here you go: You would need to set up 3 variables, each a pointer to the button class. and the variables to check if the buttons have been clicked create the objects using the new command, initialize each of them. check if they were clicked and are now not clicked draw the buttons.
Loop that (make sure you use offscreenonly and View.Update!) and it should work ![]() |
Author: | SNIPERDUDE [ Sun Dec 23, 2007 9:47 pm ] | ||
Post subject: | Re: Simple Button Class | ||
do note that if you made your programme so the user or programmer only had to call one line, it would make it easier. for example:
|
Author: | Degensquared [ Thu Dec 27, 2007 11:04 pm ] |
Post subject: | RE:Simple Button Class |
hmm... well I personally like to split my programs into, input, calculations, and output. so that's why I split the draw and clicked commands, but I do think I could have labels included in the initialization. |