Just another Progressbar

Share your advanced PureBasic knowledge/code with the community.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

breeze4me's code works okay here. Nice work by the way, I'll make use of this. :D
I may look like a mule, but I'm not a complete ass.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Code: Select all

;PercentBar 
;2005 by Hroudtwolf 
;Progressbar with percentdisplay 
; 
;Declaring all needed procedures 
Declare Setpercents (Gadget.l,Position.l,gadgetreturn$) 
Declare.s PercentbarGadget (Gadget.l,x.l,y.l,pcwidth.l,pcheigth.l,max.l) 

hwnd.l = OpenWindow(0, 100, 100, 300, 60, "PercentBar", #PB_Window_TitleBar|#PB_Window_ScreenCentered) 
If hwnd.l 
  If CreateGadgetList (hwnd.l) 
    info$=PercentbarGadget (1,10,20,280,20,40); PercentGadget erstellen(creating  the percentgadget) 
  EndIf 
  Repeat 
    EventID.l = WindowEvent() 
    Setpercents (1,xx,info$); Das PercentGadget aktualisieren;(actualizing the p-gadget) 
    xx=xx+1 
    If xx>40:xx=0:EndIf 
    Delay(100) 
  Until EventID = #PB_Event_CloseWindow 
  
EndIf 
End 

;The PercentGadget 
Procedure.s PercentbarGadget (Gadget.l,x.l,y.l,pcwidth.l,pcheight.l,max.l) 
  gadgetreturn$=Str(pcwidth.l)+"|"+Str(pcheight.l)+"|"+Str(max.l) 
  Setpercents (Gadget.l,0,gadgetreturn$) 
  ImageGadget (Gadget.l,x.l,y.l,pcwidth.l,pcheigth.l,ImageID (800+Gadget.l)) 
  ProcedureReturn gadgetreturn$ 
EndProcedure 

;Actualizer for the Percentgadget 
Procedure Setpercents (Gadget.l,Position.l,gadgetreturn$) 
  pcwidth.l=Val(StringField(gadgetreturn$, 1, "|")) 
  pcheight.l=Val(StringField(gadgetreturn$, 2, "|")) 
  max.l=Val(StringField(gadgetreturn$, 3, "|")) 
  ;Prozentberechnung 
  onepercent.f=max/100 
  If onepercent.f=0:onepercent.f=1:EndIf 
  percent.l=Position.l/onepercent.f 
  
  ;Systemfarben ermitteln(get the systemcolors) 
  HFarbe.l=GetSysColor_(#COLOR_BTNFACE ) 
  RFarbe1.l=GetSysColor_(#COLOR_3DHIGHLIGHT) 
  RFarbe2.l=GetSysColor_(#COLOR_3DSHADOW) 
  TFarbe.l=GetSysColor_(#COLOR_BTNTEXT ) 
  ;Gadgetstyle erstellen (making the gadgetstyle) 
  If IsImage (800+Gadget.l)=0:CreateImage (800+Gadget.l,pcwidth.l,pcheight.l):EndIf 
  If StartDrawing (ImageOutput (800+Gadget.l)) 
    DrawingMode(0) 
    Box (0,0,pcwidth.l,pcheight.l,HFarbe.l) 
    Line (0,0,0,pcheight.l,RFarbe2.l) 
    Line (0,0,pcwidth.l,0,RFarbe2.l) 
    Line (0,pcheight.l-1,pcwidth.l,0,RFarbe1.l) 
    Line (pcwidth.l-1,0,0,pcheight.l,RFarbe1.l) 
    Box (1,1,((pcwidth.l*Position)/max)-2,pcheight.l-2,RGB(100,100,250)) 
    For x=10 To pcwidth.l-10 Step 10 
      Line (x,1,0,pcheight.l-2,HFarbe.l) 
    Next x 
    DrawingMode(1) 

    rot.l=Red(TFarbe.l) 
    gruen.l=Green(TFarbe.l) 
    blau.l=Blue(TFarbe.l) 
    FrontColor (RGB(rot.l,gruen.l,blau.l)) 
    Text$=Str(percent.l)+ " %" 
    DrawText (Int(pcwidth.l/2)-20,2,Text$) 
    StopDrawing () 
  EndIf 
  If IsGadget (Gadget.l):SetGadgetState (Gadget.l,ImageID (800+Gadget.l)):EndIf 
EndProcedure
Doesnt that work in PB4?
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Fangbeast wrote:Nice stuff but all this seems to be for pb 3.94. When I change the obvious for pb4, I stull get errors I don't know how to handle like an error message about Locate() not being an array, linked list etc.
Can anyone convert all this to pb4?
The above code from breeze4me works for me with PB4.00 final.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

gnozal wrote:
Fangbeast wrote:Nice stuff but all this seems to be for pb 3.94. When I change the obvious for pb4, I stull get errors I don't know how to handle like an error message about Locate() not being an array, linked list etc.
Can anyone convert all this to pb4?
The above code from breeze4me works for me with PB4.00 final.
Confirmed.
Fangbeast seems to have drunk too much beer or something :P
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
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 »

Psychophanta wrote:
gnozal wrote:
Fangbeast wrote:Nice stuff but all this seems to be for pb 3.94. When I change the obvious for pb4, I stull get errors I don't know how to handle like an error message about Locate() not being an array, linked list etc.
Can anyone convert all this to pb4?
The above code from breeze4me works for me with PB4.00 final.
Confirmed.
Fangbeast seems to have drunk too much beer or something :P
I don't drink alcohol. Must have been your armpits making my glasses fog up and my eyestalks crossed. :D :D
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply