Combobox: How to color items

Re: Combobox: How to color items

Postby nageswaragunupudi » Tue Feb 27, 2018 6:24 am

ukoenig wrote:Rao,

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

Image

regards
Uwe :D


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: Select all  Expand view
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: Select all  Expand view
#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
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Combobox: How to color items

Postby ukoenig » Tue Feb 27, 2018 9: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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Combobox: How to color items

Postby ukoenig » 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 :D

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 :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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Combobox: How to color items

Postby Horizon » Mon Oct 07, 2019 5:13 pm

ukoenig wrote:A test

Image

Image

Image

Image

Image

Image

Image

Code: Select all  Expand view

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 :D


Hi,

Can we use resource bmp?

Code: Select all  Expand view
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: Select all  Expand view
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: Select all  Expand view
Error BASE/1003  Variable does not exist: BMP_SWHITE


Changed like that.
Code: Select all  Expand view
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.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 100 guests