FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Combobox: How to color items
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Combobox: How to color items
Posted: Tue Feb 27, 2018 06:24 AM
ukoenig wrote:Rao,

the left upper corner is different in color
to show a black frame



regards
Uwe :-)


On the subject of bitmaps like this, I can suggest a small function which can create such bitmaps on the fly.
We can specify the inner color, border color and thickness. We can even specify translucent alpha colors.
We can specify width, height and shape, rectangle, square, circle, ellipse.
The bitmap produced is an alpha bitmap.

Code (fw): Select all Collapse
function ColorBlockBmp( nColor, nBorderColor, nWidth, nHeight, nBorderSize, lEllipse )

   local hBmp, x, cShape, aShapes := {}

   DEFAULT nColor := CLR_WHITE, nBorderColor := CLR_BLACK, nWidth := 64, nHeight := 16, ;
           nBorderSize := 2, lEllipse := .f.

   x        := Ceiling( nBorderSize / 2 )
   cShape   := If( lEllipse, "E", "R" )

   AAdd( aShapes, { cShape, nColor,  0, nWidth, nHeight, 0, 0, nHeight - 1, nWidth - 1 } )
   if nBorderSize > 0
      AAdd( aShapes, { cShape, nBorderColor, nBorderSize, nWidth, nHeight, x, x, ;
                            nHeight - x - 1, nWidth - x - 1 } )
   endif

   hBmp  := FW_CreateBitmap( { nWidth, nHeight, aShapes } )

return hBmp


This is a test program using the above function.
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local aBmp[ 3 ]
   local oWnd, oBrush

   aBmp[ 1 ]   := ColorBlockBmp( CLR_HGREEN, CLR_BLACK,128,  48, 4 )
   aBmp[ 2 ]   := ColorBlockBmp( nARGB( 128, CLR_WHITE ), CLR_HBLUE, 128,128, 6, .T. )
   aBmp[ 3 ]   := ColorBlockBmp( CLR_YELLOW, CLR_HRED, 128, 128, 6 )

   DEFINE BRUSH oBrush FILE "\fwh\bitmaps\sea.bmp" RESIZE

   DEFINE WINDOW oWnd BRUSH oBrush

   ACTIVATE WINDOW oWnd ON PAINT ( ;
      oWnd:DrawImage( aBmp[ 1 ], { 0,   0, 200, 150 } ), ;
      oWnd:DrawImage( aBmp[ 2 ], { 0, 150, 200, 300 } ), ;
      oWnd:DrawImage( aBmp[ 3 ], { 0, 300, 200, 600 } )  )

   AEval( aBmp, { |o| DeleteObject( o ) } )
   RELEASE BRUSH oBrush

return nil


Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Combobox: How to color items
Posted: Tue Feb 27, 2018 09:02 AM

Mr. Rao,

thank You very much
The solutionn makes painting of these image-types easy :shock: :shock:
I'm always interested on graphic-solutions.

regards
Uwe :D

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: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Combobox: How to color items
Posted: Thu Mar 01, 2018 12:48 PM
Mr. Rao,

I'm creating a BMP-painter for this special kind of images using Your function.
With my first tests it works great :-)

We can do a visual design of styles, colors and size
The design can be saved as BMP.
It saves a lot of time instead using a external Paint-program.
It will be next in line after finishing my forum-sample-import

I remember there is still another style 4 < Roundrect > can this be included ?

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: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Combobox: How to color items
Posted: Mon Oct 07, 2019 05:13 PM
ukoenig wrote:A test















Code (fw): Select all Collapse
REDEFINE COMBOBOX oCbx2 VAR cItem4 ;
ID 140 OF oDlg ;
ITEMS   { "   White", "   Blue", "   Rosso", "   Yellow", "   Green", "   Red" } ;
BITMAPS { c_path + "sWhite.bmp",;
                c_path + "sBlue.bmp",;
                c_path + "sRosso.bmp",;
                c_path + "sYellow.bmp",;
               c_path + "sGreen.bmp",;
               c_path + "sRed.bmp" }
oCbx2:nItemHeight( 22 )


regards
Uwe :-)


Hi,

Can we use resource bmp?

Code (fw): Select all Collapse
Bmp_sBlue       BITMAP "Res\\sblue.bmp"
Bmp_sGreen  BITMAP "Res\\sgreen.bmp"
Bmp_sRed        BITMAP "Res\\sred.bmp"
Bmp_sRosso  BITMAP "Res\\srosso.bmp"
Bmp_sWhite  BITMAP "Res\\swhite.bmp"
Bmp_sYellow BITMAP "Res\\syellow.bmp"


Code (fw): Select all Collapse
REDEFINE COMBOBOX oCbx2 VAR cItem4 ;
ID 140 OF oDlg ;
ITEMS   { "   White", "   Blue", "   Rosso", "   Yellow", "   Green", "   Red" } ;
BITMAPS { Bmp_sWhite, Bmp_sBlue, Bmp_sRosso, Bmp_sYellow, Bmp_sGreen, Bmp_sRed }
oCbx2:nItemHeight( 22 )


It gives an error :
Code (fw): Select all Collapse
Error BASE/1003  Variable does not exist: BMP_SWHITE


Changed like that.
Code (fw): Select all Collapse
REDEFINE COMBOBOX oCbx2 VAR cItem4 ;
ID 140 OF oDlg ;
ITEMS   { "   White", "   Blue", "   Rosso", "   Yellow", "   Green", "   Red" } ;
BITMAPS { "Bmp_sWhite", "Bmp_sBlue", "Bmp_sRosso", "Bmp_sYellow", "Bmp_sGreen", "Bmp_sRed" }
oCbx2:nItemHeight( 22 )


There is not any bitmaps in combobox.

Any Solution? Thanks.
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06

Continue the discussion