1 | unit BasicControls;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Graphics;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
53 | implementation
|
---|
54 |
|
---|
55 | { TLabel }
|
---|
56 |
|
---|
57 | procedure TLabel.Paint;
|
---|
58 | begin
|
---|
59 | if not Assigned(Canvas) then Exit;
|
---|
60 | with Canvas do begin
|
---|
61 | TextOut(Bounds.Left, Bounds.Top, Text);
|
---|
62 | end;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | { TButton }
|
---|
66 |
|
---|
67 | procedure TButton.Paint;
|
---|
68 | begin
|
---|
69 | inherited Paint;
|
---|
70 | end;
|
---|
71 |
|
---|
72 | { TControl }
|
---|
73 |
|
---|
74 | procedure TControl.SetEnabled(AValue: Boolean);
|
---|
75 | begin
|
---|
76 | if FEnabled = AValue then Exit;
|
---|
77 | FEnabled := AValue;
|
---|
78 | if Assigned(Canvas) then Paint;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | procedure TControl.MouseUp(Position: TPoint);
|
---|
82 | begin
|
---|
83 | if Enabled and Bounds.Contains(Position) then
|
---|
84 | if Assigned(FOnClick) then FOnClick(Self);
|
---|
85 | end;
|
---|
86 |
|
---|
87 | constructor TControl.Create;
|
---|
88 | begin
|
---|
89 | FEnabled := True;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TControl.Paint;
|
---|
93 | begin
|
---|
94 | end;
|
---|
95 |
|
---|
96 | { TImage }
|
---|
97 |
|
---|
98 | constructor TImage.Create;
|
---|
99 | begin
|
---|
100 | inherited;
|
---|
101 | Bitmap := TBitmap.Create;
|
---|
102 | BitmapDisabled := TBitmap.Create;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | destructor TImage.Destroy;
|
---|
106 | begin
|
---|
107 | FreeAndNil(Bitmap);
|
---|
108 | FreeAndNil(BitmapDisabled);
|
---|
109 | inherited;
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TImage.Paint;
|
---|
113 | begin
|
---|
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);
|
---|
119 | end;
|
---|
120 |
|
---|
121 | end.
|
---|
122 |
|
---|