Changeset 63 for trunk/Packages/Common


Ignore:
Timestamp:
Jan 5, 2023, 11:03:33 PM (2 years ago)
Author:
chronos
Message:
  • Added: Snap package definition.
Location:
trunk/Packages/Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UGeometric.pas

    r54 r63  
    99  TPointArray = array of TPoint;
    1010
     11  { TVector }
     12
     13  TVector = record
     14    Position: TPoint;
     15    Direction: TPoint;
     16    function GetLength: Integer;
     17    function GetAngle: Double;
     18  end;
     19
    1120function Distance(P1, P2: TPoint): Integer;
    1221function Dot(const P1, P2: TPoint): Double;
    1322function AddPoint(const P1, P2: TPoint): TPoint;
    1423function SubPoint(const P1, P2: TPoint): TPoint;
    15 function PointToLineDistance(const P, V, W: TPoint): Integer;
     24function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer;
    1625function ComparePoint(P1, P2: TPoint): Boolean;
    1726function RotatePoint(Center, P: TPoint; Angle: Double): TPoint;
     
    5059end;
    5160
    52 function PointToLineDistance(const P, V, W: TPoint): Integer;
     61function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer;
    5362var
    5463  l2, t: Double;
     
    6877  if T < 0 then begin
    6978    Result := Distance(P, V);       // Beyond the 'v' end of the segment
    70     exit;
     79    Intersect := V;
     80    Exit;
    7181  end
    7282  else if T > 1 then begin
    7383    Result := Distance(P, W);  // Beyond the 'w' end of the segment
     84    Intersect := W;
    7485    Exit;
    7586  end;
     
    7788  TT.Y := Trunc(V.Y + T * (W.Y - V.Y));
    7889  Result := Distance(P, TT);
     90  Intersect := TT;
    7991end;
    8092
     
    162174end;
    163175
     176{ TVector }
     177
     178function TVector.GetLength: Integer;
     179begin
     180  Result := Trunc(Sqrt(Sqr(Direction.X) + Sqr(Direction.Y)));
     181end;
     182
     183function TVector.GetAngle: Double;
     184begin
     185  Result := ArcTan2(Direction.Y, Direction.X);
     186end;
    164187
    165188end.
  • trunk/Packages/Common/UPersistentForm.pas

    r54 r63  
    11unit UPersistentForm;
    2 
    3 // Date: 2020-11-26
    42
    53interface
     
    2119    procedure SaveControl(Control: TControl);
    2220  public
    23     FormNormalSize: TRect;
    2421    FormRestoredSize: TRect;
    2522    FormWindowState: TWindowState;
     
    155152    RootKey := RegistryContext.RootKey;
    156153    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
    164155    // Restored size
    165156    FormRestoredSize.Left := ReadIntegerWithDefault('RestoredLeft', FormRestoredSize.Left);
     
    169160    FormRestoredSize.Bottom := ReadIntegerWithDefault('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top)
    170161      + FormRestoredSize.Top;
     162
    171163    // Other state
    172164    FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState)));
     
    183175    RootKey := RegistryContext.RootKey;
    184176    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
    191179    WriteInteger('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left);
    192180    WriteInteger('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top);
    193181    WriteInteger('RestoredTop', FormRestoredSize.Top);
    194182    WriteInteger('RestoredLeft', FormRestoredSize.Left);
     183
    195184    // Other state
    196185    WriteInteger('WindowState', Integer(FormWindowState));
     
    257246begin
    258247  Self.Form := Form;
     248
    259249  // Set default
    260   FormNormalSize := Bounds((Screen.Width - Form.Width) div 2,
    261     (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
    262250  FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2,
    263251    (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
     
    267255  LoadFromRegistry(RegistryContext);
    268256
    269   if not EqualRect(FormNormalSize, FormRestoredSize) or
    270     DefaultMaximized then begin
     257  if (FormWindowState = wsMaximized) or DefaultMaximized then begin
    271258    // Restore to maximized state
    272259    Form.WindowState := wsNormal;
     
    277264    // Restore to normal state
    278265    Form.WindowState := wsNormal;
    279     if FEntireVisible then FormNormalSize := CheckEntireVisible(FormNormalSize)
     266    if FEntireVisible then FormRestoredSize := CheckEntireVisible(FormRestoredSize)
    280267      else if FMinVisiblePart > 0 then
    281     FormNormalSize := CheckPartVisible(FormNormalSize, FMinVisiblePart);
    282     if not EqualRect(FormNormalSize, Form.BoundsRect) then
    283       Form.BoundsRect := FormNormalSize;
     268        FormRestoredSize := CheckPartVisible(FormRestoredSize, FMinVisiblePart);
     269    if not EqualRect(FormRestoredSize, Form.BoundsRect) then
     270      Form.BoundsRect := FormRestoredSize;
    284271  end;
    285272  if FormFullScreen then SetFullScreen(True);
     
    290277begin
    291278  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;
    297289  SaveToRegistry(RegistryContext);
    298290  SaveControl(Form);
     
    312304  if State then begin
    313305    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;
    317313    FormWindowState := Form.WindowState;
     314    Form.WindowState := wsMaximized;
     315    Form.WindowState := wsNormal;
    318316    ShowWindow(Form.Handle, SW_SHOWFULLSCREEN);
    319317    {$IFDEF WINDOWS}
     
    327325    ShowWindow(Form.Handle, SW_SHOWNORMAL);
    328326    if FormWindowState = wsNormal then begin
    329       Form.BoundsRect := FormNormalSize;
     327      Form.WindowState := wsNormal;
     328      Form.BoundsRect := FormRestoredSize;
    330329    end else
    331330    if FormWindowState = wsMaximized then begin
Note: See TracChangeset for help on using the changeset viewer.