Changeset 63 for trunk/Packages/Common
- Timestamp:
- Jan 5, 2023, 11:03:33 PM (2 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UGeometric.pas
r54 r63 9 9 TPointArray = array of TPoint; 10 10 11 { TVector } 12 13 TVector = record 14 Position: TPoint; 15 Direction: TPoint; 16 function GetLength: Integer; 17 function GetAngle: Double; 18 end; 19 11 20 function Distance(P1, P2: TPoint): Integer; 12 21 function Dot(const P1, P2: TPoint): Double; 13 22 function AddPoint(const P1, P2: TPoint): TPoint; 14 23 function SubPoint(const P1, P2: TPoint): TPoint; 15 function PointToLineDistance(const P, V, W: TPoint ): Integer;24 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 16 25 function ComparePoint(P1, P2: TPoint): Boolean; 17 26 function RotatePoint(Center, P: TPoint; Angle: Double): TPoint; … … 50 59 end; 51 60 52 function PointToLineDistance(const P, V, W: TPoint ): Integer;61 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 53 62 var 54 63 l2, t: Double; … … 68 77 if T < 0 then begin 69 78 Result := Distance(P, V); // Beyond the 'v' end of the segment 70 exit; 79 Intersect := V; 80 Exit; 71 81 end 72 82 else if T > 1 then begin 73 83 Result := Distance(P, W); // Beyond the 'w' end of the segment 84 Intersect := W; 74 85 Exit; 75 86 end; … … 77 88 TT.Y := Trunc(V.Y + T * (W.Y - V.Y)); 78 89 Result := Distance(P, TT); 90 Intersect := TT; 79 91 end; 80 92 … … 162 174 end; 163 175 176 { TVector } 177 178 function TVector.GetLength: Integer; 179 begin 180 Result := Trunc(Sqrt(Sqr(Direction.X) + Sqr(Direction.Y))); 181 end; 182 183 function TVector.GetAngle: Double; 184 begin 185 Result := ArcTan2(Direction.Y, Direction.X); 186 end; 164 187 165 188 end. -
trunk/Packages/Common/UPersistentForm.pas
r54 r63 1 1 unit UPersistentForm; 2 3 // Date: 2020-11-264 2 5 3 interface … … 21 19 procedure SaveControl(Control: TControl); 22 20 public 23 FormNormalSize: TRect;24 21 FormRestoredSize: TRect; 25 22 FormWindowState: TWindowState; … … 155 152 RootKey := RegistryContext.RootKey; 156 153 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 157 // Normal size 158 FormNormalSize.Left := ReadIntegerWithDefault('NormalLeft', FormNormalSize.Left); 159 FormNormalSize.Top := ReadIntegerWithDefault('NormalTop', FormNormalSize.Top); 160 FormNormalSize.Right := ReadIntegerWithDefault('NormalWidth', FormNormalSize.Right - FormNormalSize.Left) 161 + FormNormalSize.Left; 162 FormNormalSize.Bottom := ReadIntegerWithDefault('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top) 163 + FormNormalSize.Top; 154 164 155 // Restored size 165 156 FormRestoredSize.Left := ReadIntegerWithDefault('RestoredLeft', FormRestoredSize.Left); … … 169 160 FormRestoredSize.Bottom := ReadIntegerWithDefault('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top) 170 161 + FormRestoredSize.Top; 162 171 163 // Other state 172 164 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState))); … … 183 175 RootKey := RegistryContext.RootKey; 184 176 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 185 // Normal state 186 WriteInteger('NormalWidth', FormNormalSize.Right - FormNormalSize.Left); 187 WriteInteger('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top); 188 WriteInteger('NormalTop', FormNormalSize.Top); 189 WriteInteger('NormalLeft', FormNormalSize.Left); 190 // Restored state 177 178 // Restored size 191 179 WriteInteger('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left); 192 180 WriteInteger('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top); 193 181 WriteInteger('RestoredTop', FormRestoredSize.Top); 194 182 WriteInteger('RestoredLeft', FormRestoredSize.Left); 183 195 184 // Other state 196 185 WriteInteger('WindowState', Integer(FormWindowState)); … … 257 246 begin 258 247 Self.Form := Form; 248 259 249 // Set default 260 FormNormalSize := Bounds((Screen.Width - Form.Width) div 2,261 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);262 250 FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2, 263 251 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); … … 267 255 LoadFromRegistry(RegistryContext); 268 256 269 if not EqualRect(FormNormalSize, FormRestoredSize) or 270 DefaultMaximized then begin 257 if (FormWindowState = wsMaximized) or DefaultMaximized then begin 271 258 // Restore to maximized state 272 259 Form.WindowState := wsNormal; … … 277 264 // Restore to normal state 278 265 Form.WindowState := wsNormal; 279 if FEntireVisible then Form NormalSize := CheckEntireVisible(FormNormalSize)266 if FEntireVisible then FormRestoredSize := CheckEntireVisible(FormRestoredSize) 280 267 else if FMinVisiblePart > 0 then 281 FormNormalSize := CheckPartVisible(FormNormalSize, FMinVisiblePart);282 if not EqualRect(Form NormalSize, Form.BoundsRect) then283 Form.BoundsRect := Form NormalSize;268 FormRestoredSize := CheckPartVisible(FormRestoredSize, FMinVisiblePart); 269 if not EqualRect(FormRestoredSize, Form.BoundsRect) then 270 Form.BoundsRect := FormRestoredSize; 284 271 end; 285 272 if FormFullScreen then SetFullScreen(True); … … 290 277 begin 291 278 Self.Form := Form; 292 FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 293 if not FormFullScreen then 294 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 295 Form.RestoredHeight); 296 FormWindowState := Form.WindowState; 279 if not FormFullScreen then begin 280 FormWindowState := Form.WindowState; 281 if FormWindowState = wsMaximized then begin 282 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 283 Form.RestoredHeight); 284 end else 285 if FormWindowState = wsNormal then begin 286 FormRestoredSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 287 end; 288 end; 297 289 SaveToRegistry(RegistryContext); 298 290 SaveControl(Form); … … 312 304 if State then begin 313 305 FormFullScreen := True; 314 FormNormalSize := Form.BoundsRect; 315 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 316 Form.RestoredHeight); 306 if Form.WindowState = wsMaximized then begin 307 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 308 Form.RestoredHeight); 309 end else 310 if Form.WindowState = wsNormal then begin 311 FormRestoredSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 312 end; 317 313 FormWindowState := Form.WindowState; 314 Form.WindowState := wsMaximized; 315 Form.WindowState := wsNormal; 318 316 ShowWindow(Form.Handle, SW_SHOWFULLSCREEN); 319 317 {$IFDEF WINDOWS} … … 327 325 ShowWindow(Form.Handle, SW_SHOWNORMAL); 328 326 if FormWindowState = wsNormal then begin 329 Form.BoundsRect := FormNormalSize; 327 Form.WindowState := wsNormal; 328 Form.BoundsRect := FormRestoredSize; 330 329 end else 331 330 if FormWindowState = wsMaximized then begin
Note:
See TracChangeset
for help on using the changeset viewer.