From 7a712d00e656f9e10846b8501bc10bc9760bd3be Mon Sep 17 00:00:00 2001 From: Berni8k Date: Sun, 21 Oct 2018 10:10:50 +0100 Subject: [PATCH] Added multitouch example --- examples/Makefile | 1 + examples/core/core_multitouch.c | 90 ++++++++++++++++++++++++++++++ examples/core/core_multitouch.png | Bin 0 -> 17177 bytes 3 files changed, 91 insertions(+) create mode 100644 examples/core/core_multitouch.c create mode 100644 examples/core/core_multitouch.png diff --git a/examples/Makefile b/examples/Makefile index a7a85661..a26e0bbb 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -375,6 +375,7 @@ EXAMPLES = \ core/core_2d_camera \ core/core_world_screen \ core/core_vr_simulator \ + core/core_multitouch \ shapes/shapes_logo_raylib \ shapes/shapes_basic_shapes \ shapes/shapes_colors_palette \ diff --git a/examples/core/core_multitouch.c b/examples/core/core_multitouch.c new file mode 100644 index 00000000..c059ac03 --- /dev/null +++ b/examples/core/core_multitouch.c @@ -0,0 +1,90 @@ +/******************************************************************************************* +* +* raylib [core] example - Multitouch input +* +* This example has been created using raylib 2.1 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Example by Berni +* +********************************************************************************************/ + +#include "raylib.h" +#include + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - multitouch input"); + + Vector2 ballPosition = { -100.0f, -100.0f }; + Color ballColor; + int PressedCounter = 0; + Vector2 TouchPos; + char Str[16]; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + ballPosition = GetMousePosition(); + + ballColor = BEIGE; + + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) ballColor = MAROON; + if (IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) ballColor = LIME; + if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) PressedCounter = 10; + if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) PressedCounter = 10; + if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) PressedCounter = 10; + if(PressedCounter > 0) + PressedCounter--; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Multitouch + for (int i = 0; i < MAX_TOUCH_POINTS; ++i) + { + TouchPos = GetTouchPosition(i); // Get the touch point + + if( (TouchPos.x >= 0) && (TouchPos.y >= 0) ) // Make sure point is not (-1,-1) as this means there is no touch for it + { + DrawCircleV(TouchPos, 34, ORANGE); // Draw a circle there + + sprintf(Str,"%d",i); + DrawText(Str, TouchPos.x - 10, TouchPos.y - 70, 40, BLACK); // Also show its index number + } + } + + // Draw the normal mouse location + DrawCircleV(ballPosition, 30 + (PressedCounter * 3), ballColor); + + DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); + DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/core/core_multitouch.png b/examples/core/core_multitouch.png new file mode 100644 index 0000000000000000000000000000000000000000..74284f82aa86e62d8d429d4d46e75aab63c0eeba GIT binary patch literal 17177 zcmeHOdt8ip+n{&qN1S4Fh8z@^{VZiv_mFFQ z6iMqlR~6_m<8wx?Qqfq%knf+6njmhJGMH&>PC%k6?n?n(ERqmE!WhaDnessETO>}= zx;Yd!B+BBKZ9Qyvt;qTEsFlS7hxwTOu)E^^kd00?P)4E2UXS@LSdxpuqRm&oq5H{ZeEhR?~?YZR6rN< z_>~tA?pM7Cj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