@@ -182,53 +182,26 @@ void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color colo
182182 rlEnd ();
183183}
184184
185- void DrawLineDashed (Vector2 startPos , Vector2 endPos , int dashSize , int whiteSpaceSize , Color color )
185+ // Draw a line defining thickness
186+ void DrawLineEx (Vector2 startPos , Vector2 endPos , float thick , Color color )
186187{
187- // Calculate the vector and length of the line
188- float dx = endPos .x - startPos .x ;
189- float dy = endPos .y - startPos .y ;
190- float lineLength = sqrtf (dx * dx + dy * dy );
191-
192- // If the line is too short for dashing or dash size is invalid, draw a solid thick line
193- if (lineLength < (dashSize + whiteSpaceSize ) || dashSize <= 0 )
194- {
195- DrawLineV (startPos , endPos , color );
196- return ;
197- }
198-
199- // Calculate the normalized direction vector of the line
200- float invLineLength = 1 / lineLength ;
201- float dirX = dx * invLineLength ;
202- float dirY = dy * invLineLength ;
203-
204- Vector2 currentPos = startPos ;
205- float distanceTraveled = 0 ;
206-
207- rlBegin (RL_LINES );
208- rlColor4ub (color .r , color .g , color .b , color .a );
188+ Vector2 delta = { endPos .x - startPos .x , endPos .y - startPos .y };
189+ float length = sqrtf (delta .x * delta .x + delta .y * delta .y );
209190
210- while ( distanceTraveled < lineLength )
191+ if (( length > 0 ) && ( thick > 0 ) )
211192 {
212- // Calculate the end of the current dash
213- float dashEndDist = distanceTraveled + dashSize ;
214- if (dashEndDist > lineLength )
215- {
216- dashEndDist = lineLength ;
217- }
218-
219- Vector2 dashEndPos = { startPos .x + dashEndDist * dirX , startPos .y + dashEndDist * dirY };
193+ float scale = thick /(2 * length );
220194
221- // Draw the dash segment
222- rlVertex2f (currentPos .x , currentPos .y );
223- rlVertex2f (dashEndPos .x , dashEndPos .y );
195+ Vector2 radius = { - scale * delta .y , scale * delta .x };
196+ Vector2 strip [4 ] = {
197+ { startPos .x - radius .x , startPos .y - radius .y },
198+ { startPos .x + radius .x , startPos .y + radius .y },
199+ { endPos .x - radius .x , endPos .y - radius .y },
200+ { endPos .x + radius .x , endPos .y + radius .y }
201+ };
224202
225- // Update the distance traveled and move the current position for the next dash
226- distanceTraveled = dashEndDist + whiteSpaceSize ;
227- currentPos .x = startPos .x + distanceTraveled * dirX ;
228- currentPos .y = startPos .y + distanceTraveled * dirY ;
203+ DrawTriangleStrip (strip , 4 , color );
229204 }
230-
231- rlEnd ();
232205}
233206
234207// Draw a line (using gl lines)
@@ -295,26 +268,50 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
295268 DrawTriangleStrip (points , 2 * SPLINE_SEGMENT_DIVISIONS + 2 , color );
296269}
297270
298- // Draw a line defining thickness
299- void DrawLineEx (Vector2 startPos , Vector2 endPos , float thick , Color color )
271+ // Draw a dashed line
272+ void DrawLineDashed (Vector2 startPos , Vector2 endPos , int dashSize , int spaceSize , Color color )
300273{
301- Vector2 delta = { endPos .x - startPos .x , endPos .y - startPos .y };
302- float length = sqrtf (delta .x * delta .x + delta .y * delta .y );
274+ // Calculate the vector and length of the line
275+ float dx = endPos .x - startPos .x ;
276+ float dy = endPos .y - startPos .y ;
277+ float lineLength = sqrtf (dx * dx + dy * dy );
303278
304- if ((length > 0 ) && (thick > 0 ))
279+ // If the line is too short for dashing or dash size is invalid, draw a solid thick line
280+ if ((lineLength < (dashSize + spaceSize )) || (dashSize <= 0 ))
305281 {
306- float scale = thick /(2 * length );
282+ DrawLineV (startPos , endPos , color );
283+ return ;
284+ }
307285
308- Vector2 radius = { - scale * delta .y , scale * delta .x };
309- Vector2 strip [4 ] = {
310- { startPos .x - radius .x , startPos .y - radius .y },
311- { startPos .x + radius .x , startPos .y + radius .y },
312- { endPos .x - radius .x , endPos .y - radius .y },
313- { endPos .x + radius .x , endPos .y + radius .y }
314- };
286+ // Calculate the normalized direction vector of the line
287+ float invLineLength = 1.0f /lineLength ;
288+ float dirX = dx * invLineLength ;
289+ float dirY = dy * invLineLength ;
315290
316- DrawTriangleStrip (strip , 4 , color );
317- }
291+ Vector2 currentPos = startPos ;
292+ float distanceTraveled = 0 ;
293+
294+ rlBegin (RL_LINES );
295+ rlColor4ub (color .r , color .g , color .b , color .a );
296+
297+ while (distanceTraveled < lineLength )
298+ {
299+ // Calculate the end of the current dash
300+ float dashEndDist = distanceTraveled + dashSize ;
301+ if (dashEndDist > lineLength ) dashEndDist = lineLength ;
302+
303+ Vector2 dashEndPos = { startPos .x + dashEndDist * dirX , startPos .y + dashEndDist * dirY };
304+
305+ // Draw the dash segment
306+ rlVertex2f (currentPos .x , currentPos .y );
307+ rlVertex2f (dashEndPos .x , dashEndPos .y );
308+
309+ // Update the distance traveled and move the current position for the next dash
310+ distanceTraveled = dashEndDist + spaceSize ;
311+ currentPos .x = startPos .x + distanceTraveled * dirX ;
312+ currentPos .y = startPos .y + distanceTraveled * dirY ;
313+ }
314+ rlEnd ();
318315}
319316
320317// Draw a color-filled circle
0 commit comments