FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Button-group RADIO-style
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Button-group RADIO-style
Posted: Sun Jan 18, 2015 06:04 PM
Hello,

I needed a button-group that works like radios.
The position of the selected button is saved to a INI.
After a new start, the saved button shows the status ( selected image ).
That all works like a radio, but with a visual-effect.

The result :

A color selection



selecting a new color
the image changes on focus




the new selected color
the old selected button ( white ) restores the image




best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Button-group RADIO-style
Posted: Fri Jan 23, 2015 08:43 AM

Uwe,

You could use a group of TBitmap controls and keep track of all them using an array.

But not sure if you can make a TBitmap control paint as a circle.

have you ever tried it ? :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Button-group RADIO-style
Posted: Fri Jan 23, 2015 08:05 PM

Antonio,

thank You for the info,
I will have a closer look at this solution and tell about the result.

best regards
Uwe :)

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Button-group RADIO-style
Posted: Mon Jan 26, 2015 09:27 PM
Code (fw): Select all Collapse
#include "fivewin.ch"
#define SRCCOPY      0x00CC0020

static oBmp, nSelect := 2

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBrush, n
   local aBtn[ 4 ]
   local aClr := { CLR_YELLOW, CLR_HRED, CLR_GREEN, CLR_HBLUE }

   DEFINE BITMAP oBmp   FILE "c:\fwh\bitmaps\32x32\yes2.bmp"
   DEFINE BRUSH  oBrush FILE "c:\fwh\bitmaps\olga1.jpg" RESIZE
   DEFINE WINDOW oWnd  BRUSH oBrush

   for n := 1 to 4
      @ -48 + n * 64,200 BTNBMP aBtn[ n ] SIZE 64,64 PIXEL OF oWnd NOBORDER TRANSPARENT UPDATE ACTION ( nSelect := ::Cargo, oWnd:Update() )
      aBtn[ n ]:SetColor( CLR_BLACK, aClr[ n ] )
      aBtn[ n ]:Cargo := n
      aBtn[ n ]:bPainted := { |hDC,hPS,oBtn| BmpPaint( hDC, oBtn ) }
   next

   ACTIVATE WINDOW oWnd CENTERED
   RELEASE BRUSH oBrush
   oBmp:End()

return nil

//----------------------------------------------------------------------------//

static function BmpPaint( hDC, oBtn )

   local hBrush    := CreateSolidBrush( oBtn:nClrPane )
   local hOldBrush := SelectObject( hDC, hBrush )
   local hPen := CreatePen( hDC, 2, If( oBtn:lFocused .or. oBtn:lMOver, CLR_WHITE, oBtn:nClrPane ) )
   local n, w, h

   n := 3

   Ellipse( hDC, n, n, oBtn:nWidth - 1 - n, oBtn:nHeight - 1 - n, hPen )

   SelectObject( oBtn:hDC, hOldBrush )
   DeleteObject( hPen )
   DeleteObject( hBrush )

   if oBtn:Cargo == nSelect
      W     := nBmpWidth(  oBmp:hBitmap )
      h     := nBmpHeight( oBmp:hBitmap )
      PalBmpDraw( hDC, ( oBtn:nWidth - w ) / 2, ( oBtn:nHeight - h ) / 2 , oBmp:hBitmap, oBmp:hPalette, w, h, SRCCOPY, .t., oBtn:nClrPane )
   endif

return nil

//----------------------------------------------------------------------------//
Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Button-group RADIO-style
Posted: Tue Jan 27, 2015 11:19 PM
Mr. Rao,

Trying the function, there was a problem painting the buttons ( only a visible border ).
I found another possible solution with a visible focus :

Different button-styles :
1. coloed buttons
2. buttons with image and connected text like normal radios.
-- The textcolor could change on focus as well.



I wanted to use a FOR / NEXT for
oRBtn[1]:bClrGrad = { | lMouseOver | If( ! lMouseOver, aBack[1], aFocus[1] ) }
but all buttuns are using color 6
thats the reason there is a line for each button
Maybe possible just one line with :cargo ?

Code (fw): Select all Collapse
Local aFocus[6], aBack[6], aRColor[6], oRBtn[6]
...
...
aRColor[1] := 0
aRColor[2] := 16777215
aRColor[3] := 54121
aRColor[4] := 16711680
aRColor[5] := 255
aRColor[6] := 65535
I := 1
nTop := 58
FOR I := 1 to 6 // 6 buttons
    @ nTop, 325 BTNBMP oRBtn[I] OF oDlg  ;
    SIZE 15, 15 NOBORDER TRANSPARENT 2007 UPDATE ;
    ACTION ( nBtnPos := ::Cargo, ;
      nTxtColor := BMPPAINT( oDlg, oRBtn, nBtnPos, aRColor ) ) // value saved to INI    
    oRBtn[ I ]:lEllipse = .T.
    oRBtn[ I ]:Cargo := I
    // can be different !!!   
    aFocus[I] := { { 0.1, aRColor[I], aRColor[I] }, { 0.1, aRColor[I], aRColor[I] } } 
    
    aBack[I]   := { { 0.1, aRColor[I], aRColor[I] }, { 0.1, aRColor[I], aRColor[I] } }
    nTop := nTop + 18
NEXT

// possible to include in FOR / NEXT ???
oRBtn[1]:bClrGrad = { | lMouseOver | If( ! lMouseOver, aBack[1], aFocus[1] ) }
oRBtn[2]:bClrGrad = { | lMouseOver | If( ! lMouseOver, aBack[2], aFocus[2] ) }
oRBtn[3]:bClrGrad = { | lMouseOver | If( ! lMouseOver, aBack[3], aFocus[3] ) }
oRBtn[4]:bClrGrad = { | lMouseOver | If( ! lMouseOver, aBack[4], aFocus[4] ) }
oRBtn[5]:bClrGrad = { | lMouseOver | If( ! lMouseOver, aBack[5], aFocus[5] ) }
oRBtn[6]:bClrGrad = { | lMouseOver | If( ! lMouseOver, aBack[6], aFocus[6] ) }

// loaded from INI
nTxtColor := BMPPAINT( oDlg, oRBtn, nBtnPos, aRColor )
...
...
// ------------------

FUNCTION BMPPAINT( oDlg, oRBtn, nBtnPos, aRColor )
LOCAL I := 1, nRColor := 0

FOR I := 1 TO LEN( oRBtn )
     IF nBtnPos = I
          nRColor := aRColor[I]
     ENDIF
     oRBtn[I]:SetFile( NIL, NIL )
     IF I = nBtnPos
          oRBtn[I]:SetFile( c_path1 + "Yes.Bmp", c_path1 + "Yes.Bmp" )
     ENDIF
NEXT

AEVAL( oDlg:aControls, { | oCtl | IIF( oCtl:ClassName() == "TSAY", ; // only SAY is used
     ( oCtl:Setcolor( nRColor,  ), oCtl:Refresh() ), NIL ) } )

RETURN nRColor


best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Button-group RADIO-style
Posted: Wed Jan 28, 2015 06:00 PM

we should never use loop variables in codeblock created inside a loop. We should use detached variable concept. you can find many examples.

I provided an approach in my sample. you can improve upon it to your taste

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion