AnimateData: instant graphic animation for network transfers

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

AnimateData: instant graphic animation for network transfers

Post by netmaestro »

If you'd like to see what this looks like, you can run this (tiny) demo:

http://www.networkmaestro.com/animatedata.exe

And if you'd like to easily add this control to your projects, this is where to get the library and help files:

http://www.networkmaestro.com/animatedata.zip

Code: Select all

;==========================================
; Userlibrary:     AnimateData(w,h,delay)
; Author:          netmaestro
; Date:            June 30, 2006
; Target Compiler: PureBasic 4.0
; Target OS:       Windows all
;==========================================
;
ProcedureDLL AnimateData(w.l,h.l,delay.l)
  Static tt.l=0,cc.l=0,c1.l=0,c2.l=0,aniimage.l=0,init.l=0
  If Not init
    init=#True
    Static Dim t.s(17)
    t(0)=  "110100000000000000"
    t(1)=  "011010000000000000"
    t(2)=  "001101000000000000"
    t(3)=  "000110100000000000"
    t(4)=  "000011010000000000"
    t(5)=  "000001101000000000"
    t(6)=  "000000110100000000"
    t(7)=  "000000011010000000"
    t(8)=  "000000001101000000"
    t(9)=  "000000000110100000"
    t(10)= "000000000011010000"
    t(11)= "000000000001101000"
    t(12)= "000000000000110100"
    t(13)= "000000000000011010"
    t(14)= "000000000000001101"
    t(15)= "100000000000000110"
    t(16)= "010000000000000011"
    t(17)= "101000000000000001"
    *unpacked = AllocateMemory(3128)
    UnpackMemory(?PicPak, *unpacked)
    computer = CatchImage(#PB_Any, *unpacked, 3128)
    FreeMemory(*unpacked)
    StartDrawing(ImageOutput(computer))
      For i=0 To 31
        For j=0 To 31
          If Point(i,j)=RGB(255,0,255)
            Plot(i,j,GetSysColor_(#COLOR_BTNFACE))
          EndIf
        Next
      Next
    StopDrawing()
    c1=CreateImage(#PB_Any,36,32)
    c2=CreateImage(#PB_Any,36,32)
    StartDrawing(ImageOutput(c1))
      Box(0,0,36,32,GetSysColor_(#COLOR_BTNFACE))
      DrawImage(ImageID(computer),0,0)
    StopDrawing()
    StartDrawing(ImageOutput(c2))
      Box(0,0,36,32,GetSysColor_(#COLOR_BTNFACE))
      DrawImage(ImageID(computer),4,0)
    StopDrawing()
    aniimage=CreateImage(#PB_Any, 224,32)
  EndIf
  If ElapsedMilliseconds()-tt > delay
    StartDrawing(ImageOutput(aniimage))
      DrawImage(ImageID(c1),0,0)
      DrawImage(ImageID(c1),188,0)
    StopDrawing()
    tt=ElapsedMilliseconds()
    cc+1
    StartDrawing(ImageOutput(aniimage))
      Box(0,0,224,32,GetSysColor_(#COLOR_BTNFACE))
      DrawText(40,10,t(cc),0,GetSysColor_(#COLOR_BTNFACE))
    StopDrawing()
    If cc >= 17
      cc=0
    EndIf
    StartDrawing(ImageOutput(aniimage))
      If cc=13
        DrawImage(ImageID(c1),188,0)
      Else
        DrawImage(ImageID(c2),188,0)
      EndIf
      If cc=14
        DrawImage(ImageID(c2),188,0)
      Else
        DrawImage(ImageID(c1),188,0)
      EndIf    
      If cc=1
        DrawImage(ImageID(c1),0,0)
      Else
        DrawImage(ImageID(c2),0,0)
      EndIf
      If cc=2
        DrawImage(ImageID(c2),0,0)
      Else
        DrawImage(ImageID(c1),0,0)
      EndIf          
    StopDrawing()
    ResizeImage(aniimage,w,h)
    ProcedureReturn ImageID(aniimage)
  Else
    ProcedureReturn 0  
  EndIf
  
  DataSection
    PicPak:
    Data.b $4A,$43,$38,$0C,$00,$00,$DB,$6D,$A9,$6B,$B3,$A9,$D0,$20,$69,$14,$61,$88,$12,$CA
    Data.b $08,$B0,$48,$40,$27,$90,$04,$8E,$01,$C6,$5B,$28,$31,$10,$9F,$02,$0C,$02,$35,$60
    Data.b $08,$F0,$02,$0C,$38,$F5,$60,$06,$01,$E6,$00,$03,$CC,$5D,$EF,$02,$36,$AF,$66,$1E
    Data.b $60,$15,$00,$03,$6E,$35,$C0,$FC,$81,$EE,$A3,$C7,$8C,$2A,$11,$CB,$EF,$00,$37,$BE
    Data.b $31,$23,$16,$96,$80,$53,$4B,$30,$30,$AC,$CA,$2A,$C0,$E8,$1A,$33,$2A,$43,$D7,$EC
    Data.b $4E,$30,$8C,$E2,$36,$4B,$EF,$31,$B3,$07,$12,$BE,$00,$CB,$30,$50,$B5,$59,$09,$66
    Data.b $C7,$56,$51,$03,$9C,$7F,$4B,$42,$6D,$6A,$C0,$8C,$7B,$26,$F8,$0F,$30,$AF,$01,$B7
    Data.b $37,$E3,$CC,$51,$55,$80,$62,$24,$66,$6F,$32,$FE,$02,$2C,$E7,$6C,$CC,$B8,$6B,$66
    Data.b $F3,$B6,$F7,$BC,$0A,$8E,$2E,$F0,$BC,$62,$82,$F2,$0F,$30,$FA,$78,$3D,$FA,$33,$BF
    Data.b $4C,$28,$B3,$1B,$CC,$18,$02,$33,$6E,$14,$03,$E0,$F8,$FF,$78,$38,$2A,$EB,$60,$8E
    Data.b $2E,$C0,$FA,$86,$8A,$7A,$EC,$13,$F7,$E2,$3B,$AB,$F5,$A9,$81,$8E,$7F,$01,$3B,$91
    Data.b $CB,$FB,$EC,$AE,$06,$8C,$00,$00,$88,$44
    PicPakend:
  EndDataSection
EndProcedure
Last edited by netmaestro on Fri Jun 30, 2006 5:12 pm, edited 3 times in total.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Dammit, first few guys that downloaded please re-download as there was an array accidentally left global t.s(24) which could mess you up. It's fixed now and everything is verified protected.

I can't seem to get one of these out the door clean the first time... :?
BERESHEIT
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

damnit, one function, what a huge userlib :D .

it's nice thanks.


maybe you can add a 2nd function in your lib :
you can grab my usual 'please wait' here :
http://www.penguinbyte.com/apps/pbwebst ... 4/BUSY.zip
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

This is nice - but I wonder why is there a WM_TIMER event when the timer is non-existent? Try running the below and note the debug message from the #WM_TIMER. Maybe this is coming from somewhere else, but where? I don't want to see any busy icon when the timer hasn't started yet (i.e. only appears when timer is running).

Code: Select all

OpenWindow(0, 0, 0, 320, 240, "test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateStatusBar(0, WindowID(0))

For i = 2 To 9
  LoadImage(i, "busy"+Str(i)+".ico")
Next

;SetTimer_(WindowID(0), 1, 80, 0)
;StatusBarText(0, 0, "Veuillez patienter, traitement en cours...")

Repeat
  Select WaitWindowEvent()
    Case #WM_CLOSE
      Break
    Case #WM_TIMER
      Debug "we got a timer event"
      i+1 : If i>9 : i=2 : EndIf
      StatusBarIcon(0, 0, ImageID(i))
  EndSelect
ForEver

;KillTimer_(WindowID(0), 1)
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Are the computers at either end supposed to "jitter" like that or is that just a glitch in the graphics?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Yes, the jitter is intentional, whether it's a good idea or not is another matter... :D

@mskuma, I haven't seen this lib in a while, I'll take a look.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Thanks netmaestro. Even without running the lib, this test code is enough to show the issue (i.e. you can see the debug message).

Code: Select all

OpenWindow(0, 0, 0, 320, 240, "test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
CreateStatusBar(0, WindowID(0)) 

Repeat 
  Select WaitWindowEvent() 
    Case #WM_CLOSE 
      Break 
    Case #WM_TIMER 
      Debug "we got a timer event" 
  EndSelect 
ForEver 
Post Reply