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

Username:   Password: 
 RegisterRegister   
 Creating a custom button
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jeffmagma




PostPosted: Wed Jan 06, 2016 8:53 pm   Post subject: Creating a custom button

What is it you are trying to achieve?
Create a custom button


What is the problem you are having?
I cannot have more than one button on the screen at the same time. Since there is a loop inside the procedure, it will never get to the next button.


Describe what you have tried to solve this problem
Well... I've thought about it... and thought about it some more...


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This creates ONE button on the screen

Turing:
%Shows a custom button with a starting animation
proc showbuttonc (x, y : int, text : string, procs : procedure x ())
    var mx, my, mb : int
    for i : 0 .. 14
        drawline (x, y + i + 10, x + 100, y + i + 10, black)
        drawline (x, y - i + 13, x + 100, y - i + 13, black)
        drawline (x, y + i + 11, x + 100, y + i + 11, 53)
        drawline (x, y - i + 12, x + 100, y - i + 12, 53)
        drawfillbox (x, y + i + 9, x + 100, y - i + 14, 52)
        View.Update
        delay (50)
    end for
    drawfillbox (x, y, x + 100, y + 23, 52)
    Font.Draw (text, x + 50 - (Font.Width (text, fontButton) div 2), y + 4, fontButton, black)
    View.Update
    loop
        mousewhere (mx, my, mb)
        exit when mx > x and mx < x + 100 and my > y and my < y + 23 and mb = 1
    end loop
    procs
end showbuttonc


Please specify what version of Turing you are using
OpenTuring 1.0.1 (Wait what happened to OpenT?)
Sponsor
Sponsor
Sponsor
sponsor
nulldev




PostPosted: Wed Jan 06, 2016 9:14 pm   Post subject: Re: Creating a custom button

This problem is easily solved using OOP (Object Oriented Programming). Go read up on OOP if you don't know what it is. Create a class for a button and have it store the button's shape. When creating the buttons, create instances of the button class and add them to an array. The you can loop over each of the buttons in the array in the game loop and continuously check if the mouse is inside any of them.

Here is a link to the guide for OOP in Turing (it's REALLLLYYYY LOOONG): http://compsci.ca/holtsoft/OOTRef.pdf
Here is a link to a shorter OOP guide but it applies to any programming language: http://www.aonaware.com/OOP1.htm
Insectoid




PostPosted: Thu Jan 07, 2016 4:20 pm   Post subject: RE:Creating a custom button

Learning OOP is a huge undertaking (My university has an entire class dedicated to it) and Turing's implementation of it is pretty awful, so I wouldn't bother until you get around to learning a more useful language.

You can make multiple buttons pretty easily, but you'll need to restructure your program a bit. The only button that should activate an 'exit when' is your quit button. All other buttons should activate procedures. Your program structure should look like this:

code:

loop
    Mouse.Where ()
    %draw all buttons here

    %if (button 1 is clicked) then
        %do stuff
    else if (button 2 is clicked) then
        %do other stuff
    %repeat for other buttons
    end if
    exit when (exit button clicked)
end loop
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: