show a btnbmp pressed on buttonbar

Post Reply
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

show a btnbmp pressed on buttonbar

Post by Silvio.Falconi »

Image

On a buttonbar (2015) I have these btnbmps

and I would like that when I press a button it stays pressed to simulate the select option , so I made

DEFINE BUTTON oSelf:oPlus FILENAME ".\bitmaps\plus.bmp" OF ::oBar ;
TOOLTIP "plus numbers" ;
ACTION (oSelf:oPlus:lPressed:=!oSelf:oPlus:lPressed, oSelf:oPlus:refresh())

but it is pressed but not change the color how resolve?
Last edited by Silvio.Falconi on Mon Oct 17, 2022 3:02 pm, edited 1 time in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Antonio Linares
Site Admin
Posts: 42512
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: show a btnbmp pressed

Post by Antonio Linares »

Dear Silvio,

Maybe replacing the bitmap with another with different color ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: show a btnbmp pressed

Post by Silvio.Falconi »

Antonio Linares wrote:Dear Silvio,

Maybe replacing the bitmap with another with different color ?


I did not think about it
but otherwise in the ribbonbar it does it automatically if you use lselected as you can see here

Image


why on buttonbar not is the same ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: show a btnbmp pressed

Post by Silvio.Falconi »

I tried

DEFINE BUTTON oSelf:oPlus FILENAME ".\bitmaps\plus.bmp" OF ::oBar ;
TOOLTIP "plus numbers" ;
ACTION (oSelf:oPlus:lPressed:=!oSelf:oPlus:lPressed,;
oSelf:oPlus:setcolor( CLR_BLUE, If( oSelf:oPlus:lPressed == .t., CLR_RED, CLR_BLUE )) ,;
oSelf:oPlus:refresh()

but not run ok
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: show a btnbmp pressed

Post by Silvio.Falconi »

No I made

DEFINE BUTTON oSelf:oPlus FILENAME ".\bitmaps\plus.bmp" OF ::oBar ;
TOOLTIP "plus numbers" ;
ACTION (ChangePressedBtn(oSelf:oPlus))


Code: Select all | Expand


Function ChangePressedBtn(oBtn)
   local  bClrGradSelect := {| lPressed | if( lPressed  ,;
      { ;
         {2/5, nRGB( 253,212,168 ), nRGB( 251,178,99 ) },;
        {3/5, nRGB( 250,157,52 ), nRGB( 252,234,163 ) };
      },;
      { ;
         {2/5, nRGB( 245,177,110 ), nRGB( 243,165,89 ) },;
        {3/5, nRGB( 216,136,52 ), nRGB( 249,202,98 ) } ;
      } ) }

    local  bClrGradNormal := { | lPressed | if ( lPressed,;
        { ;
          { 2/5, RGB( 194, 213, 242 ), RGB( 194, 213, 242 ) } , ;
          { 3/5, RGB( 194, 213, 242 ), RGB( 194, 213, 242 ) } ;
        },;
        {;
          { 2/5, nRGB( 201, 224, 247 ), nRGB( 201, 224, 247 ) } , ;
          { 3/5, nRGB( 201, 224, 247 ), nRGB( 201, 224, 247 ) } ;
        } ) }

    oBtn:lPressed:=!oBtn:lPressed

    ?  oBtn:lPressed

    If oBtn:lPressed
       oBtn:bClrGrad    := bClrGradSelect
   else
       oBtn:bClrGrad    :=  bClrGradNormal
   Endif


   oBtn:refresh()

   return nil
 


Image

It run but when we put it back it doesn't take away the color maybe I did something wrong :) lpressed is alway .t.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: show a btnbmp pressed

Post by Silvio.Falconi »

Please try this test

Code: Select all | Expand

#include "fivewin.ch"

Function test()
local oWnd
local oBar,oPlus,oNumber,oCancel

DEFINE WINDOW  oWnd


 DEFINE BUTTONBAR oBar TOP  OF oWnd  2015

DEFINE BUTTON oNumber FILENAME "one.bmp"  OF oBar    ;
      TOOLTIP "one n umber"  ;
      ACTION  ChangePressedBtn(oNumber)

DEFINE BUTTON oPlus FILENAME "plus.bmp"  OF oBar    ;
      TOOLTIP "plus numbers"  ;
      ACTION ChangePressedBtn(oPlus)


DEFINE BUTTON oCancel  FILENAME "delete.bmp"    OF oBar    ;
      TOOLTIP "cancel"  ;
      ACTION (ChangePressedBtn(oPlus),;
              ChangePressedBtn(oNumber) )



ACTIVATE WINDOW oWnd
RETURN NIL
//---------------------------------------------------------------------//

Function ChangePressedBtn(oBtn)

 local  bClrGradSelect :=   { | lInvert | If( ! lInvert,;
                    { { 1, RGB( 244, 244, 245 ), RGB( 244, 244, 245 ) } },;
                    { { 1, RGB( 255, 253, 222 ), RGB( 255, 231, 151 ) } } ) }

 local  bClrGradNormal :=  { | lInvert | If( ! lInvert,;
                    { { 1, RGB( 244, 244, 245 ), RGB( 244, 244, 245 ) } },;
                    { { 1, RGB( 145, 201, 247 ), RGB( 145, 201, 247 ) } } ) }

   oBtn:Toggle()

    If oBtn:lPressed
       oBtn:bClrGrad    := bClrGradSelect
   else
      oBtn:bClrGrad    :=  bClrGradNormal
    Endif

    oBtn:refresh()
   return ni


plus.bmp
Image

one.bmp
Image

delete.bmp
Image



it seem run ok but when I press X (3th button) it not refresh
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: show a btnbmp pressed on buttonbar

Post by karinha »

Dear Silvio, mira C:\FWH..\SAMPLES\TESTSK1.PRG si ayuda.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: show a btnbmp pressed on buttonbar

Post by karinha »

Estimado Silvio, única forma en que logré hacerlo funcionar.

Dear Silvio, only way I managed to make it work.

Code: Select all | Expand


// C:\FWH..\SAMPLES\GRADSIL.PRG

#include "FiveWin.ch"

#define K_F5  (-4)
#Define aPubGrad {| lInvert | If( lInvert, ;
                 { { 1 / 3, nRGB( 255, 253, 222 ), nRGB( 255, 231, 151 ) }, ;
                 { 2 / 3, nRGB( 255, 215,  84 ), nRGB( 255, 233, 162 ) }    ;
                 },                                                         ;
                 { { 1 / 2, nRGB( 219, 230, 244 ), nRGB( 207 - 50, 221 - 25, 255 ) }, ;
                 { 1 / 2, nRGB( 201 - 50, 217 - 25, 255 ), nRGB( 231, 242, 255 ) }    ;
                 } ) }

