Thanks, good points...
Rashad, tried both variants, the first hasn't worked here (or I did something wrong), but the second method works excellent.
I am still confused about what's going on in two points:
1. why I need to polish the #WaitTemp image after grabbing? The color depth is already 24 bit, so what is missing?
2. what about memory management? I am updating the imagegadget thousand of times, how can I free the generated images?
PS: I avoided CanvasGadget because I tried to preserve the background of the dialog and draw an overlaying image - but meantime I also think about grabbing the background content at the beginning which saves me to do overlays on the fly...
Here's a small example 'bout the actual trends...
Code: Select all
#AntiFlickering=0
Procedure Init()
Enumeration
#Win
#MakeStateProgress
#WaitIcon
#WaitTemp
EndEnumeration
#WaitSize= 21
#WaitSpace=3
#WaitBox= #WaitSize+#WaitSpace*2
#WaitHeight=#WaitSize
#WaitWidth= #WaitSize/3
#WaitLineX= #WaitSize
#WaitLineY= #WaitSize-3
#WaitLoop= (#WaitLineX+#WaitLineY-#WaitWidth*2)*4
#WaitColor= #Blue
#Wait_End= #WaitLoop*#WaitBox
OpenWindow(#Win,0,0,320,100,"Image Refresh",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CompilerIf #AntiFlickering<2
ImageGadget(#MakeStateProgress,148,40,#WaitBox,#WaitHeight,0)
CompilerElse
CanvasGadget(#MakeStateProgress,148,40,#WaitBox,#WaitHeight)
CompilerEndIf
AddWindowTimer(#Win,0,5)
CompilerIf #AntiFlickering
CreateImage(#WaitIcon,#Wait_End,#WaitHeight,24,GetSysColor_(#COLOR_BTNFACE))
CompilerElse
CreateImage(#WaitIcon,#Wait_End,#WaitHeight,32,#PB_Image_Transparent)
CompilerEndIf
StartDrawing(ImageOutput(#WaitIcon))
For i=0 To #WaitLoop-1
o=#WaitLineY*4+#WaitLineX*2-#WaitWidth*6
If i>=o
n=#WaitLineX-#WaitWidth
direction=3
Else
o=#WaitLineY*2+#WaitLineX*2-#WaitWidth*4
If i>=o
n=#WaitLineY-#WaitWidth
direction=2
Else
o=#WaitLineY*2-#WaitWidth*2
If i>=o
n=#WaitLineX-#WaitWidth
direction=1
Else
o=0
n=#WaitLineY-#WaitWidth
direction=0
EndIf
EndIf
EndIf
mode=i-o
m=mode/n*n
n+#WaitWidth
phase=mode-m
pos=Bool(m)*phase
If m
len=n-phase
Else
len=#WaitWidth+phase
EndIf
w=#WaitWidth
h=len
If direction&1
Swap w,h
EndIf
Select direction
Case 0
x=0 : y=n-pos-len
Case 1
x=pos : y=0
Case 2
x=#WaitLineX-#WaitWidth : y=pos
Case 3
x=n-pos-len : y=#WaitLineY-#WaitWidth
EndSelect
DrawingMode(#PB_2DDrawing_AllChannels|#PB_2DDrawing_Outlined)
Box(i*#WaitBox,0,#WaitBox,#WaitHeight,$FFFFFFFF)
x+i*#WaitBox+#WaitSpace
y+#WaitSpace-1
DrawingMode(#PB_2DDrawing_AllChannels)
Box(x,y,w,h,$FF000000)
Box(x+1,y+1,w-2,h-2,$FFff7060)
Next i
StopDrawing()
EndProcedure
Procedure Update(n)
GrabImage(#WaitIcon,#WaitTemp,(n%#WaitLoop)*#WaitBox,0,#WaitBox,#WaitHeight)
CompilerSelect #AntiFlickering
CompilerCase 0; 32-Bit Image
If GetKeyState_(#VK_SHIFT)&128
n=GadgetID(#MakeStateProgress)
GetClientRect_(n,r)
ValidateRect_(n,r)
EndIf
SetGadgetState(#MakeStateProgress,ImageID(#WaitTemp))
CompilerCase 1; 24-Bit Image
Protected Image
Image=CopyImage_(ImageID(#WaitTemp),#IMAGE_BITMAP,#WaitBox,#WaitHeight,#LR_COPYDELETEORG)
SetGadgetState(#MakeStateProgress,Image)
CompilerCase 2; 24-Bit Image & CanvasGadget
StartDrawing(CanvasOutput(#MakeStateProgress))
DrawImage(ImageID(#WaitTemp),0,0)
StopDrawing()
CompilerEndSelect
EndProcedure
Init()
While #True
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Timer
Update(n)
n+1
EndSelect
Wend