mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
EXAMPLES: Format tweaks
This commit is contained in:
@ -69,7 +69,7 @@ int main(void)
|
||||
|
||||
// Draw line Cubic Bezier, in-out interpolation (easing), no control points
|
||||
DrawLineBezier(startPoint, endPoint, 4.0f, BLUE);
|
||||
|
||||
|
||||
// Draw start-end spline circles with some details
|
||||
DrawCircleV(startPoint, CheckCollisionPointCircle(mouse, startPoint, 10.0f)? 14.0f : 8.0f, moveStartPoint? RED : BLUE);
|
||||
DrawCircleV(endPoint, CheckCollisionPointCircle(mouse, endPoint, 10.0f)? 14.0f : 8.0f, moveEndPoint? RED : BLUE);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shapes] example - Draw raylib logo using basic shapes
|
||||
* raylib [shapes] example - draw raylib logo using basic shapes
|
||||
*
|
||||
* Example complexity rating: [★☆☆☆] 1/4
|
||||
*
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shapes] example - Rectangle advanced
|
||||
* raylib [shapes] example - advanced rectangle drawing
|
||||
*
|
||||
* Example complexity rating: [★★★★] 4/4
|
||||
*
|
||||
@ -33,9 +33,9 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - rectangle avanced");
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@ -195,7 +195,7 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
||||
}
|
||||
|
||||
// Here we use the 'Diagram' to guide ourselves to which point receives what color
|
||||
// By choosing the color correctly associated with a pointe the gradient effect
|
||||
// By choosing the color correctly associated with a pointe the gradient effect
|
||||
// will naturally come from OpenGL interpolation
|
||||
|
||||
// [2] Upper Rectangle
|
||||
@ -266,7 +266,7 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
||||
#else
|
||||
|
||||
// Here we use the 'Diagram' to guide ourselves to which point receives what color.
|
||||
// By choosing the color correctly associated with a pointe the gradient effect
|
||||
// By choosing the color correctly associated with a pointe the gradient effect
|
||||
// will naturally come from OpenGL interpolation.
|
||||
// But this time instead of Quad, we think in triangles.
|
||||
|
||||
@ -280,10 +280,10 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
||||
if (k == 1) color = right, radius = radiusRight; // [3] Upper Right Corner
|
||||
if (k == 2) color = right, radius = radiusRight; // [5] Lower Right Corner
|
||||
if (k == 3) color = left, radius = radiusLeft; // [7] Lower Left Corner
|
||||
|
||||
|
||||
float angle = angles[k];
|
||||
const Vector2 center = centers[k];
|
||||
|
||||
|
||||
for (int i = 0; i < segments; i++)
|
||||
{
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
@ -65,7 +65,7 @@ int main(void)
|
||||
// Check minimum rec size
|
||||
if (rec.width < MOUSE_SCALE_MARK_SIZE) rec.width = MOUSE_SCALE_MARK_SIZE;
|
||||
if (rec.height < MOUSE_SCALE_MARK_SIZE) rec.height = MOUSE_SCALE_MARK_SIZE;
|
||||
|
||||
|
||||
// Check maximum rec size
|
||||
if (rec.width > (GetScreenWidth() - rec.x)) rec.width = GetScreenWidth() - rec.x;
|
||||
if (rec.height > (GetScreenHeight() - rec.y)) rec.height = GetScreenHeight() - rec.y;
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
#define MAX_SPLINE_POINTS 32
|
||||
|
||||
// Cubic Bezier spline control points
|
||||
// NOTE: Every segment has two control points
|
||||
// NOTE: Every segment has two control points
|
||||
typedef struct {
|
||||
Vector2 start;
|
||||
Vector2 end;
|
||||
@ -57,17 +57,17 @@ int main(void)
|
||||
{ 520.0f, 60.0f },
|
||||
{ 710.0f, 260.0f },
|
||||
};
|
||||
|
||||
// Array required for spline bezier-cubic,
|
||||
|
||||
// Array required for spline bezier-cubic,
|
||||
// including control points interleaved with start-end segment points
|
||||
Vector2 pointsInterleaved[3*(MAX_SPLINE_POINTS - 1) + 1] = { 0 };
|
||||
|
||||
|
||||
int pointCount = 5;
|
||||
int selectedPoint = -1;
|
||||
int focusedPoint = -1;
|
||||
Vector2 *selectedControlPoint = NULL;
|
||||
Vector2 *focusedControlPoint = NULL;
|
||||
|
||||
|
||||
// Cubic Bezier control points initialization
|
||||
ControlPoint control[MAX_SPLINE_POINTS-1] = { 0 };
|
||||
for (int i = 0; i < pointCount - 1; i++)
|
||||
@ -79,9 +79,9 @@ int main(void)
|
||||
// Spline config variables
|
||||
float splineThickness = 8.0f;
|
||||
int splineTypeActive = SPLINE_LINEAR; // 0-Linear, 1-BSpline, 2-CatmullRom, 3-Bezier
|
||||
bool splineTypeEditMode = false;
|
||||
bool splineTypeEditMode = false;
|
||||
bool splineHelpersActive = true;
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@ -114,14 +114,14 @@ int main(void)
|
||||
}
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectedPoint = focusedPoint;
|
||||
}
|
||||
|
||||
|
||||
// Spline point movement logic
|
||||
if (selectedPoint >= 0)
|
||||
{
|
||||
points[selectedPoint] = GetMousePosition();
|
||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedPoint = -1;
|
||||
}
|
||||
|
||||
|
||||
// Cubic Bezier spline control points logic
|
||||
if ((splineTypeActive == SPLINE_BEZIER) && (focusedPoint == -1))
|
||||
{
|
||||
@ -144,7 +144,7 @@ int main(void)
|
||||
}
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectedControlPoint = focusedControlPoint;
|
||||
}
|
||||
|
||||
|
||||
// Spline control point movement logic
|
||||
if (selectedControlPoint != NULL)
|
||||
{
|
||||
@ -152,7 +152,7 @@ int main(void)
|
||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) selectedControlPoint = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Spline selection logic
|
||||
if (IsKeyPressed(KEY_ONE)) splineTypeActive = 0;
|
||||
else if (IsKeyPressed(KEY_TWO)) splineTypeActive = 1;
|
||||
@ -168,7 +168,7 @@ int main(void)
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
if (splineTypeActive == SPLINE_LINEAR)
|
||||
{
|
||||
// Draw spline: linear
|
||||
@ -191,7 +191,7 @@ int main(void)
|
||||
{
|
||||
// Draw spline: catmull-rom
|
||||
DrawSplineCatmullRom(points, pointCount, splineThickness, RED); // Provide connected points array
|
||||
|
||||
|
||||
/*
|
||||
for (int i = 0; i < (pointCount - 3); i++)
|
||||
{
|
||||
@ -202,20 +202,20 @@ int main(void)
|
||||
}
|
||||
else if (splineTypeActive == SPLINE_BEZIER)
|
||||
{
|
||||
// NOTE: Cubic-bezier spline requires the 2 control points of each segnment to be
|
||||
// NOTE: Cubic-bezier spline requires the 2 control points of each segnment to be
|
||||
// provided interleaved with the start and end point of every segment
|
||||
for (int i = 0; i < (pointCount - 1); i++)
|
||||
for (int i = 0; i < (pointCount - 1); i++)
|
||||
{
|
||||
pointsInterleaved[3*i] = points[i];
|
||||
pointsInterleaved[3*i + 1] = control[i].start;
|
||||
pointsInterleaved[3*i + 2] = control[i].end;
|
||||
}
|
||||
|
||||
|
||||
pointsInterleaved[3*(pointCount - 1)] = points[pointCount - 1];
|
||||
|
||||
// Draw spline: cubic-bezier (with control points)
|
||||
DrawSplineBezierCubic(pointsInterleaved, 3*(pointCount - 1) + 1, splineThickness, RED);
|
||||
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 3*(pointCount - 1); i += 3)
|
||||
{
|
||||
@ -234,7 +234,7 @@ int main(void)
|
||||
else if (focusedControlPoint == &control[i].end) DrawCircleV(control[i].end, 8, GREEN);
|
||||
DrawLineEx(points[i], control[i].start, 1.0f, LIGHTGRAY);
|
||||
DrawLineEx(points[i + 1], control[i].end, 1.0f, LIGHTGRAY);
|
||||
|
||||
|
||||
// Draw spline control lines
|
||||
DrawLineV(points[i], control[i].start, GRAY);
|
||||
//DrawLineV(control[i].start, control[i].end, LIGHTGRAY);
|
||||
@ -258,7 +258,7 @@ int main(void)
|
||||
|
||||
// Check all possible UI states that require controls lock
|
||||
if (splineTypeEditMode || (selectedPoint != -1) || (selectedControlPoint != NULL)) GuiLock();
|
||||
|
||||
|
||||
// Draw spline config
|
||||
GuiLabel((Rectangle){ 12, 62, 140, 24 }, TextFormat("Spline thickness: %i", (int)splineThickness));
|
||||
GuiSliderBar((Rectangle){ 12, 60 + 24, 140, 16 }, NULL, NULL, &splineThickness, 1.0f, 40.0f);
|
||||
@ -269,7 +269,7 @@ int main(void)
|
||||
|
||||
GuiLabel((Rectangle){ 12, 10, 140, 24 }, "Spline type:");
|
||||
if (GuiDropdownBox((Rectangle){ 12, 8 + 24, 140, 28 }, "LINEAR;BSPLINE;CATMULLROM;BEZIER", &splineTypeActive, splineTypeEditMode)) splineTypeEditMode = !splineTypeEditMode;
|
||||
|
||||
|
||||
GuiUnlock();
|
||||
|
||||
EndDrawing();
|
||||
|
||||
@ -55,7 +55,7 @@ LightInfo lights[MAX_LIGHTS] = { 0 };
|
||||
void MoveLight(int slot, float x, float y)
|
||||
{
|
||||
lights[slot].dirty = true;
|
||||
lights[slot].position.x = x;
|
||||
lights[slot].position.x = x;
|
||||
lights[slot].position.y = y;
|
||||
|
||||
// update the cached bounds
|
||||
@ -99,7 +99,7 @@ void DrawLightMask(int slot)
|
||||
|
||||
// If we are valid, then draw the light radius to the alpha mask
|
||||
if (lights[slot].valid) DrawCircleGradient((int)lights[slot].position.x, (int)lights[slot].position.y, lights[slot].outerRadius, ColorAlpha(WHITE, 0), WHITE);
|
||||
|
||||
|
||||
rlDrawRenderBatchActive();
|
||||
|
||||
// Cut out the shadows from the light radius by forcing the alpha to maximum
|
||||
@ -114,7 +114,7 @@ void DrawLightMask(int slot)
|
||||
}
|
||||
|
||||
rlDrawRenderBatchActive();
|
||||
|
||||
|
||||
// Go back to normal blend mode
|
||||
rlSetBlendMode(BLEND_ALPHA);
|
||||
|
||||
@ -156,7 +156,7 @@ bool UpdateLight(int slot, Rectangle* boxes, int count)
|
||||
if (!CheckCollisionRecs(lights[slot].bounds, boxes[i])) continue;
|
||||
|
||||
// Check the edges that are on the same side we are, and cast shadow volumes out from them
|
||||
|
||||
|
||||
// Top
|
||||
Vector2 sp = (Vector2){ boxes[i].x, boxes[i].y };
|
||||
Vector2 ep = (Vector2){ boxes[i].x + boxes[i].width, boxes[i].y };
|
||||
@ -219,7 +219,7 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - top down lights");
|
||||
|
||||
// Initialize our 'world' of boxes
|
||||
@ -274,7 +274,7 @@ int main(void)
|
||||
{
|
||||
// Build up the light mask
|
||||
BeginTextureMode(lightMask);
|
||||
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
// Force the blend mode to only set the alpha of the destination
|
||||
@ -300,10 +300,10 @@ int main(void)
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
// Draw the tile background
|
||||
DrawTextureRec(backgroundTexture, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, Vector2Zero(), WHITE);
|
||||
|
||||
|
||||
// Overlay the shadows from all the lights
|
||||
DrawTextureRec(lightMask.texture, (Rectangle){ 0, 0, (float)GetScreenWidth(), -(float)GetScreenHeight() }, Vector2Zero(), ColorAlpha(WHITE, showLines? 0.75f : 1.0f));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user