Page 1 of 2

Progress Circle

Posted: Sat Dec 15, 2007 6:26 am
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 :)

Posted: Sat Dec 15, 2007 7:17 am
by npath
Cool effect.

Posted: Sat Dec 15, 2007 7:49 am
by rsts
very nice :)

Thanks for sharing.

cheers

Posted: Sat Dec 15, 2007 11:10 am
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!

Posted: Sun Dec 16, 2007 1:26 am
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.

Posted: Sun Dec 16, 2007 10:44 am
by srod
Not at the minute, I have my 5 year old niece bouncing up and down on my head!

Arghhhhhhhhhhhhhhh....

Posted: Sun Dec 16, 2007 11:04 am
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.

Posted: Mon Dec 17, 2007 7:23 am
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.

Posted: Mon Dec 17, 2007 7:26 am
by Dare
lol. :D

Trampoline head!

Posted: Mon Dec 17, 2007 11:44 am
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:

Posted: Mon Dec 17, 2007 10:21 pm
by electrochrisso
You could always pacify her srod and start teaching her how to be a guru PB coder. :lol:

Posted: Mon Dec 17, 2007 10:36 pm
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! :)

Posted: Mon Dec 17, 2007 10:41 pm
by electrochrisso
:lol: :lol: :lol:

Posted: Tue Dec 18, 2007 12:49 am
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 ?

Posted: Tue Dec 18, 2007 11:24 am
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.