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

Username:   Password: 
 RegisterRegister   
 Custom Buttons with Variable Parameter Action Procedures!
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Clayton




PostPosted: Fri Dec 07, 2007 8:05 pm   Post subject: Custom Buttons with Variable Parameter Action Procedures!

Well, it's a start at least. A few things you should know for now:

  1. This is a very rough implementation, and nowhere near complete
  2. There is absolutely no commenting in the code, this was written in ~1/2 an hour, so give me a break
  3. This is being released with the expectation that if this is being used, credit will be given to the original author
  4. That being said, modify away! Just remember the credit Smile
  5. I'm planning on reworking this, for now, just deal with it if you want to use it.


With that, I'd like to document this for now. To start with, you can still use this the exact same way you could've before I added the action procedure code. However, if you want to experiment, I'll give some documentation on how to do so.

First, the old documentation on all of the old methods for creating the buttons:
Turing:
Buttons.Create (x, y : int, text : string) : int


Give Create an (x, y) orderec pair, along with the text you want on it, it'll do the rest.

Turing:
Buttons.CreateFull (x, y, width, height : int, text : string) : int


Allows you to customize your button's width and height, otherwise, everything else is the same.

Turing:
Buttons.Refresh (button_id : int)


Redraws the button that you pass it.

Turing:
Buttons.EnableRollover (button_id : int, choice : boolean, clr : int)


Enables/disables the rollover effect of your button based on whether choice is true or false. true sets rollover to on, false, off.

Turing:
Buttons.Pressed (button_id : int) : boolean


Returns true if the button passed to Pressed has been pressed down on.

Now, you need to realize that in order to do this, I really had to redo the way you handle basic data types. Each of the four has it's own class, all of which subclass from Object. So, instead of having reals, strings, ints, and booleans, you now have a class representing each, Float, String, Integer, and Boolean respectively. Each class has it's own setter and getter methods (the setter a procedure, the getter a function), as well as a to_s function and a is_a function. The to_s function represents your data as a string (Ruby users will recognize that), and the is_a function, taking a string as an argument, will return a boolean if the object_type of your data is the same as the argument you pass to it.

As a side note, the getters and setters for each data type is in the form of get/set_<datatype>_value. Unfortunately, right now, you can't create your own objects to use for parameters because I had to handle things a really clunky way. I am working on a way to handle any and all types that are Objects.

With that, to create your button that points to an action procedure, you need to take advantage of Buttons.CreateFullAction() function. It looks like this:

Turing:
Buttons.CreateFullAction (x, y, width, height : int, text : string, action_proc : procedure action (args : array 1 .. * of ^Object)) : int


So, your action procedure must take all of it's arguments as a single array of Objects, with which you can do what you wish. Now, to detect when the button has been pressed, and call your action procedure, you need to use the Buttons.ProcessForAction() procedure, where you pass the button's ID, as well as the array of arguments you wish to pass to it.

Turing:
Buttons.ProcessForAction (button_id : int, arguments : array 1 .. * of ^Object)


Well, it's kind of hard to explain this all in type, so I've included an example program in the attached folder called Test.t. Check it out for more information on how it works. Updates to come.



Multiple Var Action Procedures.zip
 Description:
All of the unit files and example program you need.

Download
 Filename:  Multiple Var Action Procedures.zip
 Filesize:  3.98 KB
 Downloaded:  191 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Fri Dec 07, 2007 8:19 pm   Post subject: RE:Custom Buttons with Variable Parameter Action Procedures!

thats really cool its kinda little confusing at first then it sinks in : "omg this is amazing"
also I remember when we both tried to figure this out, guess you beat me to the punch Wink
Clayton




PostPosted: Fri Dec 07, 2007 8:28 pm   Post subject: RE:Custom Buttons with Variable Parameter Action Procedures!

Yeah, well, this feels extremely hackish to me (and it is). The issue lies with the fact that Turing can't polymorphisize (sp?) procedures/functions into other procedures/functions with different parameter types. I'm still brainstorming a couple of other ways to handle this problem as I'm typing this out.
CodeMonkey2000




