source: trunk/BasicControls.pas

Last change on this file was 143, checked in by chronos, 11 months ago

Removed U prefix from all units.

File size: 2.1 KB
Line 
1unit BasicControls;
2
3interface
4
5uses
6 Classes, SysUtils, Graphics;
7
8type
9
10 { TControl }
11
12 TControl = class
13 private
14 FEnabled: Boolean;
15 FOnClick: TNotifyEvent;
16 procedure SetEnabled(AValue: Boolean);
17 public
18 Ref: TObject;
19 Bounds: TRect;
20 Canvas: TCanvas;
21 procedure MouseUp(Position: TPoint);
22 constructor Create; virtual;
23 procedure Paint; virtual;
24 property Enabled: Boolean read FEnabled write SetEnabled;
25 property OnClick: TNotifyEvent read FOnClick write FOnClick;
26 end;
27
28 { TLabel }
29
30 TLabel = class(TControl)
31 Text: string;
32 procedure Paint; override;
33 end;
34
35 { TButton }
36
37 TButton = class(TControl)
38 Text: string;
39 procedure Paint; override;
40 end;
41
42 { TImage }
43
44 TImage = class(TControl)
45 Bitmap: TBitmap;
46 BitmapDisabled: TBitmap;
47 constructor Create; override;
48 destructor Destroy; override;
49 procedure Paint; override;
50 end;
51
52
53implementation
54
55{ TLabel }
56
57procedure TLabel.Paint;
58begin
59 if not Assigned(Canvas) then Exit;
60 with Canvas do begin
61 TextOut(Bounds.Left, Bounds.Top, Text);
62 end;
63end;
64
65{ TButton }
66
67procedure TButton.Paint;
68begin
69 inherited Paint;
70end;
71
72{ TControl }
73
74procedure TControl.SetEnabled(AValue: Boolean);
75begin
76 if FEnabled = AValue then Exit;
77 FEnabled := AValue;
78 if Assigned(Canvas) then Paint;
79end;
80
81procedure TControl.MouseUp(Position: TPoint);
82begin
83 if Enabled and Bounds.Contains(Position) then
84 if Assigned(FOnClick) then FOnClick(Self);
85end;
86
87constructor TControl.Create;
88begin
89 FEnabled := True;
90end;
91
92procedure TControl.Paint;
93begin
94end;
95
96{ TImage }
97
98constructor TImage.Create;
99begin
100 inherited;
101 Bitmap := TBitmap.Create;
102 BitmapDisabled := TBitmap.Create;
103end;
104
105destructor TImage.Destroy;
106begin
107 FreeAndNil(Bitmap);
108 FreeAndNil(BitmapDisabled);
109 inherited;
110end;
111
112procedure TImage.Paint;
113begin
114 if not Assigned(Canvas) then Exit;
115 if Canvas.Brush.Color = clNone then Canvas.Brush.Style := bsClear
116 else Canvas.Brush.Style := bsSolid;
117 if FEnabled then Canvas.StretchDraw(Bounds, Bitmap)
118 else Canvas.StretchDraw(Bounds, BitmapDisabled);
119end;
120
121end.
122
Note: See TracBrowser for help on using the repository browser.