STATIC oWnd, oBmp, oBtn1, oBtn2, oBtn3, oBtn4, oBtn5, oBtn6, oBtn7, oBtn8, oBtn9

function Main()

   local oBrush, oBar, hDLL
   local oSkinB

   SET _3DLOOK ON

   oSkinB = TSkinButton():New()
   oSkinB:nClrBorder0_N = RGB( 249, 194, 179 )
   oSkinB:nClrBorder1_N = RGB( 181, 61, 29 )
   oSkinB:aClrNormal    = { { 0.2, RGB( 254, 154, 128 ), RGB( 254, 154, 128 ) }, ;
                            { 0.8, RGB( 252, 85, 40 ), RGB( 181, 61, 29 ) } }
   
   SkinButtons( oSkinB )

   // don't use VK_F5 because VK_F5 and 't' have the same code !
   // for VK_F5 use Clipper's K_F5
   SetKey( K_F5, { || MsgInfo( "Testing SetKey feature..." ) } )

   DEFINE BRUSH oBrush STYLE BORLAND

   DEFINE WINDOW oWnd FROM 1, 5 TO 20, 75 BRUSH oBrush        ;
      TITLE "Cambiar los colores de los botones de ButtonBar" ;
      MENU  BuildMenu()

   DEFINE BUTTONBAR oBar _3D SIZE 31, 33 OF oWnd // 2007 // no use 2007/2015

   WITH OBJECT oBar  // VER: ANCHO.PRG

      oBar:bClrGrad := aPubGrad

      oBar:bRClicked := { || NIL } // Botao direito  do Mouse desligado.
      oBar:bLClicked := { || NIL } // Botao Esquerdo do Mouse desligado.

      // oBar:SetFont( oFont )
      // Cor no Prompt dos Botoes
      // oBar:nClrText := CLR_HBLUE // BLACK
      oBar:Adjust()

   END

   DEFINE BUTTON oBtn1 FILE "..\bitmaps\Select.bmp" OF oBar ;
      MESSAGE "Testing a sample selection dialog" NOBORDER  ;
      TOOLTIP "Selection Dialog"

   DEFINE BUTTON oBtn2 FILE "..\bitmaps\Edit.bmp"   OF oBar ;
      MESSAGE "Testing a typical bussiness dialog" NOBORDER ;
      TOOLTIP "Images DataBase"

   DEFINE BUTTON oBtn3 FILE "..\bitmaps\Browse.bmp"   OF oBar ;
      MESSAGE "Easy and powerfull Browsers" NOBORDER          ;
      TOOLTIP "Browse"

   DEFINE BUTTON oBtn4 FILE "..\bitmaps\Exit.bmp"   OF oBar   ;
      ACTION _Exit() MESSAGE "When you want to end"  NOBORDER ;
      TOOLTIP "Exit"

   DEFINE BUTTON oBtn5 FILE "..\bitmaps\Colors.bmp" OF oBar   ;
      ACTION ChooseColor() GROUP                              ;
      MESSAGE "Calling Windows standard color selection dialog" NOBORDER ;
      TOOLTIP "Colors"

   DEFINE BUTTON oBtn6 FILE "..\bitmaps\Dlg.bmp"    OF oBar ;
      ACTION cGetFile( "*.dbf", "Select a DBF" ) ;
      MESSAGE "Calling Windows standard Get a File dialog" NOBORDER ;
      TOOLTIP "GetFile"

   DEFINE BUTTON oBtn7 FILE "..\bitmaps\Fonts.bmp"  OF oBar ACTION ChooseFont() ;
      MESSAGE "Calling Windows standard font selection dialog" NOBORDER ;
      TOOLTIP "GetFont"

   DEFINE BUTTON oBtn8 FILE "..\bitmaps\Blocks.bmp" OF oBar GROUP ;
      MESSAGE "About FiveWin designers" NOBORDER ;
      TOOLTIP "About"

   DEFINE BUTTON oBtn9 FILE "..\bitmaps\Open.bmp" OF oBar ;
      ACTION CAMBIA_COLOR() MESSAGE "Cambiar colores de los Buttons" NOBORDER ;
      TOOLTIP "Cambiar colores de los Buttons"

   //   @ 6, 18 BITMAP oBmp FILENAME "..\bitmaps\Luck.bmp" OF oWnd
   DEFINE BITMAP oBmp FILENAME "..\bitmaps\fiveback.bmp"

   oWnd:bPainted = { | hDC | BmpTiled( hDC, oWnd, oBmp ) }

   SET MESSAGE OF oWnd ;
      TO "FiveWin - Cambiar los colores de los botones de ButtonBar!" ;
      CENTERED 2007

   ACTIVATE WINDOW oWnd MAXIMIZED

