@@ -101,15 +101,18 @@ int main(void)
101
101
}
102
102
103
103
// Spline point focus and selection logic
104
- for ( int i = 0 ; i < pointCount ; i ++ )
104
+ if (( selectedPoint == -1 ) && (( splineTypeActive != SPLINE_BEZIER ) || ( selectedControlPoint == NULL )) )
105
105
{
106
- if (CheckCollisionPointCircle (GetMousePosition (), points [i ], 8.0f ))
106
+ focusedPoint = -1 ;
107
+ for (int i = 0 ; i < pointCount ; i ++ )
107
108
{
108
- focusedPoint = i ;
109
- if (IsMouseButtonDown (MOUSE_LEFT_BUTTON )) selectedPoint = i ;
110
- break ;
109
+ if (CheckCollisionPointCircle (GetMousePosition (), points [i ], 8.0f ))
110
+ {
111
+ focusedPoint = i ;
112
+ break ;
113
+ }
111
114
}
112
- else focusedPoint = -1 ;
115
+ if ( IsMouseButtonPressed ( MOUSE_LEFT_BUTTON )) selectedPoint = focusedPoint ;
113
116
}
114
117
115
118
// Spline point movement logic
@@ -123,21 +126,23 @@ int main(void)
123
126
if ((splineTypeActive == SPLINE_BEZIER ) && (focusedPoint == -1 ))
124
127
{
125
128
// Spline control point focus and selection logic
126
- for ( int i = 0 ; i < pointCount - 1 ; i ++ )
129
+ if ( selectedControlPoint == NULL )
127
130
{
128
- if (CheckCollisionPointCircle (GetMousePosition (), control [i ].start , 6.0f ))
129
- {
130
- focusedControlPoint = & control [i ].start ;
131
- if (IsMouseButtonDown (MOUSE_LEFT_BUTTON )) selectedControlPoint = & control [i ].start ;
132
- break ;
133
- }
134
- else if (CheckCollisionPointCircle (GetMousePosition (), control [i ].end , 6.0f ))
131
+ focusedControlPoint = NULL ;
132
+ for (int i = 0 ; i < pointCount - 1 ; i ++ )
135
133
{
136
- focusedControlPoint = & control [i ].end ;
137
- if (IsMouseButtonDown (MOUSE_LEFT_BUTTON )) selectedControlPoint = & control [i ].end ;
138
- break ;
134
+ if (CheckCollisionPointCircle (GetMousePosition (), control [i ].start , 6.0f ))
135
+ {
136
+ focusedControlPoint = & control [i ].start ;
137
+ break ;
138
+ }
139
+ else if (CheckCollisionPointCircle (GetMousePosition (), control [i ].end , 6.0f ))
140
+ {
141
+ focusedControlPoint = & control [i ].end ;
142
+ break ;
143
+ }
139
144
}
140
- else focusedControlPoint = NULL ;
145
+ if ( IsMouseButtonPressed ( MOUSE_LEFT_BUTTON )) selectedControlPoint = focusedControlPoint ;
141
146
}
142
147
143
148
// Spline control point movement logic
@@ -153,6 +158,9 @@ int main(void)
153
158
else if (IsKeyPressed (KEY_TWO )) splineTypeActive = 1 ;
154
159
else if (IsKeyPressed (KEY_THREE )) splineTypeActive = 2 ;
155
160
else if (IsKeyPressed (KEY_FOUR )) splineTypeActive = 3 ;
161
+
162
+ // Clear selection when changing to a spline without control points
163
+ if (IsKeyPressed (KEY_ONE ) || IsKeyPressed (KEY_TWO ) || IsKeyPressed (KEY_THREE )) selectedControlPoint = NULL ;
156
164
//----------------------------------------------------------------------------------
157
165
158
166
// Draw
@@ -249,18 +257,20 @@ int main(void)
249
257
}
250
258
251
259
// Check all possible UI states that require controls lock
252
- if (splineTypeEditMode ) GuiLock ();
260
+ if (splineTypeEditMode || ( selectedPoint != -1 ) || ( selectedControlPoint != NULL ) ) GuiLock ();
253
261
254
262
// Draw spline config
255
263
GuiLabel ((Rectangle ){ 12 , 62 , 140 , 24 }, TextFormat ("Spline thickness: %i" , (int )splineThickness ));
256
264
GuiSliderBar ((Rectangle ){ 12 , 60 + 24 , 140 , 16 }, NULL , NULL , & splineThickness , 1.0f , 40.0f );
257
265
258
266
GuiCheckBox ((Rectangle ){ 12 , 110 , 20 , 20 }, "Show point helpers" , & splineHelpersActive );
259
267
260
- GuiUnlock ();
268
+ if ( splineTypeEditMode ) GuiUnlock ();
261
269
262
270
GuiLabel ((Rectangle ){ 12 , 10 , 140 , 24 }, "Spline type:" );
263
271
if (GuiDropdownBox ((Rectangle ){ 12 , 8 + 24 , 140 , 28 }, "LINEAR;BSPLINE;CATMULLROM;BEZIER" , & splineTypeActive , splineTypeEditMode )) splineTypeEditMode = !splineTypeEditMode ;
272
+
273
+ GuiUnlock ();
264
274
265
275
EndDrawing ();
266
276
//----------------------------------------------------------------------------------
0 commit comments