----------------------------------- recneps Mon Feb 09, 2004 4:13 pm Buttons for Dummies! ----------------------------------- I saw someone make a post in AsianSensation's "Suggest a Tutorial" post and thought i'd clarify it for the people. First off, lets see what the Turing Reference Says about buttons. : Syntax GUI.CreateButton (x, y, width : int, text : string, actionProc : procedure x ()) : int GUI.CreateButtonFull (x, y, width : int, text : string, actionProc : procedure x (), height : int, shortcut : char, default : boolean) : int Description Creates a button and returns the button's widget ID. The button widget is used to implement a textual button. When you click on a button, the button's action procedure is called. If a button is given a short cut, then entering the keystroke will cause the action procedure to be called. It will not visibly cause the button to depress. Two Buttons The x and y parameters specify the lower-left corner of the button. The width parameter specifies the width of the button. If width is less than the size necessary to display the button, the button is automatically enlarged to fit the text. The text parameter specifies the text to appear in the button. The actionProc parameter is the name of a procedure that is called when the button is pressed. For GUI.CreateButtonFull, the height parameter specifies the height of the button. If height is less than the size necessary to display the button, the button is automatically enlarged to fit the text. The shortcut parameter is the keystroke to be used as the button's shortcut. The default parameter is a boolean indicating whether the button should be the default button. If there is already a default button, and default is set to true, then this button becomes the new default button. Since this is "Buttons for Dummies", forget the CreateButtonFull. Got that? Bye! So now, we have The syntax, the description, and the explanation of the syntax. So let me clarify. this is how you use the GUI.CreateButton command. First, tell Turing you're gonna be using GUI, place this line at the top of your program. import GUI Next, create procedures containing all the work you want that button to do, like.... procedure hello put "Hello User, you have clicked Button #1!" end hello procedure hi put "Hello User, you have clicked Button #2!!" end hi Next, declare the button names as variables. var button1 :int var button2:int and Turn those variables into buttons! var button1:int:=GUI.CreateButton var button2:int:=GUI.CreateButton And finally, fill in the parameters for them. var button1:int:=GUI.CreateButton(x,y,0,"Button Text",procedure) var button2:int:=GUI.CreateButton(x,y,0,"Button Text",procedure) Where x and y are the bottom left corner of the button, and "0 is the width of the button( note: The width will be incresed if the button text is larger than the width of the button specified) "ButtonText" is the text on the button's face, and procedure is the procedure you named above that you want the button to call when being pressed. Finally, you need to have a little thing in there to keep the program going until a button is pressed, otherwise it would just draw the button, and then finish the program. so we add: loop exit when GUI.ProcessEvent end loop And thats it! So now we put it all together...... import GUI setscreen("graphics:300;125") procedure hello locate(1,1) put "Hello User, you have clicked Button #1!" end hello procedure hi locate(1,1) put "Hello User, you have clicked Button #2!!" end hi var button1:int:=GUI.CreateButton(25,25,0,"Button 1",hello) var button2:int:=GUI.CreateButton(25,50,0,"button 2",hi) loop exit when GUI.ProcessEvent end loop ----------------------------------- Paul Mon Feb 09, 2004 4:18 pm ----------------------------------- Hey! Are you implying Im a dummy? (j/k), thanks for the tutorial +bits. Oh yea, the import is lowercase, and the text writes over the buttons. What does GUI.ProcessEvent do exactly? Does it call anything with GUI in it? Thats why I don't know how to clear it. :( ----------------------------------- recneps Mon Feb 09, 2004 4:22 pm ----------------------------------- oops! forgot to make those changes! Its fixed now. And GUI . Process Event... if you break it down, it literally starts an infinite loop, UNTIL that GUI processes something (the button click) Get it? ----------------------------------- Paul Mon Feb 09, 2004 4:27 pm ----------------------------------- Oh, so when you do this: var button1:int:=GUI.CreateButton var button2:int:=GUI.CreateButton The buttons are automatically drawn? ----------------------------------- Delta Mon Feb 09, 2004 6:27 pm ----------------------------------- Heck no! Writing the : var button1:int:=GUI.CreateButton var button2:int:=GUI.CreateButton does absolutely nothing, besides giving you an error of course... I'm not sure why he would put that in there :? sure its for dummies but still it gets ppl confused :? And ya without the GUI.ProcessEvent your GUI commands won't work... GUI.ProcessEvent processes and event such as keyboard or mouse events (clicks, key strokes) if one of these events call a widget(your button/textfield/gui stuff) then it works... ----------------------------------- AsianSensation Mon Feb 09, 2004 9:13 pm ----------------------------------- good attempts at tutorials now if everyone begins to write a tutorial, we'll soon have enough to get all kinds of people at all different levels started. here, have some bits. +35 bits ----------------------------------- shorthair Mon Feb 09, 2004 10:04 pm ----------------------------------- i think there is a thread about how to reset , the gui event , so that you can have multiple buttons in differnt parts of the program , but in hte turing 5 documentation there is a F9 about a command that resets it automatically , its a good update , if i had turing handy id give it to you, but im sure someonne here knows what it is ----------------------------------- recneps Tue Feb 10, 2004 3:56 pm ----------------------------------- Well, i wrote it in pieces, set by step of what you have to do, so that was the first part var button1:int:=GUI.CreateButton var button2:int:=GUI.CreateButton and then i went on to tell you you needed to add things to it, like: var button1:int:=GUI.CreateButton(x,y,width,"text",proc) var button2:int:=GUI.CreateButton(x2,y2,width2,"text2",proc2) Understand now? the button will be drawn after you add in the parameters, x and y positions of the bottom left corner, height(automatically expands to fit the text if needed), the text on the button face, and the procedure the button calls when clicked. P.S. Thanks for bits! :D I'm thinking of more tutorials that people really need :) ----------------------------------- the_short1 Tue Feb 10, 2004 7:26 pm ----------------------------------- VERY COOL!!!! i was just thinking on asking Templest for help on this ssince hes the Aclaimed master GUI! i want to fix my unit converter with each button and have a pop up area show the buttons FULL NAME!!!! Id give you bits... but i saving up for a email now...only 1900 to go... (i have lots in my title) ----------------------------------- the_short1 Tue Feb 10, 2004 8:26 pm ----------------------------------- btw is there a specific command for making a rounded button (oval) for my unit converter words.... the normal ones are too big....even with just letter a in button and width of 0 or should i just make a Menu for the Base and new unit of measure? Thanks,.....(I AM GUI NOOB) ----------------------------------- recneps Tue Feb 10, 2004 8:41 pm ----------------------------------- I dont believe there is a command for round buttons, if there is, then I dont know :D but you could make your own buttons , they just wouldnt look as nice :) like drawoval(100,100,10,10,7) buttonwait("down",x,y,button,updown)%Or something like that. :p if x>90 and x90 and y