Fixed few stuff about animation curve example (#287)

Co-authored-by: AnstroPleuton <anstro.pleuton@proton.me>
This commit is contained in:
Anstro Pleuton
2023-05-22 00:06:11 +05:30
committed by GitHub
parent 78ad65365e
commit 135718ee04

View File

@ -59,26 +59,26 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
typedef struct { typedef struct {
Vector2 position = (Vector2) {0,0}; // In normalized space [0.f, 1.f] Vector2 position; // In normalized space [0.f, 1.f]
Vector2 tangents = (Vector2) {0,0}; // The derivatives (left/right) of the 1D curve Vector2 tangents; // The derivatives (left/right) of the 1D curve
// Let the curve editor calculate tangents to linearize part of the curve // Let the curve editor calculate tangents to linearize part of the curve
bool leftLinear = false; bool leftLinear;
bool rightLinear = false; bool rightLinear;
} GuiCurveEditPoint; } GuiCurveEditPoint;
typedef struct { typedef struct {
float start = 0; // Value at y = 0 float start; // Value at y = 0
float end = 1; // Value at y = 1 float end; // Value at y = 1
// Always valid (unless you manualy change state's point array) // Always valid (unless you manualy change state's point array). Make sure to set it to -1 before init
int selectedIndex = -1; // -1 before Init int selectedIndex;
// Unsorted array with at least one point (constant curve) // Unsorted array with at least one point (constant curve)
GuiCurveEditPoint points[GUI_CURVE_EDIT_MAX_POINTS]; GuiCurveEditPoint points[GUI_CURVE_EDIT_MAX_POINTS];
int numPoints = 0; int numPoints;
// private part // private part
bool editLeftTangent = false; bool editLeftTangent;
bool editRightTangent = false; bool editRightTangent;
Vector2 mouseOffset = (Vector2) {0,0}; Vector2 mouseOffset;
} GuiCurveEditState; } GuiCurveEditState;
@ -284,7 +284,7 @@ void GuiCurveEdit(GuiCurveEditState *state, Rectangle bounds){
} }
} }
// Select a point // Select a point
else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && hoveredPointIndex != -1 CheckCollisionPointRec(mouse, bounds)){ else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && hoveredPointIndex != -1 && CheckCollisionPointRec(mouse, bounds)){
state->selectedIndex = hoveredPointIndex; state->selectedIndex = hoveredPointIndex;
const GuiCurveEditPoint* p = &state->points[state->selectedIndex]; const GuiCurveEditPoint* p = &state->points[state->selectedIndex];
const Vector2 screenPos = (Vector2){p->position.x*innerBounds.width+innerBounds.x, innerBounds.y+innerBounds.height-p->position.y*innerBounds.height}; const Vector2 screenPos = (Vector2){p->position.x*innerBounds.width+innerBounds.x, innerBounds.y+innerBounds.height-p->position.y*innerBounds.height};