Colors

From Free Pascal wiki
Revision as of 17:32, 1 May 2010 by Mattias2 (talk | contribs) (New page: =Overview= The standard color in the LCL is TColor, which is compatible to Delphi's TColor. TColor can be an RGB, 3x8bit, value or a '''system''' color like '''clDefault'''. The LCL can w...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

The standard color in the LCL is TColor, which is compatible to Delphi's TColor. TColor can be an RGB, 3x8bit, value or a system color like clDefault. The LCL can work together with the fpImage system which uses the TFPColor (RGBA, 4x16bit).

Convert TColor to RGB and back

The unit Graphics provide the following functions:

<Delphi> function Blue(rgb: TColor): BYTE; // does not work on system color function Green(rgb: TColor): BYTE; // does not work on system color function Red(rgb: TColor): BYTE; // does not work on system color function RGBToColor(R, G, B: Byte): TColor; procedure RedGreenBlue(rgb: TColor; out Red, Green, Blue: Byte); // does not work on system color function FPColorToTColor(const FPColor: TFPColor): TColor; function TColorToFPColor(const c: TColor): TFPColor; // does not work on system color </Delphi>


There are some predefined color constants: <Delphi>

 // standard colors
 clBlack   = TColor($000000);
 clMaroon  = TColor($000080);
 clGreen   = TColor($008000);
 clOlive   = TColor($008080);
 clNavy    = TColor($800000);
 clPurple  = TColor($800080);
 clTeal    = TColor($808000);
 clGray    = TColor($808080);
 clSilver  = TColor($C0C0C0);
 clRed     = TColor($0000FF);
 clLime    = TColor($00FF00);
 clYellow  = TColor($00FFFF);
 clBlue    = TColor($FF0000);
 clFuchsia = TColor($FF00FF);
 clAqua    = TColor($FFFF00);
 clLtGray  = TColor($C0C0C0); // clSilver alias
 clDkGray  = TColor($808080); // clGray alias
 clWhite   = TColor($FFFFFF);

</Delphi>


System colors

System colors are color constants with a special meaning. Their real value depends on the context and theme. The following table lists how the system colors are defined. Using them outside the scope of the definition is undefined and the result depends on the widgetset and theme. For example clBackground is the normal background brush of the used device context. If you want to paint button elements on your own custom controls use the drawing functions of the unit Themes.

  • clNone - normally it means: draw nothing. Using it as Control's color is undefined. The control will not get transparent.
  • clDefault - the normal background brush of the target DC (device context). On a Form's canvas a FillRect will paint a rectangular area filled with the normal background of a standard window. This is whatever the widgetset and theme defines. This might be the color gray or a gradient or a picture. Using it as Pen color is not defined. Using clDefault on the Canvas of a TListBox will paint with the normal background, which is normally white on Windows. So in a TListBox clDefault is the same as clWindow.
  • clScrollBar - ?
  • clBackground - ?
  • clActiveCaption - ? Font color for selected text. Defined for controls with editable text like TEdit, TComboBox, TMemo, TListBox, TTreeView.
  • clInactiveCaption - ?
  • clMenu - ?
  • clWindow - the normal background brush of unselected text. Defined for controls like TEdit, TComboBox, TMemo, TListBox, TTreeView.
  • clWindowFrame - ?
  • clMenuText - ?
  • clWindowText - ?
  • clCaptionText - ?
  • clActiveBorder - ?
  • clInactiveBorder - ?
  • clAppWorkspace - ?
  • clHighlight - ?
  • clHighlightText - Font color of selected text.
  • clBtnFace - ?
  • clBtnShadow - ?
  • clGrayText - ?
  • clBtnText - ?
  • clInactiveCaptionText - ?
  • clBtnHighlight - ?
  • cl3DDkShadow - ?
  • cl3DLight - ?
  • clInfoText - Font color for hints. Use together with clInfoBk.
  • clInfoBk - Brush color for hints. Use together with clInfoText.
  • clHotLight - ?
  • clGradientActiveCaption - ?
  • clGradientInactiveCaption - ?
  • clMenuHighlight - ?
  • clMenuBar - ?
  • clForm - ?
  • clColorDesktop - ?
  • cl3DFace - ?
  • cl3DShadow - ?
  • cl3DHiLight - ?
  • clBtnHiLight - ?

Drawing theme elements on your custom controls

The unit Themes provides functions to draw single elements of standard controls. For example to draw an expand sign like a TTreeView use the following code:

<Delphi> uses Themes;

...

procedure TYourCustomControl.Paint; const

 PlusMinusDetail: array[Boolean {Hot}, Boolean {Expanded}] of TThemedTreeview =
 (
   (ttGlyphClosed, ttGlyphOpened),
   (ttHotGlyphClosed, ttHotGlyphOpened)
 );

var

 Details: TThemedElementDetails;
 R: TRect;
 Collapse: boolean;

begin

 ...
 //draw a themed expand sign.
 Details := ThemeServices.GetElementDetails(PlusMinusDetail[False, Collapse]);
 R := Rect(ALeft, ATop, ARight + 1, ABottom + 1);
 ThemeServices.DrawElement(Canvas.Handle, Details, R, nil);
 ...

end; </Delphi>