Difference between revisions of "Colors/ru"
Line 173: | Line 173: | ||
|} | |} | ||
− | == | + | ==Системные цвета== |
− | === | + | ===Пример: clInfoBk, clInfoText=== |
− | + | Системные цвета - это цветовые константы с особым значением. Их реальное значение зависит от контекста и темы. Они не являются просто цветом. Например, '''clInfoBk''': | |
− | |||
− | <syntaxhighlight lang="pascal">Form1.Canvas.Brush.Color:=clInfoBk; // | + | <syntaxhighlight lang="pascal">Form1.Canvas.Brush.Color:=clInfoBk; // используем цвет кисти по умолчанию для фона в окнах подсказок |
Form1.Canvas.FillRect(10,10,50,50);</syntaxhighlight> | Form1.Canvas.FillRect(10,10,50,50);</syntaxhighlight> | ||
− | + | Окно подсказок в MS Windows может иметь белый фон, поэтому вышеприведенный цвет будет отображаться белым. В Linux/gtk2 это может быть металлическая текстура, поэтому вышеприведенный будет рисовать текстуру. Если вы хотите поместить какой-либо текст в это окно, вам понадобится соответствующий контрастный цвет, например, '''clInfoText''', иначе ваш текст может быть нечитаемым для пользователя. Например: | |
− | <syntaxhighlight lang="pascal">Form1.Canvas.Brush.Color:=clInfoBk; // | + | <syntaxhighlight lang="pascal">Form1.Canvas.Brush.Color:=clInfoBk; // используем цвет кисти по умолчанию для фона в окнах подсказок |
Form1.Canvas.FillRect(10,10,50,50); | Form1.Canvas.FillRect(10,10,50,50); | ||
− | Form1.Canvas.Font.Color:=clInfoText; // | + | Form1.Canvas.Font.Color:=clInfoText; // используем цвет текста по умолчанию в окнах подсказок |
Form1.Canvas.TextOut(10,10,'Hint');</syntaxhighlight> | Form1.Canvas.TextOut(10,10,'Hint');</syntaxhighlight> | ||
− | + | Системный цвет '''clInfoBk''' не может использоваться для Pen.Color и Font.Color. Если вы сделаете это, результат не определен и зависит от набора виджетов и пользовательской темы. То же самое для '''clInfoText''': он может использоваться только как Font.Color. Использование его в качестве Brush.Color может не работать. На данный момент все виджеты позволяют использовать его как Pen.Color. | |
− | |||
===Theme changes=== | ===Theme changes=== |
Revision as of 20:02, 2 June 2020
│
Deutsch (de) │
English (en) │
español (es) │
suomi (fi) │
français (fr) │
日本語 (ja) │
русский (ru) │
中文(中国大陆) (zh_CN) │
Обзор
В LCL TColor - это стандартный тип цвета. Он совместим с TColor Delphi. TColor может представляться как в виде значения RGB (3x8bit), так и в виде системного цвета наподобие clDefault. LCL также может работать с системой fpImage, которая использует тип TFPColor (RGBA (4x16bit), а не RGB (3x8bit), как TColor).
Преобразование значений между TColor и RGB
Модуль Graphics предосталяет следующие функции:
function Blue(rgb: TColor): BYTE; // не работает с системным цветом
function Green(rgb: TColor): BYTE; // не работает с системным цветом
function Red(rgb: TColor): BYTE; // не работает с системным цветом
function RGBToColor(R, G, B: Byte): TColor;
procedure RedGreenBlue(rgb: TColor; out Red, Green, Blue: Byte); // не работает с системным цветом
function FPColorToTColor(const FPColor: TFPColor): TColor;
function TColorToFPColor(const c: TColor): TFPColor; // не работает с системным цветом
function IsSysColor(AColor: TColorRef): Boolean;
Преобразование типа TColor в/из строки
Функции для преобразования строк вроде "25500" или "$AA0088" или "clNavy" в TColor:
- StringToColor
- StringToColorDef
Чтобы преобразовать TColor в красивую строку, такую как "clNavy" или "$AA0002":
- ColorToString
Преобразование типа TColor в/из HTML-строки #rrggbb
Смотрите код в Преобразовать цвет в/из HTML.
Таблица стандартных цветов
Предусмотрено около 20 предопределенных цветовых Констант, которые совместимы с Delphi:
Цветовая константа | Описание цвета | Шестнадцатеричное представление для использования с TColor | Пример |
---|---|---|---|
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 |
clDkGray | Темно-серый | TColor($808080); | псевдоним для clGray |
clWhite | Белый | TColor($FFFFFF); | |
clCream | Кремовый | TColor($F0FBFF); | Lazarus 1.2 и новее |
clMedGray | Средне-серый | TColor($A4A0A0); | Lazarus 1.2 и новее |
clMoneyGreen | Денежная зелень | TColor($C0DCC0); | Lazarus 1.2 и новее |
clSkyBlue | Небесно-голубой | TColor($F0CAA6); | Lazarus 1.2 и новее |
Системные цвета
Пример: clInfoBk, clInfoText
Системные цвета - это цветовые константы с особым значением. Их реальное значение зависит от контекста и темы. Они не являются просто цветом. Например, clInfoBk:
Form1.Canvas.Brush.Color:=clInfoBk; // используем цвет кисти по умолчанию для фона в окнах подсказок
Form1.Canvas.FillRect(10,10,50,50);
Окно подсказок в MS Windows может иметь белый фон, поэтому вышеприведенный цвет будет отображаться белым. В Linux/gtk2 это может быть металлическая текстура, поэтому вышеприведенный будет рисовать текстуру. Если вы хотите поместить какой-либо текст в это окно, вам понадобится соответствующий контрастный цвет, например, clInfoText, иначе ваш текст может быть нечитаемым для пользователя. Например:
Form1.Canvas.Brush.Color:=clInfoBk; // используем цвет кисти по умолчанию для фона в окнах подсказок
Form1.Canvas.FillRect(10,10,50,50);
Form1.Canvas.Font.Color:=clInfoText; // используем цвет текста по умолчанию в окнах подсказок
Form1.Canvas.TextOut(10,10,'Hint');
Системный цвет clInfoBk не может использоваться для Pen.Color и Font.Color. Если вы сделаете это, результат не определен и зависит от набора виджетов и пользовательской темы. То же самое для clInfoText: он может использоваться только как Font.Color. Использование его в качестве Brush.Color может не работать. На данный момент все виджеты позволяют использовать его как Pen.Color.
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
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.
Constant | LCL definition | Delphi notes | Supported Widgetsets |
---|---|---|---|
clNone | Indicates "do not paint". Using it as Control's color is undefined. The control will not get transparent. | - | all |
clDefault | Using it for Brush will use the normal background brush of the target DC (device context).
|
- | all |
clScrollBar | Scrollbar body | - | all |
clBackground | Desktop background color | - | 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 |
Finding the rgb values of a system color
Use the function ColorToRGB (in unit Graphics to determine the rgb components of a system color. This functions detects whether a color is a system color and, if this is true, looks up the system color in the themes color. The returned Longint can be understood as a normal color:
// This example has a TColorBox on a form and uses this OnChange handler for the TColorbox:
procedure TForm1.ColorBox1Change(Sender: TObject);
var
c: TColor;
begin
c := ColorToRGB(ColorBox1.Selected);
Caption := Format('R%d G%d B%d', [Red(c), Green(c), Blue(c)]);
end;
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:
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;