You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.5 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - Cubic-bezier lines
  4. *
  5. * Example originally created with raylib 1.7, last time updated with raylib 1.7
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2017-2024 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //--------------------------------------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. SetConfigFlags(FLAG_MSAA_4X_HINT);
  24. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines");
  25. Vector2 startPoint = { 30, 30 };
  26. Vector2 endPoint = { (float)screenWidth - 30, (float)screenHeight - 30 };
  27. bool moveStartPoint = false;
  28. bool moveEndPoint = false;
  29. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. Vector2 mouse = GetMousePosition();
  37. if (CheckCollisionPointCircle(mouse, startPoint, 10.0f) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) moveStartPoint = true;
  38. else if (CheckCollisionPointCircle(mouse, endPoint, 10.0f) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) moveEndPoint = true;
  39. if (moveStartPoint)
  40. {
  41. startPoint = mouse;
  42. if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveStartPoint = false;
  43. }
  44. if (moveEndPoint)
  45. {
  46. endPoint = mouse;
  47. if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveEndPoint = false;
  48. }
  49. //----------------------------------------------------------------------------------
  50. // Draw
  51. //----------------------------------------------------------------------------------
  52. BeginDrawing();
  53. ClearBackground(RAYWHITE);
  54. DrawText("MOVE START-END POINTS WITH MOUSE", 15, 20, 20, GRAY);
  55. // Draw line Cubic Bezier, in-out interpolation (easing), no control points
  56. DrawLineBezier(startPoint, endPoint, 4.0f, BLUE);
  57. // Draw start-end spline circles with some details
  58. DrawCircleV(startPoint, CheckCollisionPointCircle(mouse, startPoint, 10.0f)? 14.0f : 8.0f, moveStartPoint? RED : BLUE);
  59. DrawCircleV(endPoint, CheckCollisionPointCircle(mouse, endPoint, 10.0f)? 14.0f : 8.0f, moveEndPoint? RED : BLUE);
  60. EndDrawing();
  61. //----------------------------------------------------------------------------------
  62. }
  63. // De-Initialization
  64. //--------------------------------------------------------------------------------------
  65. CloseWindow(); // Close window and OpenGL context
  66. //--------------------------------------------------------------------------------------
  67. return 0;
  68. }