Some Tips using VectorDrawing lib.
Some Tips using VectorDrawing lib.
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
Last edited by RASHAD on Tue Nov 14, 2017 4:56 am, edited 3 times in total.
Egypt my love
Re: Some Tips using VectorDrawing lib.
@RASHAD,
More very nice examples.
Thank you very much for sharing.
More very nice examples.
Thank you very much for sharing.
DE AA EB
- Andre
- PureBasic Team
- Posts: 2071
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: Some Tips using VectorDrawing lib.
Very nice, thank you!
Re: Some Tips using VectorDrawing lib.
Another Path (no Vector)
Gif here :
https://icons8.com/preloaders/en/free
et bien voilaaaa !!
ou bien :
ça aussi c'est cool :
peut meme faire en 3d
du texte:
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
Gif here :
https://icons8.com/preloaders/en/free
et bien voilaaaa !!
ou bien :
ça aussi c'est cool :
peut meme faire en 3d
du texte:
- Kwai chang caine
- Always Here
- Posts: 5357
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Some Tips using VectorDrawing lib.
Thanks RASHAD for sharing this usefull examples
The happiness is a road...
Not a destination
Not a destination
Re: Some Tips using VectorDrawing lib.
Thanks guys
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
Last edited by RASHAD on Mon Nov 13, 2017 9:18 pm, edited 2 times in total.
Egypt my love
Re: Some Tips using VectorDrawing lib.
Very cool, thanks for all the examples!
Re: Some Tips using VectorDrawing lib.
Nice!
But isn't it a problem to draw from threads? In my experience, every threaded access to any gadget created in the main thread lead to strange behavior up to crashes. While it seem to work somehow on Windows, on Linux and Mac it was a guarantee for crashes.
Is the Canvas thread-save in this way?
But isn't it a problem to draw from threads? In my experience, every threaded access to any gadget created in the main thread lead to strange behavior up to crashes. While it seem to work somehow on Windows, on Linux and Mac it was a guarantee for crashes.
Is the Canvas thread-save in this way?
Re: Some Tips using VectorDrawing lib.
Thanks guys
Previous post updated
- Graphics modified little bit
- Added check for existing of the CanvasGadget
@Kukulkan
It should be very safe now
It is just drawing to a gadget created in the main loop(that is all)
Using thread is the best way to avoid stop while moving or resizing the main window and leave the main window free from affected by the required delay time
Previous post updated
- Graphics modified little bit
- Added check for existing of the CanvasGadget
@Kukulkan
It should be very safe now
It is just drawing to a gadget created in the main loop(that is all)
Using thread is the best way to avoid stop while moving or resizing the main window and leave the main window free from affected by the required delay time
Egypt my love
Re: Some Tips using VectorDrawing lib.
Hi RASHAD, nice examples.
I do see random crashes within runCB() when closing the window.
Or
Moving the window and then closing it.
The runCB() drawing functions have nowhere to paint if the window closes before the thread ends.
Even adding
Case #PB_Event_CloseWindow
Quit = 1
WaitThread(thread, 6000)
does not always work.
I do see random crashes within runCB() when closing the window.
Or
Moving the window and then closing it.
The runCB() drawing functions have nowhere to paint if the window closes before the thread ends.
Even adding
Case #PB_Event_CloseWindow
Quit = 1
WaitThread(thread, 6000)
does not always work.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Some Tips using VectorDrawing lib.
Hi skywalk
Thanks
That is why I added check for existing of the CanvasGadget() in the last example and it should be added to every example in the first post
Please check the last example again
Waiting for your results
Thanks
That is why I added check for existing of the CanvasGadget() in the last example and it should be added to every example in the first post
Please check the last example again
Waiting for your results
Egypt my love
Re: Some Tips using VectorDrawing lib.
Yes, the error happens with your last example.
Maybe IsGadget(0) is not updated when the app quits?
Maybe IsGadget(0) is not updated when the app quits?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Some Tips using VectorDrawing lib.
I can not replicate the error
Try
Or try other different timeout
Or try next snippet to avoid KillThread(thread)
Try
Code: Select all
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
KillThread(thread)
Quit = 1
EndSelect
Until Quit = 1
Or try next snippet to avoid KillThread(thread)
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
Egypt my love
Re: Some Tips using VectorDrawing lib.
I had tried waitthread() where you put killthread() and that still had errors.
Monitoring qFlag in the thread works.
Monitoring qFlag in the thread works.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Some Tips using VectorDrawing lib.
@skywalk thanks
The problem is we must use the thread to get the proper functionality
Glad to know that qFlag works
Thanks again
The problem is we must use the thread to get the proper functionality
Glad to know that qFlag works
Thanks again
Egypt my love