Changeset 170 for trunk/UGame.pas
- Timestamp:
- Nov 23, 2017, 5:02:49 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r168 r170 161 161 TCanvasEx = class(TCanvas) 162 162 class procedure TextOutEx(Canvas: TCanvas; X,Y: Integer; const Text: string; MovePen: Boolean = True); 163 class procedure PolygonEx(Canvas: TCanvas; const Points: array of TPoint; Winding: Boolean);163 class procedure PolygonEx(Canvas: TCanvas; const Points: array of Classes.TPoint; Winding: Boolean); 164 164 end; 165 165 … … 957 957 with CellLink do begin 958 958 if Length(Points) >= 2 then begin 959 MoveTo( View.CellToCanvasPos(Points[0]));959 MoveTo(PointToStdPoint(View.CellToCanvasPos(Points[0]))); 960 960 for I := 1 to Length(Points) - 1 do 961 LineTo( View.CellToCanvasPos(Points[I]));961 LineTo(PointToStdPoint(View.CellToCanvasPos(Points[I]))); 962 962 end; 963 963 end; … … 999 999 for NeighCell in Cell.MapCell.Neighbors do begin 1000 1000 Pen.Color := clYellow; 1001 MoveTo( View.CellToCanvasPos(Cell.MapCell.PosPx));1002 LineTo( View.CellToCanvasPos(NeighCell.PosPx));1001 MoveTo(PointToStdPoint(View.CellToCanvasPos(Cell.MapCell.PosPx))); 1002 LineTo(PointToStdPoint(View.CellToCanvasPos(NeighCell.PosPx))); 1003 1003 end; 1004 1004 … … 1022 1022 Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X)); 1023 1023 if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi; 1024 ArrowCenter := View.CellToCanvasPos( Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),1024 ArrowCenter := View.CellToCanvasPos(TPoint.Create(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2), 1025 1025 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2))); 1026 1026 Player.Game.Map.DrawArrow(Canvas, View, ArrowCenter, … … 1051 1051 end; 1052 1052 1053 class procedure TCanvasEx.PolygonEx(Canvas: TCanvas; const Points: array of TPoint; Winding: Boolean);1053 class procedure TCanvasEx.PolygonEx(Canvas: TCanvas; const Points: array of Classes.TPoint; Winding: Boolean); 1054 1054 begin 1055 1055 //Changing; … … 1349 1349 for Cell in Cells do begin 1350 1350 for NeighborCell in Cell.Neighbors do 1351 NeighborCell.Angle := ArcTan2Point(Point( 1352 NeighborCell.PosPx.X - Cell.PosPx.X, 1353 NeighborCell.PosPx.Y - Cell.PosPx.Y)); 1351 NeighborCell.Angle := TLine.Create(Cell.PosPx, NeighborCell.PosPx).GetAngle; 1354 1352 1355 1353 Cell.Neighbors.Sort(CompareCellAngle); … … 1375 1373 Rect := PixelRect; 1376 1374 with Image.Picture.Bitmap do begin 1377 Pos := Point(Trunc(Coord.X / (Rect.Right - Rect.Left)* Width),1378 Trunc(Coord.Y / (Rect.Bottom - Rect.Top)* Height));1375 Pos := TPoint.Create(Trunc(Coord.X / Rect.Size.X * Width), 1376 Trunc(Coord.Y / Rect.Size.Y * Height)); 1379 1377 Color := Canvas.Pixels[Pos.X, Pos.Y]; 1380 1378 end; … … 1383 1381 msRounded: begin 1384 1382 Rect := PixelRect; 1385 Center := Point(Rect.Left + (Rect.Right - Rect.Left) div 2, 1386 Rect.Top + (Rect.Bottom - Rect.Top) div 2); 1387 Result := Sqr(Coord.X - Center.X) / Sqr((Rect.Right - Rect.Left) div 2) + 1388 Sqr(Coord.Y - Center.Y) / Sqr((Rect.Bottom - Rect.Top) div 2) > 1; 1383 Center := Rect.Center; 1384 Result := Sqr(Coord.X - Center.X) / Sqr(Rect.Size.X div 2) + 1385 Sqr(Coord.Y - Center.Y) / Sqr(Rect.Size.Y div 2) > 1; 1389 1386 end 1390 1387 else Result := False; … … 1395 1392 Angle: Double; Text: string); 1396 1393 var 1397 Points: array of TPoint;1394 Points: array of Classes.TPoint; 1398 1395 FPoints: array of TFloatPoint; 1399 1396 I: Integer; … … 1404 1401 SetLength(Points, 8); 1405 1402 SetLength(FPoints, 8); 1406 ArrowSize := Point(Trunc(DefaultCellSize.X / 3 * View.Zoom),1403 ArrowSize := TPoint.Create(Trunc(DefaultCellSize.X / 3 * View.Zoom), 1407 1404 Trunc(DefaultCellSize.Y / 3 * View.Zoom)); 1408 1405 FPoints[0] := FloatPoint(+0.5 * ArrowSize.X, +0 * ArrowSize.Y); … … 1480 1477 Node2: TDOMNode; 1481 1478 begin 1482 Size := Point(ReadInteger(Node, 'SizeX', 0), ReadInteger(Node, 'SizeY', 0));1479 Size := TPoint.Create(ReadInteger(Node, 'SizeX', 0), ReadInteger(Node, 'SizeY', 0)); 1483 1480 DefaultCellSize.X := ReadInteger(Node, 'DefaultCellSizeX', 1); 1484 1481 DefaultCellSize.Y := ReadInteger(Node, 'DefaultCellSizeY', 1); … … 1565 1562 I: Integer; 1566 1563 TextPos: TPoint; 1567 Points: array of TPoint;1564 Points: array of Classes.TPoint; 1568 1565 TextSize: TSize; 1569 1566 begin … … 1590 1587 SetLength(Points, Length(Cell.Polygon.Points)); 1591 1588 for I := 0 to Length(Points) - 1 do 1592 Points[I] := View.CellToCanvasPos(Cell.Polygon.Points[I]);1589 Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.Polygon.Points[I])); 1593 1590 Brush.Style := bsSolid; 1594 1591 //Polygon(Points, False, 0, Length(Points)); … … 1640 1637 NewCell := TCell.Create; 1641 1638 NewCell.Map := Self; 1642 NewCell.PosPx := Point(X * DefaultCellSize.X, Y * DefaultCellSize.Y);1639 NewCell.PosPx := TPoint.Create(X * DefaultCellSize.X, Y * DefaultCellSize.Y); 1643 1640 NewCell.Id := GetNewCellId; 1644 1641 SetLength(NewCell.Polygon.Points, 1); … … 1731 1728 begin 1732 1729 MaxPower := 99; 1733 DefaultCellSize := Point(220, 220);1730 DefaultCellSize := TPoint.Create(220, 220); 1734 1731 Cells := TCells.Create; 1735 1732 Cells.Map := Self; 1736 Size := Point(0, 0);1733 Size := TPoint.Create(0, 0); 1737 1734 Image := TImage.Create(nil); 1738 1735 CellLinks := TCellLinks.Create; … … 1743 1740 destructor TMap.Destroy; 1744 1741 begin 1745 Size := Point(0, 0);1742 Size := TPoint.Create(0, 0); 1746 1743 FreeAndNil(Areas); 1747 1744 FreeAndNil(CellLinks); … … 1756 1753 CellRect: TRect; 1757 1754 begin 1758 Result := Rect(0, 0, 0, 0);1755 Result := TRect.Create(TPoint.Create(0, 0), TPoint.Create(0, 0)); 1759 1756 // This is generic algorithm to determine pixel size of entire map 1760 1757 for I := 0 to Cells.Count - 1 do begin … … 1762 1759 if I = 0 then Result := CellRect 1763 1760 else begin 1764 if CellRect.Right > Result.Right then Result.Right := CellRect.Right; 1765 if CellRect.Bottom > Result.Bottom then Result.Bottom := CellRect.Bottom; 1766 if CellRect.Left < Result.Left then Result.Left := CellRect.Left; 1767 if CellRect.Top < Result.Top then Result.Top := CellRect.Top; 1761 Result.P1 := TPoint.Min(Result.P1, CellRect.P1); 1762 Result.P2 := TPoint.Max(Result.P2, CellRect.P2); 1768 1763 end; 1769 1764 end; … … 1840 1835 raise Exception.Create(SZeroZoomNotAlowed); 1841 1836 FZoom := AValue; 1842 SourceRect := Bounds(Trunc(SourceRect.Left + (SourceRect.Right - SourceRect.Left) div 2 - (DestRect.Right - DestRect.Left)/ Zoom / 2),1843 Trunc(SourceRect. Top + (SourceRect.Bottom - SourceRect.Top) div 2 - (DestRect.Bottom - DestRect.Top) / Zoom / 2),1844 T runc((DestRect.Right - DestRect.Left)/ Zoom),1845 Trunc( (DestRect.Bottom - DestRect.Top) / Zoom));1837 SourceRect := TRect.CreateBounds(TPoint.Create(Trunc(SourceRect.P1.X + SourceRect.Size.X div 2 - DestRect.Size.X / Zoom / 2), 1838 Trunc(SourceRect.P1.Y + SourceRect.Size.Y div 2 - DestRect.Size.Y / Zoom / 2)), 1839 TPoint.Create(Trunc(DestRect.Size.X / Zoom), 1840 Trunc(DestRect.Size.Y / Zoom))); 1846 1841 end; 1847 1842 … … 1856 1851 Diff: TPoint; 1857 1852 begin 1858 if RectEquals(FDestRect, AValue)then Exit;1859 Diff := Point(Trunc((DestRect.Right - DestRect.Left) / Zoom - (AValue.Right - AValue.Left)/ Zoom) div 2,1860 Trunc( (DestRect.Bottom - DestRect.Top) / Zoom - (AValue.Bottom - AValue.Top)/ Zoom) div 2);1853 if FDestRect = AValue then Exit; 1854 Diff := TPoint.Create(Trunc(DestRect.Size.X / Zoom - AValue.Size.X / Zoom) div 2, 1855 Trunc(DestRect.Size.Y / Zoom - AValue.Size.Y / Zoom) div 2); 1861 1856 FDestRect := AValue; 1862 SourceRect := Bounds(SourceRect.Left + Diff.X, SourceRect.Top + Diff.Y,1863 T runc((DestRect.Right - DestRect.Left)/ Zoom),1864 Trunc( (DestRect.Bottom - DestRect.Top) / Zoom));1857 SourceRect := TRect.CreateBounds(TPoint.Create(SourceRect.P1.X + Diff.X, SourceRect.P1.Y + Diff.Y), 1858 TPoint.Create(Trunc(DestRect.Size.X / Zoom), 1859 Trunc(DestRect.Size.Y / Zoom))); 1865 1860 end; 1866 1861 … … 1984 1979 Node2 := Node3.FirstChild; 1985 1980 while Assigned(Node2) and (Node2.NodeName = 'Point') do begin 1986 Polygon.AddPoint( Point(ReadInteger(Node2, 'X', 0), ReadInteger(Node2, 'Y', 0)));1981 Polygon.AddPoint(TPoint.Create(ReadInteger(Node2, 'X', 0), ReadInteger(Node2, 'Y', 0))); 1987 1982 Node2 := Node2.NextSibling; 1988 1983 end; … … 2034 2029 function TCell.IsVisible(View: TView): Boolean; 2035 2030 var 2036 RectA, RectB: TRect; 2037 begin 2038 RectA := Polygon.GetRect; 2039 RectB := View.SourceRect; 2040 Result := ((RectA.Left < RectB.Right) and (RectA.Right > RectB.Left) and 2041 (RectA.Top < RectB.Bottom) and (RectA.Bottom > RectB.Top)); 2031 RectPolygon, RectView: TRect; 2032 begin 2033 RectPolygon := Polygon.GetRect; 2034 RectView := View.SourceRect; 2035 Result := ( 2036 (RectPolygon.P1.X < RectView.P2.X) and 2037 (RectPolygon.P2.X > RectView.P1.X) and 2038 (RectPolygon.P1.Y < RectView.P2.Y) and 2039 (RectPolygon.P2.Y > RectView.P1.Y) 2040 ); 2042 2041 end; 2043 2042 … … 2108 2107 function TView.CanvasToCellPos(Pos: TPoint): TPoint; 2109 2108 begin 2110 Result := Point(Trunc(Pos.X / Zoom + SourceRect.Left),2111 Trunc(Pos.Y / Zoom + SourceRect. Top));2109 Result := TPoint.Create(Trunc(Pos.X / Zoom + SourceRect.P1.X), 2110 Trunc(Pos.Y / Zoom + SourceRect.P1.Y)); 2112 2111 end; 2113 2112 2114 2113 function TView.CellToCanvasPos(Pos: TPoint): TPoint; 2115 2114 begin 2116 Result := Point(Trunc((Pos.X - SourceRect.Left) * Zoom),2117 Trunc((Pos.Y - SourceRect. Top) * Zoom));2115 Result := TPoint.Create(Trunc((Pos.X - SourceRect.P1.X) * Zoom), 2116 Trunc((Pos.Y - SourceRect.P1.Y) * Zoom)); 2118 2117 end; 2119 2118 2120 2119 function TView.CanvasToCellRect(Pos: TRect): TRect; 2121 2120 begin 2122 Result. TopLeft := CanvasToCellPos(Pos.TopLeft);2123 Result. BottomRight := CanvasToCellPos(Pos.BottomRight);2121 Result.P1 := CanvasToCellPos(Pos.P1); 2122 Result.P2 := CanvasToCellPos(Pos.P2); 2124 2123 end; 2125 2124 2126 2125 function TView.CellToCanvasRect(Pos: TRect): TRect; 2127 2126 begin 2128 Result. TopLeft := CellToCanvasPos(Pos.TopLeft);2129 Result. BottomRight := CellToCanvasPos(Pos.BottomRight);2127 Result.P1 := CellToCanvasPos(Pos.P1); 2128 Result.P2 := CellToCanvasPos(Pos.P2); 2130 2129 end; 2131 2130 … … 2578 2577 begin 2579 2578 MapRect := Game.Map.PixelRect; 2580 SourceRect := Bounds(MapRect.Left + (MapRect.Right - MapRect.Left) div 2 - (SourceRect.Right - SourceRect.Left)div 2,2581 MapRect. Top + (MapRect.Bottom - MapRect.Top) div 2 - (SourceRect.Bottom - SourceRect.Top) div 2,2582 SourceRect.Right - SourceRect.Left,2583 SourceRect. Bottom - SourceRect.Top);2579 SourceRect := TRect.CreateBounds(TPoint.Create(MapRect.P1.X + MapRect.Size.X div 2 - SourceRect.Size.X div 2, 2580 MapRect.P1.Y + MapRect.Size.Y div 2 - SourceRect.Size.Y div 2), 2581 TPoint.Create(SourceRect.Size.X, 2582 SourceRect.Size.Y)); 2584 2583 end; 2585 2584 2586 2585 procedure TView.CenterPlayerCity(Player: TPlayer); 2587 2586 begin 2588 SourceRect := Bounds(Player.StartCell.PosPx.X - (SourceRect.Right - SourceRect.Left)div 2,2589 Player.StartCell.PosPx.Y - (SourceRect.Bottom - SourceRect.Top) div 2,2590 SourceRect.Right - SourceRect.Left,2591 SourceRect. Bottom - SourceRect.Top);2587 SourceRect := TRect.CreateBounds(TPoint.Create(Player.StartCell.PosPx.X - SourceRect.Size.X div 2, 2588 Player.StartCell.PosPx.Y - SourceRect.Size.Y div 2), 2589 TPoint.Create(SourceRect.Size.X, 2590 SourceRect.Size.Y)); 2592 2591 end; 2593 2592 … … 3247 3246 with Config do begin 3248 3247 MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagon))); 3249 Map.Size := Point(GetValue(DOMString(Path + '/MapSizeX'), 10),3248 Map.Size := TPoint.Create(GetValue(DOMString(Path + '/MapSizeX'), 10), 3250 3249 GetValue(DOMString(Path + '/MapSizeY'), 10)); 3251 3250 MapImageFileName := string(GetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName))); … … 3508 3507 3509 3508 Map.Game := Self; 3510 Map.Size := Point(3, 3);3509 Map.Size := TPoint.Create(3, 3); 3511 3510 end; 3512 3511 … … 3601 3600 with CellLink do begin 3602 3601 if Length(Points) >= 2 then begin 3603 MoveTo( View.CellToCanvasPos(Points[0]));3602 MoveTo(PointToStdPoint(View.CellToCanvasPos(Points[0]))); 3604 3603 for I := 1 to Length(Points) - 1 do 3605 LineTo( View.CellToCanvasPos(Points[I]));3604 LineTo(PointToStdPoint(View.CellToCanvasPos(Points[I]))); 3606 3605 end; 3607 3606 end; … … 3630 3629 Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X)); 3631 3630 if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi; 3632 ArrowCenter := View.CellToCanvasPos( Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),3631 ArrowCenter := View.CellToCanvasPos(TPoint.Create(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2), 3633 3632 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2))); 3634 3633 DrawArrow(Canvas, View, ArrowCenter,
Note:
See TracChangeset
for help on using the changeset viewer.