Page 1 of 1

Simple Progress Bar

Posted: Mon Feb 26, 2018 6:36 pm
by RASHAD
Hi all

Code: Select all


Procedure _ProgressBar(gadget,x,y,w,h,color)
  If h > w
    CreateImage(0,w,h,32)
  Else
    CreateImage(0,h,w,32)
  EndIf
  StartVectorDrawing(ImageVectorOutput(0))
    VectorSourceLinearGradient(-10, 0, 30, 0)
    VectorSourceGradientColor(RGBA(Red(Color), Green(Color), Blue(Color), 255), 0.4)
    If h > w
      AddPathBox(0,0,w,h)
    Else
      AddPathBox(0,0,h,w)
    EndIf
    FillPath()    
  StopVectorDrawing()
  cont = ContainerGadget(#PB_Any,x,y,w,h,#PB_Container_Single)
      SetGadgetColor(cont,#PB_Gadget_BackColor,$B6B6B6)
      CanvasGadget(gadget,-w,1,w,h-2)
      StartVectorDrawing(CanvasVectorOutput(gadget))        
        If w > h
          MovePathCursor(w, 0)        
          RotateCoordinates(0, 0, 90)
        Else
          MovePathCursor(0,0)
        EndIf                        
        DrawVectorImage(ImageID(0))
    StopVectorDrawing()
  CloseGadgetList()
EndProcedure

flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,400,300,"My ProgressBar",Flags)
_ProgressBar(0,10,10,200,30,RGB(87, 252, 63))
_ProgressBar(1,10,40,20,200,RGB(251, 201, 62))
w1 = GadgetWidth(0) :h1 = GadgetHeight(0)
w2 = GadgetWidth(1) :h2 = GadgetHeight(1)
ButtonGadget(2,10,265,60,24,"RUN",#PB_Button_Toggle)
Repeat           
  Select WaitWindowEvent()      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Timer
          If x < w1      
            ResizeGadget(0,x-w1,0,w1,h1)
            x+1
          EndIf
          If y < h2       
            ResizeGadget(1,0,h2-y,w2,h2)
            y+1
          EndIf
          If x >= w1 Or y >= w1
            SetGadgetState(2,0)            
            x = 0 : y = 0
            SetGadgetText(2,"RUN")
            RemoveWindowTimer(0,100)
          EndIf  
;       
      Case #PB_Event_Menu
          Select EventMenu() 
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 2
              If GetGadgetState(2) = 1
                SetGadgetText(2,"STOP")                
                AddWindowTimer(0,100,50)
              Else
                SetGadgetText(2,"RUN")                
                RemoveWindowTimer(0,100)
              EndIf
               
          EndSelect
          

  EndSelect 

Until Quit = 1
End
Edit :Modified # 1

Re: Simple Progress Bar

Posted: Mon Feb 26, 2018 11:02 pm
by davido
@RASHAD,
Very nice thank you for sharing.

Re: Simple Progress Bar

Posted: Tue Feb 27, 2018 1:49 am
by RASHAD
@davido
Thanks mate
Added Set & Get State

Code: Select all


Procedure _ProgressBar(gadget,x,y,w,h,color)
  If h > w
    CreateImage(0,w,h,32)
  Else
    CreateImage(0,h,w,32)
  EndIf
  StartVectorDrawing(ImageVectorOutput(0))
    VectorSourceLinearGradient(-10, 0, 30, 0)
    VectorSourceGradientColor(RGBA(Red(Color), Green(Color), Blue(Color), 255), 0.4)
    If h > w
      AddPathBox(0,0,w,h)
    Else
      AddPathBox(0,0,h,w)
    EndIf
    FillPath()    
  StopVectorDrawing()
  cont = ContainerGadget(#PB_Any,x,y,w,h,#PB_Container_Single)
      SetGadgetColor(cont,#PB_Gadget_BackColor,$B6B6B6)
      CanvasGadget(gadget,-w,1,w,h-2)
      StartVectorDrawing(CanvasVectorOutput(gadget))        
        If w > h
          MovePathCursor(w, 0)        
          RotateCoordinates(0, 0, 90)
        Else
          MovePathCursor(0,0)
        EndIf                        
        DrawVectorImage(ImageID(0))
    StopVectorDrawing()
  CloseGadgetList()
EndProcedure

Procedure GetProgressState(gadget)
  If GadgetWidth(gadget) > GadgetHeight(gadget)    
    state = GadgetWidth(gadget)+ GadgetX(gadget)
  Else
    state = GadgetHeight(gadget) - GadgetY(gadget)
  EndIf
  ProcedureReturn state
EndProcedure

Procedure SetProgressState(gadget,state)
  If GadgetWidth(gadget) > GadgetHeight(gadget) 
    ResizeGadget(gadget,state-GadgetWidth(gadget),0,GadgetWidth(gadget),GadgetHeight(gadget))
  Else
    ResizeGadget(gadget,0,GadgetHeight(gadget)-state,GadgetWidth(gadget),GadgetHeight(gadget))
  EndIf
EndProcedure

flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,400,300,"My ProgressBar",Flags)
_ProgressBar(0,10,10,300,30,RGB(87, 252, 63))
_ProgressBar(1,10,40,60,200,RGB(251, 201, 62))
w1 = GadgetWidth(0) :h1 = GadgetHeight(0)
w2 = GadgetWidth(1) :h2 = GadgetHeight(1)
ButtonGadget(2,10,265,60,24,"RUN",#PB_Button_Toggle)
ButtonGadget(3,80,265,60,24,"Set")
ButtonGadget(4,150,265,60,24,"Get")
Repeat           
  Select WaitWindowEvent()      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Timer
          If x < w1      
            ResizeGadget(0,x-w1,0,w1,h1)
            x+1
          EndIf
          If y < h2       
            ResizeGadget(1,0,h2-y,w2,h2)
            y+1
          EndIf
          If x >= w1 Or y <= 0
            SetGadgetState(2,0)
            SetGadgetText(2,"RUN")
            RemoveWindowTimer(0,100)
          EndIf  
;       
      Case #PB_Event_Menu
          Select EventMenu() 
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 2
              If GetGadgetState(2) = 1
                SetGadgetText(2,"STOP")                            
                x = GetProgressState(0) : y = GetProgressState(1)
                If x >= w1-3
                  x = 0
                EndIf
                If y >= h2-3
                  y = 0
                EndIf
                AddWindowTimer(0,100,10)
              Else
                SetGadgetText(2,"RUN")                
                RemoveWindowTimer(0,100)
              EndIf
              
            Case 3
              SetProgressState(0,100)
              SetProgressState(1,60)
            
            Case 4
              Debug GetProgressState(0)
              Debug "*******"
              Debug GetProgressState(1)
              
               
          EndSelect
          

  EndSelect 

Until Quit = 1
End

Re: Simple Progress Bar

Posted: Tue Feb 27, 2018 6:52 am
by kinglestat
this is great
how about progress bar has transparent background (so container does not show?)

Re: Simple Progress Bar

Posted: Tue Feb 27, 2018 6:59 am
by kinglestat
Figured it out!

Incidentally, shouldn't the image be freed after drawing it on container?

Re: Simple Progress Bar

Posted: Tue Feb 27, 2018 10:01 am
by Bisonte
kinglestat wrote:Figured it out!

Incidentally, shouldn't the image be freed after drawing it on container?
In this example, the image have always the number 0. So FreeImage() is not necessary.
Its overwritten everytime...

Re: Simple Progress Bar

Posted: Tue Feb 27, 2018 10:45 am
by JHPJHP
Hi RASHAD,

Keya said it best...
Keya wrote:Impressive result! there doesn't appear to be enough code for it though, lol
Great effect :!:

I also really like your Ver 2 : VectorDrawing Chart.

Re: Simple Progress Bar

Posted: Tue Feb 27, 2018 11:29 am
by RASHAD
@kinglestat,Bisonte & JHPJHP
Thanks a lot guys

@JHPJHP
That GIF Toolkit is great
Somebody around should be very happy with it :P (KCC)
I miss that guy (Keya)
He was a good addition to the forum
I do not know why he left

Re: Simple Progress Bar

Posted: Tue Feb 27, 2018 1:01 pm
by RASHAD
removed

Re: Simple Progress Bar

Posted: Sat Mar 03, 2018 9:48 am
by RASHAD
For Windows

Code: Select all


Procedure _ProgressBar(gadget,x,y,w,h,color)
  If h > w
    CreateImage(0,w,h,32)
  Else
    CreateImage(0,h,w,32)
  EndIf
  StartVectorDrawing(ImageVectorOutput(0))
    If h > w
      VectorSourceLinearGradient(-w/2, 0, w, 0)
    Else
      VectorSourceLinearGradient(-h/2, 0, h, 0)
    EndIf
    VectorSourceGradientColor(RGBA(Red(Color), Green(Color), Blue(Color), 255), 0.5)
    If h > w
      AddPathBox(0,0,w,h)
    Else
      AddPathBox(0,0,h,w)
    EndIf
    FillPath()    
  StopVectorDrawing()
  cont = ContainerGadget(#PB_Any,x,y,w,h)      
    SetClassLongPtr_(GadgetID(cont), #GCL_HBRBACKGROUND,GetStockObject_(#NULL_BRUSH)) 
      CanvasGadget(gadget,-w,0,w,h)
      StartVectorDrawing(CanvasVectorOutput(gadget))        
        If h > w
          MovePathCursor(0,0)
        Else
          MovePathCursor(w, 0)        
          RotateCoordinates(0, 0, 90)
        EndIf                        
        DrawVectorImage(ImageID(0))
    StopVectorDrawing()
  CloseGadgetList()
EndProcedure

Procedure GetProgress(win,gadget)
  If GadgetWidth(gadget) > GadgetHeight(gadget)    
    state = GadgetWidth(gadget)+ GadgetX(gadget)+1
  Else
    state = Abs(GadgetY(gadget) - GadgetHeight(gadget))+1
  EndIf
  ProcedureReturn state
EndProcedure

Procedure SetProgress(win,gadget,state)
  If GadgetWidth(gadget) > GadgetHeight(gadget) 
    ResizeGadget(gadget,state-GadgetWidth(gadget)-1,0,GadgetWidth(gadget),GadgetHeight(gadget))
  Else
    ResizeGadget(gadget,0,GadgetHeight(gadget)-state+1,GadgetWidth(gadget),GadgetHeight(gadget))
  EndIf
  RedrawWindow_(WindowID(win),#Null,#Null,#RDW_INVALIDATE |#RDW_UPDATENOW|#RDW_ERASE	) 
EndProcedure

Procedure sizeCB()  
  ResizeGadget(2,10,WindowHeight(0)-34,#PB_Ignore,#PB_Ignore)
  ResizeGadget(3,80,WindowHeight(0)-34,#PB_Ignore,#PB_Ignore)
  ResizeGadget(4,150,WindowHeight(0)-34,#PB_Ignore,#PB_Ignore)
  ResizeGadget(5,WindowWidth(0)-70,WindowHeight(0)-34,#PB_Ignore,#PB_Ignore)
EndProcedure

; CreateImage(0, 400,300)
; StartDrawing(ImageOutput(0))
;   For X = 0 To 399
;     For Y = 0 To 299
;       Plot(X, Y, RGB(X, Y, X*Y/20))
;     Next
;   Next
; StopDrawing()

LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp")

hBrush = CreatePatternBrush_(ImageID(0))

flags = #PB_Window_SystemMenu|  #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,400,300,"My ProgressBar",Flags)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
_ProgressBar(0,10,10,300,30,RGB(87, 252, 63))
_ProgressBar(1,10,40,60,200,RGB(59, 241, 252))
w1 = GadgetWidth(0) :h1 = GadgetHeight(0)
w2 = GadgetWidth(1) :h2 = GadgetHeight(1)
ButtonGadget(2,10,265,60,24,"RUN",#PB_Button_Toggle)
ButtonGadget(3,80,265,60,24,"Set")
ButtonGadget(4,150,265,60,24,"Get")
ButtonGadget(5,330,265,60,24,"Reset")

BindEvent(#PB_Event_SizeWindow,@sizeCB())
Repeat           
  Select WaitWindowEvent()      
      Case #PB_Event_CloseWindow
          Quit = 1
     
      Case #PB_Event_Timer
          If x < w1   
            ResizeGadget(0,x-w1,0,w1,h1)
            x+1
          EndIf
          If y < h2    
            ResizeGadget(1,0,h2-y,w2,h2)
            y+1
          EndIf
          If x >= w1 Or y =< 0
            SetGadgetState(2,0)
            SetGadgetText(2,"RUN")
            RemoveWindowTimer(0,100)
          EndIf 
      
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 2
            If GetGadgetState(2) = 1
              SetGadgetText(2,"STOP")                                            
              x = GetProgress(0,0) : y = GetProgress(0,1)
              If x > w1
                x = 0
              EndIf
              If y >= h2
                y = 0
              EndIf
              AddWindowTimer(0,100,10)
            Else
              SetGadgetText(2,"RUN")              
              RemoveWindowTimer(0,100)
            EndIf
            
          Case 3                         
            SetProgress(0,0,100)
            SetProgress(0,1,60)                
          
          Case 4
            Debug GetProgress(0,0)
            Debug "*******"
            Debug GetProgress(0,1)
            
          Case 5                         
            SetProgress(0,0,0)
            SetProgress(0,1,0)
             
        EndSelect
  EndSelect
Until Quit = 1
End
Cross Platform

Code: Select all

Procedure _ProgressBar(gadget,x,y,w,h,color)
  If h > w
    CreateImage(0,w,h+2,32)
  Else
    CreateImage(0,h,w+2,32)
  EndIf
  StartVectorDrawing(ImageVectorOutput(0))
    VectorSourceLinearGradient(-10, 0, 30, 0)
    VectorSourceGradientColor(RGBA(Red(Color), Green(Color), Blue(Color), 255), 0.4)
    If h > w
      AddPathBox(0,0,w+1,h)
    Else
      AddPathBox(0,0,h,w+1)
    EndIf
    FillPath()   
  StopVectorDrawing()
  ContainerGadget(gadget,x,y,0,0,#PB_Container_BorderLess)
      cangad = CanvasGadget(#PB_Any,0,0,w+1,h+1,#PB_Canvas_Border)
      StartVectorDrawing(CanvasVectorOutput(cangad))       
        If w > h
          MovePathCursor(w, 0)       
          RotateCoordinates(0, 0, 90)
        Else
          MovePathCursor(0,0)
        EndIf                       
        DrawVectorImage(ImageID(0))
    StopVectorDrawing()
  CloseGadgetList()
EndProcedure

Procedure GetProgressState(gadget)
  If GadgetWidth(gadget) > GadgetHeight(gadget)   
    state = GadgetWidth(gadget)
  Else
    state = GadgetHeight(gadget)
  EndIf
  ProcedureReturn state
EndProcedure

Procedure SetProgressState(gadget,state)
  If gadget = 0
    ResizeGadget(gadget,GadgetX(gadget),GadgetY(gadget),state, GadgetHeight(gadget))
  Else
    ResizeGadget(gadget,GadgetX(gadget),GadgetHeight(gadget)+ GadgetY(gadget)-state,GadgetWidth(gadget),state)
  EndIf
  HideWindow(0,0)
EndProcedure

CreateImage(100, 400,300)
StartDrawing(ImageOutput(100))
  For X = 0 To 399
    For Y = 0 To 299
      Plot(X, Y, RGB(X, Y, X*Y/20))
    Next
  Next
StopDrawing()

flags = #PB_Window_SystemMenu|  #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,400,300,"My ProgressBar",Flags)
ImageGadget(100,0,0,400,300,ImageID(100))
DisableGadget(100,1)

x1 = 10 : y1 = 10 :w1 = 302 :h1 = 32
_ProgressBar(0,x1,y1,w1,h1,RGB(87, 252, 63))
x2 = 10 : y2 = 40 :w2 = 61 :h2 = 202
_ProgressBar(1,x2,y2,w2,h2,RGB(251, 201, 62))
ButtonGadget(2,10,265,60,24,"RUN",#PB_Button_Toggle)

ButtonGadget(3,80,265,60,24,"Set")
ButtonGadget(4,150,265,60,24,"Get")
Repeat           
  Select WaitWindowEvent()     
      Case #PB_Event_CloseWindow
            Quit = 1
     
      Case #PB_Event_Timer
          If w < w1     
            ResizeGadget(0,x1,y1,w,h1)
            w+2
          EndIf
          If h < h2       
            ResizeGadget(1,x2,h2+y2-h,w2,h)
            h+2
          EndIf
          If w >= w1 Or h <= 0
            SetGadgetState(2,0)
            SetGadgetText(2,"RUN")
            RemoveWindowTimer(0,100)
          EndIf 
;       
      Case #PB_Event_Menu
          Select EventMenu()
          EndSelect
     
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 2
              If GetGadgetState(2) = 1
                SetGadgetText(2,"STOP")                           
                w = GetProgressState(0) : h = GetProgressState(1)
                If w >= w1
                  w = 0
                EndIf
                If h >= h2
                  h = 0
                EndIf
                AddWindowTimer(0,100,50)
              Else
                SetGadgetText(2,"RUN")               
                RemoveWindowTimer(0,100)
              EndIf
             
            Case 3
              SetProgressState(0,100)
              SetProgressState(1,60)
           
            Case 4
              Debug GetProgressState(0)
              Debug "*******"
              Debug GetProgressState(1)
             
               
          EndSelect
         

  EndSelect

Until Quit = 1
End

Re: Simple Progress Bar

Posted: Tue Mar 06, 2018 11:04 am
by Kwai chang caine
Merveillous !!!!

Image

It's incredible how you can create a professional effect 3D, without numerous lines of code :shock:

RASHAD you are really one of my favorite magician 8)

Image

One thousand of thanks for sharing this style of jewel code 8) 8) 8)