Difference between revisions of "Colors/es"
Line 168: | Line 168: | ||
=System colors= | =System colors= | ||
− | == | + | ==Ejemplo: clInfoBk, clInfoText== |
− | + | Los colores de sistema son colores constantes con un significado especial. Su valor real depende del contexto y tema. No son colores simples. | |
− | |||
− | <syntaxhighlight>Form1.Canvas.Brush.Color:=clInfoBk; // | + | Por ejemplo '''clInfoBk''': |
+ | |||
+ | <syntaxhighlight>Form1.Canvas.Brush.Color:=clInfoBk; // Utiliza la brocha por defecto del fondo de una ventana de sugerencia. | ||
Form1.Canvas.FillRect(10,10,50,50);</syntaxhighlight> | Form1.Canvas.FillRect(10,10,50,50);</syntaxhighlight> | ||
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: | 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: | ||
− | <syntaxhighlight>Form1.Canvas.Brush.Color:=clInfoBk; // | + | <syntaxhighlight>Form1.Canvas.Brush.Color:=clInfoBk; // Utiliza el color de brocha para fondo de una ventana de sugerencia. |
Form1.Canvas.FillRect(10,10,50,50); | Form1.Canvas.FillRect(10,10,50,50); | ||
− | Form1.Canvas.Font.Color:=clInfoText; // | + | Form1.Canvas.Font.Color:=clInfoText; // Utiliza el color de texto por defecto de una ventana de sugerencia. |
Form1.Canvas.TextOut(10,10,'Hint');</syntaxhighlight> | Form1.Canvas.TextOut(10,10,'Hint');</syntaxhighlight> | ||
Line 186: | Line 187: | ||
Lo mismo para '''clInfoText''': Solamente puede utilizarse como Font.Color. Utilizarlo para '''Brush.Color''' puede que no funcione. Hasta el momento, todos los widgetsets permiten utilizarlo con '''Pen.Color''' también. | Lo mismo para '''clInfoText''': Solamente puede utilizarse como Font.Color. Utilizarlo para '''Brush.Color''' puede que no funcione. Hasta el momento, todos los widgetsets permiten utilizarlo con '''Pen.Color''' también. | ||
− | Por ejemplo un listado de colores y su aspecto visible | + | Por ejemplo un listado de colores y su aspecto visible utilizado en fuentes: |
[[File:ListadoColoresFuentes.png|center|200px]] | [[File:ListadoColoresFuentes.png|center|200px]] |
Revision as of 14:31, 17 September 2015
Overview
In the LCL TColor is the standard color type. It is compatible with Delphi's TColor. TColor can represent either an RGB (3x8bit) value, or a system color like clDefault. The LCL can also work with the fpImage system which uses the TFPColor type (which is RGBA (4x16bit), not RGB (3x8bit) like TColor).
Conversions between TColor and RGB values
The Graphics unit provides 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
function IsSysColor(AColor: TColorRef): Boolean;
Convert TColor to/from string
Functions to convert strings like "25500" or "$AA0088" or "clNavy" to TColor:
- StringToColor
- StringToColorDef
To convert TColor to a nice string:
- ColorToString
Table of standard colors
About 20 predefined color constants are provided, which are Delphi-compatible:
Colour constant | Meaning | Hexadecimal value for use with TColor | Example |
---|---|---|---|
clBlack | Black | TColor($000000); | |
clMaroon | Maroon | TColor($000080); | |
clGreen | Green | TColor($008000); | |
clOlive | Olive Green | TColor($008080); | |
clNavy | Navy Blue | TColor($800000); | |
clPurple | Purple | TColor($800080); | |
clTeal | Teal | TColor($808000); | |
clGray | Grey | TColor($808080); | |
clSilver | Silver | TColor($C0C0C0); | |
clRed | Red | TColor($0000FF); | |
clLime | Lime Green | TColor($00FF00); | |
clYellow | Yellow | TColor($00FFFF); | |
clBlue | Blue | TColor($FF0000); | |
clFuchsia | Fuchsia | TColor($FF00FF); | |
clAqua | Aqua | TColor($FFFF00); | |
clLtGray | Light Grey | TColor($C0C0C0); | clSilver alias |
clDkGray | Dark Grey | TColor($808080); | clGray alias |
clWhite | White | TColor($FFFFFF); | |
clCream | Cream | TColor($F0FBFF); | Lazarus 1.2 and newer |
clMedGray | Medium Grey | TColor($A4A0A0); | Lazarus 1.2 and newer |
clMoneyGreen | Mint Green | TColor($C0DCC0); | Lazarus 1.2 and newer |
clSkyBlue | Sky Blue | TColor($F0CAA6); | Lazarus 1.2 and newer |
System colors
Ejemplo: clInfoBk, clInfoText
Los colores de sistema son colores constantes con un significado especial. Su valor real depende del contexto y tema. No son colores simples.
Por ejemplo clInfoBk:
Form1.Canvas.Brush.Color:=clInfoBk; // Utiliza la brocha por defecto del fondo de una ventana de sugerencia.
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; // Utiliza el color de brocha para fondo de una ventana de sugerencia.
Form1.Canvas.FillRect(10,10,50,50);
Form1.Canvas.Font.Color:=clInfoText; // Utiliza el color de texto por defecto de una ventana de sugerencia.
Form1.Canvas.TextOut(10,10,'Hint');
El color de sistema clInfoBk no se puede utilizar para Pen.Color ni para Font.Color. Si lo utilizas el resultado no está definido y depende tanto del widgetset como del tema del usuario. Lo mismo para clInfoText: Solamente puede utilizarse como Font.Color. Utilizarlo para Brush.Color puede que no funcione. Hasta el momento, todos los widgetsets permiten utilizarlo con Pen.Color también.
Por ejemplo un listado de colores y su aspecto visible utilizado en fuentes:
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
...
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
Tabla de colores del sistema
La siguente tabla lista los colores del sistema y su significado. Utilizarlos fuera de lo especificado en la definición no estaría definido y el resultado obtenido depende del widgetset y del tema. Por ejemplo clDefault es el color de fondo para la brocha (brush) en el contexto de dispositivo utilizado. Si lo que necesitas es pintar elementos tipo button en tus propios controles personalizados entonces utiliza las funciones de la unidad Themes.
Constant | Definición LCL | Notas Delphi | Widgetsets Soportados |
---|---|---|---|
clNone | Indicates "do not paint". Utilizarlos como color de Control no esta definido. El control no será transparente. | - | todos |
clDefault | Using it for Brush will use the normal background brush of the target DC (device context).
|
- | all |
clScrollBar | Scrollbar body | - | all |
clBackground | ? | - | all |
clActiveCaption | Active window titlebar | - | none |
clInactiveCaption | Inactive window titlebar | - | none |
clMenu | Regular menu item background color | - | none |
clWindow | The normal background brush of unselected text. Defined for controls like TEdit, TComboBox, TMemo, TListBox, TTreeView. | - | none |
clWindowFrame | Color of frame around the window | - | none |
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 |
clBtnShadow | Button shadow color (bottom right) used to achieve 3D effect | - | none |
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 |
clGradientActiveCaption | The second color used to make gradient of active window titlebar | - | none |
clGradientInactiveCaption | The second color used to make gradient for inactive window titlebar | - | none |
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
La unidad Themes aporta funciones para dibujar elementos individuales de controles estandar. Por ejemplo, para dibujar un signo de expansión como un TTreeView utiliza el siguiente código:
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;