summaryrefslogtreecommitdiffhomepage
path: root/examples/web/core/core_input_gestures.c
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-18 01:27:54 +0200
committerRay <[email protected]>2019-05-18 01:27:54 +0200
commit210d5ec72bbc4ba426b21f69e6f65b6d75923d05 (patch)
treec01f6e14d673504534602c7ae9609b3dff248806 /examples/web/core/core_input_gestures.c
parent85b11a6baf64a2b4e02c81d4d47b15eb578dc074 (diff)
downloadraylib.com-210d5ec72bbc4ba426b21f69e6f65b6d75923d05.tar.gz
raylib.com-210d5ec72bbc4ba426b21f69e6f65b6d75923d05.zip
Update examples to raylib 2.5 -WIP-
Remove old examples
Diffstat (limited to 'examples/web/core/core_input_gestures.c')
-rw-r--r--examples/web/core/core_input_gestures.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/examples/web/core/core_input_gestures.c b/examples/web/core/core_input_gestures.c
new file mode 100644
index 0000000..507fb3b
--- /dev/null
+++ b/examples/web/core/core_input_gestures.c
@@ -0,0 +1,146 @@
+/*******************************************************************************************
+*
+* raylib [core] example - Input Gestures Detection
+*
+* This example has been created using raylib 1.4 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2016 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+#include <string.h>
+
+#if defined(PLATFORM_WEB)
+ #include <emscripten/emscripten.h>
+#endif
+
+#define MAX_GESTURE_STRINGS 20
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+const int screenWidth = 800;
+const int screenHeight = 450;
+
+// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
+
+Vector2 touchPosition = { 0.0f };
+Rectangle touchArea = { 0 };
+
+int gesturesCount = 0;
+char gestureStrings[MAX_GESTURE_STRINGS][32];
+
+int currentGesture = GESTURE_NONE;
+int lastGesture = GESTURE_NONE;
+
+//----------------------------------------------------------------------------------
+// Module Functions Declaration
+//----------------------------------------------------------------------------------
+void UpdateDrawFrame(void); // Update and Draw one frame
+
+//----------------------------------------------------------------------------------
+// Main Enry Point
+//----------------------------------------------------------------------------------
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures");
+
+ touchArea = (Rectangle){ 220, 10, screenWidth - 230, screenHeight - 20 };
+
+ //SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
+
+#if defined(PLATFORM_WEB)
+ emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
+#else
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ UpdateDrawFrame();
+ }
+#endif
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition
+//----------------------------------------------------------------------------------
+void UpdateDrawFrame(void)
+{
+ // Update
+ //----------------------------------------------------------------------------------
+ lastGesture = currentGesture;
+ currentGesture = GetGestureDetected();
+ touchPosition = GetTouchPosition(0);
+
+ if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != GESTURE_NONE))
+ {
+ if (currentGesture != lastGesture)
+ {
+ // Store gesture string
+ switch (currentGesture)
+ {
+ case GESTURE_TAP: strcpy(gestureStrings[gesturesCount], "GESTURE TAP"); break;
+ case GESTURE_DOUBLETAP: strcpy(gestureStrings[gesturesCount], "GESTURE DOUBLETAP"); break;
+ case GESTURE_HOLD: strcpy(gestureStrings[gesturesCount], "GESTURE HOLD"); break;
+ case GESTURE_DRAG: strcpy(gestureStrings[gesturesCount], "GESTURE DRAG"); break;
+ case GESTURE_SWIPE_RIGHT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE RIGHT"); break;
+ case GESTURE_SWIPE_LEFT: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE LEFT"); break;
+ case GESTURE_SWIPE_UP: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE UP"); break;
+ case GESTURE_SWIPE_DOWN: strcpy(gestureStrings[gesturesCount], "GESTURE SWIPE DOWN"); break;
+ case GESTURE_PINCH_IN: strcpy(gestureStrings[gesturesCount], "GESTURE PINCH IN"); break;
+ case GESTURE_PINCH_OUT: strcpy(gestureStrings[gesturesCount], "GESTURE PINCH OUT"); break;
+ default: break;
+ }
+
+ gesturesCount++;
+
+ // Reset gestures strings
+ if (gesturesCount >= MAX_GESTURE_STRINGS)
+ {
+ for (int i = 0; i < MAX_GESTURE_STRINGS; i++) strcpy(gestureStrings[i], "\0");
+
+ gesturesCount = 0;
+ }
+ }
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawRectangleRec(touchArea, GRAY);
+ DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, RAYWHITE);
+
+ DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, Fade(GRAY, 0.5f));
+
+ for (int i = 0; i < gesturesCount; i++)
+ {
+ if (i%2 == 0) DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.5f));
+ else DrawRectangle(10, 30 + 20*i, 200, 20, Fade(LIGHTGRAY, 0.3f));
+
+ if (i < gesturesCount - 1) DrawText(gestureStrings[i], 35, 36 + 20*i, 10, DARKGRAY);
+ else DrawText(gestureStrings[i], 35, 36 + 20*i, 10, MAROON);
+ }
+
+ DrawRectangleLines(10, 29, 200, screenHeight - 50, GRAY);
+ DrawText("DETECTED GESTURES", 50, 15, 10, GRAY);
+
+ if (currentGesture != GESTURE_NONE) DrawCircleV(touchPosition, 30, MAROON);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+}