| 1 | /******************************************************************************************* |
| 2 | * |
| 3 | * raylib [core] example - Input multitouch |
| 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 | * Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5) |
| 9 | * |
| 10 | * Copyright (c) 2019 Berni (@Berni8k) and Ramon Santamaria (@raysan5) |
| 11 | * |
| 12 | ********************************************************************************************/ |
| 13 | |
| 14 | #include "raylib.h" |
| 15 | |
| 16 | int main(void) |
| 17 | { |
| 18 | // Initialization |
| 19 | //-------------------------------------------------------------------------------------- |
| 20 | const int screenWidth = 800; |
| 21 | const int screenHeight = 450; |
| 22 | |
| 23 | InitWindow(screenWidth, screenHeight, "raylib [core] example - input multitouch" ); |
| 24 | |
| 25 | Vector2 ballPosition = { -100.0f, -100.0f }; |
| 26 | Color ballColor = BEIGE; |
| 27 | |
| 28 | int touchCounter = 0; |
| 29 | Vector2 touchPosition = { 0.0f }; |
| 30 | |
| 31 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
| 32 | //--------------------------------------------------------------------------------------- |
| 33 | |
| 34 | // Main game loop |
| 35 | while (!WindowShouldClose()) // Detect window close button or ESC key |
| 36 | { |
| 37 | // Update |
| 38 | //---------------------------------------------------------------------------------- |
| 39 | ballPosition = GetMousePosition(); |
| 40 | |
| 41 | ballColor = BEIGE; |
| 42 | |
| 43 | if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) ballColor = MAROON; |
| 44 | if (IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) ballColor = LIME; |
| 45 | if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE; |
| 46 | |
| 47 | if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) touchCounter = 10; |
| 48 | if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) touchCounter = 10; |
| 49 | if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) touchCounter = 10; |
| 50 | |
| 51 | if (touchCounter > 0) touchCounter--; |
| 52 | //---------------------------------------------------------------------------------- |
| 53 | |
| 54 | // Draw |
| 55 | //---------------------------------------------------------------------------------- |
| 56 | BeginDrawing(); |
| 57 | |
| 58 | ClearBackground(RAYWHITE); |
| 59 | |
| 60 | // Multitouch |
| 61 | for (int i = 0; i < MAX_TOUCH_POINTS; ++i) |
| 62 | { |
| 63 | touchPosition = GetTouchPosition(i); // Get the touch point |
| 64 | |
| 65 | if ((touchPosition.x >= 0) && (touchPosition.y >= 0)) // Make sure point is not (-1,-1) as this means there is no touch for it |
| 66 | { |
| 67 | // Draw circle and touch index number |
| 68 | DrawCircleV(touchPosition, 34, ORANGE); |
| 69 | DrawText(FormatText("%d" , i), touchPosition.x - 10, touchPosition.y - 70, 40, BLACK); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Draw the normal mouse location |
| 74 | DrawCircleV(ballPosition, 30 + (touchCounter*3), ballColor); |
| 75 | |
| 76 | DrawText("move ball with mouse and click mouse button to change color" , 10, 10, 20, DARKGRAY); |
| 77 | DrawText("touch the screen at multiple locations to get multiple balls" , 10, 30, 20, DARKGRAY); |
| 78 | |
| 79 | EndDrawing(); |
| 80 | //---------------------------------------------------------------------------------- |
| 81 | } |
| 82 | |
| 83 | // De-Initialization |
| 84 | //-------------------------------------------------------------------------------------- |
| 85 | CloseWindow(); // Close window and OpenGL context |
| 86 | //-------------------------------------------------------------------------------------- |
| 87 | |
| 88 | return 0; |
| 89 | } |