[solved] ImageGadget - SetGadget State Flicker
Posted: Tue Aug 05, 2014 11:03 pm
The snippet below shows basically what I'm trying to do, and the flicker issue caused by an ImageGadget() update.
In fact in the real world the flicker is far worst, because shapes/lines are drawn dynamically by the User by dragging the mouse. If the drawing output is to the Window rather than the image, there is of course no flicker problem but there are issues updating dynamic shapes/lines as they intersect others and Undo -Redo is slow. A CanvasGadget() might be the answer to all these issues, but it can't be transparent?
Code: Select all
Enumeration
#Win
#Img
#ImageGdt
#Cntr
#BtnBox
#BtnExit
EndEnumeration
Global igTrans = RGBA(128,128,000,000) ;Transparent
Global igOpaque = RGBA(128,128,000,255)
Procedure Win()
;--------------
Protected iExit.i = #False
Protected iFlags.i = #PB_Container_BorderLess | #PB_Container_Flat
If OpenWindow(#Win, 0, 0, 800, 600, "", #PB_Window_ScreenCentered)
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(#Win), igTrans, 0, #LWA_COLORKEY)
CreateImage(#Img, 800, 550, 32, igOpaque)
ImageGadget(#ImageGdt, 0, 50, 800, 550, ImageID(#Img))
ContainerGadget(#Cntr, 0, 0, 800, 50, iFlags)
ButtonGadget(#BtnBox, 2, 2, 100, 26, "Draw Boxes")
ButtonGadget(#BtnExit, 105, 2, 100, 26, "Exit")
SetGadgetColor(#Cntr, #PB_Gadget_BackColor, RGB(096,096,096))
CloseGadgetList()
StickyWindow(#Win, #True)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_Gadget
Select EventGadget()
Case #BtnExit: iExit = #True
Case #BtnBox
If StartDrawing(ImageOutput(#Img))
Box(150,100,100,100,RGB(Random(255),Random(255),Random(255)))
Box(250,200,100,100,RGB(Random(255),Random(255),Random(255)))
Box(300,300,100,100,RGB(Random(255),Random(255),Random(255)))
Box(450,100,100,100,RGB(Random(255),Random(255),Random(255)))
Box(350,200,100,100,RGB(Random(255),Random(255),Random(255)))
StopDrawing()
EndIf
SetGadgetState(#ImageGdt,ImageID(#Img))
EndSelect
EndSelect
Until iExit = #True
EndIf
EndProcedure
Win()
End