Changeset 24 for trunk


Ignore:
Timestamp:
Mar 3, 2014, 12:03:16 AM (11 years ago)
Author:
chronos
Message:
  • Fixed: Cell position conversion and map painting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r23 r24  
    625625      if (CX >= 0) and (CY >= 0) and (CY < Size.Y) and (CX < Size.X) then
    626626      if Cells[CY, CX].Terrain = ttNormal then begin
    627         Points := GetHexagonPolygon(Point(Trunc(X * CellSize.X - Frac(SourceRect.Left / CellSize.X) * CellSize.X),
    628           Trunc(Y * CellSize.Y - Frac(SourceRect.Top / CellSize.Y) * CellSize.Y)),
     627        Points := GetHexagonPolygon(Point(Trunc(X * CellSize.X),
     628          Trunc(Y * CellSize.Y)),
    629629          Point(Trunc(HexSize.X), Trunc(HexSize.Y)));
    630630        if PtInPoly(Points, Pos) then begin
     
    645645begin
    646646  with View do begin
    647   CellSize := FloatPoint(DefaultCellSize.X / CellMulX * View.Zoom, DefaultCellSize.Y / CellMulY * View.Zoom);
    648   HexSize := FloatPoint(DefaultCellSize.X * View.Zoom, DefaultCellSize.Y * View.Zoom);
    649   X := Cell.Pos.X - Trunc(SourceRect.Left / CellSize.X);
    650   Y := Cell.Pos.Y - Trunc(SourceRect.Top / CellSize.Y);
     647  CellSize := FloatPoint(DefaultCellSize.X / CellMulX, DefaultCellSize.Y / CellMulY);
     648  HexSize := FloatPoint(DefaultCellSize.X, DefaultCellSize.Y);
     649  X := Cell.Pos.X;
     650  Y := Cell.Pos.Y;
    651651  if (Cell.Pos.Y and 1) = 1 then begin
    652652    X := X + 0.5;
     
    654654  end;
    655655
    656   Result.X := Trunc(X * CellSize.X - Frac(SourceRect.Left / CellSize.X) * CellSize.X);
    657   Result.Y := Trunc(Y * CellSize.Y - Frac(SourceRect.Top / CellSize.Y) * CellSize.Y);
    658   end;
    659 end;
    660 
     656  Result.X := Trunc(X * CellSize.X);
     657  Result.Y := Trunc(Y * CellSize.Y);
     658  end;
     659end;
    661660
    662661procedure THexMap.Paint(Canvas: TCanvas; View: TView; SelectedCell: TCell; FocusedCell: TCell);
     
    672671  PosFrom, PosTo: TPoint;
    673672
    674 procedure PaintHexagon(X, Y: Double; Text: string);
     673procedure PaintHexagon(Pos: TPoint; Text: string);
    675674var
    676675  Points: array of TPoint;
     
    684683      Pen.Style := psClear;
    685684    end;
    686     Points := GetHexagonPolygon(Point(Trunc(X), Trunc(Y)), Point(Trunc(HexSize.X), Trunc(HexSize.Y)));
     685    Points := GetHexagonPolygon(Point(Trunc(Pos.X), Trunc(Pos.Y)), Point(Trunc(HexSize.X), Trunc(HexSize.Y)));
    687686    Polygon(Points);
    688687    Pen.Style := psSolid;
    689688    Font.Color := clWhite;
    690689    Font.Size := Trunc(12 * View.Zoom);
    691     TextOut(Round(X) - TextWidth(Text) div 2, Round(Y) - TextHeight(Text) div 2, Text);
     690    TextOut(Round(Pos.X) - TextWidth(Text) div 2, Round(Pos.Y) - TextHeight(Text) div 2, Text);
    692691  end;
    693692end;
     
    709708    for CY := Trunc(SourceRect.Top / CellSize.Y) to Trunc(SourceRect.Bottom / CellSize.Y) + 1 do
    710709    for CX := Trunc(SourceRect.Left / CellSize.X) to Trunc(SourceRect.Right / CellSize.X) + 1 do begin
    711       X := CX - Trunc(SourceRect.Left / CellSize.X);
    712       Y := CY - Trunc(SourceRect.Top / CellSize.Y);
     710      X := CX;
     711      Y := CY;
    713712      if (CY and 1) = 1 then begin
    714713        X := X + 0.5;
     
    722721            else Brush.Color := Cell.GetColor;
    723722          Pen.Color := clBlack;
    724           PaintHexagon(X * CellSizeZoomed.X - Frac(SourceRect.Left / CellSize.X) * CellSizeZoomed.X,
    725             Y * CellSizeZoomed.Y - Frac(SourceRect.Top / CellSize.Y) * CellSizeZoomed.Y, IntToStr(Cell.GetAvialPower));
     723          PaintHexagon(View.CellToCanvasPos(Point(Trunc(X * CellSize.X),
     724            Trunc(Y * CellSize.Y))),
     725            IntToStr(Cell.GetAvialPower));
    726726          // Draw arrows
    727727          Pen.Color := clCream;
     
    729729            PosFrom := CellToPos(Cell, View);
    730730            PosTo := CellToPos(TMove(Cell.MovesFrom[I]).CellTo, View);
    731             Line(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 4),
    732               Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 4),
    733               Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),
    734               Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2));
     731            Line(View.CellToCanvasPos(Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 4),
     732              Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 4))),
     733              View.CellToCanvasPos(Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),
     734              Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2))));
    735735          end;
    736736        end;
Note: See TracChangeset for help on using the changeset viewer.