Changeset 77 for trunk/UMenu.pas
- Timestamp:
- May 19, 2021, 11:30:41 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMenu.pas
r76 r77 6 6 7 7 uses 8 Classes, SysUtils, Graphics, Controls, fgl ;8 Classes, SysUtils, Graphics, Controls, fgl, UControls; 9 9 10 10 type … … 13 13 { TMenuItem } 14 14 15 TMenuItem = class 15 TMenuItem = class(TControl) 16 16 BackgroundColor: TColor; 17 17 BackgroundSelectedColor: TColor; 18 18 Kind: TMenuItemKind; 19 19 Text: string; 20 Bounds: TRect;21 20 Selected: Boolean; 22 21 FontSize: Integer; 23 22 FontColor: Integer; 24 Enabled: Boolean;25 procedure Paint(Canvas: TCanvas; P: TPoint); virtual;26 23 function GetOutputText: string; virtual; 27 constructor Create; virtual;24 constructor Create; override; 28 25 end; 29 26 … … 35 32 public 36 33 Checked: Boolean; 37 procedure Paint (Canvas: TCanvas; P: TPoint); override;34 procedure Paint; override; 38 35 property OnChanged: TNotifyEvent read FOnChanged write FOnChanged; 39 36 end; … … 49 46 constructor Create; override; 50 47 destructor Destroy; override; 51 procedure Paint (Canvas: TCanvas; P: TPoint); override;48 procedure Paint; override; 52 49 function GetOutputText: string; override; 53 50 property OnChanged: TNotifyEvent read FOnChanged write FOnChanged; … … 57 54 58 55 TMenuItemButton = class(TMenuItem) 59 private60 FOnClick: TNotifyEvent;61 56 public 62 procedure Paint(Canvas: TCanvas; P: TPoint); override; 63 property OnClick: TNotifyEvent read FOnClick write FOnClick; 64 end; 65 66 { TMenuItemImage } 67 68 TMenuItemImage = class(TMenuItem) 69 private 70 FOnClick: TNotifyEvent; 71 public 72 Bitmap: TBitmap; 73 procedure Paint(Canvas: TCanvas; P: TPoint); override; 74 property OnClick: TNotifyEvent read FOnClick write FOnClick; 75 constructor Create; override; 76 destructor Destroy; override; 57 procedure Paint; override; 77 58 end; 78 59 … … 118 99 implementation 119 100 120 { TMenuItemImage }121 122 procedure TMenuItemImage.Paint(Canvas: TCanvas; P: TPoint);123 begin124 if Selected then Canvas.Brush.Color := BackgroundSelectedColor125 else Canvas.Brush.Color := BackgroundColor;126 if Canvas.Brush.Color = clNone then Canvas.Brush.Style := bsClear127 else Canvas.Brush.Style := bsSolid;128 Canvas.StretchDraw(Bounds, Bitmap);129 end;130 131 constructor TMenuItemImage.Create;132 begin133 inherited;134 Bitmap := TBitmap.Create;135 end;136 137 destructor TMenuItemImage.Destroy;138 begin139 FreeAndNil(Bitmap);140 inherited;141 end;142 143 101 { TMenuItemButton } 144 102 145 procedure TMenuItemButton.Paint(Canvas: TCanvas; P: TPoint); 146 begin 103 procedure TMenuItemButton.Paint; 104 var 105 P: TPoint; 106 begin 107 P := Point(Bounds.Left, Bounds.Top); 147 108 if Selected then Canvas.Brush.Color := BackgroundSelectedColor 148 109 else Canvas.Brush.Color := BackgroundColor; … … 155 116 { TMenuItemCheckBox } 156 117 157 procedure TMenuItemCheckBox.Paint (Canvas: TCanvas; P: TPoint);118 procedure TMenuItemCheckBox.Paint; 158 119 var 159 120 OutputText: string; 160 begin 121 P: TPoint; 122 begin 123 P := Point(Bounds.Left, Bounds.Top); 161 124 OutputText := Text; 162 125 if Checked then OutputText := '✓' + OutputText; … … 171 134 { TMenuItem } 172 135 173 procedure TMenuItem.Paint(Canvas: TCanvas; P: TPoint);174 begin175 end;176 177 136 function TMenuItem.GetOutputText: string; 178 137 begin … … 201 160 end; 202 161 203 procedure TMenuItemComboBox.Paint(Canvas: TCanvas; P: TPoint); 204 begin 162 procedure TMenuItemComboBox.Paint; 163 var 164 P: TPoint; 165 begin 166 P := Point(Bounds.Left, Bounds.Top); 205 167 if Selected then Canvas.Brush.Color := BackgroundSelectedColor 206 168 else Canvas.Brush.Color := BackgroundColor; … … 235 197 if Items[I].Bounds.Contains(Position) then begin 236 198 if (Items[I] is TMenuItemButton) then begin 237 if Assigned(TMenuItemButton(Items[I]). FOnClick) then238 TMenuItemButton(Items[I]). FOnClick(Items[I]);199 if Assigned(TMenuItemButton(Items[I]).OnClick) then 200 TMenuItemButton(Items[I]).OnClick(Items[I]); 239 201 end else 240 202 if (Items[I] is TMenuItemCheckBox) then begin … … 286 248 Font.Size := Items[I].FontSize; 287 249 Font.Color := Items[I].FontColor; 288 Items[I].Paint(Canvas, Point(X, Y)); 250 Items[I].Bounds.Left := X; 251 Items[I].Bounds.Top := Y; 252 Items[I].Canvas := Canvas; 253 Items[I].Paint; 289 254 LineHeight := Round(TextHeight('I') * 1.1); 290 255 Inc(Y, LineHeight);
Note:
See TracChangeset
for help on using the changeset viewer.