Buttons
Blitz3D Forums/Blitz3D Beginners Area/Buttons
| ||
So, I am trying to learn to create buttons. But I get a big problem. I want to create the button on the main screen. And I can't. There are no decent instructions for this. I am supposed to create the button as part of a group. I want the button to be on my main window. So far, the only group I have figured out exists is a new window. But I don't want a new window. What are the possible groups? Is it possible to have just a button without any group? The code I used was: SetBuffer BackBuffer() Cls While Not KeyHit(1) ;;;;;;;;;;;;;;;;;;;;;;;;;;;Interface;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SetFont LoadFont("Arial",14) Color 200,100,80 Rect 0,0,640,480,1 Color 150,200,225 Rect 0,0,640,20,1 ;;;;;;;;;;;;;;;;;;; Buttons ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; k1=0 kx=30 ky=80 Color 0,0,200 CreateButton( "First Button",100,100,100,20,MAINWINDOW,1) Flip Wend End ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; I have to create a window called MAINWINDOW to make this work. I don't want that. Thanks for helping with this! Guillermo |
| ||
You cannot create a button that's not part of a window... |
| ||
hm.. looks like you're mixing up 2d and gui here .. create a mainwindow, put a canvas on it, that'll be your drawing area for all your old 2d functions. next to the canvas you can put your buttons .. If you don't want to see the window border (the _[]x and the dragbar etc.), then use flag 0 for createwindow. and put a canvas on it, the size of the window you created. for full-screen: you could (1) define a window as big as your screeen with a similar sized canvas on it. Or (2) create a window as big as your screen, put a canvas on it which equals the size of your preferred 'output' and stretch it to the size of the window. e.g. in a 1024x768 window you can place a 640x480 canvas and stretch it to 1024x768. Now you can draw for 640x480, and still see it at 1024x768. If you make a game which should have a user-customizable resolution, without supporting special resolution-optimized gfx, use option 2. |
| ||
Thank you this helps somewhat. But I still end up with an original window that I don't use. Can't I just create my gui and every thing else in a single window? I do end up with two open windows, one black and one with my graphics and buttons. The code I used was: Graphics 800,600,0,3 w=CreateWindow( "Title1",0,0,600,400) cv=CreateCanvas( 5,5,590,390,w) SetBuffer CanvasBuffer(cv) Cls While Not KeyHit(1) ;;;;;;;;;;;;;;;;;;;;;;;;;;;Interface;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SetFont LoadFont("Arial",14) Color 200,100,80 Rect 0,0,640,480,1 Color 150,200,225 Rect 0,0,640,20,1 ;;;;;;;;;;;;;;;;;;; Buttons ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; k1=0 kx=30 ky=80 Color 0,0,200 CreateButton( "First Button",100,100,100,20,cv,1) Flip Wend End |
| ||
'graphics' does indeed open another window.. I'd say, ditch that whole 'graphics' command, and use a gui window with a canvas from now on. |
| ||
When I try ditching the praphics command, the computer requests it. I get a "you are not in graphics mode" message when I try to run the program. How do I solve this? |
| ||
For gfx commands you need to set the current drawing buffer to a canvas. setbuffer canvasbuffer(mylousydorkycanvas) ; your gfx commands here flipcanvas mylousydorkycanvas here, try this: (it's a fullscreen gfx-app based on a canvas, with all the advantages of the GUI stuff) notice: in the beginning I define a canvas, the size of 640x480. This means: the amount of pixels in the canvas, if you stretch the canvas (setgadgetshape, using setgadgetlayout settings), then you get bigger blurred pixels. Global sw=ClientWidth(Desktop()) Global sh=ClientHeight(Desktop()) Global APP=CreateWindow("",0,0,sw,sh,0,0) Global APPcanvas=CreateCanvas(0,0,640,480,APP) SetGadgetLayout APPcanvas,1,0,1,0 SetGadgetShape APPcanvas,0,0,sw,sh yourbutt=CreateButton ("quit!",64,32,32,32,APPcanvas) ; make a starfield! SetBuffer CanvasBuffer(APPcanvas) For t=0 To 1000 b#=Rnd(0,1) r#=b# * b# * b# g#=b# * b# b#=b# Color r#*255,g#*255,b*255 Plot Rnd(0,640),Rnd(0,480) Next FlipCanvas APPcanvas Confirm "u like it ? :)" quit=False timer=CreateTimer(50) Repeat f=f+1 WaitEvent() If EventID()=$803 ; alt f4 quit=True EndIf If EventID()=$401 ; button pressed quit=True EndIf If EventID()=$4001 ; timer event SetBuffer CanvasBuffer(APPcanvas) If (f Mod 100)=0 Cls SetGadgetShape yourbutt,Rnd(0,sw-32),Rnd(0,sh-32),32,32 EndIf Color Rnd(0,255),Rnd(0,255),Rnd(32,255) amp=Sin(f*11)*100 x=Sin(f*3)*(100-amp) y=Cos(f*2)*(100+amp) Line 320+x,240+y,0,0 Line 320+x,240+y,639,479 Line 320+x,240+y,639,0 Line 320+x,240+y,0,479 FlipCanvas APPcanvas EndIf Until quit ; opportunity to free images, banks, etc. here.. End |