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

Username:   Password: 
 RegisterRegister   
 [Module] Button Class
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raknarg




PostPosted: Tue Jan 24, 2012 3:57 pm   Post subject: [Module] Button Class

Hey guys. I made a button class for a certain game, and I decided I'd share it with everyone. If you know how to use classes, it should be pretty straightforward. Here's an example program I made to go along with it. If you click the button, the number in the top right goes up by one:
Turing:

import "Buttons2.tu"

setscreen ("offscreenonly")

var n : int := 0

var but : pointer to button
new button, but

button (but).initialize (25, 100, 200, 175, Font.New ("Arial:30"), grey, darkgrey, white, 30, "Click me!")

loop
    if button (but).is_clicked = true then
        n += 1
    end if
    put n
    button (but).draw
    View.UpdateArea (0, 0, maxx, maxy)
    cls
end loop

Some notes here:
-the first four parameters are like the first four in Draw.Box
-If you make the y2 smaller than y1 or x2 smaller than x1, it wont ever detect anything
-Those three colours there are respectively fill colour, border colour and font colour
-The last number is the size of the font
-when you use the colour, the button pressed will be the colour you entered, hovering will be darker and not touching it will be darkest

Also, I forgot that when I made this topic, it's not actually a module, its a class. Sorry.



Buttons2.tu
 Description:
Save the example and class in the same place

Download
 Filename:  Buttons2.tu
 Filesize:  2.44 KB
 Downloaded:  338 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Wed Jan 25, 2012 9:16 am   Post subject: RE:[Module] Button Class

Actlually, I forgot that this was in the wrong section entirely. Could a mod move this to submissions?
smool




PostPosted: Wed Feb 15, 2012 9:17 pm   Post subject: RE:[Module] Button Class

Looks nice, may I suggest a border around the edges? And perhaps the option of making the button a picture?
Raknarg




PostPosted: Thu Feb 16, 2012 11:32 am   Post subject: RE:[Module] Button Class

There is a border, just the color i picked makes it less distinct Razz
and yeah, I was considering that. I'll try that.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: