REXM: RENAME: example: core_input_gestures_web --> core_input_gestures_testbed

This commit is contained in:
Ray
2025-09-04 15:59:53 +02:00
parent c17f82a78c
commit e21093d434
7 changed files with 121 additions and 116 deletions

View File

@@ -518,7 +518,7 @@ CORE = \
core/core_high_dpi \ core/core_high_dpi \
core/core_input_gamepad \ core/core_input_gamepad \
core/core_input_gestures \ core/core_input_gestures \
core/core_input_gestures_web \ core/core_input_gestures_testbed \
core/core_input_keys \ core/core_input_keys \
core/core_input_mouse \ core/core_input_mouse \
core/core_input_mouse_wheel \ core/core_input_mouse_wheel \

View File

@@ -518,7 +518,7 @@ CORE = \
core/core_high_dpi \ core/core_high_dpi \
core/core_input_gamepad \ core/core_input_gamepad \
core/core_input_gestures \ core/core_input_gestures \
core/core_input_gestures_web \ core/core_input_gestures_testbed \
core/core_input_keys \ core/core_input_keys \
core/core_input_mouse \ core/core_input_mouse \
core/core_input_mouse_wheel \ core/core_input_mouse_wheel \
@@ -737,7 +737,7 @@ core/core_input_gamepad: core/core_input_gamepad.c
core/core_input_gestures: core/core_input_gestures.c core/core_input_gestures: core/core_input_gestures.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
core/core_input_gestures_web: core/core_input_gestures_web.c core/core_input_gestures_testbed: core/core_input_gestures_testbed.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
core/core_input_keys: core/core_input_keys.c core/core_input_keys: core/core_input_keys.c

View File

