Changeset 238 for trunk/UClientGUI.pas
- Timestamp:
- Sep 21, 2018, 12:15:23 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UClientGUI.pas
r237 r238 32 32 function CanvasToCellPos(Pos: TPoint): TPoint; 33 33 function CellToCanvasPos(Pos: TPoint): TPoint; 34 function CellToCanvasPosF(Pos: TPointF): TPointF; 34 35 function CanvasToCellRect(Pos: TRect): TRect; 35 36 function CellToCanvasRect(Pos: TRect): TRect; 37 function CellToCanvasRectF(Pos: TRectF): TRectF; 36 38 procedure Assign(Source: TView); 37 39 property DestRect: TRect read FDestRect write SetDestRect; … … 46 48 public 47 49 View: TView; 50 procedure DrawArrow(Canvas: TCanvas; Pos: TPoint; Angle: Double; 51 Text: string; View: TView); 48 52 procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView; 49 53 Cell: TPlayerCell); … … 242 246 243 247 if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi; 244 ArrowCenter := View.CellToCanvasPos(TPoint.Create(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2), 245 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2))); 246 TGame(Game).Map.DrawArrow(Canvas, ArrowCenter, 247 Angle, IntToStr(Move.CountOnce), View.Zoom); 248 end; 249 end; 250 end; 248 ArrowCenter := View.CellToCanvasPos(TPoint.Create( 249 Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2), 250 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2) 251 )); 252 DrawArrow(Canvas, ArrowCenter, 253 Angle, IntToStr(Move.CountOnce), View); 254 end; 255 end; 256 end; 257 258 procedure TClientGUI.DrawArrow(Canvas: TCanvas; Pos: TPoint; 259 Angle: Double; Text: string; View: TView); 260 var 261 Points: array of Classes.TPoint; 262 Arrow: TPolygonF; 263 I: Integer; 264 ArrowSize: TPoint; 265 RectPolygon: TRectF; 266 begin 267 SetLength(Arrow.Points, 8); 268 ArrowSize := TPoint.Create(Trunc(TGame(Game).Map.DefaultCellSize.X / 3 * View.Zoom), 269 Trunc(TGame(Game).Map.DefaultCellSize.Y / 3 * View.Zoom)); 270 Arrow.Points[0] := TPointF.Create(+0.5 * ArrowSize.X, +0 * ArrowSize.Y); 271 Arrow.Points[1] := TPointF.Create(+0 * ArrowSize.X, +0.5 * ArrowSize.Y); 272 Arrow.Points[2] := TPointF.Create(+0 * ArrowSize.X, +0.25 * ArrowSize.Y); 273 Arrow.Points[3] := TPointF.Create(-0.5 * ArrowSize.X, +0.25 * ArrowSize.Y); 274 Arrow.Points[4] := TPointF.Create(-0.5 * ArrowSize.X, -0.25 * ArrowSize.Y); 275 Arrow.Points[5] := TPointF.Create(+0 * ArrowSize.X, -0.25 * ArrowSize.Y); 276 Arrow.Points[6] := TPointF.Create(+0 * ArrowSize.X, -0.5 * ArrowSize.Y); 277 Arrow.Points[7] := TPointF.Create(+0.5 * ArrowSize.X, 0 * ArrowSize.Y); 278 // Rotate 279 for I := 0 to Length(Arrow.Points) - 1 do begin 280 Arrow.Points[I] := TPointF.Create( 281 Arrow.Points[I].X * Cos(Angle) - Arrow.Points[I].Y * Sin(Angle), 282 Arrow.Points[I].X * Sin(Angle) + Arrow.Points[I].Y * Cos(Angle) 283 ); 284 Arrow.Points[I] := Arrow.Points[I] + TPointF.Create(Pos.X, Pos.Y); 285 end; 286 287 RectPolygon := Arrow.GetRect; 288 if (RectPolygon.P1.X < View.DestRect.Size.X) and 289 (RectPolygon.P2.X > 0) and 290 (RectPolygon.P1.Y < View.DestRect.Size.Y) and 291 (RectPolygon.P2.Y > 0) then begin 292 293 // Convert to standard points 294 SetLength(Points, 8); 295 for I := 0 to Length(Points) - 1 do 296 Points[I] := Point(Trunc(Arrow[I].X), Trunc(Arrow[I].Y)); 297 with Canvas do begin 298 Pen.Color := clBlack; 299 Brush.Color := clWhite; 300 Brush.Style := bsSolid; 301 Polygon(Points); 302 Brush.Style := bsClear; 303 Font.Color := clBlack; 304 Font.Size := Trunc(18 * View.Zoom); 305 TextOut(Pos.X - TextWidth(Text) div 2, Pos.Y - TextHeight(Text) div 2, Text); 306 Pen.Width := 1; 307 end; 308 end; 309 end; 310 251 311 252 312 procedure TClientGUI.DrawCells(Canvas: TCanvas; View: TView); … … 396 456 end; 397 457 458 function TView.CellToCanvasPosF(Pos: TPointF): TPointF; 459 begin 460 Result := TPointF.Create((Pos.X - SourceRect.P1.X) * Zoom + DestRect.P1.X, 461 (Pos.Y - SourceRect.P1.Y) * Zoom + DestRect.P1.Y); 462 end; 463 398 464 function TView.CanvasToCellRect(Pos: TRect): TRect; 399 465 begin … … 406 472 Result.P1 := CellToCanvasPos(Pos.P1); 407 473 Result.P2 := CellToCanvasPos(Pos.P2); 474 end; 475 476 function TView.CellToCanvasRectF(Pos: TRectF): TRectF; 477 begin 478 Result.P1 := CellToCanvasPosF(Pos.P1); 479 Result.P2 := CellToCanvasPosF(Pos.P2); 408 480 end; 409 481 … … 491 563 function TView.IsCellVisible(Cell: TCell): Boolean; 492 564 var 493 RectPolygon, RectView: TRect; 494 begin 495 RectPolygon := Cell.Polygon.GetRect; 496 RectView := SourceRect; 565 RectPolygon: TRect; 566 begin 567 RectPolygon := CellToCanvasRect(Cell.Polygon.GetRect); 497 568 Result := ( 498 (RectPolygon.P1.X < RectView.P2.X) and499 (RectPolygon.P2.X > RectView.P1.X) and500 (RectPolygon.P1.Y < RectView.P2.Y) and501 (RectPolygon.P2.Y > RectView.P1.Y)569 (RectPolygon.P1.X < DestRect.Size.X) and 570 (RectPolygon.P2.X > 0) and 571 (RectPolygon.P1.Y < DestRect.Size.Y) and 572 (RectPolygon.P2.Y > 0) 502 573 ); 503 Result := True;504 574 end; 505 575
Note:
See TracChangeset
for help on using the changeset viewer.