The only way I can find to clear a transparent canvas from its previous drawing is
to FREE the canvas an create it again.... works fine
However after another window was shown the canvas never shows again, until I refresh the browserpage (F5)
QUESTION: WHAT am I doing wrong here.
Code: Select all
Enumeration
#grid
#canvas
#redraw_button
#menu_button
#mainwindow
#popupwindow
EndEnumeration
Procedure drawbar()
For tmp.i = 0 To 800 Step 50
h.i = Random(0,400)
AddPathBox(tmp,500-h,40,h)
VectorSourceColor(RGBA(Random(0,255),Random(0,255),Random(0,255),255))
FillPath(#PB_Path_Preserve)
StrokePath(2)
Next tmp
EndProcedure
Procedure Event_on_gadget()
Select EventType()
Case #PB_EventType_LeftClick ;left clicks
Select EventGadget()
Case #redraw_button
CloseWindow(#popupwindow)
SetActiveWindow(#mainwindow)
;remark below line to NOT recreate the drawing canvas
If IsGadget(#canvas):FreeGadget(#canvas):CanvasGadget(#canvas,100,100,800,500,#PB_Canvas_Border | #PB_Canvas_Transparent): EndIf
StartVectorDrawing(CanvasVectorOutput(#canvas))
drawbar()
ResetPath()
StopVectorDrawing()
Case #menu_button
OpenWindow(#popupwindow,500,50, 740, 410, "WINDOW WILL BE KILLED with REDRAW button",#PB_Window_SystemMenu | #PB_Window_TitleBar)
EndSelect
EndSelect
EndProcedure
If OpenWindow(#mainwindow, 100, 100, 1000, 700, "2DDrawing Example")
CanvasGadget(#grid,100,100,800,500,#PB_Canvas_Border)
StartDrawing(CanvasOutput(#grid))
For tmp.i = 0 To 800 Step 10
LineXY(tmp,0,tmp,500,RGB(200,200,200))
Next tmp
For tmp.i = 0 To 500 Step 10
LineXY(0,tmp,800,tmp,RGB(200,200,200))
Next tmp
StopDrawing()
ButtonGadget(#redraw_button,20,20,50,25,"redraw")
ButtonGadget(#menu_button,20,60,50,25,"menu")
CanvasGadget(#canvas,100,100,800,500,#PB_Canvas_Transparent)
BindEvent(#PB_Event_Gadget,@Event_on_gadget())
EndIf