Changeset 3
- Timestamp:
- Mar 26, 2015, 11:06:50 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BigMetro.lpi
r2 r3 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 3">35 <Units Count="4"> 36 36 <Unit0> 37 37 <Filename Value="BigMetro.lpr"/> 38 38 <IsPartOfProject Value="True"/> 39 <UnitName Value="BigMetro"/>40 39 </Unit0> 41 40 <Unit1> … … 43 42 <IsPartOfProject Value="True"/> 44 43 <ComponentName Value="FormMain"/> 44 <HasResources Value="True"/> 45 45 <ResourceBaseClass Value="Form"/> 46 46 <UnitName Value="UFormMain"/> … … 51 51 <UnitName Value="UEngine"/> 52 52 </Unit2> 53 <Unit3> 54 <Filename Value="UGeometric.pas"/> 55 <IsPartOfProject Value="True"/> 56 <UnitName Value="UGeometric"/> 57 </Unit3> 53 58 </Units> 54 59 </ProjectOptions> -
trunk/BigMetro.lpr
r2 r3 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UFormMain, UEngine 10 Forms, UFormMain, UEngine, UGeometric 11 11 { you can add units after this }; 12 12 -
trunk/UEngine.pas
r2 r3 70 70 TargetStation: TMetroStation; 71 71 function GetPos: TPoint; 72 function GetNextStation: TMetroStation;73 72 constructor Create; 74 73 destructor Destroy; override; … … 115 114 function GetExistStationShapes: TStationShapeSet; 116 115 function GetStationOnPos(Pos: TPoint): TMetroStation; 116 function GetLineOnPos(Pos: TPoint): TMetroLine; 117 117 procedure DrawLine(Canvas: TCanvas; Pos: TPoint); 118 118 procedure DrawShape(Canvas: TCanvas; Position: TPoint; Shape: TStationShape; … … 133 133 procedure Tick; 134 134 procedure MouseMove(Position: TPoint); 135 procedure MouseClick(Button: TMouseButton; Position: TPoint); 135 procedure MouseUp(Button: TMouseButton; Position: TPoint); 136 procedure MouseDown(Button: TMouseButton; Position: TPoint); 136 137 procedure Reset; 137 138 constructor Create; … … 155 156 implementation 156 157 157 158 function Distance(P1, P2: TPoint): Integer; 159 begin 160 Result := Trunc(Sqrt(Sqr(P2.x - P1.X) + Sqr(P2.Y - P1.Y))); 161 end; 158 uses 159 UGeometric; 162 160 163 161 { TMetroPassengers } … … 303 301 end; 304 302 305 function TMetroTrain.GetNextStation: TMetroStation;306 begin307 308 end;309 310 303 constructor TMetroTrain.Create; 311 304 begin … … 361 354 if I < Stations.Count then Result := TMetroStation(Stations[I]) 362 355 else Result := nil; 356 end; 357 358 function TEngine.GetLineOnPos(Pos: TPoint): TMetroLine; 359 var 360 I: Integer; 361 T: Integer; 362 D: Integer; 363 const 364 Distance = 30; 365 begin 366 Result := nil; 367 I := 0; 368 while (I < Lines.Count) do 369 with TMetroLine(Lines[I]) do begin 370 for T := 1 to High(TrackPoints) do begin 371 D := PointToLineDistance(Pos, TrackPoints[T - 1], TrackPoints[T]); 372 if D < Distance then begin 373 Result := TMetroLine(Lines[I]); 374 Break; 375 end; 376 end; 377 if Assigned(Result) then Break; 378 Inc(I); 379 end; 363 380 end; 364 381 … … 515 532 end; 516 533 517 procedure TEngine.Mouse Click(Button: TMouseButton; Position: TPoint);534 procedure TEngine.MouseUp(Button: TMouseButton; Position: TPoint); 518 535 var 519 536 Station: TMetroStation; 537 Line: TMetroLine; 520 538 I: Integer; 521 539 Train: TMetroTrain; 522 540 begin 523 541 if Button = mbLeft then begin 542 // Line color selection 524 543 for I := 0 to Lines.Count - 1 do 525 544 if Distance(Point(View.Size.X div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist, … … 529 548 end; 530 549 550 // Station selection 531 551 Station := GetStationOnPos(Position); 532 552 if Assigned(Station) then 533 if Assigned(SelectedLine) and (SelectedLine.Stations.IndexOf(Station) = -1) then begin 553 if Assigned(SelectedLine) and ((SelectedLine.Stations.IndexOf(Station) = -1) or 554 (((SelectedLine.Stations.First = Station) and (SelectedLine.Stations.Last <> Station)))) then begin 534 555 SelectedLine.Stations.Add(Station); 535 556 Station.Lines.Add(SelectedLine); … … 548 569 end; 549 570 end; 571 Exit 550 572 end; 573 574 // Line selection 575 Line := GetLineOnPos(Position); 576 if Assigned(Line) then begin 577 SelectedLine := Line; 578 Exit; 579 end; 551 580 end; 552 581 if Button = mbRight then begin 553 582 SelectedLine := nil; 554 583 end; 584 end; 585 586 procedure TEngine.MouseDown(Button: TMouseButton; Position: TPoint); 587 begin 588 555 589 end; 556 590 -
trunk/UFormMain.pas
r2 r3 70 70 Shift: TShiftState; X, Y: Integer); 71 71 begin 72 72 Engine.MouseDown(Button, Point(X, Y)); 73 73 end; 74 74 … … 82 82 Shift: TShiftState; X, Y: Integer); 83 83 begin 84 Engine.Mouse Click(Button, Point(X, Y));84 Engine.MouseUp(Button, Point(X, Y)); 85 85 end; 86 86
Note:
See TracChangeset
for help on using the changeset viewer.