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.

89 lines
3.5 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Multitouch input
  4. *
  5. * This example has been created using raylib 2.1 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. * Example by Berni
  10. *
  11. ********************************************************************************************/
  12. #include "raylib.h"
  13. #include <stdio.h>
  14. int main()
  15. {
  16. // Initialization
  17. //--------------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. InitWindow(screenWidth, screenHeight, "raylib [core] example - multitouch input");
  21. Vector2 ballPosition = { -100.0f, -100.0f };
  22. Color ballColor;
  23. int PressedCounter = 0;
  24. Vector2 TouchPos;
  25. char Str[16];
  26. SetTargetFPS(60);
  27. //---------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. ballPosition = GetMousePosition();
  34. ballColor = BEIGE;
  35. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
  36. if (IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
  37. if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
  38. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) PressedCounter = 10;
  39. if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) PressedCounter = 10;
  40. if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) PressedCounter = 10;
  41. if(PressedCounter > 0)
  42. PressedCounter--;
  43. //----------------------------------------------------------------------------------
  44. // Draw
  45. //----------------------------------------------------------------------------------
  46. BeginDrawing();
  47. ClearBackground(RAYWHITE);
  48. // Multitouch
  49. for (int i = 0; i < MAX_TOUCH_POINTS; ++i)
  50. {
  51. TouchPos = GetTouchPosition(i); // Get the touch point
  52. if( (TouchPos.x >= 0) && (TouchPos.y >= 0) ) // Make sure point is not (-1,-1) as this means there is no touch for it
  53. {
  54. DrawCircleV(TouchPos, 34, ORANGE); // Draw a circle there
  55. sprintf(Str,"%d",i);
  56. DrawText(Str, TouchPos.x - 10, TouchPos.y - 70, 40, BLACK); // Also show its index number
  57. }
  58. }
  59. // Draw the normal mouse location
  60. DrawCircleV(ballPosition, 30 + (PressedCounter * 3), ballColor);
  61. DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
  62. DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, DARKGRAY);
  63. EndDrawing();
  64. //----------------------------------------------------------------------------------
  65. }
  66. // De-Initialization
  67. //--------------------------------------------------------------------------------------
  68. CloseWindow(); // Close window and OpenGL context
  69. //--------------------------------------------------------------------------------------
  70. return 0;
  71. }