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.

79 lines
3.3 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Input multitouch
  4. *
  5. * Example originally created with raylib 2.1, last time updated with raylib 2.5
  6. *
  7. * Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
  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) 2019-2024 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. #define MAX_TOUCH_POINTS 10
  17. //------------------------------------------------------------------------------------
  18. // Program main entry point
  19. //------------------------------------------------------------------------------------
  20. int main(void)
  21. {
  22. // Initialization
  23. //--------------------------------------------------------------------------------------
  24. const int screenWidth = 800;
  25. const int screenHeight = 450;
  26. InitWindow(screenWidth, screenHeight, "raylib [core] example - input multitouch");
  27. Vector2 touchPositions[MAX_TOUCH_POINTS] = { 0 };
  28. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  29. //---------------------------------------------------------------------------------------
  30. // Main game loop
  31. while (!WindowShouldClose()) // Detect window close button or ESC key
  32. {
  33. // Update
  34. //----------------------------------------------------------------------------------
  35. // Get the touch point count ( how many fingers are touching the screen )
  36. int tCount = GetTouchPointCount();
  37. // Clamp touch points available ( set the maximum touch points allowed )
  38. if(tCount > MAX_TOUCH_POINTS) tCount = MAX_TOUCH_POINTS;
  39. // Get touch points positions
  40. for (int i = 0; i < tCount; ++i) touchPositions[i] = GetTouchPosition(i);
  41. //----------------------------------------------------------------------------------
  42. // Draw
  43. //----------------------------------------------------------------------------------
  44. BeginDrawing();
  45. ClearBackground(RAYWHITE);
  46. for (int i = 0; i < tCount; ++i)
  47. {
  48. // Make sure point is not (0, 0) as this means there is no touch for it
  49. if ((touchPositions[i].x > 0) && (touchPositions[i].y > 0))
  50. {
  51. // Draw circle and touch index number
  52. DrawCircleV(touchPositions[i], 34, ORANGE);
  53. DrawText(TextFormat("%d", i), (int)touchPositions[i].x - 10, (int)touchPositions[i].y - 70, 40, BLACK);
  54. }
  55. }
  56. DrawText("touch the screen at multiple locations to get multiple balls", 10, 10, 20, DARKGRAY);
  57. EndDrawing();
  58. //----------------------------------------------------------------------------------
  59. }
  60. // De-Initialization
  61. //--------------------------------------------------------------------------------------
  62. CloseWindow(); // Close window and OpenGL context
  63. //--------------------------------------------------------------------------------------
  64. return 0;
  65. }