return nil

FUNCTION CAMBIA_COLOR()

   LOCAL nCor

   nCor := ChooseColor()

   oBtn1:nClrText := nCor
   oBtn1:nClrPane := nCor

   oBtn2:nClrText := nCor
   oBtn2:nClrPane := nCor

   oBtn3:nClrText := nCor
   oBtn3:nClrPane := nCor

   oBtn4:nClrText := nCor
   oBtn4:nClrPane := nCor

   oBtn5:nClrText := nCor
   oBtn5:nClrPane := nCor

   oBtn6:nClrText := nCor
   oBtn6:nClrPane := nCor

   oBtn7:nClrText := nCor
   oBtn7:nClrPane := nCor

   oBtn8:nClrText := nCor
   oBtn8:nClrPane := nCor

   oBtn9:nClrText := nCor
   oBtn9:nClrPane := nCor

RETURN NIL

function BuildMenu()

   local oMenu

   MENU oMenu 2007

      MENUITEM "Some &Dialogs"
      MENU
         MENUITEM "Make a selection..." ;
            MESSAGE "It's time to start building Windows applications easily!"

         MENUITEM "Now you have a real chance..." ;
            MESSAGE "Quick and easy Windows applications using your Clipper!!!"

         SEPARATOR

         MENUITEM "End..." MESSAGE "Exit this demo" ACTION _Exit()     // UDF
      ENDMENU

      MENUITEM "Some &Standards..."
      MENU
         MENUITEM "Choose A &Color..." ;
            MESSAGE "Calling standard Windows dialogs" ACTION ChooseColor()

         MENUITEM "Getting a &file..." ;
            MESSAGE "Hey, see how easy this is" ;
            ACTION cGetFile( "*.dbf", "Select a DBF" )

         MENUITEM "Selecting a f&ont..." ;
            MESSAGE "Any Windows facility is ready for you" ;
            ACTION ChooseFont()
      ENDMENU

      MENUITEM "About..." ;
         MESSAGE "Come on... we would like to see your name here soon!"

   ENDMENU

