Changeset 268 for trunk/UMapType.pas


Ignore:
Timestamp:
Jan 20, 2019, 9:32:16 PM (6 years ago)
Author:
chronos
Message:
  • Added: New menu action show/hide map grid lines.
  • Modified: Draw cell polygons without a gap so it can be drawn as solid surface without grid lines.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMapType.pas

    r258 r268  
    2020  private
    2121    const
    22       CellMulX = 1.12;
    23       CellMulY = 1.292;
     22      CellMulX = 1.12 * 1.028;
     23      CellMulY = 1.292 * 1.03;
    2424    function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean;
    2525    procedure GetCellPosNeighbors(CellPos: TPoint; Cell: TCell);
     
    3838  TSquareMap = class(TMap)
    3939  private
    40     const
    41       CellMulX = 1.05;
    42       CellMulY = 1.05;
    4340    function GetSquarePolygon(Pos: TPoint; Size: TPoint): TPolygon;
    4441  public
    4542    procedure Generate; override;
    46     function CalculatePixelRect: TRect; override;
    4743  end;
    4844
     
    5248  private
    5349    const
    54       CellMulX = 0.55;
    55       CellMulY = 1.05;
     50      CellMulX = 0.5;
     51      CellMulY = 1;
    5652    function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPolygon;
    5753  protected
     
    7672  private
    7773    const
    78       CellMulX = 0.95;
    79       CellMulY = 3.35;
     74      CellMulX = 1;
     75      CellMulY = 3.5;
    8076    function GetTilePolygon(Pos: TPoint; Size: TPoint): TPolygon;
    8177  protected
     
    173169  Result := inherited CalculatePixelRect;
    174170  Result.P2 := Result.P2 - TPoint.Create(
    175     Trunc(0.45 * DefaultCellSize.X / CellMulX),
    176     Trunc(0.90 * DefaultCellSize.Y / CellMulY)
     171    Trunc(0.5 * DefaultCellSize.X / CellMulX),
     172    Trunc(DefaultCellSize.Y / CellMulY)
    177173  );
    178174end;
     
    212208  Shift := TPointF.Create(0.5, 0.5) * TPointF.Create(Cos(Angle), Sin(Angle));
    213209  Result.P2 := Result.P2 - TPoint.Create(
    214     Trunc(0.47 * DefaultCellSize.X / CellMulX),
    215     Trunc(1.2 * Shift.Y * DefaultCellSize.Y / CellMulY)
     210    Trunc(0.5 * DefaultCellSize.X / CellMulX),
     211    Trunc(1.35 * Shift.Y * DefaultCellSize.Y / CellMulY)
    216212  );
    217213end;
     
    344340    NewCell := TCell.Create;
    345341    NewCell.Map := Self;
    346     NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * CellMulX),
    347       Trunc(Y * DefaultCellSize.Y * CellMulY));
     342    NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X),
     343      Trunc(Y * DefaultCellSize.Y));
    348344    NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize);
    349345    NewCell.Id := GetNewCellId;
     
    382378
    383379  FPixelRect := CalculatePixelRect;
    384 end;
    385 
    386 function TSquareMap.CalculatePixelRect: TRect;
    387 begin
    388   Result := inherited CalculatePixelRect;
    389   Result.P2 := Result.P2 + TPoint.Create(
    390     Trunc(0.05 * DefaultCellSize.X / CellMulX),
    391     Trunc(0.05 * DefaultCellSize.Y / CellMulY)
    392   );
    393380end;
    394381
     
    424411  AreaSize: TPoint;
    425412const
    426   CellGapWidth = 4;
     413  LinkTolerance = 8;
    427414begin
    428415  Clear;
     
    457444        LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx +
    458445          TPoint.Create(X * AreaSize.X, Y * AreaSize.Y));
    459         LinkLine.Distance := LinkLine.Distance - CellGapWidth;
     446        LinkLine.Distance := LinkLine.Distance;
    460447        MP := LinkLine.GetMiddle;
    461448        // Create half plane vector
     
    473460      if Cell2 <> Cell then begin
    474461        LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx);
    475         LinkLine.Distance := LinkLine.Distance - CellGapWidth;
     462        LinkLine.Distance := LinkLine.Distance;
    476463        MP := LinkLine.GetMiddle;
    477464        // Create half plane vector
     
    493480        P := Cells[J].Polygon;
    494481        P.Move(TPoint.Create(X * AreaSize.X, Y * AreaSize.Y));
    495         if Cells[I].Polygon.EdgeDistance(P) < 2 * CellGapWidth then
     482        if Cells[I].Polygon.EdgeDistance(P) < LinkTolerance then
    496483          Cells[I].ConnectTo(Cells[J]);
    497484      end;
     
    500487    for I := 0 to Cells.Count - 1 do begin
    501488      for J := I + 1 to Cells.Count - 1 do begin
    502         if Cells[I].Polygon.EdgeDistance(Cells[J].Polygon) < 2 * CellGapWidth then
     489        if Cells[I].Polygon.EdgeDistance(Cells[J].Polygon) < LinkTolerance then
    503490          Cells[I].ConnectTo(Cells[J]);
    504491      end;
     
    603590  Result := inherited CalculatePixelRect;
    604591  Result.P2 := Result.P2 + TPoint.Create(
    605     Trunc(0.05 * DefaultCellSize.X / CellMulX - 0.30 * DefaultCellSize.X / CellMulX),
    606     Trunc(0.05 * DefaultCellSize.Y / CellMulY)
     592    Trunc(- 0.25 * DefaultCellSize.X / CellMulX),
     593    0
    607594  );
    608595end;
Note: See TracChangeset for help on using the changeset viewer.