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

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




PostPosted: Tue Feb 19, 2013 2:41 pm   Post subject: [Class] ButtonGroup

Hey guys. I made a new version of my button class, called ButtonGroup. This way the buttons can interact with each other, which means that you can have button layering that works. If the mouse is within the bounds of two buttons, only the button on top will be activated by hovering or clicking, the one underneath will not react.

This is achieved by a parameter called order (because apparently the word priority is already preset... If someone could explain it, that'd be nice), which sets the priority of buttons. If button A has an order of 2 and button B has an order of 1, button A will take priority over button B.

These are the usable functions as listed:

new_button (order_, x1_, y1_, x2_, y2_, font_, c_, bc_, fontc_ : int, text_ : string)
Order: the priority of buttons, highest priority is the highest number. They can be the same number, btw.
x1, x2, y1, y2: Coordinates of the button. Doesn't matter what order you state them in, it'll automatically adjust them.
font: Font ID
c: border colour
bc: back colour
fontc: font colour
text: What you want written on the button

Note that the buttons are set in an array, so you can call specific buttons by calling buttonGroup -> button (x)

delete_button (x : int)
x: The number of the button you want deleted.

is_hovering (bNum : int, b : buttonData)
bNum: button number (they are listed in the order of creation)
b: The button itself (ex. buttonGroup -> button (3))

is_clicking (bNum : int)

is_clicked (bNum : int)

draw

Here's an example program to show it (save the class and the example in the same file):


Note: press the orange button to subtract and the white button to add. The red will do nothing.
Turing:

import ButtonGroup

setscreen ("offscreenonly")

var buttonGroup : ^ButtonGroup

new ButtonGroup, buttonGroup

buttonGroup -> new_button (1, 50, 50, 100, 100, 0, black, white, 0, "")
buttonGroup -> new_button (3, 75, 75, 125, 125, 0, black, 42, 0, "")
buttonGroup -> new_button (2, 60, 40, 110, 90, 0, black, brightred, 0, "")

var num : int := 0

loop
    if buttonGroup -> is_clicked (1) then
        num += 1
    elsif buttonGroup -> is_clicked (2) then
        num -= 1
    end if
    put num
    buttonGroup -> draw
    View.Update
    cls
end loop



ButtonGroup.tu
 Description:

Download
 Filename:  ButtonGroup.tu
 Filesize:  4.58 KB
 Downloaded:  178 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Tue Feb 19, 2013 3:58 pm   Post subject: RE:[Class] ButtonGroup

note there are a couple bugs, if anyone finds them and wants the fixes, I'll update it
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  [ 2 Posts ]
Jump to:   


Style:  
Search: