Canvas fill the whole window?
BlitzMax Forums/MaxGUI Module/Canvas fill the whole window?
| ||
| How do I make a canvas always be the entire size of the window even after the window is resized? I tried this but it doesn't seem to make the canvas larger when the windown gets larger than the size it started at. SetGadgetShape(canvas,0,0,GadgetWidth(window),GadgetHeight(window)) |
| ||
SetGadgetShape canvas,EDGE_CENTERED,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED insert this after you create the canvas and the canvas will automatically be resized. Also, you should use ClientWidth and ClientHeight instead of GadgetWidth and GadgetHeight to find the client area of the window. |
| ||
Ok you mean setgadgetlayout, I just did that and now it *almost* works. Heres my code, it runs by itself.
Strict
Local window:tgadget
window = CreateWindow("",200,100,400,400)
Local canvas:tgadget
canvas = CreateCanvas(0, 0, ClientWidth(window), ClientHeight(window), window)
SetGadgetLayout canvas,EDGE_CENTERED,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED
SetGraphics CanvasGraphics(canvas)
Repeat
PollEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_WINDOWSIZE
SetGadgetShape(canvas,0,0,ClientWidth(window),ClientHeight(window))
EndSelect
SetColor Rnd(255),0,0
DrawRect Rnd(2000),Rnd(2000),33,33
Flip
Forever
|
| ||
window = CreateWindow("",200,100,400,400,Null,WINDOW_CLIENTCOORDS)Let me know if this works, cos its the only major differance I can see between yours and mine(cept for some reason tgadget isnt being reconised, so cannot run it. Syncing) Edit: Ok Synced. Seemed to have lost MaxGui? Weird. Anyway it does exactly what you asked for (that is The Canvas fills the whole window, but its probably not what you wanted. oh um) |
| ||
| hmm adding that didn't do the trick. When I resize the window to make it larger, it still only draws rectangles on the area that was the original size of the window. |
| ||
| @Curtastic: You also need to reset the viewport and redraw the canvas like so:
SuperStrict
Local window:TGadget = CreateWindow("",200,100,400,400)
Local canvas:TGadget = CreateCanvas(0, 0, ClientWidth(window), ClientHeight(window), window)
SetGadgetLayout canvas, EDGE_CENTERED, EDGE_ALIGNED, EDGE_CENTERED, EDGE_ALIGNED
SetGraphics CanvasGraphics(canvas)
Local rectsize:Int = 33
Repeat
PollEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_WINDOWSIZE
SetGadgetShape(canvas, 0, 0, ClientWidth(window), ClientHeight(window))
SetViewport 0, 0, ClientWidth(window), ClientHeight(window)
RedrawGadget(canvas)
Case EVENT_GADGETPAINT
SetGraphics CanvasGraphics(canvas)
Cls
EndSelect
SetColor Rnd(255), 0, 0
DrawRect Rand(GadgetWidth(canvas) - rectsize), Rand(GadgetHeight(canvas) - rectsize), rectsize ,rectsize
Flip
Forever
CODE EDIT: Added Cls in EVENT_GADGETPAINT case. |
| ||
| Ah I never thought about resetting the viewport. Thanks a bunch! |
| ||
| Seriously. This was driving me a bit nuts. |