@@ -40,7 +40,7 @@ void DDEditorUI::selectObjects(CCArray* objects, bool ignoreFilter) {
4040 DurationDrag::get ()->updateObjects ();
4141}
4242
43- void DurationDragDraw::drawDottedLine (const CCPoint& start, const CCPoint& end, const LineColor& color, float lineWidth , float dashLength , float gapLength ) {
43+ void DurationDragDraw::drawDottedLine (const CCPoint& start, const CCPoint& end, const LineColor& color, float minX , float maxX , float minY, float maxY ) {
4444 float dx = end.x - start.x ;
4545 float dy = end.y - start.y ;
4646 float totalDist = std::sqrt (dx * dx + dy * dy);
@@ -50,16 +50,26 @@ void DurationDragDraw::drawDottedLine(const CCPoint& start, const CCPoint& end,
5050 float dirX = dx / totalDist;
5151 float dirY = dy / totalDist;
5252
53+ constexpr float dashLength = 10 .f ;
54+ constexpr float lineWidth = 2 .f ;
55+ constexpr float gapLength = 5 .f ;
56+
5357 float traveled = 0 .f ;
5458 while (traveled < totalDist) {
5559 float segmentLength = std::min (dashLength, totalDist - traveled);
5660
5761 ccVertex2F segStart = { start.x + dirX * traveled, start.y + dirY * traveled };
5862 ccVertex2F segEnd = { start.x + dirX * (traveled + segmentLength), start.y + dirY * (traveled + segmentLength) };
5963
60- DrawGridAPI::get ().drawLine (segStart, segEnd, color, lineWidth);
64+ if (segStart.x > maxX || segStart.y > maxY) break ;
65+
66+ traveled += (dashLength + gapLength);
6167
62- traveled += dashLength + gapLength;
68+ if (segEnd.x < minX || segEnd.y < minY) {
69+ continue ;
70+ }
71+
72+ DrawGridAPI::get ().drawLine (segStart, segEnd, color, lineWidth);
6373 }
6474}
6575
@@ -127,7 +137,7 @@ void DurationDragDraw::draw(DrawGridLayer* dgl, float minX, float maxX, float mi
127137 end.x = std::max (end.x , 0 .f );
128138 }
129139
130- drawDottedLine (end, centerPoint, {145 , 170 , 255 , 180 });
140+ drawDottedLine (end, centerPoint, {145 , 170 , 255 , 180 }, minX, maxX, minY, maxY );
131141 }
132142 }
133143 }
@@ -150,7 +160,7 @@ void DurationDragDraw::draw(DrawGridLayer* dgl, float minX, float maxX, float mi
150160
151161 if (object->getPositionX () < 0 && !object->m_isSpawnTriggered ) {
152162
153- drawDottedLine (object->getPosition (), {0 , object->getPositionY ()}, color);
163+ drawDottedLine (object->getPosition (), {0 , object->getPositionY ()}, color, minX, maxX, minY, maxY );
154164
155165 if (object->m_objectID == 1006 ) {
156166 drawPulseLine (object, 0 );
0 commit comments