@@ -56,7 +56,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c
| [core_custom_frame_control](core/core_custom_frame_control.c) | <img src="core/core_custom_frame_control.png" alt="core_custom_frame_control" width="80"> | ⭐⭐⭐⭐️ | 4.0 | 4.0 | [Ramon Santamaria](https://github.com/raysan5) | | [core_custom_frame_control](core/core_custom_frame_control.c) | <img src="core/core_custom_frame_control.png" alt="core_custom_frame_control" width="80"> | ⭐⭐⭐⭐️ | 4.0 | 4.0 | [Ramon Santamaria](https://github.com/raysan5) |
| [core_smooth_pixelperfect](core/core_smooth_pixelperfect.c) | <img src="core/core_smooth_pixelperfect.png" alt="core_smooth_pixelperfect" width="80"> | ⭐⭐⭐☆ | 3.7 | 4.0 | [Giancamillo Alessandroni](https://github.com/NotManyIdeasDev) | | [core_smooth_pixelperfect](core/core_smooth_pixelperfect.c) | <img src="core/core_smooth_pixelperfect.png" alt="core_smooth_pixelperfect" width="80"> | ⭐⭐⭐☆ | 3.7 | 4.0 | [Giancamillo Alessandroni](https://github.com/NotManyIdeasDev) |
| [core_random_sequence](core/core_random_sequence.c) | <img src="core/core_random_sequence.png" alt="core_random_sequence" width="80"> | ⭐☆☆☆ | 5.0 | 5.0 | [Dalton Overmyer](https://github.com/REDl3east) | | [core_random_sequence](core/core_random_sequence.c) | <img src="core/core_random_sequence.png" alt="core_random_sequence" width="80"> | ⭐☆☆☆ | 5.0 | 5.0 | [Dalton Overmyer](https://github.com/REDl3east) |
| [core_input_gestures_web](core/core_input_gestures_web.c) | <img src="core/core_input_gestures_web.png" alt="core_input_gestures_web" width="80"> | ⭐⭐☆☆ | 4.6 | 4.6 | [ubkp](https://github.com/ubkp) | | [core_input_gestures_testbed](core/core_input_gestures_testbed.c) | <img src="core/core_input_gestures_testbed.png" alt="core_input_gestures_testbed" width="80"> | ⭐⭐☆☆ | 4.6 | 4.6 | [ubkp](https://github.com/ubkp) |
| [core_automation_events](core/core_automation_events.c) | <img src="core/core_automation_events.png" alt="core_automation_events" width="80"> | ⭐⭐⭐☆ | 5.0 | 5.0 | [Ramon Santamaria](https://github.com/raysan5) | | [core_automation_events](core/core_automation_events.c) | <img src="core/core_automation_events.png" alt="core_automation_events" width="80"> | ⭐⭐⭐☆ | 5.0 | 5.0 | [Ramon Santamaria](https://github.com/raysan5) |
| [core_high_dpi](core/core_high_dpi.c) | <img src="core/core_high_dpi.png" alt="core_high_dpi" width="80"> | ⭐☆☆☆ | 5.0 | 5.0 | [Jonathan Marler](https://github.com/marler8997) | | [core_high_dpi](core/core_high_dpi.c) | <img src="core/core_high_dpi.png" alt="core_high_dpi" width="80"> | ⭐☆☆☆ | 5.0 | 5.0 | [Jonathan Marler](https://github.com/marler8997) |

View File

@@ -17,91 +17,97 @@
#include "raylib.h" #include "raylib.h"
#include "math.h" // Required for the protractor angle graphic drawing #include <math.h> // Required for the protractor angle graphic drawing
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h> // Required for the Web/HTML5 #include <emscripten/emscripten.h> // Required for the Web/HTML5
#endif #endif
//-------------------------------------------------------------------------------------- #define GESTURE_LOG_SIZE 20
// Global definitions and declarations #define MAX_TOUCH_COUNT 32
//--------------------------------------------------------------------------------------
// Common variables definitions
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; // Update depending on web canvas // Global Variables Definition
const int screenHeight = 450; //--------------------------------------------------------------------------------------
Vector2 messagePosition = { 160, 7 }; static int screenWidth = 800; // Update depending on web canvas
static const int screenHeight = 450;
static Vector2 messagePosition = { 160, 7 };
// Last gesture variables definitions // Last gesture variables definitions
//-------------------------------------------------------------------------------------- static int lastGesture = 0;
int lastGesture = 0; static Vector2 lastGesturePosition = { 165, 130 };
Vector2 lastGesturePosition = { 165, 130 };
// Gesture log variables definitions and functions declarations // Gesture log variables definitions
//-------------------------------------------------------------------------------------- // NOTE: The gesture log uses an array (as an inverted circular queue) to store the performed gestures
#define GESTURE_LOG_SIZE 20 static char gestureLog[GESTURE_LOG_SIZE][12] = { "" };
char gestureLog[GESTURE_LOG_SIZE][12] = { "" }; // The gesture log uses an array (as an inverted circular queue) to store the performed gestures // NOTE: The index for the inverted circular queue (moving from last to first direction, then looping around)
int gestureLogIndex = GESTURE_LOG_SIZE; // The index for the inverted circular queue (moving from last to first direction, then looping around) static int gestureLogIndex = GESTURE_LOG_SIZE;
int previousGesture = 0; static int previousGesture = 0;
char const *GetGestureName(int i) // Log mode values:
{ // - 0 shows repeated events
switch (i) { // - 1 hides repeated events
case 0: return "None"; break; // - 2 shows repeated events but hide hold events
case 1: return "Tap"; break; // - 3 hides repeated events and hide hold events
case 2: return "Double Tap"; break; static int logMode = 1;
case 4: return "Hold"; break;
case 8: return "Drag"; break;
case 16: return "Swipe Right"; break;
case 32: return "Swipe Left"; break;
case 64: return "Swipe Up"; break;
case 128: return "Swipe Down"; break;
case 256: return "Pinch In"; break;
case 512: return "Pinch Out"; break;
default: return "Unknown"; break;
}
}
Color GetGestureColor(int i) static Color gestureColor = { 0, 0, 0, 255 };
{ static Rectangle logButton1 = { 53, 7, 48, 26 };
switch (i) { static Rectangle logButton2 = { 108, 7, 36, 26 };
case 0: return BLACK; break; static Vector2 gestureLogPosition = { 10, 10 };
case 1: return BLUE; break;
case 2: return SKYBLUE; break;
case 4: return BLACK; break;
case 8: return LIME; break;
case 16: return RED; break;
case 32: return RED; break;
case 64: return RED; break;
case 128: return RED; break;
case 256: return VIOLET; break;
case 512: return ORANGE; break;
default: return BLACK; break;
}
}
int logMode = 1; // Log mode values: 0 shows repeated events; 1 hides repeated events; 2 shows repeated events but hide hold events; 3 hides repeated events and hide hold events
Color gestureColor = { 0, 0, 0, 255 };
Rectangle logButton1 = { 53, 7, 48, 26 };
Rectangle logButton2 = { 108, 7, 36, 26 };
Vector2 gestureLogPosition = { 10, 10 };
// Protractor variables definitions // Protractor variables definitions
//-------------------------------------------------------------------------------------- static float angleLength = 90.0f;
float angleLength = 90.0f; static float currentAngleDegrees = 0.0f;
float currentAngleDegrees = 0.0f; static Vector2 finalVector = { 0.0f, 0.0f };
Vector2 finalVector = { 0.0f, 0.0f }; static char currentAngleStr[7] = "";
char currentAngleStr[7] = ""; static Vector2 protractorPosition = { 266.0f, 315.0f };
Vector2 protractorPosition = { 266.0f, 315.0f };
// Update //----------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------- // Module Functions Declaration
void Update(void) //----------------------------------------------------------------------------------
static void UpdateDrawFrame(void); // Update and Draw one frame
static char const *GetGestureName(int i);
static Color GetGestureColor(int i);
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{ {
// Handle common // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures testbed");
#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
//--------------------------------------------------------------------------------------
return 0;
}
//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
static void UpdateDrawFrame(void)
{
// Update
//--------------------------------------------------------------------------------------
// Handle common gestures data
int i, ii; // Iterators that will be reused by all for loops int i, ii; // Iterators that will be reused by all for loops
const int currentGesture = GetGestureDetected(); const int currentGesture = GetGestureDetected();
const float currentDragDegrees = GetGestureDragAngle(); const float currentDragDegrees = GetGestureDragAngle();
@@ -109,11 +115,10 @@ void Update(void)
const int touchCount = GetTouchPointCount(); const int touchCount = GetTouchPointCount();
// Handle last gesture // Handle last gesture
//-------------------------------------------------------------------------------------- if ((currentGesture != 0) && (currentGesture != 4) && (currentGesture != previousGesture))
if ((currentGesture != 0) && (currentGesture != 4) && (currentGesture != previousGesture)) lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display
// Handle gesture log // Handle gesture log
//--------------------------------------------------------------------------------------
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
{ {
if (CheckCollisionPointRec(GetMousePosition(), logButton1)) if (CheckCollisionPointRec(GetMousePosition(), logButton1))
@@ -171,7 +176,6 @@ void Update(void)
} }
// Handle protractor // Handle protractor
//--------------------------------------------------------------------------------------
if (currentGesture > 255) // aka Pinch In and Pinch Out if (currentGesture > 255) // aka Pinch In and Pinch Out
{ {
currentAngleDegrees = currentPitchDegrees; currentAngleDegrees = currentPitchDegrees;
@@ -189,9 +193,6 @@ void Update(void)
finalVector = (Vector2){ (angleLength*sinf(currentAngleRadians)) + protractorPosition.x, (angleLength*cosf(currentAngleRadians)) + protractorPosition.y }; // Calculate the final vector for display finalVector = (Vector2){ (angleLength*sinf(currentAngleRadians)) + protractorPosition.x, (angleLength*cosf(currentAngleRadians)) + protractorPosition.y }; // Calculate the final vector for display
// Handle touch and mouse pointer points // Handle touch and mouse pointer points
//--------------------------------------------------------------------------------------
#define MAX_TOUCH_COUNT 32
Vector2 touchPosition[MAX_TOUCH_COUNT] = { 0 }; Vector2 touchPosition[MAX_TOUCH_COUNT] = { 0 };
Vector2 mousePosition = {0, 0}; Vector2 mousePosition = {0, 0};
if (currentGesture != GESTURE_NONE) if (currentGesture != GESTURE_NONE)
@@ -202,22 +203,20 @@ void Update(void)
} }
else mousePosition = GetMousePosition(); else mousePosition = GetMousePosition();
} }
//--------------------------------------------------------------------------------------
// Draw // Draw
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Draw common // Draw common elements
//--------------------------------------------------------------------------------------
DrawText("*", messagePosition.x + 5, messagePosition.y + 5, 10, BLACK); DrawText("*", messagePosition.x + 5, messagePosition.y + 5, 10, BLACK);
DrawText("Example optimized for Web/HTML5\non Smartphones with Touch Screen.", messagePosition.x + 15, messagePosition.y + 5, 10, BLACK); DrawText("Example optimized for Web/HTML5\non Smartphones with Touch Screen.", messagePosition.x + 15, messagePosition.y + 5, 10, BLACK);
DrawText("*", messagePosition.x + 5, messagePosition.y + 35, 10, BLACK); DrawText("*", messagePosition.x + 5, messagePosition.y + 35, 10, BLACK);
DrawText("While running on Desktop Web Browsers,\ninspect and turn on Touch Emulation.", messagePosition.x + 15, messagePosition.y + 35, 10, BLACK); DrawText("While running on Desktop Web Browsers,\ninspect and turn on Touch Emulation.", messagePosition.x + 15, messagePosition.y + 35, 10, BLACK);
// Draw last gesture // Draw last gesture
//--------------------------------------------------------------------------------------
DrawText("Last gesture", lastGesturePosition.x + 33, lastGesturePosition.y - 47, 20, BLACK); DrawText("Last gesture", lastGesturePosition.x + 33, lastGesturePosition.y - 47, 20, BLACK);
DrawText("Swipe Tap Pinch Touch", lastGesturePosition.x + 17, lastGesturePosition.y - 18, 10, BLACK); DrawText("Swipe Tap Pinch Touch", lastGesturePosition.x + 17, lastGesturePosition.y - 18, 10, BLACK);
DrawRectangle(lastGesturePosition.x + 20, lastGesturePosition.y, 20, 20, lastGesture == GESTURE_SWIPE_UP ? RED : LIGHTGRAY); DrawRectangle(lastGesturePosition.x + 20, lastGesturePosition.y, 20, 20, lastGesture == GESTURE_SWIPE_UP ? RED : LIGHTGRAY);
@@ -235,7 +234,6 @@ void Update(void)
for (i = 0; i < 4; i++) DrawCircle(lastGesturePosition.x + 180, lastGesturePosition.y + 7 + i*15, 5, touchCount <= i? LIGHTGRAY : gestureColor); for (i = 0; i < 4; i++) DrawCircle(lastGesturePosition.x + 180, lastGesturePosition.y + 7 + i*15, 5, touchCount <= i? LIGHTGRAY : gestureColor);
// Draw gesture log // Draw gesture log
//--------------------------------------------------------------------------------------
DrawText("Log", gestureLogPosition.x, gestureLogPosition.y, 20, BLACK); DrawText("Log", gestureLogPosition.x, gestureLogPosition.y, 20, BLACK);
// Loop in both directions to print the gesture log array in the inverted order (and looping around if the index started somewhere in the middle) // Loop in both directions to print the gesture log array in the inverted order (and looping around if the index started somewhere in the middle)
@@ -256,7 +254,6 @@ void Update(void)
DrawText("Hold", logButton1.x + 62, logButton1.y + 13, 10, WHITE); DrawText("Hold", logButton1.x + 62, logButton1.y + 13, 10, WHITE);
// Draw protractor // Draw protractor
//--------------------------------------------------------------------------------------
DrawText("Angle", protractorPosition.x + 55, protractorPosition.y + 76, 10, BLACK); DrawText("Angle", protractorPosition.x + 55, protractorPosition.y + 76, 10, BLACK);
const char *angleString = TextFormat("%f", currentAngleDegrees); const char *angleString = TextFormat("%f", currentAngleDegrees);
const int angleStringDot = TextFindIndex(angleString, "."); const int angleStringDot = TextFindIndex(angleString, ".");
@@ -278,7 +275,6 @@ void Update(void)
if (currentAngleDegrees != 0.0f) DrawLineEx(protractorPosition, finalVector, 3.0f, gestureColor); if (currentAngleDegrees != 0.0f) DrawLineEx(protractorPosition, finalVector, 3.0f, gestureColor);
// Draw touch and mouse pointer points // Draw touch and mouse pointer points
//--------------------------------------------------------------------------------------
if (currentGesture != GESTURE_NONE) if (currentGesture != GESTURE_NONE)
{ {
if ( touchCount != 0 ) if ( touchCount != 0 )
@@ -300,33 +296,42 @@ void Update(void)
EndDrawing(); EndDrawing();
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
} }
//------------------------------------------------------------------------------------ static char const *GetGestureName(int i)
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{ {
// Initialization switch (i)
//-------------------------------------------------------------------------------------- {
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures web"); case 0: return "None"; break;
//-------------------------------------------------------------------------------------- case 1: return "Tap"; break;
case 2: return "Double Tap"; break;
// Main game loop case 4: return "Hold"; break;
//-------------------------------------------------------------------------------------- case 8: return "Drag"; break;
#if defined(PLATFORM_WEB) case 16: return "Swipe Right"; break;
emscripten_set_main_loop(Update, 0, 1); case 32: return "Swipe Left"; break;
#else case 64: return "Swipe Up"; break;
SetTargetFPS(60); case 128: return "Swipe Down"; break;
while (!WindowShouldClose()) Update(); // Detect window close button or ESC key case 256: return "Pinch In"; break;
#endif case 512: return "Pinch Out"; break;
//-------------------------------------------------------------------------------------- default: return "Unknown"; break;
}
// De-Initialization }
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context static Color GetGestureColor(int i)
//-------------------------------------------------------------------------------------- {
switch (i)
return 0; {
case 0: return BLACK; break;
case 1: return BLUE; break;
case 2: return SKYBLUE; break;
case 4: return BLACK; break;
case 8: return LIME; break;
case 16: return RED; break;
case 32: return RED; break;
case 64: return RED; break;
case 128: return RED; break;
case 256: return VIOLET; break;
case 512: return ORANGE; break;
default: return BLACK; break;
}
} }

View File

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@@ -39,7 +39,7 @@ core;core_basic_screen_manager;⭐️☆☆☆;4.0;4.0;"Ramon Santamaria";@raysa
core;core_custom_frame_control;⭐️⭐️⭐️⭐️;4.0;4.0;"Ramon Santamaria";@raysan5 core;core_custom_frame_control;⭐️⭐️⭐️⭐️;4.0;4.0;"Ramon Santamaria";@raysan5
core;core_smooth_pixelperfect;⭐️⭐️⭐️☆;3.7;4.0;"Giancamillo Alessandroni";@NotManyIdeasDev core;core_smooth_pixelperfect;⭐️⭐️⭐️☆;3.7;4.0;"Giancamillo Alessandroni";@NotManyIdeasDev
core;core_random_sequence;⭐️☆☆☆;5.0;5.0;"Dalton Overmyer";@REDl3east core;core_random_sequence;⭐️☆☆☆;5.0;5.0;"Dalton Overmyer";@REDl3east
core;core_input_gestures_web;⭐️⭐️☆☆;4.6-dev;4.6-dev;"ubkp";@ubkp core;core_input_gestures_testbed;⭐️⭐️☆☆;4.6-dev;4.6-dev;"ubkp";@ubkp
core;core_automation_events;⭐️⭐️⭐️☆;5.0;5.0;"Ramon Santamaria";@raysan5 core;core_automation_events;⭐️⭐️⭐️☆;5.0;5.0;"Ramon Santamaria";@raysan5
core;core_high_dpi;⭐️☆☆☆;5.0;5.0;"Jonathan Marler";@marler8997 core;core_high_dpi;⭐️☆☆☆;5.0;5.0;"Jonathan Marler";@marler8997
shapes;shapes_basic_shapes;⭐️☆☆☆;1.0;4.2;"Ramon Santamaria";@raysan5 shapes;shapes_basic_shapes;⭐️☆☆☆;1.0;4.2;"Ramon Santamaria";@raysan5

View File

@@ -53,9 +53,9 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{0981CA98-E4A5-4DF1-987F-A41D09131EFC}</ProjectGuid> <ProjectGuid>{0981CA98-E4A5-4DF1-987F-A41D09131EFC}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>core_input_gestures_web</RootNamespace> <RootNamespace>core_input_gestures_testbed</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>core_input_gestures_web</ProjectName> <ProjectName>core_input_gestures_testbed</ProjectName>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -553,7 +553,7 @@
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\examples\core\core_input_gestures_web.c" /> <ClCompile Include="..\..\..\examples\core\core_input_gestures_testbed.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="..\..\..\examples\examples.rc" /> <ResourceCompile Include="..\..\..\examples\examples.rc" />