Changeset 534
- Timestamp:
- May 26, 2019, 8:29:38 PM (6 years ago)
- Location:
- DpiControls
- Files:
-
- 5 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
DpiControls/Demo/DpiComponentsDemo.lpi
r533 r534 48 48 </Unit1> 49 49 <Unit2> 50 <Filename Value="UDpiForm .pas"/>50 <Filename Value="UDpiFormMain.pas"/> 51 51 <IsPartOfProject Value="True"/> 52 <ComponentName Value="DpiForm 1"/>52 <ComponentName Value="DpiFormMain"/> 53 53 <HasResources Value="True"/> 54 54 </Unit2> -
DpiControls/Demo/DpiComponentsDemo.lpr
r533 r534 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UFormMain, UDpiForm 10 Forms, UFormMain, UDpiFormMain 11 11 { you can add units after this }; 12 12 -
DpiControls/Demo/UDpiFormMain.lfm
r533 r534 1 object DpiForm 1: TDpiForm11 object DpiFormMain: TDpiFormMain 2 2 Top = 504 3 3 Left = 865 4 4 Width = 0 5 5 Height = 0 6 Visible = False7 On Show = DpiForm1Show6 Visible = True 7 OnCreate = DpiFormMainCreate 8 8 object DpiButton1: TDpiButton 9 Top = 1 5410 Left = 209 Top = 128 10 Left = 8 11 11 Width = 150 12 12 Height = 40 … … 14 14 Caption = 'Test' 15 15 OnClick = DpiButton1Click 16 left = 8817 top = 8818 16 end 19 17 end -
DpiControls/Demo/UDpiFormMain.pas
r533 r534 1 unit UDpiForm ;1 unit UDpiFormMain; 2 2 3 3 {$mode objfpc}{$H+} … … 10 10 type 11 11 12 { TDpiForm 1}12 { TDpiFormMain } 13 13 14 TDpiForm 1= class(TDpiForm)14 TDpiFormMain = class(TDpiForm) 15 15 DpiButton1: TDpiButton; 16 16 procedure DpiButton1Click(Sender: TObject); 17 procedure DpiForm 1Show(Sender: TObject);17 procedure DpiFormMainCreate(Sender: TObject); 18 18 private 19 19 … … 23 23 24 24 var 25 DpiForm 1: TDpiForm1;25 DpiFormMain: TDpiFormMain; 26 26 27 27 implementation … … 29 29 {$R *.lfm} 30 30 31 { TDpiForm 1}31 { TDpiFormMain } 32 32 33 procedure TDpiForm 1.DpiForm1Show(Sender: TObject);33 procedure TDpiFormMain.DpiFormMainCreate(Sender: TObject); 34 34 var 35 35 DpiButton: TDpiButton; 36 36 DpiImage: TDpiImage; 37 37 begin 38 DpiButton := TDpiButton.Create(DpiForm 1);39 DpiButton.Parent := DpiForm1;38 DpiButton := TDpiButton.Create(DpiFormMain); 39 DpiButton.Parent := Self; 40 40 DpiButton.SetBounds(10, 10, 100, 30); 41 41 DpiButton.Caption := 'Click me'; … … 43 43 DpiButton1.Parent := Self; 44 44 45 DpiImage := TDpiImage.Create(DpiForm 1);46 DpiImage.Parent := DpiForm1;45 DpiImage := TDpiImage.Create(DpiFormMain); 46 DpiImage.Parent := Self; 47 47 DpiImage.SetBounds(150, 10, 100, 100); 48 48 DpiImage.Visible := True; … … 51 51 end; 52 52 53 procedure TDpiForm 1.DpiButton1Click(Sender: TObject);53 procedure TDpiFormMain.DpiButton1Click(Sender: TObject); 54 54 begin 55 55 ShowMessage('Hello'); -
DpiControls/Demo/UFormMain.lfm
r533 r534 1 1 object FormMain: TFormMain 2 Left = 573 Height = 1 264 Top = 442 Left = 127 3 Height = 168 4 Top = 66 5 5 Width = 472 6 6 Caption = 'DpiControls demo' 7 ClientHeight = 1 267 ClientHeight = 168 8 8 ClientWidth = 472 9 9 DesignTimePPI = 144 … … 29 29 ParentColor = False 30 30 end 31 object ButtonNewDpiForm: TButton 32 Left = 19 33 Height = 38 34 Top = 117 35 Width = 193 36 Caption = 'New DpiForm' 37 OnClick = ButtonNewDpiFormClick 38 TabOrder = 1 39 end 31 40 end -
DpiControls/Demo/UFormMain.pas
r533 r534 7 7 uses 8 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls, 9 ExtCtrls, UDpi Form, UDpiControls;9 ExtCtrls, UDpiControls, UDpiFormMain; 10 10 11 11 type … … 14 14 15 15 TFormMain = class(TForm) 16 ButtonNewDpiForm: TButton; 16 17 Label1: TLabel; 17 18 TrackBar1: TTrackBar; 19 procedure ButtonNewDpiFormClick(Sender: TObject); 18 20 procedure FormShow(Sender: TObject); 19 21 procedure TrackBar1Change(Sender: TObject); … … 37 39 DpiScreen.Dpi := 96 * 2; 38 40 TrackBar1.Position := DpiScreen.Dpi; 41 ButtonNewDpiFormClick(nil); 42 end; 39 43 40 DpiForm1 := TDpiForm1.Create(nil); 41 DpiForm1.Caption := DpiForm1.Name; 42 DpiForm1.SetBounds(100, 100, 400, 200); 43 DpiForm1.Show; 44 45 DpiScreen.Forms.Add(DpiForm1); 44 procedure TFormMain.ButtonNewDpiFormClick(Sender: TObject); 45 var 46 DpiForm: TDpiForm; 47 begin 48 DpiForm := TDpiFormMain.Create(nil); 49 DpiForm.Caption := DpiForm.Name; 50 DpiForm.SetBounds(100, 100, 400, 200); 51 DpiForm.Show; 52 DpiScreen.Forms.Add(DpiForm); 46 53 end; 47 54 -
DpiControls/UDpiControls.pas
r533 r534 46 46 TDpiControl = class(TComponent) 47 47 private 48 FCaption: string;49 48 FFont: TDpiFont; 50 49 FHeight: Integer; 51 50 FLeft: Integer; 51 FOnChangeBounds: TNotifyEvent; 52 FOnResize: TNotifyEvent; 52 53 FTop: Integer; 53 54 FVisible: Boolean; … … 55 56 FParent: TDpiWinControl; 56 57 procedure SetFont(AValue: TDpiFont); 58 procedure SetOnChangeBounds(AValue: TNotifyEvent); 59 procedure SetOnResize(AValue: TNotifyEvent); 60 procedure VclFormResize(Sender: TObject); 61 procedure VclChangeBounds(Sender: TObject); 62 procedure DoFormResize; 63 procedure DoChangeBounds; 57 64 protected 58 65 procedure UpdateBounds; virtual; 59 66 procedure FontChanged(Sender: TObject); virtual; 67 function GetCaption: string; virtual; 60 68 procedure SetParent(AValue: TDpiWinControl); virtual; 61 69 procedure SetCaption(AValue: string); virtual; … … 66 74 procedure SetWidth(AValue: Integer); virtual; 67 75 function GetVclControl: TControl; virtual; 76 procedure UpdateVclControl; virtual; 68 77 public 69 78 procedure ScreenChanged; virtual; … … 71 80 procedure Show; 72 81 procedure Hide; 73 function Scale(Value: Integer): Integer;74 82 constructor Create(TheOwner: TComponent); override; 75 83 destructor Destroy; override; … … 81 89 property Height: Integer read FHeight write SetHeight; 82 90 property Visible: Boolean read FVisible write SetVisible; 83 property Caption: string read FCaption write SetCaption;91 property Caption: string read GetCaption write SetCaption; 84 92 property Font: TDpiFont read FFont write SetFont; 93 property OnResize: TNotifyEvent read FOnResize write SetOnResize; 94 property OnChangeBounds: TNotifyEvent read FOnChangeBounds write SetOnChangeBounds; 85 95 end; 86 96 … … 105 115 TDpiForm = class(TDpiWinControl) 106 116 private 107 FOnShow: TNotifyEvent; 117 function GetOnCreate: TNotifyEvent; 118 function GetOnDestroy: TNotifyEvent; 119 function GetOnHide: TNotifyEvent; 120 function GetOnShow: TNotifyEvent; 121 procedure SetOnCreate(AValue: TNotifyEvent); 122 procedure SetOnDestroy(AValue: TNotifyEvent); 123 procedure SetOnHide(AValue: TNotifyEvent); 108 124 procedure SetOnShow(AValue: TNotifyEvent); 125 procedure DoOnCreate; 109 126 protected 110 127 procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override; … … 116 133 destructor Destroy; override; 117 134 published 118 property OnShow: TNotifyEvent read FOnShow write SetOnShow; 135 property OnShow: TNotifyEvent read GetOnShow write SetOnShow; 136 property OnHide: TNotifyEvent read GetOnHide write SetOnHide; 137 property OnCreate: TNotifyEvent read GetOnCreate write SetOnCreate; 138 property OnDestroy: TNotifyEvent read GetOnDestroy write SetOnDestroy; 119 139 end; 120 140 … … 158 178 private 159 179 FDpi: Integer; 180 function GetHeight: Integer; 181 function GetWidth: Integer; 160 182 procedure SetDpi(AValue: Integer); 161 183 procedure UpdateForms; … … 166 188 published 167 189 property Dpi: Integer read FDpi write SetDpi; 190 property Width: Integer read GetWidth; 191 property Height: Integer read GetHeight; 168 192 end; 169 193 … … 189 213 end; 190 214 215 function ScaleToVcl(Value: Integer): Integer; 216 begin 217 Result := Round(Value * DpiScreen.Dpi / 96); 218 end; 219 220 function ScaleFromVcl(Value: Integer): Integer; 221 begin 222 Result := Round(Value * 96 / DpiScreen.Dpi); 223 end; 224 225 191 226 { TDpiImage } 192 227 … … 290 325 end; 291 326 327 function TDpiScreen.GetWidth: Integer; 328 begin 329 Result := ScaleFromVcl(Screen.Width); 330 end; 331 332 function TDpiScreen.GetHeight: Integer; 333 begin 334 Result := ScaleFromVcl(Screen.Height); 335 end; 336 292 337 procedure TDpiScreen.UpdateForms; 293 338 var … … 354 399 if FVisible = AValue then Exit; 355 400 FVisible := AValue; 356 GetVclControl.Visible := AValue; ;401 GetVclControl.Visible := AValue; 357 402 end; 358 403 … … 367 412 begin 368 413 Result := nil; 414 end; 415 416 procedure TDpiControl.UpdateVclControl; 417 begin 418 GetVclControl.OnResize := @VclFormResize; 419 GetVclControl.OnChangeBounds := @VclChangeBounds; 369 420 end; 370 421 … … 394 445 end; 395 446 396 function TDpiControl.Scale(Value: Integer): Integer;397 begin398 Scale := Round(Value * DpiScreen.Dpi / 96);399 end;400 401 447 constructor TDpiControl.Create(TheOwner: TComponent); 402 448 begin … … 421 467 procedure TDpiControl.SetCaption(AValue: string); 422 468 begin 423 if FCaption = AValue then Exit;424 FCaption := AValue;425 469 GetVclControl.Caption := AValue; 426 470 end; … … 448 492 end; 449 493 494 procedure TDpiControl.SetOnChangeBounds(AValue: TNotifyEvent); 495 begin 496 if FOnChangeBounds = AValue then Exit; 497 FOnChangeBounds := AValue; 498 end; 499 500 procedure TDpiControl.SetOnResize(AValue: TNotifyEvent); 501 begin 502 if FOnResize = AValue then Exit; 503 FOnResize := AValue; 504 end; 505 506 procedure TDpiControl.VclFormResize(Sender: TObject); 507 begin 508 SetBounds(ScaleFromVcl(GetVclControl.Left), ScaleFromVcl(GetVclControl.Top), 509 ScaleFromVcl(GetVclControl.Width), ScaleFromVcl(GetVclControl.Height)); 510 DoFormResize; 511 end; 512 513 procedure TDpiControl.VclChangeBounds(Sender: TObject); 514 begin 515 SetBounds(ScaleFromVcl(GetVclControl.Left), ScaleFromVcl(GetVclControl.Top), 516 ScaleFromVcl(GetVclControl.Width), ScaleFromVcl(GetVclControl.Height)); 517 DoChangeBounds; 518 end; 519 520 procedure TDpiControl.DoFormResize; 521 begin 522 if Assigned(FOnResize) then FOnResize(Self); 523 end; 524 525 procedure TDpiControl.DoChangeBounds; 526 begin 527 if Assigned(FOnChangeBounds) then FOnChangeBounds(Self); 528 end; 529 530 function TDpiControl.GetCaption: string; 531 begin 532 Result := GetVclControl.Caption; 533 end; 534 450 535 procedure TDpiControl.FontChanged(Sender: TObject); 451 536 begin 452 GetVclControl.Font.Size := Scale (Font.Size);537 GetVclControl.Font.Size := ScaleToVcl(Font.Size); 453 538 end; 454 539 455 540 procedure TDpiControl.UpdateBounds; 456 541 begin 457 GetVclControl.SetBounds(Scale (Left), Scale(Top), Scale(Width), Scale(Height));542 GetVclControl.SetBounds(ScaleToVcl(Left), ScaleToVcl(Top), ScaleToVcl(Width), ScaleToVcl(Height)); 458 543 end; 459 544 … … 492 577 493 578 { TDpiForm } 579 580 function TDpiForm.GetOnCreate: TNotifyEvent; 581 begin 582 Result := VclForm.OnCreate; 583 end; 584 585 function TDpiForm.GetOnDestroy: TNotifyEvent; 586 begin 587 Result := VclForm.OnDestroy; 588 end; 589 590 function TDpiForm.GetOnHide: TNotifyEvent; 591 begin 592 Result := VclForm.OnHide; 593 end; 594 595 function TDpiForm.GetOnShow: TNotifyEvent; 596 begin 597 Result := VclForm.OnShow; 598 end; 599 600 procedure TDpiForm.SetOnCreate(AValue: TNotifyEvent); 601 begin 602 VclForm.OnCreate := AValue; 603 end; 604 605 procedure TDpiForm.SetOnDestroy(AValue: TNotifyEvent); 606 begin 607 VclForm.OnDestroy := AValue; 608 end; 609 610 procedure TDpiForm.SetOnHide(AValue: TNotifyEvent); 611 begin 612 VclForm.OnHide := AValue; 613 end; 614 615 procedure TDpiForm.SetOnShow(AValue: TNotifyEvent); 616 begin 617 VclForm.OnShow := AValue; 618 end; 619 620 procedure TDpiForm.DoOnCreate; 621 begin 622 if Assigned(VclForm.OnCreate) then 623 VclForm.OnCreate(Self); 624 end; 494 625 495 626 // This method is called by TWriter to retrieve the child components to write … … 517 648 begin 518 649 Result := VclForm; 519 end;520 521 procedure TDpiForm.SetOnShow(AValue: TNotifyEvent);522 begin523 if FOnShow = AValue then Exit;524 FOnShow := AValue;525 VclForm.OnShow := AValue;526 650 end; 527 651 … … 544 668 GlobalNameSpace.EndWrite; 545 669 end; 670 UpdateVclControl; 671 DoOnCreate; 546 672 end; 547 673
Note:
See TracChangeset
for help on using the changeset viewer.