Changeset 533


Ignore:
Timestamp:
May 26, 2019, 7:33:14 PM (5 years ago)
Author:
chronos
Message:
  • Added: TDpiImage control.
Location:
DpiControls
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • DpiControls

    • Property svn:ignore set to
      lib
  • DpiControls/Demo

    • Property svn:ignore set to
      DpiComponentsDemo
      DpiComponentsDemo.lps
      DpiComponentsDemo.res
      lib
  • DpiControls/Demo/DpiComponentsDemo.lpi

    r532 r533  
    4343        <Filename Value="UFormMain.pas"/>
    4444        <IsPartOfProject Value="True"/>
    45         <ComponentName Value="Form1"/>
     45        <ComponentName Value="FormMain"/>
    4646        <HasResources Value="True"/>
    4747        <ResourceBaseClass Value="Form"/>
     
    6262    <SearchPaths>
    6363      <IncludeFiles Value="$(ProjOutDir)"/>
    64       <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
     64      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-${BuildMode}"/>
    6565    </SearchPaths>
    6666    <Linking>
  • DpiControls/Demo/DpiComponentsDemo.lpr

    r532 r533  
    1717  Application.Scaled:=True;
    1818  Application.Initialize;
    19   Application.CreateForm(TForm1, Form1);
     19  Application.CreateForm(TFormMain, FormMain);
    2020  Application.Run;
    2121end.
  • DpiControls/Demo/UDpiForm.lfm

    r532 r533  
    77  OnShow = DpiForm1Show
    88  object DpiButton1: TDpiButton
    9     Top = 104
    10     Left = 120
     9    Top = 154
     10    Left = 20
    1111    Width = 150
    1212    Height = 40
     
    1414    Caption = 'Test'
    1515    OnClick = DpiButton1Click
     16    left = 88
     17    top = 88
    1618  end
    1719end
  • DpiControls/Demo/UDpiForm.pas

    r532 r533  
    3434var
    3535  DpiButton: TDpiButton;
     36  DpiImage: TDpiImage;
    3637begin
    3738  DpiButton := TDpiButton.Create(DpiForm1);
     
    4142  DpiButton.Visible := True;
    4243  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');
    4351end;
    4452
  • DpiControls/Demo/UFormMain.lfm

    r532 r533  
    1 object Form1: TForm1
    2   Left = 837
    3   Height = 360
    4   Top = 45
    5   Width = 480
    6   Caption = 'Form1'
    7   ClientHeight = 360
    8   ClientWidth = 480
     1object FormMain: TFormMain
     2  Left = 57
     3  Height = 126
     4  Top = 44
     5  Width = 472
     6  Caption = 'DpiControls demo'
     7  ClientHeight = 126
     8  ClientWidth = 472
    99  DesignTimePPI = 144
    1010  OnShow = FormShow
    1111  LCLVersion = '2.0.2.0'
    1212  object TrackBar1: TTrackBar
    13     Left = 24
     13    Left = 13
    1414    Height = 58
    15     Top = 102
    16     Width = 416
     15    Top = 40
     16    Width = 440
    1717    Max = 1000
    1818    Min = 96
     
    2121    TabOrder = 0
    2222  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
    2331end
  • DpiControls/Demo/UFormMain.pas

    r532 r533  
    66
    77uses
    8   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, UDpiForm,
    9   UDpiControls;
     8  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
     9  ExtCtrls, UDpiForm, UDpiControls;
    1010
    1111type
    1212
    13   { TForm1 }
     13  { TFormMain }
    1414
    15   TForm1 = class(TForm)
     15  TFormMain = class(TForm)
     16    Label1: TLabel;
    1617    TrackBar1: TTrackBar;
    1718    procedure FormShow(Sender: TObject);
     
    2425
    2526var
    26   Form1: TForm1;
     27  FormMain: TFormMain;
    2728
    2829implementation
     
    3031{$R *.lfm}
    3132
    32 { TForm1 }
     33{ TFormMain }
    3334
    34 procedure TForm1.FormShow(Sender: TObject);
     35procedure TFormMain.FormShow(Sender: TObject);
    3536begin
    3637  DpiScreen.Dpi := 96 * 2;
     
    4546end;
    4647
    47 procedure TForm1.TrackBar1Change(Sender: TObject);
     48procedure TFormMain.TrackBar1Change(Sender: TObject);
    4849begin
    4950  DpiScreen.Dpi := TrackBar1.Position;
  • DpiControls/UDpiControls.pas

    r532 r533  
    77uses
    88  Classes, SysUtils, LCLProc, LResources, Forms, FormEditingIntf, ProjectIntf,
    9   Controls, StdCtrls, fgl, Graphics;
     9  Controls, StdCtrls, fgl, Graphics, ComCtrls, ExtCtrls;
    1010
    1111type
     
    2929    procedure SetSize(AValue: Integer);
    3030    procedure DoChange;
     31  protected
     32    procedure ScreenChanged;
    3133  public
    3234    VclFont: TFont;
     
    6365    procedure SetVisible(AValue: Boolean); virtual;
    6466    procedure SetWidth(AValue: Integer); virtual;
     67    function GetVclControl: TControl; virtual;
    6568  public
    6669    procedure ScreenChanged; virtual;
     
    8891  TDpiWinControl = class(TDpiControl)
    8992  private
     93  protected
     94    function GetVclWinControl: TWinControl; virtual;
    9095  public
    9196    Controls: TDpiControls;
     
    103108    procedure SetOnShow(AValue: TNotifyEvent);
    104109  protected
    105     procedure FontChanged(Sender: TObject); override;
    106     procedure UpdateBounds; override;
    107110    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;
    110113  public
    111114    VclForm: TForm;
     
    125128    procedure SetOnClick(AValue: TNotifyEvent);
    126129  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;
    132131  public
    133132    VclButton: TButton;
     
    136135  published
    137136    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;
    138153  end;
    139154
     
    171186  DpiFormFileDesc := TDpiFormFileDesc.Create;
    172187  RegisterProjectFileDescriptor(DpiFormFileDesc);
    173   RegisterComponents('DpiControls', [TDpiButton]);
     188  RegisterComponents('DpiControls', [TDpiButton, TDpiImage]);
     189end;
     190
     191{ TDpiImage }
     192
     193procedure TDpiImage.SetStretch(AValue: Boolean);
     194begin
     195  if FStretch = AValue then Exit;
     196  FStretch := AValue;
     197  VclImage.Stretch := AValue;
     198end;
     199
     200function TDpiImage.GetVclControl: TControl;
     201begin
     202  Result := VclImage;
     203end;
     204
     205constructor TDpiImage.Create(TheOwner: TComponent);
     206begin
     207  inherited;
     208  VclImage := TImage.Create(nil);
     209end;
     210
     211destructor TDpiImage.Destroy;
     212begin
     213  FreeAndNil(VclImage);
     214  inherited Destroy;
    174215end;
    175216
     
    188229end;
    189230
     231procedure TDpiFont.ScreenChanged;
     232begin
     233  DoChange;
     234end;
     235
    190236procedure TDpiFont.SetOnChange(AValue: TNotifyEvent);
    191237begin
     
    207253
    208254{ TDpiWinControl }
     255
     256function TDpiWinControl.GetVclWinControl: TWinControl;
     257begin
     258  Result := nil;
     259end;
    209260
    210261procedure TDpiWinControl.ScreenChanged;
     
    272323end;
    273324
    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;
     325function TDpiButton.GetVclControl: TControl;
     326begin
     327  Result := VclButton;
    303328end;
    304329
     
    307332  inherited;
    308333  VclButton := TButton.Create(nil);
     334  ScreenChanged;
    309335end;
    310336
     
    328354  if FVisible = AValue then Exit;
    329355  FVisible := AValue;
     356  GetVclControl.Visible := AValue;;
    330357end;
    331358
     
    337364end;
    338365
     366function TDpiControl.GetVclControl: TControl;
     367begin
     368  Result := nil;
     369end;
     370
    339371procedure TDpiControl.ScreenChanged;
    340372begin
    341373  UpdateBounds;
    342   FontChanged(nil);
     374  Font.ScreenChanged;
    343375end;
    344376
     
    389421procedure TDpiControl.SetCaption(AValue: string);
    390422begin
    391   if FCaption=AValue then Exit;
    392   FCaption:=AValue;
     423  if FCaption = AValue then Exit;
     424  FCaption := AValue;
     425  GetVclControl.Caption := AValue;
    393426end;
    394427
     
    396429begin
    397430  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;
    399436  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;
    401442end;
    402443
     
    409450procedure TDpiControl.FontChanged(Sender: TObject);
    410451begin
     452  GetVclControl.Font.Size := Scale(Font.Size);
    411453end;
    412454
    413455procedure TDpiControl.UpdateBounds;
    414456begin
     457  GetVclControl.SetBounds(Scale(Left), Scale(Top), Scale(Width), Scale(Height));
    415458end;
    416459
     
    466509end;
    467510
    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;
     511function TDpiForm.GetVclControl: TControl;
     512begin
     513  Result := VclForm;
     514end;
     515
     516function TDpiForm.GetVclWinControl: TWinControl;
     517begin
     518  Result := VclForm;
    478519end;
    479520
     
    485526end;
    486527
    487 procedure TDpiForm.FontChanged(Sender: TObject);
    488 begin
    489   inherited;
    490   VclForm.Font.Size := Scale(Font.Size);
    491 end;
    492 
    493 procedure TDpiForm.UpdateBounds;
    494 begin
    495   inherited;
    496   VclForm.SetBounds(Scale(Left), Scale(Top), Scale(Width), Scale(Height));
    497 end;
    498 
    499528// Init the component with an IDE resource
    500529constructor TDpiForm.Create(TheOwner: TComponent);
    501530begin
     531  inherited;
    502532  VclForm := TForm.Create(nil);
     533  ScreenChanged;
    503534  DebugLn(['TDpiForm.Create ', DbgSName(TheOwner)]);
    504535  GlobalNameSpace.BeginWrite;
    505536  try
    506     inherited Create(TheOwner);
    507537    if (ClassType <> TDpiForm) and not (csDesigning in ComponentState)
    508538    then begin
Note: See TracChangeset for help on using the changeset viewer.