Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Simple Button Class
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Degensquared




PostPosted: 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 Razz.

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. Razz)

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! Smile



button class.t
 Description:
source code!

Download
 Filename:  button class.t
 Filesize:  4.25 KB
 Downloaded:  223 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: 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! Very Happy
Degensquared




PostPosted: Thu Dec 20, 2007 7:11 pm   Post subject: RE:Simple Button Class

Thanks Very Happy I'm planning on adding custom sizes and fonts for the labels Smile
Lawlly




PostPosted: 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.
Degensquared




PostPosted: 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.


code:

var button1,button2,button3 : ^button
var lastclicked, clicked : boolean

new button1
new button2
new button3

button1 -> initialize (x1,y1,x2,y2, do you want depression animation, color of the button)
...
button3 ...

button1 -> clicked (clicked, lastclicked)

if lastclicked and not clicked then
     do whatever
end if

...
button3 ...

button1 -> draw
...
button3 -> draw



Loop that (make sure you use offscreenonly and View.Update!)
and it should work Very Happy
SNIPERDUDE




PostPosted: 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:

code:

loop
    drawButton (any inside parameters such as X, Y, colour, text, procedure to be executed when pressed)
    View.Update
    exit when hasch
end loop
Degensquared




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: