Changeset 5


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

Legend:

Unmodified
Added
Removed
  • trunk/UFormMain.lfm

    r4 r5  
    2222    OnMouseUp = PaintBox1MouseUp
    2323    OnMouseLeave = PaintBox1MouseLeave
     24    OnMouseWheelDown = PaintBox1MouseWheelDown
     25    OnMouseWheelUp = PaintBox1MouseWheelUp
    2426    OnPaint = PaintBox1Paint
    2527  end
  • trunk/UFormMain.pas

    r4 r5  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9   UGame, LCLType, Menus, ActnList;
     9  UGame, LCLType, Menus, ActnList, types;
     10
     11const
     12  ZoomFactor = 1.5;
    1013
    1114type
     
    3942    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    4043      Shift: TShiftState; X, Y: Integer);
     44    procedure PaintBox1MouseWheelDown(Sender: TObject; Shift: TShiftState;
     45      MousePos: TPoint; var Handled: Boolean);
     46    procedure PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;
     47      MousePos: TPoint; var Handled: Boolean);
    4148    procedure PaintBox1Paint(Sender: TObject);
    4249    procedure EraseBackground(DC: HDC); override;
     
    125132end;
    126133
     134procedure TFormMain.PaintBox1MouseWheelDown(Sender: TObject;
     135  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
     136begin
     137  with TPlayer(Game.Players[0]) do
     138    ViewZoom := ViewZoom / ZoomFactor;
     139  PaintBox1.Repaint;
     140end;
     141
     142procedure TFormMain.PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;
     143  MousePos: TPoint; var Handled: Boolean);
     144begin
     145  with TPlayer(Game.Players[0]) do
     146    ViewZoom := ViewZoom * ZoomFactor;
     147  PaintBox1.Repaint;
     148end;
     149
    127150end.
    128151
  • 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.