Just another Progressbar

Share your advanced PureBasic knowledge/code with the community.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Just another Progressbar

Post by Hroudtwolf »

Code updated for 5.20+, see the last post of this page.

Ladys and Gentleman,

...a wonder....a new star on the PB-sky...

The........Percent-BAr...

This ist a Gadget like the original ProgressbarGadget. But there is a percentdisplay in the bar.

I wish ya a lot of fun with it....

[edited]Code wasn't up to date.[/edited]
Last edited by Hroudtwolf on Wed Feb 25, 2009 1:15 am, edited 2 times in total.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: Just another Progressbar

Post by NoahPhense »

Very nice..

- np
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Thank you very much.
That wasn't much effort. Actually I wanted to make once a LIB therewith. But I had not enough ideas for more GadGets.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Hroudtwolf wrote:Thank you very much.
That wasn't much effort. Actually I wanted to make once a LIB therewith. But I had not enough ideas for more GadGets.
Oh come on.. you can come up with more gadgets.. ;)


Have you checked out the BeatnikGUI in the codearchiv?

Might spark an idea or two..

- np
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

some cool buttons would be nice!

[just simple ones made out of lines, not some big collorfull ones.. i miss a
nice button that can eventually pop up etc :D]
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

You wish. I obey :D

ColorButton:

Code: Select all

Procedure  ColorButton(gadget,text.s,x,y,w,h,color.l,imageID)
if createimage (imageID,w,h)
if Startdrawing (imageoutput())
box(0,0,w,h,color.l)
locate (2,2)
if text.s<>"":drawtext (text.s):endif
Stopdrawing()
endif
endif
ButtonImageGadget (gadget,x,y,w,h,useimage (imageID))
EndProcedure


ButtonIconGadget:

Code: Select all

Procedure ButtonIconGadget (gadget.l,x.l,y.l,width.l,height.l,text.s,image.l,bcol.l,fcol.l)
If CreateImage (100+gadget.l,width.l,height.l)
If StartDrawing (ImageOutput ())
DrawingMode(0)
Box (0,0,width.l,height.l,bcol.l)
DrawImage (image.l,2,2,height.l-4,height.l-4)
DrawingMode (1)
rt.l=Red(fcol.l)
gr.l=Green(fcol.l)
bl.l=Blue(fcol.l)
FrontColor (rt.l,gr.l,bl.l)
Locate (height.l,7)
If text.s<>"":DrawText (text.s):EndIf
StopDrawing ()
EndIf
EndIf
ButtonImageGadget (1,x.l,y.l,width.l,height.l,UseImage (100+gadget))
EndProcedure 

Do you want more ?
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

cool enough hehe
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

I'm programming a RememberGadget. But isn't ready.

My RememberGadget is a Gadget what remember all inputs.
Like the URL-Field in your browser. It will have also an autocomplete
feature for inputs.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Just another Progressbar

Post by Psychophanta »

Useful stuff :)
By the way:
Hroudtwolf wrote:Ladys and Gentleman,
Where are the ladies ? :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

I hope to meet any gril here,too ! :D
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

if you meet a 'gril' make sure you got the 'stakes' ready... :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Sorry.. I meaned "GIRL" !
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

blueznl wrote:if you meet a 'gril' make sure you got the 'stakes' ready... :-)
:D

Always thinking about food :)
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Post by breeze4me »

Code updated for 5.20+

I couldn't find a library for PB v4, so I made this one. :D

Code: Select all

; PercentBarGadget
;
; Author: breeze4me
; Date: 1st May, 2006
;
; For PureBasic v4.00 Beta 11
;
Structure PercentBar
  ;hPercentBar.l
  img.i
  Width.l
  Height.l
  Min.l
  Max.l
  Value.i
  TextColor.l
  FrontColor.l
  BackColor.l
  TextX.l
  TextY.l
  TextFont.i
EndStructure

Declare SetPercentBarValue(GadgetNumber, Value)

