Página 1 de 1

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 12:08
por asimoes
Usando Label para trabalhar como ProgressBar
A função TelaDelay( .1 ) é só para simular um processamento qualquer ( skip )
O Label nn% vai centralizando conforme a barra anda, porque foi usado o style ss_center

Código: Selecionar todos


   @ 10,10 CONTAINER  oContainer ;
           SIZE       Thisform:nWidth - 20,20 ;
           STYLE      2;
           BACKCOLOR  hwg_GetSysColor( COLOR_3DFACE ) ; 
           BACKSTYLE  2
             
   @ 00,00 SAY oLabel CAPTION "" ;
               OF oContainer ;
               STYLE SS_CENTER ;
               COLOR hwg_RGB(0, 0, 255) 
  
   ThisForm:oContainer:oLabel:Move( 1, 1, 0, 18)

   nCol   := ThisForm:oContainer:nLeft
        
   nWidth := ThisForm:oContainer:nWidth   //200 //ThisForm:oLabel:nWidth //ThisForm:nWidth

   ThisForm:oContainer:oLabel:SetColor( Hwg_RGB( 0, 0, 255 ), hwg_RGB(255, 255, 0),  .T. ) 
                        
   nTot := 100
                        
   FOR I:=1 TO nTot
      nFinishCol := nCol + 1 + ( ( nWidth - 2 ) * i / nTot )
      ThisForm:oContainer:oLabel:Move( 1, 1, nFinishCol-13, 18 )
      ThisForm:oContainer:oLabel:SetText(  Hb_NtoS ( Int( ( i / nTot ) * 100 ) ) + "%" ) 
      TelaDelay( .1 )
   NEXT
   
FUNCTION TelaDelay( nTime ) 
LOCAL iTime := Seconds()

   DO WHILE Seconds() - iTime < nTime
      hwg_DoEvents()
   ENDDO
    
RETURN Nil  

2019-10-18 11_59_27-Form1.png
2019-10-18 11_59_27-Form1.png (10.07 KiB) Exibido 3951 vezes

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 15:37
por asimoes
2019-10-18 15_36_37-Form1.png
2019-10-18 15_36_37-Form1.png (9.92 KiB) Exibido 3944 vezes

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 15:40
por asimoes
Para esse último trocar para
Com STYLE 5 fica mais destacado a linha do box

Código: Selecionar todos

@ 10,10 CONTAINER  oContainer ;
	           SIZE       Thisform:nWidth - 20,20 ;
	           STYLE      5;
	           BACKCOLOR  hwg_GetSysColor( COLOR_3DFACE ) ;
	           BACKSTYLE  2

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 16:20
por JoséQuintas
Gostei.

E pra quem não percebeu:

Acaba sendo praticamente como criar um controle do usuário.
Já comentei muito sobre isso: a LIB não precisa ter controles sofisticados, basta permitir que se criem novos controles a partir dos existentes!!!
Não lembro disso em outra LIB.

Gostei mesmo, abre muitas possibilidades.

É no estilo da GTWVG, em OOP...
Depois do MySQL, pode ser minha próxima migração.
Misturando com GTWVG, lógico, porque não vou querer perder recursos.

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 16:52
por asimoes
Dentro do WITH OBJECT, gosto muito desse recurso do harbour

Código: Selecionar todos

   WITH OBJECT ThisForm:oContainer
      :oLabel:Move( 1, 1, 0, 18 )
      nCol   := :nLeft
      nWidth := :nWidth  
      :oLabel:SetColor( N_BLACK, N_CYAN,  .T. ) 
      *
      FOR I:=1 TO nTot
         nFinishCol := nCol + 1 + ( ( nWidth - 2 ) * i / nTot )
         IF Mod( i, 100 ) = 0
            :oLabel:Move( 1, 1, nFinishCol-13, 18 )
            :oLabel:SetText(  Hb_NtoS ( Int( ( i / nTot ) * 100 ) ) + "%" ) 
         ENDIF
         hwg_DoEvents()  
      NEXT
      *
      TelaDelay( 1 )
      *
      :oLabel:SetText("")
      :oLabel:SetColor( Hwg_Rgb( 0, 0, 0 ), hwg_GetSysColor( COLOR_3DFACE ), .T. ) 
   END

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 18:28
por asimoes

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 19:47
por asimoes

Agora usando um JPG

