Progress Circle

Share your advanced PureBasic knowledge/code with the community.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Progress Circle

Post by electrochrisso »

I was playing around in PB and came up with this.
Feel free to modify, more cosmetics could be made.

Code: Select all

;
; Progress Circle by Electrochisso, Use as you wish, PB4
;

Global PCimage,hWnd,gWnd

Procedure ProgressCircleInit(WindowTitle$,MiddleX,MiddleY)
PCimage = CreateImage(#PB_Any,MiddleX*2,MiddleY*2)
hWnd = OpenWindow(#PB_Any,0,0,MiddleX*2,MiddleY*2,WindowTitle$,#PB_Window_WindowCentered)
CreateGadgetList(WindowID(hWnd))
gWnd = ImageGadget(#PB_Any,0,0,MiddleX*2,MiddleY*2,ImageID(PCimage))
EndProcedure

Procedure ProgressCircle(grad,MiddleX,MiddleY,Radius,PCimage,gWnd,IC,Gap,C1,C2,C3,C4,C5,C6)
  StartDrawing(ImageOutput(PCimage))
  Box(0,0,MiddleX*2,MiddleY*2,C1)
  Circle(MiddleX,MiddleY,Radius+1,C2)
    LineXY(MiddleX,MiddleY,MiddleX+Sin(grad*(2*3.14159265/360))*Radius,MiddleY+Cos(grad*(2*3.14159265/360))*Radius, C3)
    If IC > 0
      Circle(MiddleX,MiddleY,Radius-Gap,C4)
    EndIf
    a.f=(grad/360)*100
    DrawText(MiddleX-8,MiddleY-6,RSet(Str(99-a),2,"0"),C5,C6)
  StopDrawing()
  SetGadgetState(gWnd,ImageID(PCimage))
  ;Delay(1)
  WaitWindowEvent(1)
EndProcedure

If OpenWindow(0,0,0,320,240,"Progress Circle Demo",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ButtonGadget(0,5,5,WindowWidth(0)-10,20,"Press here for Progress Demo 1")
    ButtonGadget(1,5,30,WindowWidth(0)-10,20,"Press here for Progress Demo 2")
  Else
    End
  EndIf
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventGadget() = 0 ;Progress Demo 1
          PCwidth=60 : PCheight=60 : InnerCircle=0 : Gap=0
          ;The order of the colors are: Background, Outer Circle, Dial, Inner Circle, Text Foreground, Text Background
          ProgressCircleInit("Progress Demo 1",PCwidth,PCheight)
          For Loop = 1 To 200 Step 1 ;Progress Simulation
            Count.f = (Loop/200)*360  ;Make the count fit into a max of 360
            ProgressCircle(360-Count,PCwidth,PCheight,PCwidth-2,PCimage,gWnd,InnerCircle,Gap,$0000FF,$00FF00,0,$00FFFF,$FF0000,$00FF00)
          Next           ; You can move anticlockwise by removing the 360- for the Count value
          CloseWindow(hWnd)
        EndIf

        If EventGadget() = 1 ;Progress Demo 2
          PCwidth=120 : PCheight=120 : InnerCircle=1 : Gap=10
          ;The order of the colors are: Background, Outer Circle, Dial, Inner Circle, Text Foreground, Text Background
          ProgressCircleInit("Progress Demo 2",PCwidth,PCheight)
          For Loop = 1 To 200 Step 1 ;Progress Simulation
            Count.f = (Loop/200)*360  ;Make the count fit into a max of 360
            ProgressCircle(Count,PCwidth,PCheight,PCwidth-2,PCimage,gWnd,InnerCircle,Gap,$BBBBBB,$B3A84C,$FFFFFF,$0483FB,$FF0000,$99FF99)
          Next           ; You can move clockwise by placing the 360- before the Count value
          CloseWindow(hWnd)
        EndIf
    EndSelect
  Until WindowEvent() = #PB_Event_CloseWindow
EndIf

End
Have Fun :)
Last edited by electrochrisso on Thu Dec 20, 2007 2:10 am, edited 1 time in total.
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

Cool effect.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

very nice :)

Thanks for sharing.

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Nice.

I think you'll want to do this in a timer or a thread because no Window's messages are being processed whilst the loops are in full swing. To see what I mean, push one of the buttons and then move the resulting window. On my system it all locks up until the loop has finished!

At the very least place the following in the loops :

Code: Select all

Delay(1) : WindowEvent()
but even this is only a stop-gap!

Otherwise, cool!
I may look like a mule, but I'm not a complete ass.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

Thanks for comments guys.
I know what you mean srod its still a bit of a work in progress and I have not done any real life testing.
I know it takes up all of system resources, so I posted it anyway so other people could have a play with it.
Well its probably about time I learned about threading, is there any chance you could mod my code to show me how to do this easily.
Thanks.
PureBasic! Purely the best 8)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Not at the minute, I have my 5 year old niece bouncing up and down on my head!

Arghhhhhhhhhhhhhhh....
I may look like a mule, but I'm not a complete ass.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

srod wrote:Not at the minute, I have my 5 year old niece bouncing up and down on my head!

Arghhhhhhhhhhhhhhh....
So what's the problem??? Isn't that where you normally store the slabs of beer?? Soooooooo, it should be nice and flat by now for the niece by now.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

No worries srod, I will leave you in peace, looks like you have your hands full. :lol:
Ill spend a bit of time over Chrissy and learn about threading.
PureBasic! Purely the best 8)
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

lol. :D

Trampoline head!
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:)

She is a terror - a real playground bully I reckon. Aye, she'll soon be holding up tuck shops everywhere.

At least she will if she's anything like her uncle srod!

:wink:
I may look like a mule, but I'm not a complete ass.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

You could always pacify her srod and start teaching her how to be a guru PB coder. :lol:
PureBasic! Purely the best 8)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

She has a worse attention span than a boiled egg and so I think it will be a while before she's up to coding! :)
I may look like a mule, but I'm not a complete ass.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

:lol: :lol: :lol:
PureBasic! Purely the best 8)
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

Post by case »

srod wrote:Nice.
At the very least place the following in the loops :

Code: Select all

Delay(1) : WindowEvent()
is a

Code: Select all

waitwindowevent(1)
will do the trick or it's better to use you're code ?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Best to use a thread or a timer! :wink:

However, in this case, yes I would say that your WaitWindowEvent(1) is fine.
I may look like a mule, but I'm not a complete ass.
Post Reply