Procedure SetPercentBarColor(GadgetNumber, FrontColor, BackColor, TextColor=$FFFFFF)
  Protected *mem, *prop.PercentBar

  If IsGadget(GadgetNumber)
    *mem = GetWindowLong_(GadgetID(GadgetNumber), #GWL_USERDATA)
    *prop = *mem
    *prop\TextColor = TextColor
    If FrontColor<>#PB_Default : *prop\FrontColor = FrontColor : EndIf
    If BackColor<>#PB_Default : *prop\BackColor = BackColor : EndIf
  EndIf
EndProcedure

Procedure PercentBarGadget(GadgetNumber, x, y, Width, Height, Min, Max)
  Protected *mem, *prop.PercentBar
  Protected hPercentBar, img=CreateImage(#PB_Any, Width, Height)
  Protected SysCol1, SysCol2
 
  If Min>=Max : ProcedureReturn 0 : EndIf
 
  If img
    hPercentBar = ImageGadget(GadgetNumber, x, y, Width, Heigth, 0)
    If hPercentBar
      *mem = AllocateMemory(SizeOf(PercentBar))
      SetWindowLong_(hPercentBar, #GWL_USERDATA, *mem)
      *prop = *mem
      ;*prop\hPercentBar= hPercentBar
      *prop\img = img
      *prop\Max = Max
      *prop\Min = Min
      *prop\Width = Width
      *prop\Height = Height
      SysCol1 = GetSysColor_(#COLOR_3DHIGHLIGHT)
      SysCol2 = GetSysColor_(#COLOR_3DSHADOW)
     
      SetPercentBarColor(GadgetNumber,GetSysColor_(#COLOR_HIGHLIGHT),GetSysColor_(#COLOR_BTNFACE), GetSysColor_(#COLOR_CAPTIONTEXT))
     
      If StartDrawing(ImageOutput(img))
        *prop\TextX = (Width-1-TextWidth("100 %"))/2
        *prop\TextY = (Height-TextHeight(" "))/2 ;+ 1
        Box(0, 0, Width, Height, *prop\BackColor)
        Line(0, 0, 0, Height, SysCol2)
        Line(0, 0, Width, 0, SysCol2)
        Line(0, Height-1, Width, 0, SysCol1)
        Line(Width-1, 0, 0, Height, SysCol1)
        StopDrawing()
      EndIf
      SetPercentBarValue(GadgetNumber, Min)
      ProcedureReturn hPercentBar
    EndIf
  EndIf
EndProcedure

Procedure SetPercentBarValue(GadgetNumber, Value)
  Protected *mem, *prop.PercentBar, ValueF.f
 
  If IsGadget(GadgetNumber)
    *mem = GetWindowLong_(GadgetID(GadgetNumber), #GWL_USERDATA)
    *prop = *mem
    If Value>*prop\Max : Value=*prop\Max : EndIf
    If Value<*prop\Min : Value=*prop\Min : EndIf
    *prop\Value = Value
   
    ValueF = (Value-*prop\Min) * 100.0 / (*prop\Max-*prop\Min)
   
    If StartDrawing(ImageOutput(*prop\img))
      Box(1, 1, *prop\Width-2, *prop\Height-2, *prop\BackColor)
      Box(1, 1, (*prop\Width-2) * ValueF / 100.0, *prop\Height-2 , *prop\FrontColor)
      DrawingMode(#PB_2DDrawing_Transparent)
      If *prop\TextFont : DrawingFont(*prop\TextFont) : EndIf
      DrawText(*prop\TextX, *prop\TextY, Str(Int(ValueF))+" %", *prop\TextColor)
      StopDrawing()
      SetGadgetState(GadgetNumber, ImageID(*prop\img))
    EndIf
  EndIf
EndProcedure

Procedure SetPercentBarFont(GadgetNumber, FontName$, YSize, Flag=0)
  Protected *mem, *prop.PercentBar

  If IsGadget(GadgetNumber)
    *mem = GetWindowLong_(GadgetID(GadgetNumber), #GWL_USERDATA)
    *prop = *mem
    *prop\TextFont = FontID(LoadFont(#PB_Any, FontName$, YSize, Flag))
    If StartDrawing(ImageOutput(*prop\img))
      DrawingFont(*prop\TextFont)
      *prop\TextX = (*prop\Width-1-TextWidth("100 %"))/2
      *prop\TextY = (*prop\Height-TextHeight(" "))/2 ;+ 1
      StopDrawing()
    EndIf
  EndIf
EndProcedure

; Test.
hWnd=OpenWindow(0, 0, 0, 300, 150, "PercentBarGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If hwnd
  PercentBarGadget(0, 10, 20, 280, 25, -100, 900)
  PercentBarGadget(1, 10, 60, 280, 45, 1000, 1500)
  PercentBarGadget(2, 10, 120, 280, 25, 0, 300)
  SetPercentBarColor(0, $951225, $EBA6B1, $E07181)
  SetPercentBarFont(1, "MS Sans Serif", 20, #PB_Font_Italic|#PB_Font_HighQuality)
  SetPercentBarColor(2, #PB_Default, #PB_Default, $9922FF)
 
  v=-100
  w=1000
  x=0
  Repeat
    e=WindowEvent()
    v+1
    w+1
    x+1
    SetPercentBarValue(0, v)
    SetPercentBarValue(1, w)
    SetPercentBarValue(2, x)
    If v>=900 : v=-100 : EndIf
    If w>=1500 : w=1000 : EndIf
    If x>=300 : x=0 : EndIf
    Delay(1)
  Until e=#PB_Event_CloseWindow
EndIf

End
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 »

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?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply