/
tfpcolorbridgepropertyeditor.pas
108 lines (92 loc) · 3.71 KB
/
tfpcolorbridgepropertyeditor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
unit TFPColorBridgePropertyEditor;
interface
uses
Classes, TypInfo, SysUtils, LCLProc, LCLType, Graphics, LCLIntf,
FPImage, PropEdits, FPColorBridge;
type
TTFPColorBridgePropertyEditor = class(TEnumPropertyEditor)
public
procedure ListMeasureWidth(const AValue: ansistring; Index:integer;
ACanvas: TCanvas; var AWidth: Integer); override;
procedure ListMeasureHeight(const AValue: ansistring; Index:integer;
ACanvas:TCanvas; var AHeight: Integer); override;
procedure ListDrawValue(const AValue: ansistring; Index:integer;
ACanvas:TCanvas; const ARect: TRect; AState: TPropEditDrawState); override;
procedure PropDrawValue(ACanvas:TCanvas; const ARect: TRect; AState: TPropEditDrawState); override;
end;
//procedure Register;
implementation
//Register editor for TTFPColorBridge enumerated type:
(*
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(TTFPColorBridge), nil,'',TTFPColorBridgePropertyEditor);
end;
*)
procedure TTFPColorBridgePropertyEditor.ListMeasureWidth(const AValue:ansistring; Index:integer;
ACanvas:TCanvas; var AWidth:Integer);
begin
AWidth := ACanvas.TextWidth('colbrLightGoldenRodYellow') + 25;
end;
procedure TTFPColorBridgePropertyEditor.ListMeasureHeight(const AValue: ansistring; Index:integer;
ACanvas:TCanvas; var AHeight: Integer);
begin
AHeight:= ACanvas.TextHeight('Mg')+ 2;
end;
{------ListDrawValue-------
This is called during the item/value render phase of the drop down list's render.}
procedure TTFPColorBridgePropertyEditor.ListDrawValue(const AValue: ansistring; Index:integer;
ACanvas:TCanvas; const ARect: TRect; AState: TPropEditDrawState);
var
vRight, vBottom: Integer;
vOldPenColor, vOldBrushColor: TColor;
vOldPenStyle: TPenStyle;
tfpColBridge: TTFPColorBridge;
begin
vRight := (ARect.Bottom - ARect.Top) + ARect.Left - 3;
vBottom:=ARect.Bottom - 3;
with ACanvas do
begin
// save off things
vOldPenStyle := Pen.Style;
vOldPenColor := Pen.Color;
vOldBrushColor := Brush.Color;
// frame things
if pedsInEdit in AState then
begin
if pedsSelected in AState then Brush.Color := clWindow
else Brush.Color := ACanvas.Brush.Color;
end
else
begin
if pedsSelected in AState then Brush.Color := clHighlightText
else Brush.Color := clWindow;
end;
Pen.Color := Brush.Color;
Pen.Style := psSolid;
FillRect(ARect);
Rectangle(ARect.Left, ARect.Top, vRight, vBottom);
// set things up and do the work
tfpColBridge:= TTFPColorBridge(GetEnumValue(GetPropType, AValue));
Brush.Color := FPColorToTColor(ToTFPColor(tfpColBridge));
Pen.Color := clBlack;
Rectangle(ARect.Left + 2, ARect.Top + 2, vRight - 2, vBottom - 2);
// restore the things we twiddled with
Brush.Color := vOldBrushColor;
Pen.Color := vOldPenColor;
Pen.Style := vOldPenStyle;
end;
inherited ListDrawValue(AValue, Index, ACanvas,
Rect(vRight, ARect.Top, ARect.Right, ARect.Bottom), AState);
end;
{-------PropDrawValue------
Called during the render of the value column of the property list.}
procedure TTFPColorBridgePropertyEditor.PropDrawValue(ACanvas:TCanvas; const ARect: TRect;
AState: TPropEditDrawState);
begin
if GetVisualValue <> '' then
ListDrawValue(GetVisualValue, -1, ACanvas, ARect, [pedsInEdit])
else
inherited PropDrawValue(ACanvas, ARect, AState);
end;
end.