- Timestamp:
- Nov 23, 2017, 5:02:49 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormCharts.lfm
r145 r170 9 9 OnClose = FormClose 10 10 OnShow = FormShow 11 LCLVersion = '1. 8.0.4'11 LCLVersion = '1.6.4.0' 12 12 object Chart1: TChart 13 13 Left = 8 … … 35 35 object ComboBox1: TComboBox 36 36 Left = 24 37 Height = 3637 Height = 28 38 38 Top = 8 39 39 Width = 392 40 ItemHeight = 040 ItemHeight = 20 41 41 ItemIndex = 0 42 42 Items.Strings = ( -
trunk/Forms/UFormMain.lfm
r157 r170 5 5 Width = 775 6 6 Caption = 'xTactics' 7 ClientHeight = 5 877 ClientHeight = 596 8 8 ClientWidth = 775 9 9 Menu = MainMenu1 … … 13 13 OnKeyUp = FormKeyUp 14 14 OnShow = FormShow 15 LCLVersion = '1. 8.0.4'15 LCLVersion = '1.6.4.0' 16 16 WindowState = wsMaximized 17 17 object StatusBar1: TStatusBar 18 18 Left = 0 19 Height = 3020 Top = 5 5719 Height = 28 20 Top = 568 21 21 Width = 775 22 22 Panels = < … … 34 34 object ToolBar1: TToolBar 35 35 Left = 0 36 Height = 5 5736 Height = 568 37 37 Top = 0 38 38 Width = 32 … … 72 72 object ToolButton6: TToolButton 73 73 Left = 1 74 Top = 1 7074 Top = 194 75 75 Action = AZoomIn 76 76 end 77 77 object ToolButton7: TToolButton 78 78 Left = 1 79 Top = 2 0279 Top = 226 80 80 Action = AZoomOut 81 81 end 82 82 object ToolButton8: TToolButton 83 83 Left = 1 84 Top = 2 3484 Top = 258 85 85 Action = AZoomAll 86 86 end 87 87 object ToolButton9: TToolButton 88 88 Left = 1 89 Height = 32 89 90 Top = 162 90 91 Width = 32 … … 93 94 object ToolButton10: TToolButton 94 95 Left = 1 95 Top = 266 96 Height = 32 97 Top = 290 96 98 Width = 32 97 99 Style = tbsSeparator … … 99 101 object ToolButton11: TToolButton 100 102 Left = 1 101 Top = 274103 Top = 322 102 104 Action = Core.AGameLoad 103 105 end 104 106 object ToolButton12: TToolButton 105 107 Left = 1 106 Top = 3 06108 Top = 354 107 109 Action = Core.AGameSave 108 110 end 109 111 object ToolButton13: TToolButton 110 112 Left = 1 111 Top = 3 38113 Top = 386 112 114 Action = Core.AExit 113 115 end … … 115 117 object PaintBox1: TPaintBox 116 118 Left = 32 117 Height = 5 57119 Height = 568 118 120 Top = 0 119 121 Width = 743 -
trunk/Forms/UFormMain.pas
r158 r170 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, 9 UGame, LCLType, Menus, ActnList, ComCtrls, types, dateutils, XMLConf, DOM; 9 UGame, LCLType, Menus, ActnList, ComCtrls, dateutils, XMLConf, DOM, 10 UGeometry; 10 11 11 12 const … … 137 138 if Assigned(Core.CurrentClient) then 138 139 with Core.CurrentClient do begin 139 View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);140 View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0), TPoint.Create(PaintBox1.Width, PaintBox1.Height)); 140 141 if csOpaque in PaintBox1.ControlStyle then begin 141 142 TempBitmap.SetSize(PaintBox1.Width, PaintBox1.Height); … … 166 167 if Assigned(Core.CurrentClient) then 167 168 with Core.CurrentClient do 168 View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);169 View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0), TPoint.Create(PaintBox1.Width, PaintBox1.Height)); 169 170 Redraw; 170 171 end; … … 252 253 with Core, Game, CurrentClient, View do begin 253 254 MapRect := Map.CalculatePixelRect; 254 Factor := FloatPoint( (DestRect.Right - DestRect.Left) / (MapRect.Right - MapRect.Left),255 (DestRect.Bottom - DestRect.Top) / (MapRect.Bottom - MapRect.Top));255 Factor := FloatPoint(DestRect.Size.X / MapRect.Size.X, 256 DestRect.Size.Y / MapRect.Size.Y); 256 257 if Factor.X < Factor.Y then NewZoom := Factor.X 257 258 else NewZoom := Factor.Y; … … 342 343 if Button = mbLeft then begin 343 344 if Assigned(Core.CurrentClient) then begin 344 StartMousePoint := Point(X, Y);345 StartViewPoint := Core.CurrentClient.View.SourceRect. TopLeft;345 StartMousePoint := TPoint.Create(X, Y); 346 StartViewPoint := Core.CurrentClient.View.SourceRect.P1; 346 347 MoveActive := True; 347 348 end; … … 366 367 (Abs(StartMousePoint.Y - Y) > Trunc(Screen.PixelsPerInch * MouseMinDiff)) then 367 368 with Core.Game.CurrentPlayer, Core.CurrentClient do begin 368 View.SourceRect := Bounds(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom), 369 Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / View.Zoom), 370 View.SourceRect.Right - View.SourceRect.Left, 371 View.SourceRect.Bottom - View.SourceRect.Top); 369 View.SourceRect := TRect.CreateBounds(TPoint.Create(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom), 370 Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / View.Zoom)), 371 View.SourceRect.Size); 372 372 Redraw; 373 373 end; … … 375 375 OldCell := Core.CurrentClient.View.FocusedCell; 376 376 with Core.Game do 377 Cell := Map.PosToCell(Core.CurrentClient.View.CanvasToCellPos( Point(X, Y)), Core.CurrentClient.View );377 Cell := Map.PosToCell(Core.CurrentClient.View.CanvasToCellPos(TPoint.Create(X, Y)), Core.CurrentClient.View ); 378 378 if Assigned(Cell) then begin 379 379 Core.CurrentClient.View.FocusedCell := Cell; … … 384 384 StatusBar1.Panels[0].Text := ''; 385 385 end; 386 CellPos := Core.CurrentClient.View.CanvasToCellPos( Point(X, Y));386 CellPos := Core.CurrentClient.View.CanvasToCellPos(TPoint.Create(X, Y)); 387 387 StatusBar1.Panels[2].Text := 'CellPos: ' + IntToStr(CellPos.X) + ', ' + IntToStr(CellPos.Y); 388 388 if Cell <> OldCell then Redraw; … … 396 396 (Abs(StartMousePoint.Y - Y) < Trunc(Screen.PixelsPerInch * MouseMinDiff)) then begin 397 397 if Core.Game.Running and (Core.Game.CurrentPlayer.Mode = pmHuman) then begin 398 Core.CurrentClient.View.SelectCell( Point(X, Y), Core.Game.CurrentPlayer, Shift);398 Core.CurrentClient.View.SelectCell(TPoint.Create(X, Y), Core.Game.CurrentPlayer, Shift); 399 399 Redraw; 400 400 end; -
trunk/Forms/UFormNew.pas
r167 r170 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, Spin, ExtCtrls, ActnList, ExtDlgs, Menus, UGame ;9 ComCtrls, Spin, ExtCtrls, ActnList, ExtDlgs, Menus, UGame, UGeometry; 10 10 11 11 type … … 363 363 Game.CityEnabled := CheckBoxCity.Checked; 364 364 Game.CityPercentage := SpinEditCityPercent.Value; 365 Game.Map.Size := Point(SpinEditMapSizeX.Value, SpinEditMapSizeY.Value);365 Game.Map.Size := TPoint.Create(SpinEditMapSizeX.Value, SpinEditMapSizeY.Value); 366 366 Game.GrowAmount := TGrowAmount(RadioGroupGrowAmount.ItemIndex); 367 367 Game.GrowCells := TGrowCells(RadioGroupGrowCells.ItemIndex); -
trunk/Languages/xtactics.cs.po
r166 r170 181 181 msgid "Help" 182 182 msgstr "Nápověda" 183 184 #: tformmain.menuitem19.caption 185 msgctxt "tformmain.menuitem19.caption" 186 msgid "-" 187 msgstr "" 188 189 #: tformmain.menuitem5.caption 190 msgctxt "tformmain.menuitem5.caption" 191 msgid "-" 192 msgstr "" 183 193 184 194 #: tformmain.menuitem8.caption -
trunk/Languages/xtactics.po
r166 r170 167 167 msgctxt "tformmain.menuitem16.caption" 168 168 msgid "Help" 169 msgstr "" 170 171 #: tformmain.menuitem19.caption 172 msgctxt "TFORMMAIN.MENUITEM19.CAPTION" 173 msgid "-" 174 msgstr "" 175 176 #: tformmain.menuitem5.caption 177 msgctxt "tformmain.menuitem5.caption" 178 msgid "-" 169 179 msgstr "" 170 180 -
trunk/Packages/Common/Common.lpk
r164 r170 17 17 <License Value="GNU/GPL"/> 18 18 <Version Minor="7"/> 19 <Files Count="2 1">19 <Files Count="22"> 20 20 <Item1> 21 21 <Filename Value="StopWatch.pas"/> … … 110 110 <UnitName Value="UGeometry"/> 111 111 </Item21> 112 <Item22> 113 <Filename Value="UGeometryClasses.pas"/> 114 <UnitName Value="UGeometryClasses"/> 115 </Item22> 112 116 </Files> 113 117 <i18n> -
trunk/Packages/Common/Common.pas
r164 r170 11 11 UMemory, UResetableThread, UPool, ULastOpenedList, URegistry, 12 12 UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort, 13 UPersistentForm, UFindFile, UScaleDPI, UGeometry, LazarusPackageIntf; 13 UPersistentForm, UFindFile, UScaleDPI, UGeometry, UGeometryClasses, 14 LazarusPackageIntf; 14 15 15 16 implementation -
trunk/Packages/Common/UGeometry.pas
r169 r170 9 9 10 10 type 11 TPointArray = array of TPoint; 12 13 { TLine } 14 15 TLine = record 11 { TGPoint } 12 13 TGPoint<T> = record 14 public 15 X: T; 16 Y: T; 17 constructor Create(const X, Y: T); 18 procedure Rotate(Base: TGPoint<T>; Angle: Double); 19 class operator Add(const A, B: TGPoint<T>): TGPoint<T>; 20 class operator Subtract(const A, B: TGPoint<T>): TGPoint<T>; 21 class operator GreaterThan(const A, B: TGPoint<T>): Boolean; 22 class operator LessThan(const A, B: TGPoint<T>): Boolean; 23 class operator Equal(const A, B: TGPoint<T>): Boolean; 24 function Min(const A, B: TGPoint<T>): TGPoint<T>; 25 function Max(const A, B: TGPoint<T>): TGPoint<T>; 26 end; 27 28 { TGPoint3D } 29 30 TGPoint3D<T> = record 31 public 32 X: T; 33 Y: T; 34 Z: T; 35 constructor Create(const X, Y, Z: T); 36 end; 37 38 { TGRect } 39 40 TGRect<T> = record 41 private 42 function GetEmpty: Boolean; 43 function GetSize: T; 44 procedure SetSize(AValue: T); 45 public 46 P1: T; 47 P2: T; 48 function IsPointInside(const P: T): Boolean; 49 function Center: T; 50 procedure SetEmpty; 51 class operator Equal(const A, B: TGRect<T>): Boolean; 52 constructor Create(const P1, P2: T); 53 constructor CreateBounds(const Origin, Size: T); 54 property Size: T read GetSize write SetSize; 55 property Empty: Boolean read GetEmpty; 56 end; 57 58 { TGLine } 59 60 TGLine<T> = record 16 61 private 17 62 function GetDistance: Double; 18 63 procedure SetDistance(AValue: Double); 19 64 public 20 P1: T Point;21 P2: T Point;22 function Create(const P1, P2: TPoint): TLine;23 function GetMiddle: T Point;65 P1: T; 66 P2: T; 67 constructor Create(const P1, P2: T); 68 function GetMiddle: T; 24 69 function GetAngle: Double; 25 function GetSize: T Point;26 function ToRect: T Rect;70 function GetSize: T; 71 function ToRect: TGRect<T>; 27 72 function DotProduct: Double; 73 class function LineIntersect(const LineA, LineB: TGLine<T>; out Intersection: T): Boolean; static; 28 74 procedure Rotate(const Angle: Double); 29 class operator Equal(const A, B: T Line): Boolean;75 class operator Equal(const A, B: TGLine<T>): Boolean; 30 76 property Distance: Double read GetDistance write SetDistance; 31 77 end; 32 78 33 { T Polygon }34 35 T Polygon= record79 { TGPolygon } 80 81 TGPolygon<T> = record 36 82 private 37 function GetPoint(const Index: Integer): T Point; inline;38 procedure SetPoint(const Index: Integer; const AValue: T Point); inline;83 function GetPoint(const Index: Integer): T; inline; 84 procedure SetPoint(const Index: Integer; const AValue: T); inline; 39 85 public 86 type 87 TPointArray = array of T; 88 var 40 89 Points: TPointArray; 41 function IsPointInside(const P: T Point): Boolean;42 function Create(const Points: TPointArray): TPolygon; overload;43 function Create(const Rect: TRect): TPolygon; overload;44 function GetRect: T Rect;45 procedure AddPoint(const P: T Point);90 function IsPointInside(const P: T): Boolean; 91 constructor Create(const Points: TPointArray); overload; 92 constructor Create(const Rect: TGRect<T>); overload; 93 function GetRect: TGRect<T>; 94 procedure AddPoint(const P: T); 46 95 procedure Clear; 47 procedure CutLine(const Vector: TLine; const PointInside: TPoint); 48 property Items[Index: Integer]: TPoint read GetPoint write SetPoint; default; 49 end; 50 51 function Distance(const P1, P2: TPoint): Integer; 52 function Dot(const P1, P2: TPoint): Double; 53 function AddPoint(const P1, P2: TPoint): TPoint; 54 function SubPoint(const P1, P2: TPoint): TPoint; 55 function PointToLineDistance(const P, V, W: TPoint): Integer; 56 function ComparePoint(const P1, P2: TPoint): Boolean; 57 function RotatePoint(const Center, P: TPoint; Angle: Double): TPoint; 58 function RotatePoints(const Center: TPoint; P: TPointArray; Angle: Double): TPointArray; 59 function LineIntersect(const LineA, LineB: TLine; out Intersection: TPoint): Boolean; 60 function ArcTan2Point(const Point: TPoint): Float; 61 function ArcTanPoint(const Point: TPoint): Float; 62 function RectEquals(const A, B: TRect): Boolean; 63 function RectEnlarge(const Rect: TRect; Value: Integer): TRect; 64 function ShiftRect(const ARect: TRect; Delta: TPoint): TRect; 65 function PointsToRect(const P1, P2: TPoint): TRect; 66 function PointInRect(const P: TPoint; aRect: TRect): Boolean; 67 function HalfDistancePoint(const P1, P2: TPoint): TPoint; 68 function NormalizeAngle(const Angle: Double): Double; 69 function SubAngle(A1, A2: Double): Double; 96 procedure CutLine(const Vector: TGLine<T>; const PointInside: T); 97 property Items[Index: Integer]: T read GetPoint write SetPoint; default; 98 end; 99 100 // Integer 101 TPoint = TGPoint<Integer>; 102 TPoint3D = TGPoint3D<Integer>; 103 TLine = TGLine<TPoint>; 104 TRect = TGRect<TPoint>; 105 TPolygon = TGPolygon<TPoint>; 106 107 // FLoating 108 TPointF = TGPoint<Single>; 109 TPoint3DF = TGPoint3D<Single>; 110 TRectF = TGRect<TPointF>; 111 TLineF = TGLine<TPointF>; 112 TPolygonF = TGPolygon<TPointF>; 113 114 function Divide(Divident, Divisor: Integer): Integer; overload; 115 function Divide(Divident, Divisor: Double): Double; overload; 116 function TypedRound(Value: Double): Integer; overload; 117 function TypedRound(Value: Double): Double; overload; 118 function StdPointToPoint(Value: Classes.TPoint): TPoint; 119 function PointToStdPoint(Value: TPoint): Classes.TPoint; 70 120 71 121 72 122 implementation 73 123 74 function Distance(const P1, P2: TPoint): Integer; 75 begin 76 Result := Trunc(Sqrt(Sqr(P2.X - P1.X) + Sqr(P2.Y - P1.Y))); 77 end; 78 79 function Dot(const P1, P2: TPoint): Double; 80 begin 81 Result := P1.X * P2.X + P1.Y * P2.Y; 82 end; 83 84 function AddPoint(const P1, P2: TPoint): TPoint; 85 begin 86 Result.X := P1.X + P2.X; 87 Result.Y := P1.Y + P2.Y; 88 end; 89 90 function SubPoint(const P1, P2: TPoint): TPoint; 91 begin 92 Result.X := P1.X - P2.X; 93 Result.Y := P1.Y - P2.Y; 94 end; 95 96 function PointToLineDistance(const P, V, W: TPoint): Integer; 97 var 98 l2, t: Double; 99 tt: TPoint; 100 begin 101 // Return minimum distance between line segment vw and point p 102 L2 := Distance(V, W); // i.e. |w-v|^2 - avoid a sqrt 103 L2 := Power(l2, 2); 104 if L2 = 0 then begin 105 Result := Distance(P, V); // v == w case 106 Exit; 107 end; 108 // Consider the line extending the segment, parameterized as v + t (w - v). 109 // We find projection of point p onto the line. 110 // It falls where t = [(p-v) . (w-v)] / |w-v|^2 111 T := Dot(SubPoint(P, V), SubPoint(W, V)) / L2; 112 if T < 0 then begin 113 Result := Distance(P, V); // Beyond the 'v' end of the segment 114 exit; 115 end 116 else if T > 1 then begin 117 Result := Distance(P, W); // Beyond the 'w' end of the segment 118 Exit; 119 end; 120 TT.X := Trunc(V.X + T * (W.X - V.X)); 121 TT.Y := Trunc(V.Y + T * (W.Y - V.Y)); 122 Result := Distance(P, TT); 123 end; 124 125 function ComparePoint(const P1, P2: TPoint): Boolean; 126 begin 127 Result := (P1.X = P2.X) and (P1.Y = P2.Y); 128 end; 129 130 function RotatePoint(const Center, P: TPoint; Angle: Double): TPoint; 131 var 132 D: TPoint; 133 begin 134 D := Point(P.X - Center.X, P.Y - Center.Y); 135 Result := Point(Center.X + Round(D.X * Cos(Angle) - D.Y * Sin(Angle)), 136 Center.Y + Round(D.X * Sin(Angle) + D.Y * Cos(Angle))); 137 end; 138 139 function RotatePoints(const Center: TPoint; P: TPointArray; Angle: Double): TPointArray; 140 var 141 I: Integer; 142 begin 143 SetLength(Result, Length(P)); 144 for I := 0 to High(P) do 145 Result[I] := RotatePoint(Center, P[I], Angle); 146 end; 147 148 function LineIntersect(const LineA, LineB: TLine; out Intersection: TPoint): Boolean; 149 Var 150 LDetLineA, LDetLineB, LDetDivInv: Double; 151 LDiffLA, LDiffLB: TPoint; 152 D: Integer; 153 begin 154 if ComparePoint(LineA.P1, LineA.P2) or ComparePoint(LineB.P1, LineB.P2) then begin 155 Result := False; 156 Exit; 157 end; 158 LDetLineA := LineA.P1.X * LineA.P2.Y - LineA.P1.Y * LineA.P2.X; 159 LDetLineB := LineB.P1.X * LineB.P2.Y - LineB.P1.Y * LineB.P2.X; 160 161 LDiffLA := SubPoint(LineA.P1, LineA.P2); 162 LDiffLB := SubPoint(LineB.P1, LineB.P2); 163 164 D := (LDiffLA.X * LDiffLB.Y) - (LDiffLA.Y * LDiffLB.X); 165 if D = 0 then begin 166 // Parallel lines without intersection 167 Result := False; 168 Exit; 169 end; 170 LDetDivInv := 1 / D; 171 172 Intersection.X := Round(((LDetLineA * LDiffLB.X) - (LDiffLA.X * LDetLineB)) * LDetDivInv); 173 Intersection.Y := Round(((LDetLineA * LDiffLB.Y) - (LDiffLA.Y * LDetLineB)) * LDetDivInv); 174 Result := True; 175 end; 176 177 function ArcTan2Point(const Point: TPoint): Float; 178 begin 179 Result := ArcTan2(Point.Y, Point.X); 180 end; 181 182 function ArcTanPoint(const Point: TPoint): Float; 183 begin 184 if Point.Y = 0 then Result := Infinity 185 else Result := ArcTan(Point.X / Point.Y); 186 end; 187 188 function RectEquals(const A, B: TRect): Boolean; 189 begin 190 Result := (A.Left = B.Left) and (A.Top = B.Top) and 191 (A.Right = B.Right) and (A.Bottom = B.Bottom); 192 end; 193 194 function RectEnlarge(const Rect: TRect; Value: Integer): TRect; 195 begin 196 Result.Left := Rect.Left - Value; 197 Result.Right := Rect.Right + Value; 198 Result.Top := Rect.Top - Value; 199 Result.Bottom := Rect.Bottom + Value; 200 end; 201 202 function ShiftRect(const ARect: TRect; Delta: TPoint): TRect; 203 begin 204 Result := Rect(ARect.Left + Delta.X, ARect.Top + Delta.Y, 205 ARect.Right + Delta.X, ARect.Bottom + Delta.Y); 206 end; 207 208 function PointsToRect(const P1, P2: TPoint): TRect; 209 begin 210 if P1.X < P2.X then Result.Left := P1.X else Result.Left := P2.X; 211 if P1.Y < P2.Y then Result.Top := P1.Y else Result.Top := P2.Y; 212 if P1.X > P2.X then Result.Right := P1.X else Result.Right := P2.X; 213 if P1.Y > P2.Y then Result.Bottom := P1.Y else Result.Bottom := P2.Y; 214 end; 215 216 function PointInRect(const P: TPoint; aRect: TRect): Boolean; 217 begin 218 Result := (P.X >= aRect.Left) and (P.X <= aRect.Right) and 219 (P.Y >= aRect.Top) and (P.Y <= aRect.Bottom); 220 end; 221 222 function HalfDistancePoint(const P1, P2: TPoint): TPoint; 223 begin 224 Result := Point(P1.X + (P2.X - P1.X) div 2, P1.Y + (P2.Y - P1.Y) div 2) 225 end; 226 227 function NormalizeAngle(const Angle: Double): Double; 228 begin 229 if Angle < 0 then Result := Angle + (Trunc(Angle / (2 * Pi)) + 1) * (2 * Pi) 230 else if Angle > 2 * Pi then Result := Angle - Trunc(Angle / (2 * Pi)) * (2 * Pi) 231 else Result := Angle; 232 end; 233 234 function SubAngle(A1, A2: Double): Double; 235 begin 236 A1 := NormalizeAngle(A1); 237 A2 := NormalizeAngle(A2); 238 if A1 < A2 then Result := A1 + 2 * Pi - A2 239 else Result := A1 - A2; 124 function Divide(Divident, Divisor: Integer): Integer; 125 begin 126 Result := Divident div Divisor; 127 end; 128 129 function Divide(Divident, Divisor: Double): Double; 130 begin 131 Result := Divident / Divisor; 132 end; 133 134 function TypedRound(Value: Double): Integer; 135 begin 136 Result := Round(Value); 137 end; 138 139 function TypedRound(Value: Double): Double; 140 begin 141 Result := Value; 142 end; 143 144 function StdPointToPoint(Value: Classes.TPoint): TPoint; 145 begin 146 Result.X := Value.X; 147 Result.Y := Value.Y; 148 end; 149 150 function PointToStdPoint(Value: TPoint): Classes.TPoint; 151 begin 152 Result.X := Value.X; 153 Result.Y := Value.Y; 240 154 end; 241 155 242 156 { TPolygon } 243 157 244 function T Polygon.GetPoint(const Index: Integer): TPoint;158 function TGPolygon<T>.GetPoint(const Index: Integer): T; 245 159 begin 246 160 Result := Points[Index]; 247 161 end; 248 162 249 procedure T Polygon.SetPoint(const Index: Integer; const AValue: TPoint);163 procedure TGPolygon<T>.SetPoint(const Index: Integer; const AValue: T); 250 164 begin 251 165 Points[Index] := AValue; 252 166 end; 253 167 254 function T Polygon.IsPointInside(const P: TPoint): Boolean;168 function TGPolygon<T>.IsPointInside(const P: T): Boolean; 255 169 var 256 170 I, J: Integer; … … 292 206 293 207 294 function TPolygon.Create(const Points: TPointArray): TPolygon;208 constructor TGPolygon<T>.Create(const Points: TPointArray); 295 209 var 296 210 I: Integer; 297 211 begin 298 SetLength( Result.Points, Length(Points));212 SetLength(Self.Points, Length(Points)); 299 213 for I := 0 to Length(Points) - 1 do 300 Result.Points[I] := Points[I];301 end; 302 303 function TPolygon.Create(const Rect: TRect): TPolygon;304 begin 305 SetLength( Result.Points, 4);306 Result.Points[0] := Point(Rect.Left, Rect.Top);307 Result.Points[1] := Point(Rect.Right, Rect.Top);308 Result.Points[2] := Point(Rect.Right, Rect.Bottom);309 Result.Points[3] := Point(Rect.Left, Rect.Bottom);310 end; 311 312 function T Polygon.GetRect: TRect;214 Self.Points[I] := Points[I]; 215 end; 216 217 constructor TGPolygon<T>.Create(const Rect: TGRect<T>); 218 begin 219 SetLength(Self.Points, 4); 220 Self.Points[0] := Rect.P1; 221 Self.Points[1] := T.Create(Rect.P2.X, Rect.P1.Y); 222 Self.Points[2] := Rect.P1; 223 Self.Points[3] := T.Create(Rect.P1.X, Rect.P2.Y); 224 end; 225 226 function TGPolygon<T>.GetRect: TGRect<T>; 313 227 var 314 228 I: Integer; 315 begin 316 Result := Rect(High(Integer), High(Integer), 317 Low(Integer), Low(Integer)); 318 for I := 0 to Length(Points) - 1 do 319 with Points[I] do begin 320 if X > Result.Right then 321 Result.Right := X; 322 if X < Result.Left then 323 Result.Left := X; 324 if Y > Result.Bottom then 325 Result.Bottom := Y; 326 if Y < Result.Top then 327 Result.Top := Y; 328 end; 329 end; 330 331 procedure TPolygon.AddPoint(const P: TPoint); 229 P1: TGPoint<T>; 230 begin 231 if Length(Points) = 0 then 232 Result.Empty 233 else begin 234 Result := TGRect<T>.Create(Points[0], Points[0]); 235 for I := 1 to Length(Points) - 1 do 236 with Points[I] do begin 237 Result.P1 := Points[I].Min(Result.P1, Points[I]); 238 Result.P2 := Points[I].Max(Result.P2, Points[I]); 239 end; 240 end; 241 end; 242 243 procedure TGPolygon<T>.AddPoint(const P: T); 332 244 begin 333 245 SetLength(Points, Length(Points) + 1); … … 335 247 end; 336 248 337 procedure T Polygon.Clear;249 procedure TGPolygon<T>.Clear; 338 250 begin 339 251 SetLength(Points, 0); 340 252 end; 341 253 342 procedure T Polygon.CutLine(const Vector: TLine; const PointInside: TPoint);254 procedure TGPolygon<T>.CutLine(const Vector: TGLine<T>; const PointInside: T); 343 255 var 344 256 I: Integer; 345 257 PointsChecked: Integer; 346 L1, L2: T Line;347 Intersection: T Point;348 NewPoly: T Polygon;258 L1, L2: TGLine<T>; 259 Intersection: T; 260 NewPoly: TGPolygon<T>; 349 261 NewPolygonStarted: Boolean; 350 262 Success: Boolean; … … 359 271 if Length(Points) > 0 then 360 272 while True do begin 361 L2 := T Line.Create(Points[I], Points[(I + 1) mod Length(Points)]);362 if LineIntersect(L1, L2, Intersection) then363 if PointInRect(Intersection, L2.ToRect) then begin273 L2 := TGLine<T>.Create(Points[I], Points[(I + 1) mod Length(Points)]); 274 if TGLine<T>.LineIntersect(L1, L2, Intersection) then 275 if L2.ToRect.IsPointInside(Intersection) then begin 364 276 if not NewPolygonStarted then begin 365 277 // Crossing line, start new polygon … … 391 303 { TLine } 392 304 393 function T Line.GetDistance: Double;305 function TGLine<T>.GetDistance: Double; 394 306 begin 395 307 Result := Sqrt(Sqr(P2.X - P1.X) + Sqr(P2.Y - P1.Y)); 396 308 end; 397 309 398 procedure T Line.SetDistance(AValue: Double);310 procedure TGLine<T>.SetDistance(AValue: Double); 399 311 var 400 312 Angle: Double; 401 313 begin 402 314 Angle := GetAngle; 403 P2 := Point(Round(P1.X + Cos(Angle) * AValue),315 P2 := T.Create(Round(P1.X + Cos(Angle) * AValue), 404 316 Round(P1.Y + Sin(Angle) * AValue)); 405 317 end; 406 318 407 function TLine.Create(const P1, P2: TPoint): TLine; 319 constructor TGLine<T>.Create(const P1, P2: T); 320 begin 321 Self.P1 := P1; 322 Self.P2 := P2; 323 end; 324 325 function TGLine<T>.GetMiddle: T; 326 begin 327 Result := T.Create(P1.X + Divide((P2.X - P1.X), 2), P1.Y + Divide((P2.Y - P1.Y), 2)); 328 end; 329 330 function TGLine<T>.GetAngle: Double; 331 begin 332 Result := ArcTan2(P2.Y - P1.Y, P2.X - P1.X); 333 end; 334 335 function TGLine<T>.GetSize: T; 336 begin 337 Result := P2 - P1; 338 end; 339 340 function TGLine<T>.ToRect: TGRect<T>; 408 341 begin 409 342 Result.P1 := P1; … … 411 344 end; 412 345 413 function TLine.GetMiddle: TPoint; 414 begin 415 Result := Point(P1.X + (P2.X - P1.X) div 2, P1.Y + (P2.Y - P1.Y) div 2); 416 end; 417 418 function TLine.GetAngle: Double; 419 begin 420 Result := ArcTan2(P2.Y - P1.Y, P2.X - P1.X); 421 end; 422 423 function TLine.GetSize: TPoint; 424 begin 425 Result := Point(P2.X - P1.X, P2.Y - P1.Y); 426 end; 427 428 function TLine.ToRect: TRect; 429 begin 430 if P1.X < P2.X then Result.Left := P1.X else Result.Left := P2.X; 431 if P1.Y < P2.Y then Result.Top := P1.Y else Result.Top := P2.Y; 432 if P1.X > P2.X then Result.Right := P1.X else Result.Right := P2.X; 433 if P1.Y > P2.Y then Result.Bottom := P1.Y else Result.Bottom := P2.Y; 434 end; 435 436 function TLine.DotProduct: Double; 346 function TGLine<T>.DotProduct: Double; 437 347 begin 438 348 Result := P1.X * P2.X + P1.Y * P2.Y; 439 349 end; 440 350 441 procedure TLine.Rotate(const Angle: Double); 442 begin 443 P2 := RotatePoint(P1, P2, Angle); 444 end; 445 446 class operator TLine.Equal(const A, B: TLine): Boolean; 447 begin 448 Result := ComparePoint(A.P1, B.P1) and ComparePoint(A.P2, B.P2); 351 procedure TGLine<T>.Rotate(const Angle: Double); 352 begin 353 P2.Rotate(P1, Angle); 354 end; 355 356 class operator TGLine<T>.Equal(const A, B: TGLine<T>): Boolean; 357 begin 358 Result := (A.P1 = B.P1) and (A.P2 = B.P2); 359 end; 360 361 { TGPoint3D } 362 363 constructor TGPoint3D<T>.Create(const X, Y, Z: T); 364 begin 365 Self.X := X; 366 Self.Y := Y; 367 Self.Z := Z; 368 end; 369 370 { TGPoint } 371 372 constructor TGPoint<T>.Create(const X, Y: T); 373 begin 374 Self.X := X; 375 Self.Y := Y; 376 end; 377 378 class operator TGPoint<T>.Equal(const A, B: TGPoint<T>): Boolean; 379 begin 380 Result := (A.X = B.X) and (A.Y = B.Y); 381 end; 382 383 class operator TGPoint<T>.Add(const A, B: TGPoint<T>): TGPoint<T>; 384 begin 385 Result.X := A.X + B.X; 386 Result.Y := A.Y + B.Y; 387 end; 388 389 class operator TGPoint<T>.Subtract(const A, B: TGPoint<T>): TGPoint<T>; 390 begin 391 Result.X := A.X - B.X; 392 Result.Y := A.Y - B.Y; 393 end; 394 395 class operator TGPoint<T>.GreaterThan(const A, B: TGPoint<T>): Boolean; 396 begin 397 Result := (B.X > A.X) and (B.Y > A.Y); 398 end; 399 400 class operator TGPoint<T>.LessThan(const A, B: TGPoint<T>): Boolean; 401 begin 402 Result := (B.X < A.X) and (B.Y < A.Y); 403 end; 404 405 { TGLine } 406 407 class function TGLine<T>.LineIntersect(const LineA, LineB: TGLine<T>; out 408 Intersection: T): Boolean; 409 Var 410 LDetLineA, LDetLineB, LDetDivInv: Double; 411 LDiffLA, LDiffLB: T; 412 D: Double; 413 begin 414 if (LineA.P1 = LineA.P2) or (LineB.P1 = LineB.P2) then begin 415 Result := False; 416 Exit; 417 end; 418 LDetLineA := LineA.P1.X * LineA.P2.Y - LineA.P1.Y * LineA.P2.X; 419 LDetLineB := LineB.P1.X * LineB.P2.Y - LineB.P1.Y * LineB.P2.X; 420 421 LDiffLA := LineA.P1 - LineA.P2; 422 LDiffLB := LineB.P1 - LineB.P2; 423 424 D := (LDiffLA.X * LDiffLB.Y) - (LDiffLA.Y * LDiffLB.X); 425 if D = 0 then begin 426 // Parallel lines without intersection 427 Result := False; 428 Exit; 429 end; 430 LDetDivInv := 1 / D; 431 432 Intersection.X := TypedRound(((LDetLineA * LDiffLB.X) - (LDiffLA.X * LDetLineB)) * LDetDivInv); 433 Intersection.Y := TypedRound(((LDetLineA * LDiffLB.Y) - (LDiffLA.Y * LDetLineB)) * LDetDivInv); 434 Result := True; 435 end; 436 437 procedure TGPoint<T>.Rotate(Base: TGPoint<T>; Angle: Double); 438 var 439 D: TGPoint<T>; 440 begin 441 D := TGPoint<T>.Create(X - Base.X, Y - Base.Y); 442 //X := Base.X + TypedRound(D.X * Cos(Angle) - D.Y * Sin(Angle)); 443 //Y := Base.Y + TypedRound(D.X * Sin(Angle) + D.Y * Cos(Angle)); 444 end; 445 446 function TGPoint<T>.Min(const A, B: TGPoint<T>): TGPoint<T>; 447 begin 448 if A.X < B.X then Result.X := A.X else Result.X := B.X; 449 if A.Y < B.Y then Result.Y := A.Y else Result.Y := B.Y; 450 end; 451 452 function TGPoint<T>.Max(const A, B: TGPoint<T>): TGPoint<T>; 453 begin 454 if A.X > B.X then Result.X := A.X else Result.X := B.X; 455 if A.Y > B.Y then Result.Y := A.Y else Result.Y := B.Y; 456 end; 457 458 { TGRect } 459 460 function TGRect<T>.IsPointInside(const P: T): Boolean; 461 begin 462 Result := (P > P1) and (P < P2); 463 end; 464 465 function TGRect<T>.GetEmpty: Boolean; 466 begin 467 Result := P1 = P2; 468 end; 469 470 procedure TGRect<T>.SetEmpty; 471 begin 472 P2 := P1; 473 end; 474 475 function TGRect<T>.Center: T; 476 begin 477 Result.X := Divide(P2.X - P1.X, 2); 478 Result.Y := Divide(P2.Y - P1.Y, 2); 479 end; 480 481 function TGRect<T>.GetSize: T; 482 begin 483 Result := P2 - P1; 484 end; 485 486 procedure TGRect<T>.SetSize(AValue: T); 487 begin 488 P2 := P1 + AValue; 489 end; 490 491 constructor TGRect<T>.Create(const P1, P2: T); 492 begin 493 Self.P1 := P1; 494 Self.P2 := P2; 495 end; 496 497 constructor TGRect<T>.CreateBounds(const Origin, Size: T); 498 begin 499 Self.P1 := Origin; 500 Self.P2 := Origin + Size; 501 end; 502 503 class operator TGRect<T>.Equal(const A, B: TGRect<T>): Boolean; 504 begin 505 Result := (A.P1 = B.P1) and (A.P2 = B.P2); 449 506 end; 450 507 -
trunk/UCore.lrt
r134 r170 15 15 TCORE.AABOUT.CAPTION=About 16 16 TCORE.AHELP.CAPTION=Help 17 TCORE.ASHOWCHARTS.CAPTION=Show charts 17 TCORE.ASHOWCHARTS.CAPTION=Charts 18 TCORE.ASHOWUNITMOVES.CAPTION=Unit moves -
trunk/UCore.pas
r166 r170 8 8 Classes, SysUtils, XMLConf, FileUtil, ActnList, Controls, Dialogs, Forms, 9 9 UGame, UApplicationInfo, UPersistentForm, UScaleDPI, UCoolTranslator, 10 URegistry, ULastOpenedList, Registry, Menus ;10 URegistry, ULastOpenedList, Registry, Menus, UGeometry; 11 11 12 12 type … … 419 419 LastOpenedList1.AddItem(FileName); 420 420 with Core.CurrentClient do 421 View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height); 421 View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0), 422 TPoint.Create(FormMain.PaintBox1.Width, FormMain.PaintBox1.Height)); 422 423 FormMain.AZoomAll.Execute; 423 424 FormMain.Redraw; -
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, -
trunk/UMap.pas
r168 r170 6 6 7 7 uses 8 Classes, SysUtils, UGame, XMLRead, XMLWrite, DOM, Contnrs, UGeometry; 8 Classes, SysUtils, UGame, XMLRead, XMLWrite, DOM, Contnrs, UGeometryClasses, 9 UGeometry; 9 10 10 11 type … … 53 54 TVoronoiMap = class(TMap) 54 55 private 55 function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPointArray;56 56 public 57 57 procedure Generate; override; … … 68 68 Shift := FloatPoint(0.5 * cos(30 / 180 * Pi), 0.5 * sin(30 / 180 * Pi)); 69 69 SetLength(Result.Points, 6); 70 Result.Points[0] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y));71 Result.Points[1] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));72 Result.Points[2] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));73 Result.Points[3] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y + 0.5 * Size.Y));74 Result.Points[4] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));75 Result.Points[5] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));70 Result.Points[0] := TPoint.Create(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y)); 71 Result.Points[1] := TPoint.Create(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y)); 72 Result.Points[2] := TPoint.Create(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y)); 73 Result.Points[3] := TPoint.Create(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y + 0.5 * Size.Y)); 74 Result.Points[4] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y)); 75 Result.Points[5] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y)); 76 76 end; 77 77 … … 139 139 for Y := -1 to 1 do 140 140 for X := -1 to 1 do 141 if IsValidIndex( Point(CellPos.X + X, CellPos.Y + Y)) and142 IsCellsPosNeighbor(CellPos, Point((CellPos.X + X), (CellPos.Y + Y))) then begin141 if IsValidIndex(TPoint.Create(CellPos.X + X, CellPos.Y + Y)) and 142 IsCellsPosNeighbor(CellPos, TPoint.Create((CellPos.X + X), (CellPos.Y + Y))) then begin 143 143 Neighbours.Add(TCell(Cells[(CellPos.Y + Y) * Size.X + (CellPos.X + X)])); 144 144 end; … … 165 165 //Y := Y + 0.5; 166 166 end; 167 NewCell.PosPx := Point(Trunc(PX * DefaultCellSize.X / HexCellMulX),167 NewCell.PosPx := TPoint.Create(Trunc(PX * DefaultCellSize.X / HexCellMulX), 168 168 Trunc(PY * DefaultCellSize.Y / HexCellMulY)); 169 169 NewCell.Polygon := GetHexagonPolygon(NewCell.PosPx, DefaultCellSize); … … 176 176 for X := 0 to Size.X - 1 do 177 177 with TCell(Cells[Y * Size.X + X]) do begin 178 GetCellPosNeighbors( Point(X, Y), Neighbors);178 GetCellPosNeighbors(TPoint.Create(X, Y), Neighbors); 179 179 end; 180 180 … … 198 198 NewCell := TCell.Create; 199 199 NewCell.Map := Self; 200 NewCell.PosPx := Point(Trunc(X * DefaultCellSize.X * SquareCellMulX),200 NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * SquareCellMulX), 201 201 Trunc(Y * DefaultCellSize.Y * SquareCellMulY)); 202 202 NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize); … … 209 209 for X := 0 to Size.X - 1 do 210 210 with TCell(Cells[Y * Size.X + X]) do begin 211 if IsValidIndex( Point(X + 1, Y + 0)) then211 if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then 212 212 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)])); 213 if IsValidIndex( Point(X + 0, Y + 1)) then213 if IsValidIndex(TPoint.Create(X + 0, Y + 1)) then 214 214 Neighbors.Add(TCell(Cells[(Y + 1) * Size.X + (X + 0)])); 215 if IsValidIndex( Point(X - 1, Y + 0)) then215 if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then 216 216 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X - 1)])); 217 if IsValidIndex( Point(X + 0, Y - 1)) then217 if IsValidIndex(TPoint.Create(X + 0, Y - 1)) then 218 218 Neighbors.Add(TCell(Cells[(Y - 1) * Size.X + (X + 0)])); 219 219 end; … … 231 231 begin 232 232 SetLength(Result.Points, 4); 233 Result.Points[0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - Size.Y / 2));234 Result.Points[1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - Size.Y / 2));235 Result.Points[2] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y + Size.Y / 2));236 Result.Points[3] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y + Size.Y / 2));233 Result.Points[0] := TPoint.Create(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - Size.Y / 2)); 234 Result.Points[1] := TPoint.Create(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - Size.Y / 2)); 235 Result.Points[2] := TPoint.Create(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y + Size.Y / 2)); 236 Result.Points[3] := TPoint.Create(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y + Size.Y / 2)); 237 237 end; 238 238 239 239 { TVoronoiMap } 240 241 function TVoronoiMap.GetTrianglePolygon(Pos: TPoint; Size: TPoint;242 Reverse: Boolean): TPointArray;243 begin244 SetLength(Result, 0);245 end;246 240 247 241 function CompareDistance(C1, C2: Pointer): Integer; … … 309 303 NewCell := TCell.Create; 310 304 NewCell.Map := Self; 311 NewCell.PosPx := Point(Trunc(Random * Size.X * DefaultCellSize.X),305 NewCell.PosPx := TPoint.Create(Trunc(Random * Size.X * DefaultCellSize.X), 312 306 Trunc(Random * Size.Y * DefaultCellSize.Y)); 313 307 SetLength(NewCell.Polygon.Points, 1); … … 324 318 NewCellDist.Cell1 := Cells[I1]; 325 319 NewCellDist.Cell2 := Cells[I2]; 326 NewCellDist.Distance := Distance(NewCellDist.Cell1.PosPx, NewCellDist.Cell2.PosPx);320 NewCellDist.Distance := TLine.Create(NewCellDist.Cell1.PosPx, NewCellDist.Cell2.PosPx).Distance; 327 321 CellsDistance.Add(NewCellDist); 328 322 end; … … 344 338 L2 := TLine.Create(TCellsDistance(SelectedCells[J]).Cell1.PosPx, 345 339 TCellsDistance(SelectedCells[J]).Cell2.PosPx); 346 if LineIntersect(L1, L2, Intersection) then begin347 if PointInRect(Intersection, L1.ToRect) and348 PointInRect(Intersection, L2.ToRect) then begin340 if TLine.LineIntersect(L1, L2, Intersection) then begin 341 if L1.ToRect.IsPointInside(Intersection) and 342 L2.ToRect.IsPointInside(Intersection) then begin 349 343 Intersected := True; 350 344 Break; … … 423 417 // Use whole map first for cell polygon 424 418 if Cell.Neighbors.Count > 0 then begin 425 Polygon := TPolygon.Create( Rect(0, 0,426 Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y));419 Polygon := TPolygon.Create(TRect.Create(TPoint.Create(0, 0), 420 TPoint.Create(Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y))); 427 421 for NeighborCell in Cell.Neighbors do begin 428 422 LinkLine := TLine.Create(Cell.PosPx, NeighborCell.PosPx); … … 430 424 MP := LinkLine.GetMiddle; 431 425 // Create half plane vector 432 L1 := TLine.Create(MP, Point(MP.X + LinkLine.GetSize.X,426 L1 := TLine.Create(MP, TPoint.Create(MP.X + LinkLine.GetSize.X, 433 427 MP.Y + LinkLine.GetSize.Y)); 434 428 … … 452 446 else Rev := 1; 453 447 SetLength(Result.Points, 3); 454 Result.Points[0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev));455 Result.Points[1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev));456 Result.Points[2] := Point(Trunc(Pos.X), Trunc(Pos.Y + (Size.Y * 1.2) / 2 * Rev));448 Result.Points[0] := TPoint.Create(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev)); 449 Result.Points[1] := TPoint.Create(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev)); 450 Result.Points[2] := TPoint.Create(Trunc(Pos.X), Trunc(Pos.Y + (Size.Y * 1.2) / 2 * Rev)); 457 451 end; 458 452 … … 481 475 if Reverse then Rev := -1 482 476 else Rev := 1; 483 NewCell.PosPx := Point(Trunc(X * DefaultCellSize.X * TriangleCellMulX),477 NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * TriangleCellMulX), 484 478 Trunc((Y * DefaultCellSize.Y * TriangleCellMulY) - (0.1 * Rev * DefaultCellSize.Y))); 485 479 NewCell.Polygon := GetTrianglePolygon(NewCell.PosPx, DefaultCellSize, Reverse); … … 494 488 if Boolean(X mod 2) xor Boolean(Y mod 2) then Rev := -1 495 489 else Rev := 1; 496 if IsValidIndex( Point(X + 1, Y + 0)) then490 if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then 497 491 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)])); 498 if IsValidIndex( Point(X + 0, Y - 1 * Rev)) then492 if IsValidIndex(TPoint.Create(X + 0, Y - 1 * Rev)) then 499 493 Neighbors.Add(TCell(Cells[(Y - 1 * Rev) * Size.X + (X + 0)])); 500 if IsValidIndex( Point(X - 1, Y + 0)) then494 if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then 501 495 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X - 1)])); 502 496 end; -
trunk/xtactics.lpr
r165 r170 11 11 CoolTranslator, TemplateGenerics, UFormPlayer 12 12 { you can add units after this }, 13 SysUtils, UFormMain, UFormMove, UFormNew, UFormCharts, UFormUnitMoves ;13 SysUtils, UFormMain, UFormMove, UFormNew, UFormCharts, UFormUnitMoves, UGeometryClasses; 14 14 15 15 {$R *.res}
Note:
See TracChangeset
for help on using the changeset viewer.