| 1 | unit UControls;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, Graphics;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 |
|
|---|
| 12 | { TControl }
|
|---|
| 13 |
|
|---|
| 14 | TControl = class
|
|---|
| 15 | private
|
|---|
| 16 | FEnabled: Boolean;
|
|---|
| 17 | FOnClick: TNotifyEvent;
|
|---|
| 18 | procedure SetEnabled(AValue: Boolean);
|
|---|
| 19 | public
|
|---|
| 20 | Bounds: TRect;
|
|---|
| 21 | Canvas: TCanvas;
|
|---|
| 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 | { TButton }
|
|---|
| 29 |
|
|---|
| 30 | TButton = class(TControl)
|
|---|
| 31 | Text: string;
|
|---|
| 32 | procedure Paint; override;
|
|---|
| 33 | end;
|
|---|
| 34 |
|
|---|
| 35 | { TImage }
|
|---|
| 36 |
|
|---|
| 37 | TImage = class(TControl)
|
|---|
| 38 | Bitmap: TBitmap;
|
|---|
| 39 | BitmapDisabled: TBitmap;
|
|---|
| 40 | constructor Create; override;
|
|---|
| 41 | destructor Destroy; override;
|
|---|
| 42 | procedure Paint; override;
|
|---|
| 43 | end;
|
|---|
| 44 |
|
|---|
| 45 | implementation
|
|---|
| 46 |
|
|---|
| 47 | { TButton }
|
|---|
| 48 |
|
|---|
| 49 | procedure TButton.Paint;
|
|---|
| 50 | begin
|
|---|
| 51 | inherited Paint;
|
|---|
| 52 | end;
|
|---|
| 53 |
|
|---|
| 54 | { TControl }
|
|---|
| 55 |
|
|---|
| 56 | procedure TControl.SetEnabled(AValue: Boolean);
|
|---|
| 57 | begin
|
|---|
| 58 | if FEnabled = AValue then Exit;
|
|---|
| 59 | FEnabled := AValue;
|
|---|
| 60 | if Assigned(Canvas) then Paint;
|
|---|
| 61 | end;
|
|---|
| 62 |
|
|---|
| 63 | constructor TControl.Create;
|
|---|
| 64 | begin
|
|---|
| 65 | FEnabled := True;
|
|---|
| 66 | end;
|
|---|
| 67 |
|
|---|
| 68 | procedure TControl.Paint;
|
|---|
| 69 | begin
|
|---|
| 70 | end;
|
|---|
| 71 |
|
|---|
| 72 | { TImage }
|
|---|
| 73 |
|
|---|
| 74 | constructor TImage.Create;
|
|---|
| 75 | begin
|
|---|
| 76 | inherited;
|
|---|
| 77 | Bitmap := TBitmap.Create;
|
|---|
| 78 | BitmapDisabled := TBitmap.Create;
|
|---|
| 79 | end;
|
|---|
| 80 |
|
|---|
| 81 | destructor TImage.Destroy;
|
|---|
| 82 | begin
|
|---|
| 83 | FreeAndNil(Bitmap);
|
|---|
| 84 | FreeAndNil(BitmapDisabled);
|
|---|
| 85 | inherited;
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | procedure TImage.Paint;
|
|---|
| 89 | begin
|
|---|
| 90 | if Canvas.Brush.Color = clNone then Canvas.Brush.Style := bsClear
|
|---|
| 91 | else Canvas.Brush.Style := bsSolid;
|
|---|
| 92 | if FEnabled then Canvas.StretchDraw(Bounds, Bitmap)
|
|---|
| 93 | else Canvas.StretchDraw(Bounds, BitmapDisabled);
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | end.
|
|---|
| 97 |
|
|---|