Changeset 5 for trunk/UGame.pas


Ignore:
Timestamp:
Feb 9, 2014, 5:30:12 PM (11 years ago)
Author:
chronos
Message:
  • Added: Zoom view using mouse wheel.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r4 r5  
    3030
    3131  TMap = class
    32     CellSize: TPoint;
     32    DefaultCellSize: TPoint;
    3333    Cells: array of array of TCell;
    34     procedure Paint(Canvas: TCanvas; Rect: TRect);
     34    procedure Paint(Canvas: TCanvas; Rect: TRect; Zoom: Double);
    3535    constructor Create;
    3636    destructor Destroy; override;
     
    4545    View: TRect;
    4646    Color: TColor;
     47    ViewZoom: Double;
    4748    procedure Paint(PaintBox: TPaintBox);
     49    constructor Create;
    4850  end;
    4951
     
    8183  View := Bounds(View.Left, View.Top, PaintBox.Width,
    8284    PaintBox.Height);
    83   Game.Map.Paint(PaintBox.Canvas, View);
     85  Game.Map.Paint(PaintBox.Canvas, View, ViewZoom);
     86end;
     87
     88constructor TPlayer.Create;
     89begin
     90  ViewZoom := 1;
    8491end;
    8592
     
    135142{ TMap }
    136143
    137 procedure TMap.Paint(Canvas: TCanvas; Rect: TRect);
     144procedure TMap.Paint(Canvas: TCanvas; Rect: TRect; Zoom: Double);
    138145var
    139146  CX, CY: Integer;
     
    141148  HexShift: TFloatPoint;
    142149  HexSize: TFloatPoint;
     150  CellSize: TFloatPoint;
    143151
    144152procedure PaintHexagon(X, Y: Double; Text: string);
     
    166174  *)
    167175    Font.Color := clWhite;
     176    Font.Size := Trunc(12 * Zoom);
    168177    TextOut(Round(X) - TextWidth(Text) div 2, Round(Y) - TextHeight(Text) div 2, Text);
    169178  end;
     
    171180
    172181begin
     182  CellSize := FloatPoint(DefaultCellSize.X / 1.15 * Zoom, DefaultCellSize.Y / 1.35 * Zoom);
    173183  HexShift := FloatPoint(0.5 * cos(30 / 180 * Pi),
    174184    0.5 * sin(30 / 180 * Pi));
    175   HexSize := FloatPoint(CellSize.X * 1.15, CellSize.Y * 1.35);
     185  HexSize := FloatPoint(DefaultCellSize.X * Zoom, DefaultCellSize.Y * Zoom);
    176186  with Canvas do try
    177187    Lock;
     
    198208constructor TMap.Create;
    199209begin
    200   CellSize := Point(62, 62);
     210  DefaultCellSize := Point(62, 62);
    201211end;
    202212
    203213destructor TMap.Destroy;
    204214begin
    205   Init(0, 0);
     215  Init(Point(0, 0));
    206216  inherited Destroy;
    207217end;
Note: See TracChangeset for help on using the changeset viewer.