// This just draws straight track along the rectangle
void Editor::drawDraggedStraight(const ITrackSegment::Direction& anAxis, int aLength)
{
- //for (int i = 0; i <
+ Point<int> where = myDragBegin;
+
+ log() << "drawDraggedStraight " << anAxis << " len=" << aLength;
+
+ for (int i = 0; i < aLength; i++) {
+ myMap->setTrackAt(where, makeStraightTrack(anAxis));
+
+ where.x += anAxis.x;
+ where.y += anAxis.z;
+ }
}
// Called when the user has finished dragging a rectangle for track
int xlen = abs(xmax - xmin) + 1;
int ylen = abs(ymax - ymin) + 1;
-
+log() << "xlen=" << xlen << ", ylen=" << ylen;
if (xlen == 1 && ylen == 1)
drawDraggedTile();
else if (xlen == 1)
- drawDraggedStraight(Axis::Y, ylen);
+ drawDraggedStraight(myDragBegin.y < myDragEnd.y ? Axis::Y : -Axis::Y, ylen);
else if (ylen == 1)
- drawDraggedStraight(Axis::X, xlen);
+ drawDraggedStraight(myDragBegin.x < myDragEnd.x ? Axis::X : -Axis::X, xlen);
/*
// Try to guess the initial orientation from a nearby track segment
if (canConnect(myDragBegin.left(), myDragBegin)
ITrackSegmentPtr makeStraightTrack(const ITrackSegment::Direction& aDirection)
{
- return ITrackSegmentPtr(new StraightTrack(aDirection));
+ ITrackSegment::Direction realDir(aDirection);
+
+ // Direction must either be along Axis::X or Axis::Y but we
+ // allow the opositite direction here too
+ if (realDir == -Axis::X || realDir == -Axis::Y)
+ realDir = -realDir;
+
+ if (realDir != Axis::X && realDir != Axis::Y)
+ throw runtime_error("Illegal straight track direction: "
+ + lexical_cast<string>(aDirection));
+
+ return ITrackSegmentPtr(new StraightTrack(realDir));
}