return oMenu

function _Exit()

   oWnd:End()

return nil

STATIC FUNCTION BmpTiled( hDC, oWnd, oBmp )

   local nWidth := oWnd:nWidth(), nHeight := oWnd:nHeight()
   local nRow := 0, nCol := 0, n
   local nBmpWidth  := oBmp:nWidth(),  nBmpHeight := oBmp:nHeight()

   if oBmp:hBitmap == 0
      return nil
   endif

   while nRow < nHeight
      nCol = 0
      while nCol < nWidth
         PalBmpDraw( hDC, nRow, nCol, oBmp:hBitmap )
         nCol += nBmpWidth
      end
      nRow += nBmpHeight
   end

return nil

// FIN / END
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Silvio.Falconi
Posts: 7133
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: show a btnbmp pressed on buttonbar

Post by Silvio.Falconi »

I have a different thing. the two btnbmp are active through a logical variable lnumber, if it is active, oPlus must be activated, if it is negative, oNumber must be activated.
Instead oCancel deselects both buttons and lnumber: = nil
I just solved it like this


Code: Select all | Expand

#include "fivewin.ch"

Function test()
local oWnd
local oBar,oPlus,oNumber,oCancel
local lNumber:=nil

DEFINE WINDOW  oWnd


 DEFINE BUTTONBAR oBar TOP  OF oWnd  2015

DEFINE BUTTON oNumber FILENAME "one.bmp"  OF oBar    ;
      TOOLTIP "one number"  ;
      ACTION  ( ChangePressedBtn(oNumber), lNumber:=.f.)

DEFINE BUTTON oPlus FILENAME "plus.bmp"  OF oBar    ;
      TOOLTIP "plus numbers"  ;
      ACTION (ChangePressedBtn(oPlus), lNumber:=.t.)


DEFINE BUTTON oCancel  FILENAME "delete.bmp"    OF oBar    ;
      TOOLTIP "cancel"  ;
      ACTION  AnnullaSelezione(oPlus,oNumber,lNumber)



ACTIVATE WINDOW oWnd
RETURN NIL
//---------------------------------------------------------------------//

Function ChangePressedBtn(oBtn)

 local  bClrGradSelect :=   { | lInvert | If( ! lInvert,;
                    { { 1, RGB( 244, 244, 245 ), RGB( 244, 244, 245 ) } },;
                    { { 1, RGB( 255, 253, 222 ), RGB( 255, 231, 151 ) } } ) }

 local  bClrGradNormal :=  { | lInvert | If( ! lInvert,;
                    { { 1, RGB( 244, 244, 245 ), RGB( 244, 244, 245 ) } },;
                    { { 1, RGB( 145, 201, 247 ), RGB( 145, 201, 247 ) } } ) }

   oBtn:Toggle()

    If oBtn:lPressed
       oBtn:bClrGrad    := bClrGradSelect
   else
      oBtn:bClrGrad    :=  bClrGradNormal
    Endif

    oBtn:refresh()
    return nil
//--------------------------------------------------------//
Function AnnullaSelezione(oPlus,oNumber,lNumber)
       IF lNumber !=nil
          IF lNumber
             ChangePressedBtn(oPlus)
          Endif
          IF !lNumber
             ChangePressedBtn(oNumber)
          Endif
          oPlus:refresh()
          oNumber:refresh()
       Endif
 return nil
//--------------------------------------------------------/
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: show a btnbmp pressed on buttonbar

Post by karinha »

Very good Silvio. Congratulations. Funciona mui bien.

Code: Select all | Expand


// C:\FWH..\SAMPLES\GRADSIL2.PRG

#Include "FiveWin.ch"