Código: Selecionar todos

  WITH OBJECT ThisForm:oContainer
      :oPicture:ReplaceBitMap( 'gradient001.jpg' )
      :oPicture:Refresh()
      :oPicture:Move( 1, 1, 0, 21 )
      nCol   := :nLeft
      nWidth := :nWidth  
      *
      FOR I:=1 TO nTot
         nFinishCol := nCol + 1 + ( ( nWidth - 2 ) * i / nTot )
         IF Mod( i, 10 ) = 0
            :oPicture:Move( 1, 1, nFinishCol-13, 29 )
         ENDIF
         TelaDelay( .1 )
      NEXT
      *
      TelaDelay( 5 )
      :oPicture:Move( 1, 1, 0, 29 )
      *
   END

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 19:56
por asimoes

Código: Selecionar todos

  nTot := 1000000
          
   WITH OBJECT ThisForm:oContainer
      :oPicture:ReplaceBitMap( 'gradient001.jpg' )
      :oPicture:Refresh()
      :oPicture:Move( 1, 1, 0, 29 )
      nCol   := :nLeft
      nWidth := :nWidth  
      *
      FOR I:=1 TO nTot
         nFinishCol := nCol + 1 + ( ( nWidth - 2 ) * i / nTot )
         IF Mod( i, 100 ) = 0
            :oPicture:Move( 1, 1, nFinishCol-13, 29 )
            :oPicture:Refresh()
            hwg_DoEvents()
         ENDIF
      NEXT
      *
      TelaDelay( 5 )
      :oPicture:Move( 1, 1, 0, 29 )
      *
   END

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 20:14
por asimoes
Agora os fontes da brincadeira
h-ProgressBar.zip
(3.66 MiB) Baixado 223 vezes

Usando Label (SAY) como ProgressBar

Enviado: 18 Out 2019 21:23
por sygecom
Parabéns, ficou muito bom.

Usando Label (SAY) como ProgressBar

Enviado: 19 Out 2019 19:57
por asimoes
Texto sobre imagem jpg

Código: Selecionar todos

      SetProgressBar( 0, 0, 10, 10, Thisform:nWidth - 5, 20 )

      nTot := 100
      
      FOR I:=1 TO nTot
         SetProgressBar(nTot, i)
         hwg_DoEvents()
         TelaDelay(.1)
      NEXT
      
      TelaDelay(1)
      
      SetProgressBar()
      
FUNCTION SetProgressBar( nTotReg, nReg, nLeft, nTop, nWidth, nHeight )

   Hb_Default(@nTotReg, 0 )
   Hb_Default(@nReg, 0 )
   Hb_Default(@nLeft, 0)
   Hb_Default(@nTop, 0)
   Hb_Default(@nWidth, 0)
   Hb_Default(@nHeight, 0)
   
   IF nLeft != 0 .AND. nTop != 0 .AND. nWidth != 0
      @ nLeft,nTop CONTAINER  oContainer ;
                   SIZE       nWidth - 20,20 ;
                   STYLE      10 ;
                   BACKCOLOR  hwg_GetSysColor( COLOR_3DFACE ) ; 
                   BACKSTYLE  2
   
      @ 0,0 BITMAP  oPicture ;
            SHOW    "" ;
            OF      oContainer ;
            SIZE    0, 0 ;
            STRETCH 2 

      @ 0,0 SAY EXTENDED oLabel ;
                CAPTION  "" ;
                OF       oContainer ;
                SIZE     oContainer:nWidth, 18 ;
                STYLE    SS_CENTER ;
                COLOR    N_BLACK ;
                BACKTRANSPARENT 

   ENDIF

   WITH OBJECT ThisForm:oContainer
      IF nTotReg > 0 .AND. nReg > 0
         IF nReg = 1
            :oLabel:Move( (:nWidth - 30 ) / 2, 1, 30, 18 )
            :oPicture:ReplaceBitMap( 'GRADIENT001.JPG' )
            :oPicture:Move( 1, 1, 0, 18 )
            :oPicture:Refresh()
         ENDIF
         nCol   := :nLeft
         nWidth := :nWidth  
         *
         nFinishCol := nCol + 1 + ( ( nWidth - 2 ) * nReg / nTotReg )
         :oPicture:Move( 1, 1, nFinishCol-13, 18 )
         :oLabel:SetText(  Hb_NtoS ( Int( ( nReg / nTotReg ) * 100 ) ) + "%" ) 
      ELSE
         *
         *
         InkeyGui(1)
         :oLabel:SetText("")
         :oLabel:Move( 1, 1, 0, 18 )
         :oPicture:Move( 1, 1, 0, 18 )
         :oPicture:Refresh()
         :oLabel:SetColor( N_BLACK, hwg_GetSysColor( COLOR_3DFACE ), .T. ) 
      ENDIF
   END
       
RETURN Nil

Usando Label (SAY) como ProgressBar

Enviado: 26 Out 2019 21:06
por asimoes
Última versão

Código: Selecionar todos

