GUI buttons
Author |
Message |
richcash
|
Posted: Wed Jun 14, 2006 6:45 pm Post subject: GUI buttons |
|
|
If I make a button and call to a procedure with a parameter it doesn't work. For example :
code: | var button := GUI.CreateButton (0, 0, 0, "button", do (1)) |
Why can't I do this? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Wed Jun 14, 2006 6:51 pm Post subject: (No subject) |
|
|
GUI module passes a reference to the function, doesn't actually make a call to the function. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Ninja
|
Posted: Wed Jun 14, 2006 6:55 pm Post subject: (No subject) |
|
|
Tony wrote: GUI module passes a reference to the function, doesn't actually make a call to the function.
Yep. for example look at this code, this is from the turing manual:
code: |
import GUI
procedure DrawRandomCircle
var r : int := Rand.Int (20, 50)
var x : int := Rand.Int (r, maxx - r)
var y : int := Rand.Int (r, maxy - r)
var c : int := Rand.Int (0, maxcolor)
Draw.FillOval (x, y, r, r, c)
% In case we drew over the buttons, redraw them.
GUI.Refresh
end DrawRandomCircle
View.Set ("graphics:300;200,nobuttonbar ")
var draw : int := GUI.CreateButtonFull (50, 10, 0, "Draw Circle",
DrawRandomCircle, 0, '^D', true)
var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit)
loop
exit when GUI.ProcessEvent
end loop |
when you are making a button using the GUI module, you have to specify what function to pass reference to. In this program the first button is passing reference to the DrawRandomCircle procedure, but the other one uses the built in function the GUI.Quit for which you dont have to write a separate procedure. |
|
|
|
|
![](images/spacer.gif) |
richcash
|
Posted: Wed Jun 14, 2006 7:02 pm Post subject: (No subject) |
|
|
Oh yeah, that's right, thx. That's kind of inconvenient, but so is the whole GUI module! |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Wed Jun 14, 2006 7:06 pm Post subject: (No subject) |
|
|
you could always hack away at the GUI module's code to get it to work for you. Remember that you'd need to include all of the files with source to compile properly.
What are you trying to do anyways? It sounds like you're trying to generate a load of buttons inside some loop. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
richcash
|
Posted: Wed Jun 14, 2006 8:44 pm Post subject: (No subject) |
|
|
Oh, I just wanted the button to call my draw procedure for a card game but I wanted to make the same procedure for both the cpu and the user. So, draw (1) gives the user a new card in his hand, and draw (2) gives the computer a new card. I only want the 'Draw' button I create to give the user a card. Obviously I can work around it, I just like doing things really efficiently! |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Wed Jun 14, 2006 8:52 pm Post subject: (No subject) |
|
|
what you can do is set up a mini-function for the button
code: |
var button := GUI.CreateButton (0, 0, 0, "button", mini_fnc() )
|
where
code: |
func mini_fnc()
%call draw on user's behalf
draw(1)
end mini_fnc
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
richcash
|
Posted: Wed Jun 14, 2006 8:59 pm Post subject: (No subject) |
|
|
Could you further explain this technique because I know you can't call functions as the action for a button? Or did you mean to make mini_fcn a proc? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Wed Jun 14, 2006 9:02 pm Post subject: (No subject) |
|
|
a procedure is a void function (does not return results). And yes, I meant a procedure. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
richcash
|
Posted: Wed Jun 14, 2006 9:07 pm Post subject: (No subject) |
|
|
Yeah, I know a procedure is really a function. I never thought of this, just calling my proc with parameters in another one for the button. Thanks for the help!!! |
|
|
|
|
![](images/spacer.gif) |
|
|