PostPosted: Fri Dec 07, 2007 9:31 pm   Post subject: RE:Custom Buttons with Variable Parameter Action Procedures!

Try ditching turing Razz. Anyway, this is pretty complicated, with all the pointer passing. My problem is how does turing know which set_variable_value it's dealing with, as it's declared in both object and variable type.

EDIT:Oh wait, it's inherited. I see now.
SNIPERDUDE




PostPosted: Sun Dec 09, 2007 5:24 pm   Post subject: Re: Custom Buttons with Variable Parameter Action Procedures!

I made a similar type of prog a while ago. After working with vb, (also hating turing's GUI) I decided to make my own class of buttons, scroll bars, messageboxes, etc. I also decided to spice it up with pic graphics and everything (I had about 5 diff styles you could choose from, one of them being XP [because it was using pics, the XP style would work on Win 2000s as well]). It worked by within the parameters you would type in the proc name, so when the button was clicked it would run that procedure.

I would have to find it, fix it, and post it which I might do later provided I remember.

good work though, through a bit more work this could be really cool.
Keep up the good work! Very Happy
LaZ3R




PostPosted: Sun Dec 09, 2007 8:13 pm   Post subject: Re: Custom Buttons with Variable Parameter Action Procedures!

Seems like it could be useful but I find this is a much more simple way, and easier to debug. Very effective and only take 10-15 lines for the base of it, and around 5-6 lines for each button with the effect you want to do with it.

Just made two buttons quickly to show


I used this type of button creation for any programs I made because, I hated the look of GUI and the retarded implementation of it into a program, and more importantly, how much cooler and better looking you can make buttons on your own like this.

Turing:
View.Set ("graphics:400;400,nobuttonbar,offscreenonly")
var f1 : int := Font.New ("comic:25:bold")
var mx, my, button : int

proc start
    put "STARTING... nothing... going back to menu"
    View.Update
    delay (2000)
    cls
end start

proc flashy
    put "Oooohhh FlashyyyYY"
    View.Update
    delay (2000)
    cls
end flashy

loop
    Mouse.Where (mx, my, button)
    if mx > 50 and mx < 200 and my > 300 and my < 325 then
        drawfillbox (50, 300, 200, 325, brightred)
        if button = 1 then
            cls
            start
        end if
    elsif mx > 50 and mx < 200 and my > 150 and my < 175 then
        for i : 1 .. 149
            Mouse.Where (mx, my, button)
            drawfillbox (50 + i, 150, 50 + i, 175, Rand.Int (1, 255))
            if button = 1 then
                cls
                flashy
            end if
        end for
    end if
    drawbox (50, 300, 200, 325, black)
    drawbox (50, 150, 200, 175, black)
    Font.Draw ("Start", 88, 300, f1, black)
    Font.Draw ("Flashy", 74, 150, f1, black)
    View.Update
    delay (15)
    cls
end loop
Clayton




PostPosted: Sun Dec 09, 2007 8:40 pm   Post subject: RE:Custom Buttons with Variable Parameter Action Procedures!

See... the thing is, my buttons take all of your code and squish it down into one line of creation. Really, if you find yourself doing that over and over again in a program, you're doing something wrong. Don't forget, keep things DRY. (Don't Repeat Yourself)
Nick




PostPosted: Sun Dec 09, 2007 9:32 pm   Post subject: RE:Custom Buttons with Variable Parameter Action Procedures!

also another added benefit to Clayton's module that you dont get with turung's GUI (or even mine for that matter) is that he allows you to pass a procedure with parameters through the buttons
Sponsor
Sponsor
Sponsor
sponsor
LaZ3R




PostPosted: Sun Dec 09, 2007 9:58 pm   Post subject: RE:Custom Buttons with Variable Parameter Action Procedures!

Yep, that's why I see the use in it :p.

Only thing is it's not like I'm making a MILLION buttons for one program!! Very Happy

Then again, some of his code looks slightly confusing to me. Smile
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  [ 9 Posts ]
Jump to:   


Style:  
Search: