Changeset 67


Ignore:
Timestamp:
Nov 28, 2020, 11:27:11 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Refactoring of Engine Paint method.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UMetaCanvas.pas

    r62 r67  
    148148    procedure Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2,
    149149      StartX, StartY, EndX, EndY: Integer); override;
    150     procedure SetSize(Size: TPoint);
    151150    procedure Reset;
    152151    procedure DrawTo(Canvas: TCanvas);
     
    155154    constructor Create;
    156155    destructor Destroy; override;
     156    property Size: TPoint read FSize write FSize;
    157157  end;
    158158
     
    622622end;
    623623
    624 procedure TMetaCanvas.SetSize(Size: TPoint);
    625 begin
    626   FSize := Size;
    627 end;
    628 
    629624procedure TMetaCanvas.Reset;
    630625begin
  • trunk/UEngine.pas

    r66 r67  
    293293    MenuGame: TMenu;
    294294    ButtonBack: TMenuItemButton;
     295    LastState: TGameState;
    295296    function GetServedDaysCount: Integer;
    296297    procedure ResizeView;
     
    305306    procedure DrawTrains(Canvas: TCanvas);
    306307    procedure DrawGameOver(Canvas: TCanvas);
     308    procedure DrawStationPassengerOverload(Canvas: TCanvas);
     309    procedure DrawLines(Canvas: TCanvas);
     310    procedure DrawStations(Canvas: TCanvas);
     311    procedure DrawGameControls(Canvas: TCanvas);
    307312    procedure ComputeShapeDistance;
    308313    procedure ComputeShapeDistanceStation(Station: TMapStation;
     
    356361    destructor Destroy; override;
    357362    procedure Tick;
    358     procedure Paint(TargetCanvas: TCanvas);
     363    procedure Paint(Canvas: TCanvas);
    359364    property Time: TDateTime read FTime;
    360365    property DarkMode: Boolean read FDarkMode write SetDarkMode;
     
    14611466  case Shape of
    14621467    ssSquare: begin
    1463       SetLength(Points, 4);
    1464       Points[0] := Point(Position.X - Size div 2, Position.Y - Size div 2);
    1465       Points[1] := Point(Position.X + Size div 2, Position.Y - Size div 2);
    1466       Points[2] := Point(Position.X + Size div 2, Position.Y + Size div 2);
    1467       Points[3] := Point(Position.X - Size div 2, Position.Y + Size div 2);
     1468      Points := [
     1469        Point(Position.X - Size div 2, Position.Y - Size div 2),
     1470        Point(Position.X + Size div 2, Position.Y - Size div 2),
     1471        Point(Position.X + Size div 2, Position.Y + Size div 2),
     1472        Point(Position.X - Size div 2, Position.Y + Size div 2)
     1473      ];
    14681474      Points := RotatePoints(Position, Points, Angle);
    14691475      Canvas.Polygon(Points);
     
    14731479      Position.X + Size div 2, Position.Y + Size div 2);
    14741480    ssTriangle: begin
    1475       SetLength(Points, 3);
    1476       Points[0] := Point(Position.X, Position.Y - Size div 2);
    1477       Points[1] := Point(Position.X + Size div 2, Position.Y + Size div 2);
    1478       Points[2] := Point(Position.X - Size div 2, Position.Y + Size div 2);
     1481      Points := [
     1482        Point(Position.X, Position.Y - Size div 2),
     1483        Point(Position.X + Size div 2, Position.Y + Size div 2),
     1484        Point(Position.X - Size div 2, Position.Y + Size div 2)
     1485      ];
    14791486      Points := RotatePoints(Position, Points, Angle);
    14801487      Canvas.Polygon(Points);
     
    14951502    end;
    14961503    ssPlus: begin
    1497       SetLength(Points, 12);
    1498       Points[0] := Point(Position.X + Size div 6, Position.Y - Size div 6);
    1499       Points[1] := Point(Position.X + Size div 2, Position.Y - Size div 6);
    1500       Points[2] := Point(Position.X + Size div 2, Position.Y + Size div 6);
    1501       Points[3] := Point(Position.X + Size div 6, Position.Y + Size div 6);
    1502       Points[4] := Point(Position.X + Size div 6, Position.Y + Size div 2);
    1503       Points[5] := Point(Position.X - Size div 6, Position.Y + Size div 2);
    1504       Points[6] := Point(Position.X - Size div 6, Position.Y + Size div 6);
    1505       Points[7] := Point(Position.X - Size div 2, Position.Y + Size div 6);
    1506       Points[8] := Point(Position.X - Size div 2, Position.Y - Size div 6);
    1507       Points[9] := Point(Position.X - Size div 6, Position.Y - Size div 6);
    1508       Points[10] := Point(Position.X - Size div 6, Position.Y - Size div 2);
    1509       Points[11] := Point(Position.X + Size div 6, Position.Y - Size div 2);
     1504      Points := [
     1505        Point(Position.X + Size div 6, Position.Y - Size div 6),
     1506        Point(Position.X + Size div 2, Position.Y - Size div 6),
     1507        Point(Position.X + Size div 2, Position.Y + Size div 6),
     1508        Point(Position.X + Size div 6, Position.Y + Size div 6),
     1509        Point(Position.X + Size div 6, Position.Y + Size div 2),
     1510        Point(Position.X - Size div 6, Position.Y + Size div 2),
     1511        Point(Position.X - Size div 6, Position.Y + Size div 6),
     1512        Point(Position.X - Size div 2, Position.Y + Size div 6),
     1513        Point(Position.X - Size div 2, Position.Y - Size div 6),
     1514        Point(Position.X - Size div 6, Position.Y - Size div 6),
     1515        Point(Position.X - Size div 6, Position.Y - Size div 2),
     1516        Point(Position.X + Size div 6, Position.Y - Size div 2)
     1517      ];
    15101518      Points := RotatePoints(Position, Points, Angle);
    15111519      Canvas.Polygon(Points);
     
    15321540    end;
    15331541    ssDiamond: begin
    1534       SetLength(Points, 4);
    1535       Points[0] := Point(Position.X, Position.Y - Size div 2);
    1536       Points[1] := Point(Position.X + Size div 2, Position.Y);
    1537       Points[2] := Point(Position.X, Position.Y + Size div 2);
    1538       Points[3] := Point(Position.X - Size div 2, Position.Y);
     1542      Points := [
     1543        Point(Position.X, Position.Y - Size div 2),
     1544        Point(Position.X + Size div 2, Position.Y),
     1545        Point(Position.X, Position.Y + Size div 2),
     1546        Point(Position.X - Size div 2, Position.Y)
     1547      ];
    15391548      Points := RotatePoints(Position, Points, Angle);
    15401549      Canvas.Polygon(Points);
    15411550    end;
    15421551    ssCross: begin
    1543       SetLength(Points, 12);
    1544       Points[0] := Point(Position.X + Size div 6, Position.Y - Size div 6);
    1545       Points[1] := Point(Position.X + Size div 2, Position.Y - Size div 6);
    1546       Points[2] := Point(Position.X + Size div 2, Position.Y + Size div 6);
    1547       Points[3] := Point(Position.X + Size div 6, Position.Y + Size div 6);
    1548       Points[4] := Point(Position.X + Size div 6, Position.Y + Size div 2);
    1549       Points[5] := Point(Position.X - Size div 6, Position.Y + Size div 2);
    1550       Points[6] := Point(Position.X - Size div 6, Position.Y + Size div 6);
    1551       Points[7] := Point(Position.X - Size div 2, Position.Y + Size div 6);
    1552       Points[8] := Point(Position.X - Size div 2, Position.Y - Size div 6);
    1553       Points[9] := Point(Position.X - Size div 6, Position.Y - Size div 6);
    1554       Points[10] := Point(Position.X - Size div 6, Position.Y - Size div 2);
    1555       Points[11] := Point(Position.X + Size div 6, Position.Y - Size div 2);
     1552      Points := [
     1553        Point(Position.X + Size div 6, Position.Y - Size div 6),
     1554        Point(Position.X + Size div 2, Position.Y - Size div 6),
     1555        Point(Position.X + Size div 2, Position.Y + Size div 6),
     1556        Point(Position.X + Size div 6, Position.Y + Size div 6),
     1557        Point(Position.X + Size div 6, Position.Y + Size div 2),
     1558        Point(Position.X - Size div 6, Position.Y + Size div 2),
     1559        Point(Position.X - Size div 6, Position.Y + Size div 6),
     1560        Point(Position.X - Size div 2, Position.Y + Size div 6),
     1561        Point(Position.X - Size div 2, Position.Y - Size div 6),
     1562        Point(Position.X - Size div 6, Position.Y - Size div 6),
     1563        Point(Position.X - Size div 6, Position.Y - Size div 2),
     1564        Point(Position.X + Size div 6, Position.Y - Size div 2)
     1565      ];
    15561566      Points := RotatePoints(Position, Points, Angle + Pi / 4);
    15571567      Canvas.Polygon(Points);
     
    19411951procedure TEngine.MenuItemGameContinue(Sender: TObject);
    19421952begin
    1943   State := gsRunning;
     1953  State := LastState;
    19441954end;
    19451955
     
    20752085begin
    20762086  Menu := MenuGame;
     2087  LastState := State;
    20772088  State := gsMenu;
    20782089  Redraw;
     
    21342145      Angle := GetAngle;
    21352146
    2136       SetLength(Points, 4);
    2137       Points[0] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle);
    2138       Points[1] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle);
    2139       Points[2] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle);
    2140       Points[3] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle);
     2147      Points := [
     2148        RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle),
     2149        RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle),
     2150        RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle),
     2151        RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle)
     2152      ];
    21412153      Canvas.Polygon(Points);
    21422154      Canvas.Brush.Color := clWhite;
     
    21592171  Text: string;
    21602172begin
    2161   Canvas.Font.Color := Colors.Text;
    21622173  with Canvas do begin
     2174    Canvas.Font.Color := Self.Colors.Text;
     2175    Brush.Style := bsSolid;
     2176    Brush.Color := Self.Colors.Background;
     2177
    21632178    Y := 100;
    21642179    Font.Size := 40;
     
    21902205    if (ServedDaysCount > HighestServedDaysCount) then
    21912206      HighestServedDaysCount := ServedDaysCount;
     2207  end;
     2208end;
     2209
     2210procedure TEngine.DrawStationPassengerOverload(Canvas: TCanvas);
     2211var
     2212  MapStation: TMapStation;
     2213  Angle: Real;
     2214begin
     2215  for MapStation in Stations do
     2216  with MapStation do begin
     2217    if OverloadDuration > 0 then begin
     2218      Canvas.Brush.Color := clSilver;
     2219      Canvas.Brush.Style := bsSolid;
     2220      Canvas.Pen.Color := clSilver;
     2221      Canvas.Pen.Style := psSolid;
     2222      Angle := OverloadDuration / MaxPassengersOveloadTime * 2 * Pi;
     2223      Canvas.Pie(Position.X - StationOverloadSize, Position.Y - StationOverloadSize,
     2224      Position.X + StationOverloadSize, Position.Y + StationOverloadSize,
     2225        Trunc(Position.X + StationOverloadSize * Cos(Angle)),
     2226        Trunc(Position.Y + StationOverloadSize * Sin(Angle)), Position.X + StationOverloadSize, Position.Y);
     2227    end;
     2228  end;
     2229end;
     2230
     2231procedure TEngine.DrawLines(Canvas: TCanvas);
     2232var
     2233  MetroLine: TMetroLine;
     2234  S: Integer;
     2235begin
     2236  for MetroLine in Lines do
     2237  with MetroLine do begin
     2238    Canvas.Pen.Color := Color;
     2239    Canvas.Pen.Style := psSolid;
     2240    Canvas.Pen.Width := MetroLineThickness;
     2241    if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].Position);
     2242    for S := 1 to Track.Points.Count - 1 do begin
     2243      Canvas.LineTo(Track.Points[S].Position);
     2244{      if (S = TrackPoints.Count - 1) then begin
     2245        Canvas.Pen.EndCap := pecSquare;
     2246        Angle := arctan2(((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y),
     2247          (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X));
     2248        EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)),
     2249          Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle)));
     2250        Canvas.LineTo(EndPoint);
     2251        Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3),
     2252          Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3)));
     2253        Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3),
     2254          Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3)));
     2255        Canvas.Pen.EndCap := pecRound;
     2256      end;}
     2257    end;
     2258(*    Canvas.Pen.Color := Color;
     2259    Canvas.Pen.Style := psSolid;
     2260    Canvas.Pen.Width := MetroLineThickness div 2;
     2261    if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].PositionDesigned);
     2262    for S := 1 to Track.Points.Count - 1 do begin
     2263      Canvas.LineTo(Track.Points[S].PositionDesigned);
     2264{      if (S = TrackPoints.Count - 1) then begin
     2265        Canvas.Pen.EndCap := pecSquare;
     2266        Angle := arctan2((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y),
     2267          (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X));
     2268        EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)),
     2269          Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle)));
     2270        Canvas.LineTo(EndPoint);
     2271        Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3),
     2272          Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3)));
     2273        Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3),
     2274          Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3)));
     2275        Canvas.Pen.EndCap := pecRound;
     2276      end;}
     2277    end;
     2278    {
     2279    if (TrackPoints.Count > 1) then begin
     2280      Canvas.Pen.EndCap := pecSquare;
     2281      Angle := arctan2((TrackPoints[1].Position.Y - TrackPoints[0].Position.Y),
     2282        (TrackPoints[1].Position.X - TrackPoints[0].Position.X));
     2283      Canvas.MoveTo(TrackPoints[0].Position);
     2284      EndPoint := Point(Round(TrackPoints[0].Position.X - EndStationLength * Cos(Angle)),
     2285        Round(TrackPoints[0].Position.Y - EndStationLength * Sin(Angle)));
     2286      Canvas.LineTo(EndPoint);
     2287      Canvas.MoveTo(Point(Round(EndPoint.X - Cos(Angle + Pi / 2) * EndStationLength / 3),
     2288        Round(EndPoint.Y - Sin(Angle + Pi / 2) * EndStationLength / 3)));
     2289      Canvas.LineTo(Point(Round(EndPoint.X - Cos(Angle - Pi / 2) * EndStationLength / 3),
     2290        Round(EndPoint.Y - Sin(Angle - Pi / 2) * EndStationLength / 3)));
     2291      Canvas.Pen.EndCap := pecRound;
     2292    end;  }
     2293    *)
     2294  end;
     2295
     2296  // Draw design time lines
     2297  if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin
     2298    Canvas.Pen.Color := TrackStationDown.Track.Line.Color;
     2299    Canvas.MoveTo(TrackStationDown.LineStation.TrackPoint.Position);
     2300    DrawLine(Canvas, View.PointDestToSrc(LastMousePos));
     2301  end;
     2302  if Assigned(TrackStationUp) and Assigned(TrackStationUp.LineStation) then begin
     2303    Canvas.Pen.Color := TrackStationUp.Track.Line.Color;
     2304    Canvas.MoveTo(TrackStationUp.LineStation.TrackPoint.Position);
     2305    DrawLine(Canvas, View.PointDestToSrc(LastMousePos));
     2306  end;
     2307end;
     2308
     2309procedure TEngine.DrawStations(Canvas: TCanvas);
     2310var
     2311  MapStation: TMapStation;
     2312  Passenger: TMetroPassenger;
     2313  PassengerPos: TPoint;
     2314  Direction: Integer;
     2315begin
     2316  Canvas.Pen.Width := 5;
     2317  for MapStation in Stations do
     2318  with MapStation do begin
     2319    Canvas.Pen.Style := psSolid;
     2320    if Assigned(SelectedLine) and (Lines.IndexOf(SelectedLine) <> -1) then begin
     2321      Canvas.Brush.Style := bsClear;
     2322      Canvas.Pen.Color := SelectedLine.Color;
     2323      DrawShape(Canvas, Position, Shape, StationSize + Canvas.Pen.Width + 4, 0);
     2324    end;
     2325
     2326    Canvas.Brush.Color := Colors.ShapeBackground;
     2327    Canvas.Brush.Style := bsSolid;
     2328    Canvas.Pen.Color := Colors.Text;
     2329    DrawShape(Canvas, Position, Shape, StationSize, 0);
     2330
     2331    // Draw passengers
     2332    Canvas.Pen.Style := psClear;
     2333    Canvas.Brush.Color := Colors.Text;
     2334    PassengerPos := Point(0, 0);
     2335    Direction := 1;
     2336    for Passenger in Passengers do
     2337    with Passenger do begin
     2338      DrawShape(Canvas, Point(Position.X + StationSize + PassengerPos.X,
     2339        Position.Y - StationSize div 2 + PassengerPos.Y),
     2340        Shape, PassengerSize, 0);
     2341      PassengerPos := Point(PassengerPos.X + Direction * (PassengerSize + 2), PassengerPos.Y);
     2342      if PassengerPos.X >= (PassengerSize + 2) * VisiblePassengersPerLine then begin
     2343        Direction := -Direction;
     2344        PassengerPos.X := PassengerPos.X - (PassengerSize + 2);
     2345        PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2);
     2346      end;
     2347      if PassengerPos.X < 0 then begin
     2348        Direction := -Direction;
     2349        PassengerPos.X := 0;
     2350        PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2);
     2351      end;
     2352    end;
     2353
     2354{    if ShowDistances then begin
     2355      Canvas.Brush.Style := bsClear;
     2356      Text := '';
     2357      for P := 0 to 5 do
     2358        Text := Text + IntToStr(ShapeDistance[TStationShape(P)]) + ',';
     2359      Canvas.TextOut(Position.X + StationSize div 2, Position.Y + StationSize div 2, Text);
     2360    end;
     2361    }
     2362  end;
     2363end;
     2364
     2365procedure TEngine.DrawGameControls(Canvas: TCanvas);
     2366var
     2367  I: Integer;
     2368  Text: string;
     2369  Radius: Integer;
     2370  Angle: Real;
     2371  Pos: TPoint;
     2372begin
     2373  // Line selection
     2374  Canvas.Pen.Width := 4;
     2375  for I := 0 to High(LineColors) do begin
     2376    if Assigned(Lines.SearchByColor(LineColors[I])) then begin
     2377      Canvas.Brush.Color := LineColors[I];
     2378      Radius := 15;
     2379    end else begin
     2380      Canvas.Brush.Color := clSilver;
     2381      Radius := 5;
     2382    end;
     2383    Canvas.Pen.Color := Colors.Text;
     2384    if Assigned(SelectedLine) and (SelectedLine.Color = LineColors[I]) then begin
     2385      Canvas.Pen.Style := psSolid;
     2386    end else begin
     2387      Canvas.Pen.Style := psClear;
     2388    end;
     2389
     2390    Canvas.EllipseC(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist,
     2391      Canvas.Height - LineColorsDist, Radius, Radius);
     2392  end;
     2393
     2394  // Draw unused trains
     2395  Text := IntToStr(Trains.GetUnusedCount);
     2396  Canvas.Draw(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 100,
     2397    Canvas.Height - LineColorsDist - ImageLocomotive.Picture.Bitmap.Height div 2, ImageLocomotive.Picture.Bitmap);
     2398  Canvas.Brush.Style := bsClear;
     2399  Canvas.Font.Size := 14;
     2400  Canvas.Font.Color := Colors.Text;
     2401  Canvas.TextOut(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - Canvas.TextWidth(Text),
     2402    Canvas.Height - LineColorsDist - Canvas.TextHeight(Text) div 2, Text);
     2403
     2404  // Status interface
     2405  Text := IntToStr(ServedPassengerCount);
     2406  Canvas.Draw(Canvas.Width - 50, Canvas.Height - 60, ImagePassenger.Picture.Bitmap);
     2407  Canvas.Brush.Style := bsClear;
     2408  Canvas.Font.Size := 14;
     2409  Canvas.Font.Color := Colors.Text;
     2410  Canvas.TextOut(Canvas.Width - 70 - Canvas.TextWidth(Text), Canvas.Height - 55, Text);
     2411
     2412  DrawClock(Canvas);
     2413
     2414  // Back button
     2415  Canvas.Font.Size := 40;
     2416  Canvas.Font.Color := Colors.Text;
     2417  ButtonBack.Paint(Canvas, Point(10, 10));
     2418
     2419  // Show train grabbed by mouse
     2420  if Assigned(SelectedTrain) then begin
     2421    Canvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color;
     2422    Canvas.Brush.Style := bsSolid;
     2423    Canvas.Pen.Style := psClear;
     2424    Pos := LastMousePos;
     2425    Angle := 0;
     2426
     2427    Canvas.Polygon([
     2428      RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle),
     2429      RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle),
     2430      RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle),
     2431      RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle)
     2432    ]);
    21922433  end;
    21932434end;
     
    22842525  LineStationUp: TLineStation;
    22852526  CurrentTrackPoint: TTrackPoint;
    2286   I: Integer;
    22872527begin
    22882528  if State = gsMenu then begin
     
    24832723  {$IFDEF DEBUG}
    24842724  if Key = KeyF2 then begin
    2485     State := gsGameOver;
    2486     Redraw;
     2725    if State = gsRunning then begin
     2726      State := gsGameOver;
     2727      Redraw;
     2728    end;
    24872729  end;
    24882730  {$ENDIF}
     
    25962838end;
    25972839
    2598 procedure TEngine.Paint(TargetCanvas: TCanvas);
    2599 var
    2600   I: Integer;
    2601   S: Integer;
    2602   Size: Integer;
    2603   Pos: TPoint;
    2604   Text: string;
    2605   Angle: Double;
    2606   PassengerPos: TPoint;
    2607   Direction: Integer;
    2608   Points: array of TPoint;
    2609   Canvas: TMetaCanvas;
    2610   MetroLine: TMetroLine;
    2611   MapStation: TMapStation;
    2612   Passenger: TMetroPassenger;
    2613 begin
    2614   Canvas := MetaCanvas;
    2615   Canvas.SetSize(Point(TargetCanvas.Width, TargetCanvas.Height));
    2616   Canvas.Reset;
    2617 
    2618   // Draw station passenger overload
    2619   for MapStation in Stations do
    2620   with MapStation do begin
    2621     if OverloadDuration > 0 then begin
    2622       Canvas.Brush.Color := clSilver;
    2623       Canvas.Brush.Style := bsSolid;
    2624       Canvas.Pen.Color := clSilver;
    2625       Canvas.Pen.Style := psSolid;
    2626       Angle := OverloadDuration / MaxPassengersOveloadTime * 2 * Pi;
    2627       Canvas.Pie(Position.X - StationOverloadSize, Position.Y - StationOverloadSize,
    2628       Position.X + StationOverloadSize, Position.Y + StationOverloadSize,
    2629         Trunc(Position.X + StationOverloadSize * Cos(Angle)),
    2630         Trunc(Position.Y + StationOverloadSize * Sin(Angle)), Position.X + StationOverloadSize, Position.Y);
    2631     end;
    2632   end;
    2633 
    2634   // Draw lines
    2635   for MetroLine in Lines do
    2636   with MetroLine do begin
    2637     Canvas.Pen.Color := Color;
    2638     Canvas.Pen.Style := psSolid;
    2639     Canvas.Pen.Width := MetroLineThickness;
    2640     if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].Position);
    2641     for S := 1 to Track.Points.Count - 1 do begin
    2642       Canvas.LineTo(Track.Points[S].Position);
    2643 {      if (S = TrackPoints.Count - 1) then begin
    2644         Canvas.Pen.EndCap := pecSquare;
    2645         Angle := arctan2(((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y),
    2646           (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X));
    2647         EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)),
    2648           Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle)));
    2649         Canvas.LineTo(EndPoint);
    2650         Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3),
    2651           Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3)));
    2652         Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3),
    2653           Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3)));
    2654         Canvas.Pen.EndCap := pecRound;
    2655       end;}
    2656     end;
    2657 (*    Canvas.Pen.Color := Color;
    2658     Canvas.Pen.Style := psSolid;
    2659     Canvas.Pen.Width := MetroLineThickness div 2;
    2660     if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].PositionDesigned);
    2661     for S := 1 to Track.Points.Count - 1 do begin
    2662       Canvas.LineTo(Track.Points[S].PositionDesigned);
    2663 {      if (S = TrackPoints.Count - 1) then begin
    2664         Canvas.Pen.EndCap := pecSquare;
    2665         Angle := arctan2((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y),
    2666           (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X));
    2667         EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)),
    2668           Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle)));
    2669         Canvas.LineTo(EndPoint);
    2670         Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3),
    2671           Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3)));
    2672         Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3),
    2673           Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3)));
    2674         Canvas.Pen.EndCap := pecRound;
    2675       end;}
    2676     end;
    2677     {
    2678     if (TrackPoints.Count > 1) then begin
    2679       Canvas.Pen.EndCap := pecSquare;
    2680       Angle := arctan2((TrackPoints[1].Position.Y - TrackPoints[0].Position.Y),
    2681         (TrackPoints[1].Position.X - TrackPoints[0].Position.X));
    2682       Canvas.MoveTo(TrackPoints[0].Position);
    2683       EndPoint := Point(Round(TrackPoints[0].Position.X - EndStationLength * Cos(Angle)),
    2684         Round(TrackPoints[0].Position.Y - EndStationLength * Sin(Angle)));
    2685       Canvas.LineTo(EndPoint);
    2686       Canvas.MoveTo(Point(Round(EndPoint.X - Cos(Angle + Pi / 2) * EndStationLength / 3),
    2687         Round(EndPoint.Y - Sin(Angle + Pi / 2) * EndStationLength / 3)));
    2688       Canvas.LineTo(Point(Round(EndPoint.X - Cos(Angle - Pi / 2) * EndStationLength / 3),
    2689         Round(EndPoint.Y - Sin(Angle - Pi / 2) * EndStationLength / 3)));
    2690       Canvas.Pen.EndCap := pecRound;
    2691     end;  }
    2692     *)
    2693   end;
    2694 
    2695   // Draw design time lines
    2696   if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin
    2697     Canvas.Pen.Color := TrackStationDown.Track.Line.Color;
    2698     Canvas.MoveTo(TrackStationDown.LineStation.TrackPoint.Position);
    2699     DrawLine(Canvas, View.PointDestToSrc(LastMousePos));
    2700   end;
    2701   if Assigned(TrackStationUp) and Assigned(TrackStationUp.LineStation) then begin
    2702     Canvas.Pen.Color := TrackStationUp.Track.Line.Color;
    2703     Canvas.MoveTo(TrackStationUp.LineStation.TrackPoint.Position);
    2704     DrawLine(Canvas, View.PointDestToSrc(LastMousePos));
    2705   end;
    2706 
    2707   DrawTrains(Canvas);
    2708 
    2709   // Draw stations
    2710   Canvas.Pen.Width := 5;
    2711   for MapStation in Stations do
    2712   with MapStation do begin
    2713     Canvas.Pen.Style := psSolid;
    2714     if Assigned(SelectedLine) and (Lines.IndexOf(SelectedLine) <> -1) then begin
    2715       Canvas.Brush.Style := bsClear;
    2716       Canvas.Pen.Color := SelectedLine.Color;
    2717       DrawShape(Canvas, Position, Shape, StationSize + Canvas.Pen.Width + 4, 0);
    2718     end;
    2719 
    2720     Canvas.Brush.Color := Colors.ShapeBackground;
    2721     Canvas.Brush.Style := bsSolid;
    2722     Canvas.Pen.Color := Colors.Text;
    2723     DrawShape(Canvas, Position, Shape, StationSize, 0);
    2724 
    2725     // Draw passengers
    2726     Canvas.Pen.Style := psClear;
    2727     Canvas.Brush.Color := Colors.Text;
    2728     PassengerPos := Point(0, 0);
    2729     Direction := 1;
    2730     for Passenger in Passengers do
    2731     with Passenger do begin
    2732       DrawShape(Canvas, Point(Position.X + StationSize + PassengerPos.X,
    2733         Position.Y - StationSize div 2 + PassengerPos.Y),
    2734         Shape, PassengerSize, 0);
    2735       PassengerPos := Point(PassengerPos.X + Direction * (PassengerSize + 2), PassengerPos.Y);
    2736       if PassengerPos.X >= (PassengerSize + 2) * VisiblePassengersPerLine then begin
    2737         Direction := -Direction;
    2738         PassengerPos.X := PassengerPos.X - (PassengerSize + 2);
    2739         PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2);
    2740       end;
    2741       if PassengerPos.X < 0 then begin
    2742         Direction := -Direction;
    2743         PassengerPos.X := 0;
    2744         PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2);
    2745       end;
    2746     end;
    2747 
    2748 {    if ShowDistances then begin
    2749       Canvas.Brush.Style := bsClear;
    2750       Text := '';
    2751       for P := 0 to 5 do
    2752         Text := Text + IntToStr(ShapeDistance[TStationShape(P)]) + ',';
    2753       Canvas.TextOut(Position.X + StationSize div 2, Position.Y + StationSize div 2, Text);
    2754     end;
    2755     }
    2756   end;
     2840procedure TEngine.Paint(Canvas: TCanvas);
     2841begin
     2842  MetaCanvas.Size := Point(Canvas.Width, Canvas.Height);
     2843  MetaCanvas.Reset;
     2844
     2845  DrawStationPassengerOverload(MetaCanvas);
     2846  DrawLines(MetaCanvas);
     2847  DrawTrains(MetaCanvas);
     2848  DrawStations(MetaCanvas);
    27572849
    27582850  // MainMenu background
    2759   TargetCanvas.Brush.Color := Colors.Background;
    2760   TargetCanvas.Brush.Style := bsSolid;
    2761   TargetCanvas.Clear;
     2851  Canvas.Brush.Color := Colors.Background;
     2852  Canvas.Brush.Style := bsSolid;
     2853  Canvas.Clear;
    27622854
    27632855  MetaCanvas.Move(Point(-View.SourceRect.Left, -View.SourceRect.Top));
     
    27652857
    27662858  // Draw meta canvas to real target canvas
    2767   MetaCanvas.DrawTo(TargetCanvas);
     2859  MetaCanvas.DrawTo(Canvas);
    27682860
    27692861  if State <> gsMenu then begin
    2770     // Line selection
    2771     TargetCanvas.Pen.Width := 4;
    2772     for I := 0 to High(LineColors) do begin
    2773       if Assigned(Lines.SearchByColor(LineColors[I])) then begin
    2774         TargetCanvas.Brush.Color := LineColors[I];
    2775         Size := 15;
    2776       end else begin
    2777         TargetCanvas.Brush.Color := clSilver;
    2778         Size := 5;
    2779       end;
    2780       TargetCanvas.Pen.Color := Colors.Text;
    2781       if Assigned(SelectedLine) and (SelectedLine.Color = LineColors[I]) then begin
    2782         TargetCanvas.Pen.Style := psSolid;
    2783       end else begin
    2784         TargetCanvas.Pen.Style := psClear;
    2785       end;
    2786 
    2787       TargetCanvas.EllipseC(TargetCanvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist,
    2788         TargetCanvas.Height - LineColorsDist, Size, Size);
    2789     end;
    2790 
    2791     // Draw unused trains
    2792     Text := IntToStr(Trains.GetUnusedCount);
    2793     TargetCanvas.Draw(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 100,
    2794       TargetCanvas.Height - LineColorsDist - ImageLocomotive.Picture.Bitmap.Height div 2, ImageLocomotive.Picture.Bitmap);
    2795     TargetCanvas.Brush.Style := bsClear;
    2796     TargetCanvas.Font.Size := 14;
    2797     TargetCanvas.Font.Color := Colors.Text;
    2798     TargetCanvas.TextOut(TargetCanvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - TargetCanvas.TextWidth(Text),
    2799       TargetCanvas.Height - LineColorsDist - TargetCanvas.TextHeight(Text) div 2, Text);
    2800 
    2801     // Status interface
    2802     Text := IntToStr(ServedPassengerCount);
    2803     TargetCanvas.Draw(TargetCanvas.Width - 50, TargetCanvas.Height - 60, ImagePassenger.Picture.Bitmap);
    2804     TargetCanvas.Brush.Style := bsClear;
    2805     TargetCanvas.Font.Size := 14;
    2806     TargetCanvas.Font.Color := Colors.Text;
    2807     TargetCanvas.TextOut(TargetCanvas.Width - 70 - TargetCanvas.TextWidth(Text), TargetCanvas.Height - 55, Text);
    2808 
    2809     DrawClock(TargetCanvas);
    2810 
    2811     // Back button
    2812     TargetCanvas.Font.Size := 40;
    2813     TargetCanvas.Font.Color := Colors.Text;
    2814     ButtonBack.Paint(TargetCanvas, Point(10, 10));
    2815   end;
    2816 
    2817   // Show train grabbed by mouse
    2818   if Assigned(SelectedTrain) then begin
    2819     TargetCanvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color;
    2820     TargetCanvas.Brush.Style := bsSolid;
    2821     TargetCanvas.Pen.Style := psClear;
    2822     Pos := LastMousePos;
    2823     Angle := 0;
    2824 
    2825     SetLength(Points, 4);
    2826     Points[0] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle);
    2827     Points[1] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle);
    2828     Points[2] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle);
    2829     Points[3] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle);
    2830     TargetCanvas.Polygon(Points);
     2862    DrawGameControls(Canvas);
    28312863  end;
    28322864
     
    28342866  if State = gsGameOver then
    28352867  begin
    2836     DrawGameOver(TargetCanvas);
     2868    DrawGameOver(Canvas);
    28372869  end else
    28382870  if State = gsMenu then begin
    2839     Menu.Paint(TargetCanvas);
     2871    Menu.Paint(Canvas);
    28402872  end;
    28412873
Note: See TracChangeset for help on using the changeset viewer.