FUNCTION SetProgressBar( nTotReg, nReg, nLeft, nTop, nWidth, nHeight, nAlturaPict, nAlturaText, cImagem )
THREAD STATIC xnLeft, xnTop, xnWidth, xnHeight, xAlturaPict, xAlturaText, xImagem
LOCAL nCol, nStartRow, nStartCol, nWidthRow, nDesc

   nTotReg     := Hb_DefaultValue(nTotReg, 0)
   nReg        := Hb_DefaultValue(nReg, 0)
   nLeft       := Hb_DefaultValue(nLeft, 0)        
   nTop        := Hb_DefaultValue(nTop, 0)
   nWidth      := Hb_DefaultValue(nWidth, 0)
   nHeight     := Hb_DefaultValue(nHeight, 0)
   nAlturaPict := Hb_DefaultValue(nAlturaPict, 32)
   nAlturaText := Hb_DefaultValue(nAlturaText, 18)
   cImagem     := Hb_DefaultValue(cImagem, "P:\GERAL\HARBOUR\GRADIENT007.JPG")     
                        
   IF nLeft != 0 .AND. nTop != 0 .AND. nWidth != 0

     xnLeft      := nLeft
     xnTop       := nTop   
     xnWidth     := nWidth   
     xnHeight    := nHeight
     xAlturaPict := nAlturaPict
     xAlturaText := nAlturaText
     xImagem     := cImagem
      
     InitProgress( xnLeft, xnTop, xnWidth, xnHeight, xAlturaPict, xAlturaText )
          
   ELSE

      WITH OBJECT oThisForm:oContainer
         IF nTotReg > 0 .AND. nReg > 0
            IF nReg = 1
               :oLabel:Move( ( :nWidth - 114 ) / 2, ( :nHeight-18 ) / 2, 114, xAlturaText )
               :oPicture:ReplaceBitMap( xImagem )
               :oPicture:Move( 1, 1, 0, :nHeight )
               :oPicture:Refresh()
            ENDIF
            nCol      := :nLeft
            nWidthRow := :nWidth 
            nStartRow := 1
            nStartCol := 1
            nDesc     := nCol + 2
            *
            nFinishCol := nCol + 1 + ( ( nWidthRow - 2 ) * nReg / nTotReg )
            :oPicture:Move( nStartCol, nStartRow, Int( nFinishCol ) - nDesc, :nHeight-2 )
            IF nReg < nTotReg
               :oLabel:SetText(  "Aguarde... (" + Hb_NtoS ( Int( ( nReg / nTotReg ) * 100 ) ) + "%)" ) 
            ELSE
               :oLabel:SetText(  "Concluído... (" + Hb_NtoS ( Int( ( nReg / nTotReg ) * 100 ) ) + "%)" ) 
            ENDIF 
         ELSE
            *
            *
            TelaDelay(1) 
            :Visible( .F. )
            :Visible( .T. )
            :oPicture:Move( 1, 1, :nWidth-3, :nHeight+1 )
            :oPicture:Move( 1, 1, 0, :nHeight+1 )
            :oPicture:Refresh()
            :Refresh()
            :oLabel:SetText(" ")
            :oLabel:SetColor( N_BLACK, hwg_GetSysColor( COLOR_3DFACE ), .T. ) 
         ENDIF
      END
   ENDIF
   
RETURN Nil

FUNCTION InitProgress( xnLeft, xnTop, xnWidth, xnHeight, xAlturaPict, xAlturaText )

   oContainer := Nil
   oPicture   := Nil
   oLabel     := Nil
   
   IF Mod( xnWidth, 2 ) = 0
      xnWidth++
   ENDIF
   
   @ xnLeft,xnTop CONTAINER  oContainer ;
                  SIZE       xnWidth - xnLeft, xAlturaPict ;
                  STYLE      10 ;
                  BACKCOLOR  hwg_GetSysColor( COLOR_3DFACE ) ; 
                  BACKSTYLE  2

   @ 0,0 BITMAP  oPicture ;
         SHOW    "" ;
         OF      oContainer ;
         SIZE    0, 0 ;
         STRETCH 0 

   @ 0,0 SAY EXTENDED oLabel ;
             CAPTION  "" ;
             OF       oContainer ;
             SIZE     oContainer:nWidth, xAlturaText ;
             STYLE    SS_CENTER ;
             COLOR    N_BLACK ;
             BACKTRANSPARENT 

RETURN Nil
                
RETURN Nil

FUNCTION TelaDelay( nTime ) 
LOCAL iTime := Seconds()

   DO WHILE Seconds() - iTime < nTime
      hwg_DoEvents()
   ENDDO
    
RETURN Nil