Changeset 3 for trunk/UEngine.pas
- Timestamp:
- Mar 26, 2015, 11:06:50 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.