Ignore:
Timestamp:
May 9, 2020, 4:02:07 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved HighDPI branch. Imported new changes from trunk branch.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Packages/CevoComponents/DrawDlg.pas

    r178 r210  
    66
    77uses
    8   Classes, SysUtils, Forms, LCLIntf, LCLType, LMessages, Messages, Graphics,
    9   Controls, ButtonBase, ButtonA, ButtonB, Area, ScreenTools, UDpiControls;
     8  UDpiControls, Classes, SysUtils, Forms, LCLIntf, LCLType, {$IFDEF LINUX}LMessages,{$ENDIF}
     9  Messages, Graphics, Controls, ButtonBase, ButtonA, ButtonB, Area, ScreenTools;
    1010
    1111type
     
    1515  public
    1616    constructor Create(AOwner: TComponent); override;
     17    destructor Destroy; override;
    1718    procedure SmartInvalidate; virtual;
     19  private
     20    MoveFormPos: TPoint;
     21    MoveMousePos: TPoint;
     22    MoveActive: Boolean;
     23    procedure VisibleChangedHandler(Sender: TObject);
    1824  protected
    19     TitleHeight: integer;
     25    TitleHeight: Integer;
    2026    // defines area to grip the window for moving (from top)
    2127    procedure InitButtons;
    2228    procedure OnEraseBkgnd(var m: TMessage); message WM_ERASEBKGND;
    2329    procedure OnHitTest(var Msg: TMessage); message WM_NCHITTEST;
     30    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
     31      override;
     32    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
     33    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
     34    procedure MouseLeave; override;
    2435  end;
    2536
     
    5869  inherited;
    5970  TitleHeight := 0;
     71  MoveActive := False;
     72  AddHandlerOnVisibleChanged(VisibleChangedHandler);
     73end;
     74
     75destructor TDrawDlg.Destroy;
     76begin
     77  RemoveHandlerOnVisibleChanged(VisibleChangedHandler);
     78  inherited Destroy;
    6079end;
    6180
     
    98117end;
    99118
     119procedure TDrawDlg.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
     120  Y: Integer);
     121{$IFDEF LINUX}
     122var
     123  MousePosNew: TPoint;
     124  NewFormPos: TPoint;
     125{$ENDIF}
     126begin
     127  inherited;
     128  {$IFDEF LINUX}
     129  // HitTest is not supported under Linux GTK2 so use form inside move mechanizm
     130  NewFormPos := ScreenToClient(Mouse.CursorPos);
     131  if (NewFormPos.X >= 0) and (NewFormPos.X < Width) and
     132    (NewFormPos.Y >= 0) and (NewFormPos.Y < Height) then begin
     133    MoveMousePos := ClientToScreen(Point(X, Y));
     134    MoveFormPos := Point(Left, Top);
     135    MousePosNew := Mouse.CursorPos;
     136    // Activate move only if mouse position was not changed during inherited call
     137    if (MousePosNew.X = MoveMousePos.X) and (MousePosNew.Y = MoveMousePos.Y) then begin
     138      MoveActive := True;
     139    end;
     140  end else MoveActive := False;
     141  {$ENDIF}
     142end;
     143
     144procedure TDrawDlg.MouseMove(Shift: TShiftState; X, Y: Integer);
     145var
     146  MousePos: TPoint;
     147begin
     148  inherited;
     149  if MoveActive then begin
     150    MousePos := ClientToScreen(Point(X, Y));
     151    SetBounds(MoveFormPos.X + MousePos.X - MoveMousePos.X,
     152      MoveFormPos.Y + MousePos.Y - MoveMousePos.Y,
     153      Width, Height);
     154  end;
     155end;
     156
     157procedure TDrawDlg.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
     158  Y: Integer);
     159begin
     160  MoveActive := False;
     161  inherited;
     162end;
     163
     164procedure TDrawDlg.MouseLeave;
     165begin
     166  MoveActive := False;
     167  inherited;
     168end;
     169
     170procedure TDrawDlg.VisibleChangedHandler(Sender: TObject);
     171begin
     172  MoveActive := False;
     173end;
     174
    100175procedure TDrawDlg.InitButtons;
    101176var
     
    103178  // ButtonDownSound, ButtonUpSound: string;
    104179begin
    105   // ButtonDownSound:=Sounds.Lookup('BUTTON_DOWN');
    106   // ButtonUpSound:=Sounds.Lookup('BUTTON_UP');
     180  // ButtonDownSound := Sounds.Lookup('BUTTON_DOWN');
     181  // ButtonUpSound := Sounds.Lookup('BUTTON_UP');
    107182  for cix := 0 to ComponentCount - 1 do
    108183    if Components[cix] is TButtonBase then
    109184    begin
    110185      TButtonBase(Components[cix]).Graphic := GrExt[HGrSystem].Data;
    111       // if ButtonDownSound<>'*' then
    112       // DownSound:=HomeDir+'Sounds' + DirectorySeparator + ButtonDownSound + '.wav';
    113       // if ButtonUpSound<>'*' then
    114       // UpSound:=HomeDir+'Sounds' + DirectorySeparator + ButtonUpSound + '.wav';
     186      // if ButtonDownSound <> '*' then
     187      // DownSound := GetSoundsDir + DirectorySeparator + ButtonDownSound + '.wav';
     188      // if ButtonUpSound <> '*' then
     189      // UpSound := GetSoundsDir + DirectorySeparator + ButtonUpSound + '.wav';
    115190      if Components[cix] is TButtonA then
    116191        TButtonA(Components[cix]).Font := UniFont[ftButton];
     
    125200  r0, r1: HRgn;
    126201begin
    127   r0 := CreateRectRgn(0, 0, ClientWidth, ClientHeight);
     202  r0 := DpiCreateRectRgn(0, 0, ClientWidth, ClientHeight);
    128203  for i := 0 to ControlCount - 1 do
    129204    if not(Controls[i] is TArea) and Controls[i].Visible then
    130205    begin
    131206      with Controls[i].BoundsRect do
    132         r1 := CreateRectRgn(Left, Top, Right, Bottom);
     207        r1 := DpiCreateRectRgn(Left, Top, Right, Bottom);
    133208      CombineRgn(r0, r0, r1, RGN_DIFF);
    134209      DeleteObject(r1);
     
    142217procedure TBaseMessgDlg.FormCreate(Sender: TObject);
    143218begin
    144   Left := (Screen.Width - Width) div 2;
     219  Left := (DpiScreen.Width - Width) div 2;
    145220  Canvas.Font.Assign(UniFont[ftNormal]);
    146221  Canvas.Brush.Style := bsClear;
    147222  MessgText := '';
    148223  TopSpace := 0;
    149   TitleHeight := Screen.Height;
     224  TitleHeight := DpiScreen.Height;
    150225  if csDesigning in ComponentState then Exit;
    151226  InitButtons;
     
    157232begin
    158233  if csDesigning in ComponentState then Exit;
    159   PaintBackground(Self, 3 + Border, 3 + Border, ClientWidth - (6 + 2 * Border),
     234  PaintBackground(self, 3 + Border, 3 + Border, ClientWidth - (6 + 2 * Border),
    160235    ClientHeight - (6 + 2 * Border));
    161236  for i := 0 to Border do
     
    218293begin
    219294  ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;
    220   Top := (Screen.Height - ClientHeight) div 2;
     295  Top := (DpiScreen.Height - ClientHeight) div 2;
    221296  for i := 0 to ControlCount - 1 do
    222297    Controls[i].Top := ClientHeight - (34 + Border);
Note: See TracChangeset for help on using the changeset viewer.