Some Tips using VectorDrawing lib.
Posted: Sat Nov 11, 2017 7:17 am
Removed
See the last post for better tech.
- Load progress
- Busy
- Animate In Out
See the last post for better tech.
- Load progress
- Busy
- Animate In Out
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
UseGIFImageDecoder()
Enumeration
#win
#bouton
#Gadget_Text
#gadget_g
#image
EndEnumeration
Restore Sign:
Declare playanimation(*hgif)
; on precharge le Gif se trouvant sur le Net
AnimatedGIF.s = GetTemporaryDirectory() + "_test.gif"
If Not FileSize(AnimatedGIF) > 0
InitNetwork()
ReceiveHTTPFile("https://icons8.com/preloaders/preloaders/301/Windows8%20loader.gif", AnimatedGIF)
EndIf
If AnimatedGIF
UseGIFImageDecoder()
hGIF = LoadImage(#PB_Any, AnimatedGIF)
If IsImage(hGIF)
nWidth = ImageWidth(hGIF) : nHeight = ImageHeight(hGIF)
ENdif
Endif
Global Thread
If OpenWindow(#win, 0, 0, 200, 300, "Signe d'attente.", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget (#bouton, 10, 10, 200, 20, "Cliquez moi")
TextGadget(#Gadget_Text, 100, 50, 100, 35, "")
ImageGadget(#Gadget_g, 50, 150, nWidth, nHeight, #Null)
Thread=CreateThread(@PlayAnimation(), hGIF)
HideGadget(#Gadget_g, #True) ; cache le gadget
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #bouton
HideGadget(#Gadget_g, #False); montre le gadget
; boucle de traitement
For i=1 to 50000
compteur_sign=compteur_sign+1
if compteur_sign=5:compteur_sign=1:Restore Sign :Endif
Read.s sig.s
SetGadgetText(#Gadget_Text, sig.s)
WindowEvent()
Next i
SetGadgetText(#Gadget_Text, "")
HideGadget(#Gadget_g, #True) ; cache le gadget
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
If IsThread(Thread)
KillThread(Thread)
Endif
FreeImage(hGIF)
EndIf
; ********* Zone Procedures *******************
Procedure PlayAnimation(*hGIF)
;JHPJHP
FrameCount = ImageFrameCount(*hGIF)
Repeat
For rtnCount = 0 To FrameCount - 1
SetImageFrame(*hGIF, rtnCount)
SetGadgetState(#Gadget_g, ImageID(*hGIF)) : Delay(40)
Next
ForEver
EndProcedure
DataSection
sign:
Data.s "|o---|"
Data.s "|-o--|"
Data.s "|--o-|"
Data.s "|---o|"
Data.s "|--o-|"
EndDataSection
Code: Select all
Global bColor.q
;x = x0 + r*Cos(t)
;y = y0 + r*Sin(t)
Procedure createIMG()
If CreateImage(0, 120, 120)
StartVectorDrawing(ImageVectorOutput(0))
VectorSourceColor(bColor)
FillVectorOutput()
alpha = 255
For angle = 30 To 361 Step 30
VectorSourceColor(RGBA(255,0,0,alpha))
x = 60 + 50*Cos(Radian(angle))
y = 60 + 50*Sin(Radian(angle))
AddPathCircle(x,y, 8)
FillPath()
alpha - 15
Next
StopVectorDrawing()
EndIf
EndProcedure
LoadFont(0, "Georgia", 8, #PB_Font_Bold)
Procedure runCB(par)
Repeat
alpha = 255
For angle = 361 To 0 Step -15
If IsGadget(0)
StartVectorDrawing(CanvasVectorOutput(0))
DrawVectorImage(ImageID(0), 255)
MovePathCursor(60, 60)
AddPathCircle(60, 60, 60, 15, angle, #PB_Path_Connected)
VectorSourceColor(bColor)
FillPath()
VectorSourceColor(RGBA(0,0,255,alpha))
MovePathCursor(40, 50)
VectorFont(FontID(0), 18)
DrawVectorText("Busy")
alpha - 15
StopVectorDrawing()
Delay(50)
EndIf
Next
ForEver
EndProcedure
If OpenWindow(0, 0, 0, 400, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,$E4E4E5)
bColor = GetWindowColor(0)
If bColor < 0
StartDrawing(WindowOutput(0))
bColor = Point(100,100)
StopDrawing()
EndIf
bColor = bColor | $FF000000
createIMG()
CanvasGadget(0, 150, 150, 120, 120)
thread = CreateThread(@runCB(),35)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
Code: Select all
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
KillThread(thread)
Quit = 1
EndSelect
Until Quit = 1
Code: Select all
Global bColor.q,qFlag
Procedure createIMG()
If CreateImage(0, 120, 120)
StartVectorDrawing(ImageVectorOutput(0))
VectorSourceColor(bColor)
FillVectorOutput()
alpha = 255
For angle = 30 To 361 Step 30
VectorSourceColor(RGBA(255,0,0,alpha))
x = 60 + 50*Cos(Radian(angle))
y = 60 + 50*Sin(Radian(angle))
AddPathCircle(x,y, 8)
FillPath()
alpha - 15
Next
StopVectorDrawing()
EndIf
EndProcedure
LoadFont(0, "Georgia", 8, #PB_Font_Bold)
Procedure runCB(par)
Repeat
alpha = 255
For angle = 361 To 0 Step -15
If qFlag = 1
Break
EndIf
StartVectorDrawing(CanvasVectorOutput(0))
DrawVectorImage(ImageID(0), 255)
MovePathCursor(60, 60)
AddPathCircle(60, 60, 60, 15, angle, #PB_Path_Connected)
VectorSourceColor(bColor)
FillPath()
VectorSourceColor(RGBA(0,0,255,alpha))
MovePathCursor(40, 50)
VectorFont(FontID(0), 18)
DrawVectorText("Busy")
alpha - 15
StopVectorDrawing()
Delay(50)
Next
ForEver
EndProcedure
If OpenWindow(0, 0, 0, 400, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,$E4E4E5)
bColor = GetWindowColor(0)
If bColor < 0
StartDrawing(WindowOutput(0))
bColor = Point(100,100)
StopDrawing()
EndIf
bColor = bColor | $FF000000
createIMG()
CanvasGadget(0, 140, 120, 120, 120)
thread = CreateThread(@runCB(),35)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
qFlag = 1
Delay(100)
Quit = 1
EndSelect
Until Quit = 1
EndIf