#Define GRAD_BTN_BLACK { | lInvert | If( ! lInvert, ;
                       { { 0.70,0      ,12429486 },{ 0.70,12429486,0       } },;
                       { { 0.40,9928844,12429486 },{ 0.40,12429486,9928844 } } ) }

#Define aPubGrad       { | lInvert | If( lInvert, ;
                       { { 1/3, nRGB( 255, 253, 222 ), nRGB( 255, 231, 151 ) }, ;
                       { 2/3, nRGB( 255, 215,  84 ), nRGB( 255, 233, 162 ) }  ;
                       }, ;
                       { { 1/2, nRGB( 219, 230, 244 ), nRGB( 207-50, 221-25, 255 ) }, ;
                       { 1/2, nRGB( 201-50, 217-25, 255 ), nRGB( 231, 242, 255 ) }  ;
                       } ) }

#Define aPubRedGr      { | lInvert | If( ! lInvert, { { 0.50,16776960,16777215 }, ;
                       { 0.50,16777215,16776960 } }, { { 0.50,128,16777215 },     ;
                       { 0.50,16777215,128 } } ) }

#Define bGrad          { | lInvert | If( ! lInvert, ;
                       { { 1, nRGB( 255, 255, 255 ), nRGB( 230, 234, 239 ) } }, ;
                       { { 1/3, nRGB( 255, 253, 222 ), nRGB( 255, 231, 151 ) }, ;
                       { 2/3, nRGB( 255, 215,  84 ), nRGB( 255, 233, 162 ) }    ;
                       } ) }

FUNCTION Test()

   LOCAL oWnd
   LOCAL oBar, oPlus, oNumber, oCancel, oExit
   LOCAL lNumber := nil

   DEFINE WINDOW  oWnd

   DEFINE BUTTONBAR oBar TOP  OF oWnd 2015

   DEFINE BUTTON oNumber FILENAME "..\bitmaps\16x16\floppy.bmp" OF oBar      ;
      TOOLTIP "one number"                                                   ;
      ACTION ( ChangePressedBtn( oNumber ), lNumber := .F. )

   DEFINE BUTTON oPlus FILENAME "..\bitmaps\16x16\plus.bmp" OF oBar          ;
      TOOLTIP "plus numbers"                                                 ;
      ACTION ( ChangePressedBtn( oPlus ), lNumber := .T. )

   DEFINE BUTTON oCancel  FILENAME "..\bitmaps\16x16\delete.bmp" OF oBar     ;
      TOOLTIP "cancel"                                                       ;
      ACTION  AnnullaSelezione( oPlus, oNumber, lNumber )

   DEFINE BUTTON oExit  FILENAME "..\bitmaps\16x16\exit.bmp"    OF oBar      ;
      TOOLTIP "Salida - Exit - Cancelar"                                     ;
      ACTION( oWnd:End() )

   ACTIVATE WINDOW oWnd

RETURN NIL

FUNCTION ChangePressedBtn( oBtn )

   LOCAL  bClrGradSelect :=   { | lInvert | If( ! lInvert,   ;
      { { 1, RGB( 244, 244, 245 ), RGB( 244, 244, 245 ) } }, ;
      { { 1, RGB( 255, 253, 222 ), RGB( 255, 231, 151 ) } } ) }

   LOCAL  bClrGradNormal :=  { | lInvert | If( ! lInvert,    ;
      { { 1, RGB( 244, 244, 245 ), RGB( 244, 244, 245 ) } }, ;
      { { 1, RGB( 145, 201, 247 ), RGB( 145, 201, 247 ) } } ) }

   oBtn:Toggle()

   IF oBtn:lPressed

      // bGrad-aPubRedGr-aPubGrad-bClrGradSelect
      oBtn:bClrGrad := GRAD_BTN_BLACK // Bello.

   ELSE

      oBtn:bClrGrad := bClrGradNormal

   ENDIF

   oBtn:refresh()

RETURN NIL

FUNCTION AnnullaSelezione( oPlus, oNumber, lNumber )

   IF lNumber != nil

      IF lNumber
         ChangePressedBtn( oPlus )
      ENDIF

      IF !lNumber
         ChangePressedBtn( oNumber )
      ENDIF

      oPlus:refresh()
      oNumber:refresh()

   ENDIF

RETURN NIL

// FIN / END
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Post Reply