Changeset 533 for DpiControls
- Timestamp:
- May 26, 2019, 7:33:14 PM (5 years ago)
- Location:
- DpiControls
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
DpiControls
-
Property svn:ignore
set to
lib
-
Property svn:ignore
set to
-
DpiControls/Demo
-
Property svn:ignore
set to
DpiComponentsDemo
DpiComponentsDemo.lps
DpiComponentsDemo.res
lib
-
Property svn:ignore
set to
-
DpiControls/Demo/DpiComponentsDemo.lpi
r532 r533 43 43 <Filename Value="UFormMain.pas"/> 44 44 <IsPartOfProject Value="True"/> 45 <ComponentName Value="Form 1"/>45 <ComponentName Value="FormMain"/> 46 46 <HasResources Value="True"/> 47 47 <ResourceBaseClass Value="Form"/> … … 62 62 <SearchPaths> 63 63 <IncludeFiles Value="$(ProjOutDir)"/> 64 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS) "/>64 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-${BuildMode}"/> 65 65 </SearchPaths> 66 66 <Linking> -
DpiControls/Demo/DpiComponentsDemo.lpr
r532 r533 17 17 Application.Scaled:=True; 18 18 Application.Initialize; 19 Application.CreateForm(TForm 1, Form1);19 Application.CreateForm(TFormMain, FormMain); 20 20 Application.Run; 21 21 end. -
DpiControls/Demo/UDpiForm.lfm
r532 r533 7 7 OnShow = DpiForm1Show 8 8 object DpiButton1: TDpiButton 9 Top = 1 0410 Left = 1209 Top = 154 10 Left = 20 11 11 Width = 150 12 12 Height = 40 … … 14 14 Caption = 'Test' 15 15 OnClick = DpiButton1Click 16 left = 88 17 top = 88 16 18 end 17 19 end -
DpiControls/Demo/UDpiForm.pas
r532 r533 34 34 var 35 35 DpiButton: TDpiButton; 36 DpiImage: TDpiImage; 36 37 begin 37 38 DpiButton := TDpiButton.Create(DpiForm1); … … 41 42 DpiButton.Visible := True; 42 43 DpiButton1.Parent := Self; 44 45 DpiImage := TDpiImage.Create(DpiForm1); 46 DpiImage.Parent := DpiForm1; 47 DpiImage.SetBounds(150, 10, 100, 100); 48 DpiImage.Visible := True; 49 DpiImage.Stretch := True; 50 DpiImage.VclImage.Picture.LoadFromFile('dance.jpg'); 43 51 end; 44 52 -
DpiControls/Demo/UFormMain.lfm
r532 r533 1 object Form 1: TForm12 Left = 8373 Height = 3604 Top = 4 55 Width = 4 806 Caption = ' Form1'7 ClientHeight = 3608 ClientWidth = 4 801 object FormMain: TFormMain 2 Left = 57 3 Height = 126 4 Top = 44 5 Width = 472 6 Caption = 'DpiControls demo' 7 ClientHeight = 126 8 ClientWidth = 472 9 9 DesignTimePPI = 144 10 10 OnShow = FormShow 11 11 LCLVersion = '2.0.2.0' 12 12 object TrackBar1: TTrackBar 13 Left = 2413 Left = 13 14 14 Height = 58 15 Top = 10216 Width = 4 1615 Top = 40 16 Width = 440 17 17 Max = 1000 18 18 Min = 96 … … 21 21 TabOrder = 0 22 22 end 23 object Label1: TLabel 24 Left = 13 25 Height = 26 26 Top = 8 27 Width = 35 28 Caption = 'DPI:' 29 ParentColor = False 30 end 23 31 end -
DpiControls/Demo/UFormMain.pas
r532 r533 6 6 7 7 uses 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, UDpiForm,9 UDpiControls;8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls, 9 ExtCtrls, UDpiForm, UDpiControls; 10 10 11 11 type 12 12 13 { TForm 1}13 { TFormMain } 14 14 15 TForm1 = class(TForm) 15 TFormMain = class(TForm) 16 Label1: TLabel; 16 17 TrackBar1: TTrackBar; 17 18 procedure FormShow(Sender: TObject); … … 24 25 25 26 var 26 Form 1: TForm1;27 FormMain: TFormMain; 27 28 28 29 implementation … … 30 31 {$R *.lfm} 31 32 32 { TForm 1}33 { TFormMain } 33 34 34 procedure TForm 1.FormShow(Sender: TObject);35 procedure TFormMain.FormShow(Sender: TObject); 35 36 begin 36 37 DpiScreen.Dpi := 96 * 2; … … 45 46 end; 46 47 47 procedure TForm 1.TrackBar1Change(Sender: TObject);48 procedure TFormMain.TrackBar1Change(Sender: TObject); 48 49 begin 49 50 DpiScreen.Dpi := TrackBar1.Position; -
DpiControls/UDpiControls.pas
r532 r533 7 7 uses 8 8 Classes, SysUtils, LCLProc, LResources, Forms, FormEditingIntf, ProjectIntf, 9 Controls, StdCtrls, fgl, Graphics ;9 Controls, StdCtrls, fgl, Graphics, ComCtrls, ExtCtrls; 10 10 11 11 type … … 29 29 procedure SetSize(AValue: Integer); 30 30 procedure DoChange; 31 protected 32 procedure ScreenChanged; 31 33 public 32 34 VclFont: TFont; … … 63 65 procedure SetVisible(AValue: Boolean); virtual; 64 66 procedure SetWidth(AValue: Integer); virtual; 67 function GetVclControl: TControl; virtual; 65 68 public 66 69 procedure ScreenChanged; virtual; … … 88 91 TDpiWinControl = class(TDpiControl) 89 92 private 93 protected 94 function GetVclWinControl: TWinControl; virtual; 90 95 public 91 96 Controls: TDpiControls; … … 103 108 procedure SetOnShow(AValue: TNotifyEvent); 104 109 protected 105 procedure FontChanged(Sender: TObject); override;106 procedure UpdateBounds; override;107 110 procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override; 108 procedure SetVisible(AValue: Boolean); override;109 procedure SetCaption(AValue: string); override;111 function GetVclControl: TControl; override; 112 function GetVclWinControl: TWinControl; override; 110 113 public 111 114 VclForm: TForm; … … 125 128 procedure SetOnClick(AValue: TNotifyEvent); 126 129 protected 127 procedure FontChanged(Sender: TObject); override; 128 procedure UpdateBounds; override; 129 procedure SetVisible(AValue: Boolean); override; 130 procedure SetCaption(AValue: string); override; 131 procedure SetParent(AValue: TDpiWinControl); override; 130 function GetVclControl: TControl; override; 132 131 public 133 132 VclButton: TButton; … … 136 135 published 137 136 property OnClick: TNotifyEvent read FOnClick write SetOnClick; 137 end; 138 139 { TDpiImage } 140 141 TDpiImage = class(TDpiControl) 142 private 143 FStretch: Boolean; 144 procedure SetStretch(AValue: Boolean); 145 protected 146 public 147 VclImage: TImage; 148 function GetVclControl: TControl; override; 149 constructor Create(TheOwner: TComponent); override; 150 destructor Destroy; override; 151 published 152 property Stretch: Boolean read FStretch write SetStretch; 138 153 end; 139 154 … … 171 186 DpiFormFileDesc := TDpiFormFileDesc.Create; 172 187 RegisterProjectFileDescriptor(DpiFormFileDesc); 173 RegisterComponents('DpiControls', [TDpiButton]); 188 RegisterComponents('DpiControls', [TDpiButton, TDpiImage]); 189 end; 190 191 { TDpiImage } 192 193 procedure TDpiImage.SetStretch(AValue: Boolean); 194 begin 195 if FStretch = AValue then Exit; 196 FStretch := AValue; 197 VclImage.Stretch := AValue; 198 end; 199 200 function TDpiImage.GetVclControl: TControl; 201 begin 202 Result := VclImage; 203 end; 204 205 constructor TDpiImage.Create(TheOwner: TComponent); 206 begin 207 inherited; 208 VclImage := TImage.Create(nil); 209 end; 210 211 destructor TDpiImage.Destroy; 212 begin 213 FreeAndNil(VclImage); 214 inherited Destroy; 174 215 end; 175 216 … … 188 229 end; 189 230 231 procedure TDpiFont.ScreenChanged; 232 begin 233 DoChange; 234 end; 235 190 236 procedure TDpiFont.SetOnChange(AValue: TNotifyEvent); 191 237 begin … … 207 253 208 254 { TDpiWinControl } 255 256 function TDpiWinControl.GetVclWinControl: TWinControl; 257 begin 258 Result := nil; 259 end; 209 260 210 261 procedure TDpiWinControl.ScreenChanged; … … 272 323 end; 273 324 274 procedure TDpiButton.FontChanged(Sender: TObject); 275 begin 276 inherited; 277 VclButton.Font.Size := Scale(Font.Size); 278 end; 279 280 procedure TDpiButton.UpdateBounds; 281 begin 282 inherited; 283 VclButton.SetBounds(Scale(Left), Scale(Top), Scale(Width), Scale(Height)); 284 end; 285 286 procedure TDpiButton.SetVisible(AValue: Boolean); 287 begin 288 inherited; 289 VclButton.Visible := AValue; 290 end; 291 292 procedure TDpiButton.SetCaption(AValue: string); 293 begin 294 inherited; 295 VclButton.Caption := AValue; 296 end; 297 298 procedure TDpiButton.SetParent(AValue: TDpiWinControl); 299 begin 300 inherited; 301 if Assigned(Owner) and (Owner is TDpiForm) then 302 VclButton.Parent := TDpiForm(Owner).VclForm; 325 function TDpiButton.GetVclControl: TControl; 326 begin 327 Result := VclButton; 303 328 end; 304 329 … … 307 332 inherited; 308 333 VclButton := TButton.Create(nil); 334 ScreenChanged; 309 335 end; 310 336 … … 328 354 if FVisible = AValue then Exit; 329 355 FVisible := AValue; 356 GetVclControl.Visible := AValue;; 330 357 end; 331 358 … … 337 364 end; 338 365 366 function TDpiControl.GetVclControl: TControl; 367 begin 368 Result := nil; 369 end; 370 339 371 procedure TDpiControl.ScreenChanged; 340 372 begin 341 373 UpdateBounds; 342 Font Changed(nil);374 Font.ScreenChanged; 343 375 end; 344 376 … … 389 421 procedure TDpiControl.SetCaption(AValue: string); 390 422 begin 391 if FCaption=AValue then Exit; 392 FCaption:=AValue; 423 if FCaption = AValue then Exit; 424 FCaption := AValue; 425 GetVclControl.Caption := AValue; 393 426 end; 394 427 … … 396 429 begin 397 430 if FParent = AValue then Exit; 398 if Assigned(FParent) then FParent.Controls.Remove(Self); 431 if Assigned(FParent) then begin 432 FParent.Controls.Remove(Self); 433 if Assigned(FParent) and (FParent is TDpiWinControl) then 434 GetVclControl.Parent := nil; 435 end; 399 436 FParent := AValue; 400 if Assigned(FParent) then FParent.Controls.Add(Self); 437 if Assigned(FParent) then begin 438 FParent.Controls.Add(Self); 439 if Assigned(FParent) and (FParent is TDpiWinControl) then 440 GetVclControl.Parent := TDpiWinControl(FParent).GetVclWinControl; 441 end; 401 442 end; 402 443 … … 409 450 procedure TDpiControl.FontChanged(Sender: TObject); 410 451 begin 452 GetVclControl.Font.Size := Scale(Font.Size); 411 453 end; 412 454 413 455 procedure TDpiControl.UpdateBounds; 414 456 begin 457 GetVclControl.SetBounds(Scale(Left), Scale(Top), Scale(Width), Scale(Height)); 415 458 end; 416 459 … … 466 509 end; 467 510 468 procedure TDpiForm.SetVisible(AValue: Boolean); 469 begin 470 inherited SetVisible(AValue); 471 VclForm.Visible := AValue; 472 end; 473 474 procedure TDpiForm.SetCaption(AValue: string); 475 begin 476 inherited; 477 VclForm.Caption:= AValue; 511 function TDpiForm.GetVclControl: TControl; 512 begin 513 Result := VclForm; 514 end; 515 516 function TDpiForm.GetVclWinControl: TWinControl; 517 begin 518 Result := VclForm; 478 519 end; 479 520 … … 485 526 end; 486 527 487 procedure TDpiForm.FontChanged(Sender: TObject);488 begin489 inherited;490 VclForm.Font.Size := Scale(Font.Size);491 end;492 493 procedure TDpiForm.UpdateBounds;494 begin495 inherited;496 VclForm.SetBounds(Scale(Left), Scale(Top), Scale(Width), Scale(Height));497 end;498 499 528 // Init the component with an IDE resource 500 529 constructor TDpiForm.Create(TheOwner: TComponent); 501 530 begin 531 inherited; 502 532 VclForm := TForm.Create(nil); 533 ScreenChanged; 503 534 DebugLn(['TDpiForm.Create ', DbgSName(TheOwner)]); 504 535 GlobalNameSpace.BeginWrite; 505 536 try 506 inherited Create(TheOwner);507 537 if (ClassType <> TDpiForm) and not (csDesigning in ComponentState) 508 538 then begin
Note:
See TracChangeset
for help on using the changeset viewer.