Changeset 51 for trunk/UGame.pas


Ignore:
Timestamp:
Aug 17, 2014, 1:22:26 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Function to paint cell moved from THexMap and TSquareMap to single generic implementation PaintCell in TMap class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r50 r51  
    8585    FSize: TPoint;
    8686    function GetSize: TPoint; virtual;
     87    procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView;
     88      Cell: TCell);
    8789    procedure SetSize(AValue: TPoint); virtual;
    8890  public
     
    468470  PosFrom, PosTo: TPoint;
    469471  Angle: Double;
    470 
    471 procedure PaintHexagon(Pos: TPoint; Text: string);
    472 var
    473   TextPos: TPoint;
    474   I: Integer;
    475 begin
    476   with Canvas do begin
    477     if Assigned(View.FocusedCell) and (View.FocusedCell = TCell(Cells[CY * FSize.X + CX])) then begin
    478       Pen.Color := clYellow;
    479       Pen.Style := psSolid;
    480       Pen.Width := 1;
    481     end else
    482     if TCell(Cells[CY * FSize.X + CX]).Terrain = ttCity then begin
    483       // Cannot set clear border as it will display shifted on gtk2
    484       //Pen.Style := psClear;
    485       Pen.Color := clBlack;
    486       Pen.Style := psSolid;
    487       Pen.Width := 3;
    488     end else begin
    489       // Cannot set clear border as it will display shifted on gtk2
    490       //Pen.Style := psClear;
    491       Pen.Color := Brush.Color;
    492       Pen.Style := psSolid;
    493       Pen.Width := 0;
    494     end;
    495     // Transform view
    496     SetLength(Points, Length(TCell(Cells[CY * FSize.X + CX]).Polygon));
    497     for I := 0 to Length(Points) - 1 do
    498       Points[I] := View.CellToCanvasPos(TCell(Cells[CY * FSize.X + CX]).Polygon[I]);
    499 
    500     Polygon(Points, False, 0, Length(Points));
    501     //Rectangle(Trunc(Pos.X), Trunc(Pos.Y), Trunc(Pos.X + HexSize.X), Trunc(Pos.Y + HexSize.Y));
    502     Pen.Style := psSolid;
    503     Font.Color := clWhite;
    504     Font.Size := Trunc(12 * View.Zoom);
    505     TextPos := View.CellToCanvasPos(Pos);
    506     TextOut(Round(TextPos.X) - TextWidth(Text) div 2, Round(TextPos.Y) - TextHeight(Text) div 2, Text);
    507   end;
    508 end;
    509 
    510472begin
    511473  CellSize := FloatPoint(DefaultCellSize.X * SquareCellMulX, DefaultCellSize.Y * SquareCellMulY);
     
    525487            else Brush.Color := Cell.GetColor;
    526488          Pen.Color := clBlack;
    527           PaintHexagon(Point(Trunc(X * CellSize.X),
     489          PaintCell(Canvas, Point(Trunc(X * CellSize.X),
    528490            Trunc(Y * CellSize.Y)),
    529             IntToStr(Cell.GetAvialPower));
     491            IntToStr(Cell.GetAvialPower), View, TCell(Cells[CY * FSize.X + CX]));
    530492          // Draw arrows
    531493          Pen.Color := clCream;
     
    670632      if Power > MaxPower then Power := MaxPower;
    671633    end;
     634  end;
     635end;
     636
     637procedure TMap.PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView;
     638  Cell: TCell);
     639var
     640  I: Integer;
     641  TextPos: TPoint;
     642  Points: array of TPoint;
     643begin
     644  with Canvas do begin
     645    if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin
     646      Pen.Color := clYellow;
     647      Pen.Style := psSolid;
     648      Pen.Width := 1;
     649    end else
     650    if Cell.Terrain = ttCity then begin
     651      // Cannot set clear border as it will display shifted on gtk2
     652      //Pen.Style := psClear;
     653      Pen.Color := clBlack;
     654      Pen.Style := psSolid;
     655      Pen.Width := 3;
     656    end else begin
     657      // Cannot set clear border as it will display shifted on gtk2
     658      //Pen.Style := psClear;
     659      Pen.Color := Brush.Color;
     660      Pen.Style := psSolid;
     661      Pen.Width := 0;
     662    end;
     663    // Transform view
     664    SetLength(Points, Length(Cell.Polygon));
     665    for I := 0 to Length(Points) - 1 do
     666      Points[I] := View.CellToCanvasPos(Cell.Polygon[I]);
     667
     668    Polygon(Points, False, 0, Length(Points));
     669    Pen.Style := psSolid;
     670    Font.Color := clWhite;
     671    Font.Size := Trunc(12 * View.Zoom);
     672    TextPos := View.CellToCanvasPos(Pos);
     673    TextOut(Round(TextPos.X) - TextWidth(Text) div 2, Round(TextPos.Y) - TextHeight(Text) div 2, Text);
    672674  end;
    673675end;
     
    16151617  Angle: Double;
    16161618  ArrowCenter: TPoint;
    1617 
    1618 procedure PaintHexagon(Pos: TPoint; Text: string; View: TView);
    1619 var
    1620   I: Integer;
    1621   TextPos: TPoint;
    1622 begin
    1623   with Canvas do begin
    1624     if Assigned(View.FocusedCell) and (View.FocusedCell = TCell(Cells[CY * FSize.X + CX])) then begin
    1625       Pen.Color := clYellow;
    1626       Pen.Style := psSolid;
    1627       Pen.Width := 1;
    1628     end else
    1629     if TCell(Cells[CY * FSize.X + CX]).Terrain = ttCity then begin
    1630       // Cannot set clear border as it will display shifted on gtk2
    1631       //Pen.Style := psClear;
    1632       Pen.Color := clBlack;
    1633       Pen.Style := psSolid;
    1634       Pen.Width := 3;
    1635     end else begin
    1636       // Cannot set clear border as it will display shifted on gtk2
    1637       //Pen.Style := psClear;
    1638       Pen.Color := Brush.Color;
    1639       Pen.Style := psSolid;
    1640       Pen.Width := 0;
    1641     end;
    1642     // Transform view
    1643     SetLength(Points, Length(TCell(Cells[CY * FSize.X + CX]).Polygon));
    1644     for I := 0 to Length(Points) - 1 do
    1645       Points[I] := View.CellToCanvasPos(TCell(Cells[CY * FSize.X + CX]).Polygon[I]);
    1646 
    1647     Polygon(Points, False, 0, Length(Points));
    1648     //Rectangle(Trunc(Pos.X), Trunc(Pos.Y), Trunc(Pos.X + HexSize.X), Trunc(Pos.Y + HexSize.Y));
    1649     Pen.Style := psSolid;
    1650     Font.Color := clWhite;
    1651     Font.Size := Trunc(12 * View.Zoom);
    1652     TextPos := View.CellToCanvasPos(Pos);
    1653     TextOut(Round(TextPos.X) - TextWidth(Text) div 2, Round(TextPos.Y) - TextHeight(Text) div 2, Text);
    1654   end;
    1655 end;
    1656 
    16571619begin
    16581620  CellSize := FloatPoint(DefaultCellSize.X / HexCellMulX, DefaultCellSize.Y / HexCellMulY);
     
    16771639            else Brush.Color := Cell.GetColor;
    16781640          Pen.Color := clBlack;
    1679           PaintHexagon(Point(Trunc(X * CellSize.X),
     1641          PaintCell(Canvas, Point(Trunc(X * CellSize.X),
    16801642            Trunc(Y * CellSize.Y)),
    1681             IntToStr(Cell.GetAvialPower), View);
     1643            IntToStr(Cell.GetAvialPower), View, TCell(Cells[CY * FSize.X + CX]));
    16821644          // Draw arrows
    16831645          Pen.Color := clCream;
Note: See TracChangeset for help on using the changeset viewer.