AutoBackgrd-Color (Say,Get) related to Fontcolor (Contrast)

AutoBackgrd-Color (Say,Get) related to Fontcolor (Contrast)

Postby ukoenig » Wed Apr 11, 2012 10:24 am

Hello,

looking for a solution, to show a font with a selected color on a contrast-background,
I used with a little change the Contrast-function from xBrowse.
Using different Fontcolors on Say on Get, the needed Background is automatically selected,
to show a visible text.

Because of fontcolor < RED >, the Say-background-color changed to white :

Image

Sample :

Code: Select all  Expand view

...
...
REDEFINE SAY oTime PROMPT cTime ID 510 OF oDlg2 UPDATE
oTime:SetColor( nTimeColor, GET_CONTR(nTimeColor))
oTime:SetFont( oTimeFont )

REDEFINE BTNBMP oBtn1 OF oDlg2 ;
ID 130  PIXEL 2007 ;
NOBORDER ;
PROMPT "&Time-color" ;
FILENAME c_path + "\Images\Select.Bmp" ;
ACTION ( nTimeColor := ChooseColor(), ;
          oTime:SetColor( nTimeColor, GET_CONTR(nTimeColor) ), ;
          oTime:Refresh ) ;
FONT oBrwFont  ;
LEFT
oBtn1:lTransparent := .t.  
oBtn1:cToolTip =  { "Time-" + CRLF + "Color","Color-Selection", 1, CLR_BLACK, 14089979 }
oBtn1:SetColor( 0, )
...
...

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

FUNCTION GET_CONTR(nFontClr)
LOCAL nClr, nLuma, nContrast

nContrast  := nFontClr

// Fontcolor
nLuma := ( 0.299 * nRGBRed( nFontClr ) + 0.587 * nRGBGreen( nFontClr ) + 0.114 * nRGBBlue( nFontClr ) )

nContrast  := IF( nLuma < 150, CLR_WHITE, CLR_BLACK )

RETURN nContrast
 


Best Regards
Uwe :lol:
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

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 124 guests