Bug in CanvasGraphics
BlitzMax Forums/MaxGUI Module/Bug in CanvasGraphics
| ||
Hi all, Is there a specific method for resizing a canvas? After resizing the window it appears that the canvas graphic object gets lost somewhere in the pipeline even though everything seems valid. Before I roll my sleeves up for some internal debugging, have I missed something obvious? This is a seriously cut down version to demonstrate. I've tried it on Win8,Win7 and Vista and get the same effect. I actually get an EAV in the real program, but this little snippet still demonstrates the loss of the graphics rendering after resizing the window. Strict Import MaxGUI.Drivers Global Window:TGadget = CreateWindow("Canvas Test",0,0,400,400,Null,WINDOW_DEFAULT|WINDOW_CENTER) Global Canvas:TGadget = CreateCanvas(0,0,ClientWidth(Window),ClientHeight(Window),Window) SetGadgetLayout(Canvas,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED) Global Timer:TTimer = CreateTimer(5) Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_WINDOWSIZE SetGraphics(Null) ' FreeGadget(Canvas) ' Uncomment for EAV Canvas = CreateCanvas(0,0,ClientWidth(Window),ClientHeight(Window),Window) Case EVENT_TIMERTICK RedrawGadget(Canvas) Case EVENT_GADGETPAINT SetGraphics(CanvasGraphics(Canvas)) Cls DrawText(Rnd(0,1000),0,0) Flip 0 EndSelect Forever Last edited 2012 |
| ||
Try to set the viewport after setting the graphics SetGraphics CanvasGraphics (Canvas) SetViewport 0,0,GadgetWidth(Canvas),GadgetHeight(Canvas) EDIT Oh, overlooked your code here: Case EVENT_WINDOWSIZE SetGraphics(Null) ' FreeGadget(Canvas) ' Uncomment for EAV Canvas = CreateCanvas(0,0,ClientWidth(Window),ClientHeight(Window),Window) Why do you set the grahics to NULL and recreate the gadget, that is normally not needed Last edited 2012 |
| ||
Still the same unfortunately. Internally, the graphic object defaults to the d3d9 driver. After resizing, the d3d9 device and graphics object seem valid, and does change with each CreateCanvas. Hmm, it seems that a handle of some kind may be being held onto when it shouldn't. |
| ||
Why do you set the grahics to NULL and recreate the gadget, that is normally not needed Lol. That was the problem. You know, I havent the faintest idea why I was doing that!!! haha. Thanks jsp. EDIT:- Ahh, I remember now why! When I was resizing, the drawn area wasn't resizing and I thought the gadget needed recreated at the bigger size. As you point out above SetViewport is what is needed. Thanks again. Last edited 2012 |
| ||
May use also a hook to paint the canvas while resizing. some code: |
| ||
Thanks, In the real code I redraw from the WM_PAINT message from a richedit textarea at the os level using a windows api hook function. I do this because MaxGUI doesn't give me an event when I want it - ( when the richedit scrolls under ALL circumstances, either via keyboard - cursors, pageup/down or via the scroll bars ). I use the fact the textarea needs redrawing to do some canvas drawing in sync with it. |