Runde ProgressBars

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
Mischa
Beiträge: 152
Registriert: 29.08.2004 06:52
Wohnort: Hellhorst

Runde ProgressBars

Beitrag von Mischa »

Code: Alles auswählen

#maxroundprogresses=10

Structure rprogress
  gadgetid.l
  imageid.l
  imagecolor.l
  backcolor.l
  frontcolor.l
  textcolor.l
  font.l
  max.l
  state.l
  extension.s
EndStructure

Dim RoundProgresses.rprogress(#maxroundprogresses)

Procedure SetRoundProgressState(id,state)
  If state<>RoundProgresses(id)\state
    UseImage(RoundProgresses(id)\imageid)
    w=ImageWidth() : h=ImageHeight()
    dc=StartDrawing(ImageOutput())
    Box(0,0,w,h,RoundProgresses(id)\imagecolor)
    pen=CreatePen_(#PS_SOLID,1,RoundProgresses(id)\backcolor)
    brush=CreateSolidBrush_(RoundProgresses(id)\backcolor)
    SelectObject_(dc,brush) : SelectObject_(dc,pen)
    Ellipse_(dc,0,0,w,h)
    DeleteObject_(brush) : DeleteObject_(pen)
    pen=CreatePen_(#PS_SOLID,1,0)
    If RoundProgresses(id)\frontcolor=-1
      cstate=state * 448 / RoundProgresses(id)\max
      If cstate<256
        color=RGB(255,cstate,0)
      Else
        cstate-256
        color=RGB(255-cstate,255,0)
      EndIf
      brush=CreateSolidBrush_(color)
    Else  
      brush=CreateSolidBrush_(RoundProgresses(id)\frontcolor)
    EndIf
    SelectObject_(dc,brush) : SelectObject_(dc,pen)
    angle.f=state * 360 / RoundProgresses(id)\max
    If angle>0
      If angle>358
        Ellipse_(dc,0,0,w,h)
      Else
        mx=w/2 : my=h/2
        rx.f = 0 - (0 - my) * Sin(6.28318531*angle/360) + mx 
        ry.f = (0 - my) * Cos(6.28318531*angle/360) + my
        x2 = rx : y2 = ry
        Pie_(dc,0,0,w,h,x2,y2,w/2,0) 
      EndIf
    EndIf
    DeleteObject_(brush) : DeleteObject_(pen)
    SelectObject_(dc,RoundProgresses(id)\font)
    SetBkMode_(dc,#TRANSPARENT)
    SetTextColor_(dc,RoundProgresses(id)\textcolor)
    text.s = Str(state)+RoundProgresses(id)\extension
    DrawText_(dc,text,-1,rect.RECT,#DT_CALCRECT)
    diffx=(w-rect\right)/2 : diffy=(h-rect\bottom)/2
    Locate(diffx,diffy)
    DrawText(text)
    StopDrawing()
    RoundProgresses(id)\state = state
  EndIf
  SetGadgetState(RoundProgresses(id)\gadgetid,UseImage(RoundProgresses(id)\imageid))
EndProcedure

Procedure RoundProgress(id,x,y,w,h,ic,bc,fc,tc,font,max,state,ext.s)
  RoundProgresses(id)\gadgetid   = ImageGadget(#PB_Any,x,y,w,h,0)
  RoundProgresses(id)\imageid    = CreateImage(#PB_Any,w,h)
  RoundProgresses(id)\imagecolor = ic
  RoundProgresses(id)\backcolor  = bc
  RoundProgresses(id)\frontcolor = fc
  RoundProgresses(id)\textcolor  = tc
  RoundProgresses(id)\font       = font
  RoundProgresses(id)\max        = max
  RoundProgresses(id)\state      = -1
  RoundProgresses(id)\extension  = ext
  SetRoundProgressState(id,state)
EndProcedure

Procedure RemoveRoundProgress(id)
  FreeImage(RoundProgresses(id)\imageid)
  FreeGadget(RoundProgresses(id)\gadgetid)
EndProcedure  



OpenWindow(0,50,50,450,230,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
font1=LoadFont(#PB_Any,"Arial",14,#PB_Font_Bold)
font2=LoadFont(#PB_Any,"Times New Roman",24,#PB_Font_Bold)
font3=LoadFont(#PB_Any,"System",10)

RoundProgress(0,10,10,100,100,GetSysColor_(#COLOR_BTNFACE),RGB(160,160,160),RGB(230,128,230),RGB(255,230,255),UseFont(font1),100,0,"%")
RoundProgress(1,120,10,100,100,GetSysColor_(#COLOR_BTNFACE),RGB(160,160,160),RGB(230,230,128),RGB(255,255,230),UseFont(font1),100,0,"%")
RoundProgress(2,230,10,210,210,GetSysColor_(#COLOR_BTNFACE),RGB(160,160,160),-1,RGB(0,0,0),UseFont(font2),100,0,"%")
RoundProgress(3,10,120,100,100,GetSysColor_(#COLOR_BTNFACE),RGB(160,160,160),RGB(128,230,230),RGB(0,0,0),UseFont(font1),1000,0," Units")
RoundProgress(4,120,120,100,45,GetSysColor_(#COLOR_BTNFACE),RGB(120,120,120),RGB(64,160,160),RGB(0,0,0),UseFont(font3),100,0,"%")
RoundProgress(5,120,175,100,45,GetSysColor_(#COLOR_BTNFACE),RGB(80,80,32),RGB(160,160,64),RGB(255,255,128),UseFont(font3),100,100,"%")

time=timeGetTime_()
Repeat
  Event=WindowEvent()
  If timeGetTime_()-time>80
    state1+1
    If state1>100
      state1=0
    EndIf
    state2+2
    If state2>100
      state2=0
    EndIf
    state3+4
    If state3>100
      state3=0
    EndIf
    state4+5
    If state4>1000
      state4=0
    EndIf
    state5+3
    If state5>100
      state5=0
    EndIf
    state6-2
    If state6<0
      state6=100
    EndIf
    SetRoundProgressState(5,state6)
    SetRoundProgressState(4,state5)
    SetRoundProgressState(3,state4)
    SetRoundProgressState(2,state1)
    SetRoundProgressState(1,state2)
    SetRoundProgressState(0,state3)
    time=timeGetTime_()
  EndIf  
  Delay(5)
Until Event=#PB_Event_CloseWindow
Gruß,
Mischa
DarkDragon
Beiträge: 6267
Registriert: 29.08.2004 08:37
Computerausstattung: Hoffentlich bald keine mehr
Kontaktdaten:

Beitrag von DarkDragon »

Guten Morgen,

Funktioniert gut hier, sieht auch ziemlich gut aus ;) .
Angenommen es gäbe einen Algorithmus mit imaginärer Laufzeit O(i * n), dann gilt O((i * n)^2) = O(-1 * n^2) d.h. wenn man diesen Algorithmus verschachtelt ist er fertig, bevor er angefangen hat.
Benutzeravatar
bluejoke
Beiträge: 1244
Registriert: 08.09.2004 16:33
Kontaktdaten:

Beitrag von bluejoke »

coole Sache!

Jetzt kann ich endlich richtig geil C: formatieren und ne Satusanzeige dazu machen :lol:
Ich bin Ausländer - fast überall
Windows XP Pro SP2 - PB 4.00
Benutzeravatar
Kiffi
Beiträge: 10621
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: Runde ProgressBars

Beitrag von Kiffi »

Hallo Mischa,

Klasse! Danke für den Code! :allright:

Grüße ... Kiffi
Hygge
Antworten