Changeset 29 for trunk


Ignore:
Timestamp:
Apr 18, 2015, 11:28:16 AM (10 years ago)
Author:
chronos
Message:
  • Added: Not finished support for map rivers.
  • Added: Design a prototype of better track structure in UTrack.
  • Added: To allow zooming of graphic canvas should store drawing elements in abstract structure TMetaCanvas.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/BigMetro.lpi

    r25 r29  
    6969      </Item1>
    7070    </RequiredPackages>
    71     <Units Count="5">
     71    <Units Count="6">
    7272      <Unit0>
    7373        <Filename Value="BigMetro.lpr"/>
     
    9797        <UnitName Value="UTrack"/>
    9898      </Unit4>
     99      <Unit5>
     100        <Filename Value="UMetaCanvas.pas"/>
     101        <IsPartOfProject Value="True"/>
     102        <UnitName Value="UMetaCanvas"/>
     103      </Unit5>
    99104    </Units>
    100105  </ProjectOptions>
  • trunk/BigMetro.lpr

    r25 r29  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, SysUtils, UFormMain, UEngine, UGeometric, UTrack
     10  Forms, SysUtils, UFormMain, UEngine, UGeometric, UTrack, UMetaCanvas
    1111  { you can add units after this };
    1212
  • trunk/UEngine.pas

    r28 r29  
    4343  TMapStations = class(TObjectList)
    4444    Engine: TEngine;
     45    function GetRect: TRect;
    4546    function AddNew: TMapStation;
    4647  end;
     
    186187  end;
    187188
     189  { TRiver }
     190
     191  TRiver = class
     192    Points: array of TPoint;
     193    procedure Paint(Canvas: TCanvas);
     194  end;
     195
     196  TRivers = class(TObjectList)
     197  end;
     198
    188199  TMap = class
    189200    Size: TPoint;
     201    Rivers: TRivers;
     202    constructor Create;
     203    destructor Destroy; override;
    190204  end;
    191205
     
    267281  clOrange = TColor($0080ff);
    268282  clBrown = TColor($003090);
    269   LineColors: array[0..7] of TColor = (clBlue, clRed, clDarkYellow, clGreen,
    270     clPurple, clGray, clOrange, clBrown);
     283  clCyan = TColor($FFFF00);
     284  LineColors: array[0..8] of TColor = (clBlue, clRed, clDarkYellow, clGreen,
     285    clPurple, clGray, clOrange, clBrown, clCyan);
    271286  StationSize = 30;
    272287  StationOverloadSize = 60;
     
    303318  SZeroZoomNotAlowed = 'Zero zoom not allowed';
    304319
     320{ TRiver }
     321
     322procedure TRiver.Paint(Canvas: TCanvas);
     323begin
     324  Canvas.Brush.Color := $ffffe0;
     325  Canvas.Brush.Style := bsSolid;
     326  Canvas.Polygon(Points);
     327end;
     328
     329{ TMap }
     330
     331constructor TMap.Create;
     332begin
     333  Rivers := TRivers.Create;
     334end;
     335
     336destructor TMap.Destroy;
     337begin
     338  Rivers.Free;
     339  inherited Destroy;
     340end;
     341
    305342{ TView }
    306343
     
    486523
    487524{ TMapStations }
     525
     526function TMapStations.GetRect: TRect;
     527var
     528  I: Integer;
     529begin
     530  if Count > 0 then begin
     531    with TMapStation(Items[0]) do
     532      Result := Rect(Position.X, Position.Y, Position.X, Position.Y);
     533    for I := 1 to Count - 1 do
     534    with TMapStation(Items[I]) do begin
     535      if Position.X < Result.Left then Result.Left := Position.X;
     536      if Position.X > Result.Right then Result.Right := Position.X;
     537      if Position.Y < Result.Top then Result.Top := Position.Y;
     538      if Position.Y > Result.Bottom then Result.Bottom := Position.Y;
     539    end;
     540  end else Result := Rect(0, 0, 0, 0);
     541end;
    488542
    489543function TMapStations.AddNew: TMapStation;
     
    15641618    LastNewStationTime := Time;
    15651619    Stations.AddNew;
     1620    // Need to see all stations on screen
     1621    View.SourceRect := RectEnlarge(Stations.GetRect, 70);
    15661622  end;
    15671623
     
    15791635      while (Passenger.Shape = Passenger.Station.Shape) or not (Passenger.Shape in GetExistStationShapes) do
    15801636        Passenger.Shape := TStationShape((Integer(Passenger.Shape) + 1) mod Integer(ShapeCount));
    1581 
    15821637    end;
    15831638  end;
     
    16841739        SelectedTrain.BaseTrackPoint := FocusedTrack.PointUp;
    16851740      end;
     1741      FocusedTrack.Free;
    16861742    end;
    16871743
     
    17611817      Exit;
    17621818    end;
     1819    if Assigned(Track) then Track.Free;
    17631820
    17641821    // New track creation from selected station as start
     
    17921849
    17931850  // Start with 3 stations with each different shape
    1794   InitialStationCount := 30;
     1851  InitialStationCount := 3;
    17951852  for I := 0 to InitialStationCount - 1 do begin
    17961853    NewStation := Stations.AddNew;
     
    18001857  end;
    18011858
    1802   for I := 0 to 7 do begin
     1859  for I := 0 to 8 do begin
    18031860    Lines.AddNew;
    18041861    NewTrain := TMetroTrain.Create;
  • trunk/UGeometric.pas

    r28 r29  
    2323function ArcTanPoint(Point: TPoint): Float;
    2424function RectEquals(A, B: TRect): Boolean;
     25function RectEnlarge(Rect: TRect; Value: Integer): TRect;
    2526
    2627implementation
     
    132133end;
    133134
     135function RectEnlarge(Rect: TRect; Value: Integer): TRect;
     136begin
     137  Rect.Left := Rect.Left - Value;
     138  Rect.Right := Rect.Right + Value;
     139  Rect.Top := Rect.Top - Value;
     140  Rect.Bottom := Rect.Bottom + Value;
     141end;
     142
    134143
    135144end.
Note: See TracChangeset for help on using the changeset viewer.