Changeset 210 for branches/highdpi/Packages/CevoComponents/DrawDlg.pas
- Timestamp:
- May 9, 2020, 4:02:07 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/CevoComponents/DrawDlg.pas
r178 r210 6 6 7 7 uses 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; 10 10 11 11 type … … 15 15 public 16 16 constructor Create(AOwner: TComponent); override; 17 destructor Destroy; override; 17 18 procedure SmartInvalidate; virtual; 19 private 20 MoveFormPos: TPoint; 21 MoveMousePos: TPoint; 22 MoveActive: Boolean; 23 procedure VisibleChangedHandler(Sender: TObject); 18 24 protected 19 TitleHeight: integer;25 TitleHeight: Integer; 20 26 // defines area to grip the window for moving (from top) 21 27 procedure InitButtons; 22 28 procedure OnEraseBkgnd(var m: TMessage); message WM_ERASEBKGND; 23 29 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; 24 35 end; 25 36 … … 58 69 inherited; 59 70 TitleHeight := 0; 71 MoveActive := False; 72 AddHandlerOnVisibleChanged(VisibleChangedHandler); 73 end; 74 75 destructor TDrawDlg.Destroy; 76 begin 77 RemoveHandlerOnVisibleChanged(VisibleChangedHandler); 78 inherited Destroy; 60 79 end; 61 80 … … 98 117 end; 99 118 119 procedure TDrawDlg.MouseDown(Button: TMouseButton; Shift: TShiftState; X, 120 Y: Integer); 121 {$IFDEF LINUX} 122 var 123 MousePosNew: TPoint; 124 NewFormPos: TPoint; 125 {$ENDIF} 126 begin 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} 142 end; 143 144 procedure TDrawDlg.MouseMove(Shift: TShiftState; X, Y: Integer); 145 var 146 MousePos: TPoint; 147 begin 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; 155 end; 156 157 procedure TDrawDlg.MouseUp(Button: TMouseButton; Shift: TShiftState; X, 158 Y: Integer); 159 begin 160 MoveActive := False; 161 inherited; 162 end; 163 164 procedure TDrawDlg.MouseLeave; 165 begin 166 MoveActive := False; 167 inherited; 168 end; 169 170 procedure TDrawDlg.VisibleChangedHandler(Sender: TObject); 171 begin 172 MoveActive := False; 173 end; 174 100 175 procedure TDrawDlg.InitButtons; 101 176 var … … 103 178 // ButtonDownSound, ButtonUpSound: string; 104 179 begin 105 // ButtonDownSound :=Sounds.Lookup('BUTTON_DOWN');106 // ButtonUpSound :=Sounds.Lookup('BUTTON_UP');180 // ButtonDownSound := Sounds.Lookup('BUTTON_DOWN'); 181 // ButtonUpSound := Sounds.Lookup('BUTTON_UP'); 107 182 for cix := 0 to ComponentCount - 1 do 108 183 if Components[cix] is TButtonBase then 109 184 begin 110 185 TButtonBase(Components[cix]).Graphic := GrExt[HGrSystem].Data; 111 // if ButtonDownSound <>'*' then112 // DownSound :=HomeDir+'Sounds'+ DirectorySeparator + ButtonDownSound + '.wav';113 // if ButtonUpSound <>'*' then114 // 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'; 115 190 if Components[cix] is TButtonA then 116 191 TButtonA(Components[cix]).Font := UniFont[ftButton]; … … 125 200 r0, r1: HRgn; 126 201 begin 127 r0 := CreateRectRgn(0, 0, ClientWidth, ClientHeight);202 r0 := DpiCreateRectRgn(0, 0, ClientWidth, ClientHeight); 128 203 for i := 0 to ControlCount - 1 do 129 204 if not(Controls[i] is TArea) and Controls[i].Visible then 130 205 begin 131 206 with Controls[i].BoundsRect do 132 r1 := CreateRectRgn(Left, Top, Right, Bottom);207 r1 := DpiCreateRectRgn(Left, Top, Right, Bottom); 133 208 CombineRgn(r0, r0, r1, RGN_DIFF); 134 209 DeleteObject(r1); … … 142 217 procedure TBaseMessgDlg.FormCreate(Sender: TObject); 143 218 begin 144 Left := ( Screen.Width - Width) div 2;219 Left := (DpiScreen.Width - Width) div 2; 145 220 Canvas.Font.Assign(UniFont[ftNormal]); 146 221 Canvas.Brush.Style := bsClear; 147 222 MessgText := ''; 148 223 TopSpace := 0; 149 TitleHeight := Screen.Height;224 TitleHeight := DpiScreen.Height; 150 225 if csDesigning in ComponentState then Exit; 151 226 InitButtons; … … 157 232 begin 158 233 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), 160 235 ClientHeight - (6 + 2 * Border)); 161 236 for i := 0 to Border do … … 218 293 begin 219 294 ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing; 220 Top := ( Screen.Height - ClientHeight) div 2;295 Top := (DpiScreen.Height - ClientHeight) div 2; 221 296 for i := 0 to ControlCount - 1 do 222 297 Controls[i].Top := ClientHeight - (34 + Border);
Note:
See TracChangeset
for help on using the changeset viewer.