source: trunk/Packages/CevoComponents/ButtonG.pas

Last change on this file was 554, checked in by chronos, 3 weeks ago
  • Added: TButtonG class as a button class component referencing TGraphicSet item.
  • Modified: Code cleanup.
File size: 4.4 KB
Line 
1unit ButtonG;
2
3interface
4
5uses
6 Classes, SysUtils, LCLIntf, LCLType, ButtonBase, GraphicSet;
7
8type
9
10 { TButtonG }
11
12 TButtonG = class(TButtonBase)
13 private
14 FBackgroundDownName: string;
15 FBackgroundDownIndex: Integer;
16 FBackgroundUpName: string;
17 FBackgroundUpIndex: Integer;
18 FGlyphIndex: Integer;
19 FGlyphName: string;
20 FGraphicSet: TGraphicSet;
21 function GetGraphicSetItem(Index: Integer; Name: string): TGraphicSetItem;
22 procedure SetBackgroundDownIndex(AValue: Integer);
23 procedure SetBackgroundDownName(AValue: string);
24 procedure SetBackgroundUpIndex(AValue: Integer);
25 procedure SetBackgroundUpName(AValue: string);
26 procedure SetGlyphIndex(AValue: Integer);
27 procedure SetGlyphName(AValue: string);
28 procedure SetGraphicSet(AValue: TGraphicSet);
29 protected
30 procedure Paint; override;
31 procedure SetVisible(Value: Boolean); override;
32 public
33 constructor Create(AOwner: TComponent); override;
34 published
35 property GraphicSet: TGraphicSet read FGraphicSet write SetGraphicSet;
36 property BackgroundUpIndex: Integer read FBackgroundUpIndex write SetBackgroundUpIndex default -1;
37 property BackgroundUpName: string read FBackgroundUpName write SetBackgroundUpName;
38 property BackgroundDownIndex: Integer read FBackgroundDownIndex write SetBackgroundDownIndex default -1;
39 property BackgroundDownName: string read FBackgroundDownName write SetBackgroundDownName;
40 property GlyphIndex: Integer read FGlyphIndex write SetGlyphIndex default -1;
41 property GlyphName: string read FGlyphName write SetGlyphName;
42 property Visible;
43 property OnClick;
44 end;
45
46procedure Register;
47
48
49implementation
50
51uses
52 ScreenTools;
53
54procedure Register;
55begin
56 RegisterComponents('C-evo', [TButtonG]);
57end;
58
59{ TButtonG }
60
61procedure TButtonG.SetGraphicSet(AValue: TGraphicSet);
62begin
63 if FGraphicSet = AValue then Exit;
64 FGraphicSet := AValue;
65end;
66
67procedure TButtonG.Paint;
68var
69 Back: TGraphicSetItem;
70 Glyph: TGraphicSetItem;
71 Drawn: Boolean;
72begin
73 Drawn := False;
74 with Canvas do begin
75 if Assigned(FGraphicSet) then begin
76 if FDown then Back := GetGraphicSetItem(FBackgroundDownIndex, FBackgroundDownName)
77 else Back := GetGraphicSetItem(FBackgroundUpIndex, FBackgroundUpName);
78 if Assigned(Back) then begin
79 BitBltCanvas(Canvas, 0, 0, Back.Width, Back.Height, FGraphic.Canvas, Back.Left,
80 Back.Top);
81 Drawn := True;
82 end;
83 Glyph := GetGraphicSetItem(FGlyphIndex, FGlyphName);
84 if Assigned(Glyph) then begin
85 BitBltCanvas(Canvas, 0, 0, Glyph.Width, Glyph.Height, FGraphic.Canvas, Glyph.Left,
86 Glyph.Top, SRCAND);
87 BitBltCanvas(Canvas, 0, 0, Glyph.Width, Glyph.Height, FGraphic.Canvas, Glyph.Left,
88 Glyph.Top, SRCPAINT);
89 Drawn := True;
90 end;
91 end;
92 if not Drawn then begin
93 Brush.Color := $0000FF;
94 FrameRect(Rect(0, 0, Width - 1, Height - 1));
95 end;
96 end;
97end;
98
99procedure TButtonG.SetVisible(Value: Boolean);
100begin
101 inherited SetVisible(Value);
102end;
103
104constructor TButtonG.Create(AOwner: TComponent);
105begin
106 inherited;
107 FBackgroundUpIndex := -1;
108 FBackgroundDownIndex := -1;
109 FGlyphIndex := -1;
110end;
111
112function TButtonG.GetGraphicSetItem(Index: Integer; Name: string): TGraphicSetItem;
113begin
114 Result := nil;
115 if Assigned(FGraphicSet) then begin
116 if (Index <> -1) and (Index < FGraphicSet.Items.Count) then
117 Result := FGraphicSet.Items[Index]
118 else if (Name <> '') then
119 Result := FGraphicSet.Items.SearchByName(Name);
120 end;
121end;
122
123procedure TButtonG.SetBackgroundDownIndex(AValue: Integer);
124begin
125 if FBackgroundDownIndex = AValue then Exit;
126 FBackgroundDownIndex := AValue;
127 FBackgroundDownName := '';
128end;
129
130procedure TButtonG.SetBackgroundDownName(AValue: string);
131begin
132 if FBackgroundDownName = AValue then Exit;
133 FBackgroundDownName := AValue;
134 FBackgroundDownIndex := -1;
135end;
136
137procedure TButtonG.SetBackgroundUpIndex(AValue: Integer);
138begin
139 if FBackgroundUpIndex = AValue then Exit;
140 FBackgroundUpIndex := AValue;
141 FBackgroundUpName := '';
142end;
143
144procedure TButtonG.SetBackgroundUpName(AValue: string);
145begin
146 if FBackgroundUpName = AValue then Exit;
147 FBackgroundUpName := AValue;
148 FBackgroundUpIndex := -1;
149end;
150
151procedure TButtonG.SetGlyphIndex(AValue: Integer);
152begin
153 if FGlyphIndex = AValue then Exit;
154 FGlyphIndex := AValue;
155 FGlyphName := '';
156end;
157
158procedure TButtonG.SetGlyphName(AValue: string);
159begin
160 if FGlyphName = AValue then Exit;
161 FGlyphName := AValue;
162 FGlyphIndex := -1;
163end;
164
165end.
166
Note: See TracBrowser for help on using the repository browser.