Page 1 of 2

Just another Progressbar

Posted: Fri Mar 04, 2005 4:29 pm
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]

Re: Just another Progressbar

Posted: Sat Mar 05, 2005 4:42 pm
by NoahPhense
Very nice..

- np

Posted: Sat Mar 05, 2005 5:24 pm
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.

Posted: Sat Mar 05, 2005 5:49 pm
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

Posted: Sat Mar 05, 2005 6:34 pm
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]

Posted: Sat Mar 05, 2005 7:03 pm
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 ?

Posted: Sat Mar 05, 2005 8:00 pm
by thefool
cool enough hehe

Posted: Sat Mar 05, 2005 8:18 pm
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.

Re: Just another Progressbar

Posted: Sat Mar 05, 2005 10:27 pm
by Psychophanta
Useful stuff :)
By the way:
Hroudtwolf wrote:Ladys and Gentleman,
Where are the ladies ? :wink:

Posted: Sat Mar 05, 2005 10:46 pm
by Hroudtwolf
I hope to meet any gril here,too ! :D

Posted: Sat Mar 05, 2005 10:58 pm
by blueznl
if you meet a 'gril' make sure you got the 'stakes' ready... :-)

Posted: Sun Mar 06, 2005 12:28 am
by Hroudtwolf
Sorry.. I meaned "GIRL" !

Posted: Sun Mar 06, 2005 10:43 am
by Berikco
blueznl wrote:if you meet a 'gril' make sure you got the 'stakes' ready... :-)
:D

Always thinking about food :)

Posted: Mon May 01, 2006 11:28 am
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

Posted: Mon May 01, 2006 11:53 am
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?