Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

87 wiersze
3.5 KiB

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