Changeset 77 for trunk/UControls.pas
- Timestamp:
- May 19, 2021, 11:30:41 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UControls.pas
r64 r77 6 6 7 7 uses 8 Classes, SysUtils ;8 Classes, SysUtils, Graphics; 9 9 10 10 type 11 12 { TControl } 13 11 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; 12 27 13 end;28 { TButton } 14 29 15 30 TButton = class(TControl) 16 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; 17 43 end; 18 44 19 45 implementation 20 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 21 96 end. 22 97
Note:
See TracChangeset
for help on using the changeset viewer.