Changeset 238 for trunk


Ignore:
Timestamp:
Sep 21, 2018, 12:15:23 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Enabled back drawing only of visible cells.
  • Added: Draw only visible arrows between cells.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Languages/xtactics.cs.po

    r234 r238  
    10041004msgstr "Divák"
    10051005
    1006 #: ugame.sunitpowermismatch
    1007 msgid "Unit move power mismatch. Cell power is %d but %d moved away."
    1008 msgstr "Chyba síly přesunu jednotek. Síla buňky je %d, ale %d přesunuto pryč."
    1009 
    10101006#: ugame.swrongfileformat
    10111007msgid "Wrong file format"
     
    10521048msgid "64-bit UInt read overflow."
    10531049msgstr "Přetečení při čtení 64-bit UInt"
     1050
  • trunk/Languages/xtactics.po

    r231 r238  
    983983msgstr ""
    984984
    985 #: ugame.sunitpowermismatch
    986 msgid "Unit move power mismatch. Cell power is %d but %d moved away."
    987 msgstr ""
    988 
    989985#: ugame.swrongfileformat
    990986msgid "Wrong file format"
  • trunk/UClientGUI.pas

    r237 r238  
    3232    function CanvasToCellPos(Pos: TPoint): TPoint;
    3333    function CellToCanvasPos(Pos: TPoint): TPoint;
     34    function CellToCanvasPosF(Pos: TPointF): TPointF;
    3435    function CanvasToCellRect(Pos: TRect): TRect;
    3536    function CellToCanvasRect(Pos: TRect): TRect;
     37    function CellToCanvasRectF(Pos: TRectF): TRectF;
    3638    procedure Assign(Source: TView);
    3739    property DestRect: TRect read FDestRect write SetDestRect;
     
    4648  public
    4749    View: TView;
     50    procedure DrawArrow(Canvas: TCanvas; Pos: TPoint; Angle: Double;
     51      Text: string; View: TView);
    4852    procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView;
    4953      Cell: TPlayerCell);
     
    242246
    243247      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;
     256end;
     257
     258procedure TClientGUI.DrawArrow(Canvas: TCanvas; Pos: TPoint;
     259  Angle: Double; Text: string; View: TView);
     260var
     261  Points: array of Classes.TPoint;
     262  Arrow: TPolygonF;
     263  I: Integer;
     264  ArrowSize: TPoint;
     265  RectPolygon: TRectF;
     266begin
     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;
     309end;
     310
    251311
    252312procedure TClientGUI.DrawCells(Canvas: TCanvas; View: TView);
     
    396456end;
    397457
     458function TView.CellToCanvasPosF(Pos: TPointF): TPointF;
     459begin
     460  Result := TPointF.Create((Pos.X - SourceRect.P1.X) * Zoom + DestRect.P1.X,
     461    (Pos.Y - SourceRect.P1.Y) * Zoom + DestRect.P1.Y);
     462end;
     463
    398464function TView.CanvasToCellRect(Pos: TRect): TRect;
    399465begin
     
    406472  Result.P1 := CellToCanvasPos(Pos.P1);
    407473  Result.P2 := CellToCanvasPos(Pos.P2);
     474end;
     475
     476function TView.CellToCanvasRectF(Pos: TRectF): TRectF;
     477begin
     478  Result.P1 := CellToCanvasPosF(Pos.P1);
     479  Result.P2 := CellToCanvasPosF(Pos.P2);
    408480end;
    409481
     
    491563function TView.IsCellVisible(Cell: TCell): Boolean;
    492564var
    493   RectPolygon, RectView: TRect;
    494 begin
    495   RectPolygon := Cell.Polygon.GetRect;
    496   RectView := SourceRect;
     565  RectPolygon: TRect;
     566begin
     567  RectPolygon := CellToCanvasRect(Cell.Polygon.GetRect);
    497568  Result := (
    498     (RectPolygon.P1.X < RectView.P2.X) and
    499     (RectPolygon.P2.X > RectView.P1.X) and
    500     (RectPolygon.P1.Y < RectView.P2.Y) and
    501     (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)
    502573  );
    503   Result := True;
    504574end;
    505575
  • trunk/UGame.pas

    r233 r238  
    127127  SWrongFileFormat = 'Wrong file format';
    128128  SNewGameFile = 'New game.xtg';
    129   SUnitPowerMismatch = 'Unit move power mismatch. Cell power is %d but %d moved away.';
    130129
    131130procedure InitStrings;
  • trunk/UMap.pas

    r233 r238  
    155155    Areas: TMapAreas;
    156156    Cyclic: Boolean;
    157     procedure DrawArrow(Canvas: TCanvas; Pos: TPoint; Angle: Double;
    158       Text: string; Zoom: Double);
    159157    function IsOutsideShape(Coord: TPoint): Boolean; virtual;
    160158    function IsCellsNeighbor(Cell1, Cell2: TCell): Boolean; virtual;
     
    549547end;
    550548
    551 procedure TMap.DrawArrow(Canvas: TCanvas; Pos: TPoint;
    552   Angle: Double; Text: string; Zoom: Double);
    553 var
    554   Points: array of Classes.TPoint;
    555   FPoints: array of TPointF;
    556   I: Integer;
    557   ArrowSize: TPoint;
    558 begin
    559   Canvas.Brush.Color := clWhite;
    560   Canvas.Pen.Color := clBlack;
    561   SetLength(Points, 8);
    562   SetLength(FPoints, 8);
    563   ArrowSize := TPoint.Create(Trunc(DefaultCellSize.X / 3 * Zoom),
    564     Trunc(DefaultCellSize.Y / 3 * Zoom));
    565   FPoints[0] := TPointF.Create(+0.5 * ArrowSize.X, +0 * ArrowSize.Y);
    566   FPoints[1] := TPointF.Create(+0 * ArrowSize.X, +0.5 * ArrowSize.Y);
    567   FPoints[2] := TPointF.Create(+0 * ArrowSize.X, +0.25 * ArrowSize.Y);
    568   FPoints[3] := TPointF.Create(-0.5 * ArrowSize.X, +0.25 * ArrowSize.Y);
    569   FPoints[4] := TPointF.Create(-0.5 * ArrowSize.X, -0.25 * ArrowSize.Y);
    570   FPoints[5] := TPointF.Create(+0 * ArrowSize.X, -0.25 * ArrowSize.Y);
    571   FPoints[6] := TPointF.Create(+0 * ArrowSize.X, -0.5 * ArrowSize.Y);
    572   FPoints[7] := TPointF.Create(+0.5 * ArrowSize.X, 0 * ArrowSize.Y);
    573   // Rotate
    574   for I := 0 to Length(Points) - 1 do
    575     FPoints[I] := TPointF.Create(FPoints[I].X * Cos(Angle) - FPoints[I].Y * Sin(Angle),
    576       FPoints[I].X * Sin(Angle) + FPoints[I].Y * Cos(Angle));
    577   // Shift
    578   for I := 0 to Length(Points) - 1 do
    579     Points[I] := Point(Trunc(FPoints[I].X + Pos.X), Trunc(FPoints[I].Y + Pos.Y));
    580   with Canvas do begin
    581     Brush.Style := bsSolid;
    582     Polygon(Points);
    583     Brush.Style := bsClear;
    584     Font.Color := clBlack;
    585     Font.Size := Trunc(26 * Zoom);
    586     TextOut(Pos.X - TextWidth(Text) div 2,
    587       Pos.Y - TextHeight(Text) div 2, Text);
    588     Pen.Width := 1;
    589   end;
    590 end;
    591 
    592549function TMap.IsCellsNeighbor(Cell1, Cell2: TCell): Boolean;
    593550begin
  • trunk/xtactics.lpr

    r231 r238  
    1111  CoolTranslator, TemplateGenerics
    1212  { you can add units after this },
    13   SysUtils, UFormMain, CoolStreaming, UMap, UPlayer, UClientGUI;
     13  SysUtils, UFormMain, CoolStreaming;
    1414
    1515{$R *.res}
Note: See TracChangeset for help on using the changeset viewer.