0% found this document useful (0 votes)
9K views5 pages

Colors - Free Pascal Wiki

The document discusses color handling in Free Pascal. It describes the TColor type used to represent colors, and provides functions to convert between TColor and RGB values. It also discusses system colors, which adapt to the current theme, and common system color constants like clInfoBk and clInfoText. A table lists many standard system color constants and their typical meanings.

Uploaded by

Budi Santo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9K views5 pages

Colors - Free Pascal Wiki

The document discusses color handling in Free Pascal. It describes the TColor type used to represent colors, and provides functions to convert between TColor and RGB values. It also discusses system colors, which adapt to the current theme, and common system color constants like clInfoBk and clInfoText. A table lists many standard system color constants and their typical meanings.

Uploaded by

Budi Santo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Colors - Free Pascal wiki Page 1

Colors
From Free Pascal wiki

Contents
1 Overview
2 Convert TColor to RGB and back
3 System colors
3.1 Example: clInfoBk, clInfoText
3.2 Theme changes
3.3 Table of system colors
4 Drawing theme elements on your custom controls

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:

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

There are some predefined color constants:

// 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);

http://wiki.freepascal.org/Colors 12/27/2012 06:38:03 AM


Colors - Free Pascal wiki Page 2

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);

System colors
Example: clInfoBk, clInfoText
System colors are color constants with a special meaning. Their real value depends on the context and theme. They
are not simple colors. For example clInfoBk:

Form1.Canvas.Brush.Color:=clInfoBk; // use the default background brush of a hint window


Form1.Canvas.FillRect(10,10,50,50);

A hint window on MS Windows might have a white background so the above will draw white. On Linux/gtk2 it
might be a metallic texture, so the above will draw the texture. If you want to put some text onto this you need a
corresponding color like clInfoText, otherwise your text might be unreadable for the user. For example:

Form1.Canvas.Brush.Color:=clInfoBk; // use the default background brush of a hint window


Form1.Canvas.FillRect(10,10,50,50);
Form1.Canvas.Font.Color:=clInfoText; // use the default text color of a hint window
Form1.Canvas.TextOut(10,10,'Hint');

The system color clInfoBk can not be used for Pen.Color and not for Font.Color. If you do so the result is
undefined and depends on the widgetset and user theme. The same for clInfoText: It can only be used as a
Font.Color. Using it as Brush.Color may not work. At the moment all widgetsets allow to use it as Pen.Color too.

Theme changes
When the user switches the theme the system colors changes. A clInfoBk might change from white to blue or from
a color to a texture. This change will happen when you allocate a new Brush handle. Keep in mind that a simple
assignment Brush.Color:=clInfoBk does not allocate a Brush Handle. The Brush Handle is allocated on use. For
example:

Form1.Canvas.Brush.Color:=clInfoBk; // this will not create a new brush handle


Form1.Canvas.FillRect(10,10,50,50); // this will create the brush handle with the currently active theme brush
for hint windows
...
// if the theme changes in this moment the Brush.Handle is still allocated with the old values
...

http://wiki.freepascal.org/Colors 12/27/2012 06:38:03 AM


Colors - Free Pascal wiki Page 3

Form1.Canvas.FillRect(10,10,50,50); // this will paint with the old theme brush


Form1.Canvas.Brush.Color:=clInfoBk; // assigning the old value will not create a new brush handle
Form1.Canvas.FillRect(10,10,50,50); // this will paint with the old theme brush
Form1.Canvas.Brush.Color:=clRed; // assigning a new color, old Handle invalid
Form1.Canvas.Brush.Color:=clInfoBk; // assigning a new color, old Handle invalid
Form1.Canvas.FillRect(10,10,50,50); // this will create a new handle and paint with the new theme

Table of system colors


The following table lists the system colors and their meaning. Using them outside the scope of the definition is
undefined and the result depends on the widgetset and theme. For example clDefault 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.

Delphi Supported
Constant LCL definition
notes Widgetsets
drawsnothing. Using it as Control's color is undefined. The
clNone - all
control will not get transparent.
Using it for Brush will use 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.
clDefault Using clDefault on the Canvas of a TListBox will - all
paint with the normal background, which is normally
white on Windows. So in a TListBox clDefault is the
same as clWindow.
Using it as Pen color will use the default line color
for the device context.
Using it as Font color will use the normal text color
of the device context.

clScrollBar Scrollbar body - all


clBackground ? - all
clActiveCaption Active window titlebar - none
clInactiveCaption Inactive window titlebar - none
clMenu Regular menu item background color - none
The normal background brush of unselected text. Defined
clWindow for controls like TEdit, TComboBox, TMemo, TListBox, - none
TTreeView.
clWindowFrame Color of frame around the window - none

http://wiki.freepascal.org/Colors 12/27/2012 06:38:03 AM


Colors - Free Pascal wiki Page 4

clMenuText The font color to use together with clMenu - none


clWindowText Font color to use together with clWindow - none
clCaptionText Active window titlebar text color - none
clActiveBorder ? - none
clInactiveBorder ? - none
clAppWorkspace MDIMain form background - none
clHighlight The brush color of selected element - none
clHighlightText Font color of selected text (to use together with clHighligh). - none
clBtnFace Button background - none
Button shadow color (bottom right) used to achieve 3D
clBtnShadow - none
effect
clGrayText The font color of disabled element - none
clBtnText Button font color to use together with clBtnFace - none
clInactiveCaptionText Inactive window titlebar text color - none
clBtnHighlight Button highlight color (top left) used to achieve 3D effect - none
cl3DDkShadow ? - none
cl3DLight ? - none
clInfoText Font color for hints. Use together with clInfoBk - all
clInfoBk Brush color for hints. Use together with clInfoText - all
clHotLight ? - none
The second color used to make gradient of active window
clGradientActiveCaption - none
titlebar
The second color used to make gradient for inactive
clGradientInactiveCaption - none
window titlebar
clMenuHighlight The background color of selected menu item - none
clMenuBar The Backround color of menu bar - none
clForm ? - none
clColorDesktop ? - none
cl3DFace ? - none
cl3DShadow ? - none
cl3DHiLight ? - none
clBtnHiLight Same as clBtnHighlight - none

Drawing theme elements on your custom controls

http://wiki.freepascal.org/Colors 12/27/2012 06:38:03 AM


Colors - Free Pascal wiki Page 5

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:

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;

Retrieved from "http://wiki.freepascal.org/index.php?title=Colors&oldid=58812"


Category: Graphics

This page was last modified on 6 May 2012, at 09:57.


Content is available under .

http://wiki.freepascal.org/Colors 12/27/2012 06:38:03 AM

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy