Ignore:
Timestamp:
May 9, 2020, 9:35:25 PM (5 years ago)
Author:
chronos
Message:
  • Fixed: Better High DPI scaling on highdpi branch.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Packages/DpiControls/UDpiControls.pas

    r210 r212  
    3838    property OnMouseUp;
    3939    property OnMouseMove;
     40    property OnMouseWheel;
     41    property OnMouseLeave;
     42    property OnMouseEnter;
    4043  end;
    4144
     
    122125    FLeft: Integer;
    123126    FOnChangeBounds: TNotifyEvent;
     127    FOnMouseUp: TMouseEvent;
    124128    FOnMouseDown: TMouseEvent;
    125129    FOnMouseMove: TMouseMoveEvent;
    126     FOnMouseUp: TMouseEvent;
     130    FOnMouseEnter: TNotifyEvent;
     131    FOnMouseLeave: TNotifyEvent;
    127132    FOnMouseWheel: TMouseWheelEvent;
    128133    FOnResize: TNotifyEvent;
     
    161166    procedure DoFormResize;
    162167    procedure DoChangeBounds;
     168    procedure MouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
     169      X, Y: Integer); virtual;
     170    procedure MouseUpHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
     171      X, Y: Integer); virtual;
     172    procedure MouseMoveHandler(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual;
     173    procedure MouseWheelHandler(Sender: TObject; Shift: TShiftState;
     174         WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual;
     175    procedure MouseLeaveHandler(Sender: TObject); virtual;
     176    procedure MouseEnterHandler(Sender: TObject); virtual;
    163177  protected
    164178    procedure UpdateBounds; virtual;
     
    174188    function GetVclControl: TControl; virtual;
    175189    procedure UpdateVclControl; virtual;
    176     procedure MouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
    177       X, Y: Integer); virtual;
    178     procedure MouseUpHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
    179       X, Y: Integer); virtual;
    180     procedure MouseMoveHandler(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual;
    181     procedure MouseWheelHandler(Sender: TObject; Shift: TShiftState;
    182          WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual;
    183190    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
    184191      X, Y: Integer); virtual;
     
    187194    procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual;
    188195    procedure MouseLeave; virtual;
     196    procedure MouseEnter; virtual;
    189197  public
    190198    function ScreenToClient(const APoint: TPoint): TPoint; virtual;
     
    333341    function GetVclGraphicControl: TGraphicControl; virtual;
    334342    procedure UpdateVclControl; override;
    335     procedure UpdateVclControlPrivate; virtual;
    336343    property OnPaint: TNotifyEvent read GetOnPaint write SetOnPaint;
    337344  public
     
    668675
    669676  TDpiPaintBox = class(TDpiGraphicControl)
    670   private
    671     procedure UpdateVclControlPrivate; override;
    672677  public
    673678    VclPaintBox: TPaintBox;
     
    689694    FForms: TDpiForms;
    690695    procedure AddForm(AForm: TDpiForm);
     696    procedure RemoveForm(AForm: TDpiForm);
    691697    function GetActiveForm: TDpiForm;
    692698    function GetCursor: TCursor;
     
    767773  end;
    768774
     775  { TDpiMouse }
     776
     777  // TMouse
     778  TDpiMouse = class
     779  private
     780    function GetCursorPos: TPoint;
     781    procedure SetCursorPos(AValue: TPoint);
     782  public
     783    property CursorPos: TPoint read GetCursorPos write SetCursorPos;
     784  end;
     785
    769786var
    770787  DpiFormFileDesc: TDpiFormFileDesc;
    771788  DpiScreen: TDpiScreen;
    772789  DpiApplication: TDpiApplication;
     790  DpiMouse: TDpiMouse;
    773791
    774792procedure Register;
     
    869887end;
    870888
     889{ TDpiMouse }
     890
     891function TDpiMouse.GetCursorPos: TPoint;
     892begin
     893  Result := ScalePointFromVcl(Mouse.CursorPos);
     894end;
     895
     896procedure TDpiMouse.SetCursorPos(AValue: TPoint);
     897begin
     898  Mouse.CursorPos := ScalePointToVcl(AValue);
     899end;
     900
    871901{ TDpiSizeConstraints }
    872902
     
    15491579{ TDpiPaintBox }
    15501580
    1551 procedure TDpiPaintBox.UpdateVclControlPrivate;
    1552 begin
    1553   VclPaintBox.OnPaint := @PaintHandler;
    1554   VclPaintBox.OnMouseDown := @MouseDownHandler;
    1555   VclPaintBox.OnMouseUp := @MouseUpHandler;
    1556   VclPaintBox.OnMouseMove := @MouseMoveHandler;
    1557 end;
    1558 
    15591581function TDpiPaintBox.GetVclGraphicControl: TGraphicControl;
    15601582begin
     
    17961818begin
    17971819  inherited;
    1798   UpdateVclControlPrivate;
    1799 end;
    1800 
    1801 procedure TDpiGraphicControl.UpdateVclControlPrivate;
    1802 begin
    18031820  TGraphicControlEx(GetVclGraphicControl).OnPaint := @PaintHandler;
    1804   TControlEx(GetVclControl).OnMouseDown := @MouseDownHandler;
    1805   TControlEx(GetVclControl).OnMouseUp := @MouseUpHandler;
    1806   TControlEx(GetVclControl).OnMouseMove := @MouseMoveHandler;
    1807   // Some VCL component event are not accessible on TGraphicControl level.
    1808   // Delegate this responsibility up
    1809   {
    1810   GetVclGraphicControl.OnPaint := @PaintHandler;
    1811   GetVclControl.OnMouseDown := @MouseDownHandler;
    1812   GetVclControl.OnMouseUp := @MouseUpHandler;
    1813   GetVclControl.OnMouseMove := @MouseMoveHandler;
    1814   }
    1815 //  raise Exception.Create('Missing inicialization of private fields for ' + ClassName);
    18161821end;
    18171822
     
    21342139end;
    21352140
     2141procedure TDpiScreen.RemoveForm(AForm: TDpiForm);
     2142begin
     2143  FForms.Remove(AForm);
     2144  if AForm = FActiveForm then FActiveForm := nil;
     2145end;
     2146
    21362147function TDpiScreen.GetActiveForm: TDpiForm;
    21372148begin
     
    21612172  FForms := TDpiForms.Create;
    21622173  FForms.FreeObjects := False;
    2163   Dpi := 150;
     2174  Dpi := Round(96 * 2); //Screen.PixelsPerInch;
    21642175end;
    21652176
     
    22142225  GetVclControl.OnResize := @VclFormResize;
    22152226  GetVclControl.OnChangeBounds := @VclChangeBounds;
     2227  TControlEx(GetVclControl).OnMouseDown := @MouseDownHandler;
     2228  TControlEx(GetVclControl).OnMouseUp := @MouseUpHandler;
     2229  TControlEx(GetVclControl).OnMouseMove := @MouseMoveHandler;
     2230  TControlEx(GetVclControl).OnMouseEnter := @MouseEnterHandler;
     2231  TControlEx(GetVclControl).OnMouseLeave := @MouseLeaveHandler;
     2232  TControlEx(GetVclControl).OnMouseWheel := @MouseWheelHandler;
    22162233end;
    22172234
     
    22442261end;
    22452262
     2263procedure TDpiControl.MouseLeaveHandler(Sender: TObject);
     2264begin
     2265  MouseLeave;
     2266  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
     2267end;
     2268
     2269procedure TDpiControl.MouseEnterHandler(Sender: TObject);
     2270begin
     2271  MouseEnter;
     2272  if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
     2273end;
     2274
    22462275procedure TDpiControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
    22472276  Y: Integer);
     
    22602289procedure TDpiControl.MouseLeave;
    22612290begin
    2262 
     2291end;
     2292
     2293procedure TDpiControl.MouseEnter;
     2294begin
    22632295end;
    22642296
     
    28172849begin
    28182850  inherited;
    2819   GetVclForm.OnMouseDown := @MouseDownHandler;
    2820   GetVclForm.OnMouseUp := @MouseUpHandler;
    2821   GetVclForm.OnMouseMove := @MouseMoveHandler;
    28222851  GetVclForm.OnActivate := @ActivateHandler;
    28232852  GetVclForm.OnDeactivate := @DeactivateHandler;
     
    28472876// Init the component with an IDE resource
    28482877constructor TDpiForm.Create(TheOwner: TComponent);
    2849 var
    2850   C: TComponent;
    28512878begin
    28522879  //inherited;
     
    28552882  try
    28562883    CreateNew(TheOwner, 1); // this calls BeginFormUpdate, which is ended in AfterConstruction
    2857     // Self
    2858     C := FindGlobalComponent('TListDlg');
    28592884    if (ClassType <> TDpiForm) and not (csDesigning in ComponentState) then begin
    28602885      if not InitResourceComponent(Self, TDataModule) then begin
     
    28782903begin
    28792904  FreeAndNil(VclForm);
     2905  DpiScreen.RemoveForm(Self);
    28802906end;
    28812907
Note: See TracChangeset for help on using the changeset viewer.