Skip to content

Commit e21093d

Browse files
committed
REXM: RENAME: example: core_input_gestures_web --> core_input_gestures_testbed
1 parent c17f82a commit e21093d

File tree

7 files changed

+118
-113
lines changed

7 files changed

+118
-113
lines changed

examples/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ CORE = \
518518
core/core_high_dpi \
519519
core/core_input_gamepad \
520520
core/core_input_gestures \
521-
core/core_input_gestures_web \
521+
core/core_input_gestures_testbed \
522522
core/core_input_keys \
523523
core/core_input_mouse \
524524
core/core_input_mouse_wheel \

examples/Makefile.Web

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ CORE = \
518518
core/core_high_dpi \
519519
core/core_input_gamepad \
520520
core/core_input_gestures \
521-
core/core_input_gestures_web \
521+
core/core_input_gestures_testbed \
522522
core/core_input_keys \
523523
core/core_input_mouse \
524524
core/core_input_mouse_wheel \
@@ -737,7 +737,7 @@ core/core_input_gamepad: core/core_input_gamepad.c
737737
core/core_input_gestures: core/core_input_gestures.c
738738
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
739739

740-
core/core_input_gestures_web: core/core_input_gestures_web.c
740+
core/core_input_gestures_testbed: core/core_input_gestures_testbed.c
741741
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
742742

743743
core/core_input_keys: core/core_input_keys.c

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c
5656
| [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) |
5757
| [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) |
5858
| [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) |
59-
| [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) |
59+
| [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) |
6060
| [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) |
6161
| [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) |
6262

examples/core/core_input_gestures_web.c renamed to examples/core/core_input_gestures_testbed.c

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -17,103 +17,108 @@
1717

1818
#include "raylib.h"
1919

20-
#include "math.h" // Required for the protractor angle graphic drawing
20+
#include <math.h> // Required for the protractor angle graphic drawing
2121

2222
#if defined(PLATFORM_WEB)
2323
#include <emscripten/emscripten.h> // Required for the Web/HTML5
2424
#endif
2525

26-
//--------------------------------------------------------------------------------------
27-
// Global definitions and declarations
28-
//--------------------------------------------------------------------------------------
26+
#define GESTURE_LOG_SIZE 20
27+
#define MAX_TOUCH_COUNT 32
2928

30-
// Common variables definitions
3129
//--------------------------------------------------------------------------------------
32-
int screenWidth = 800; // Update depending on web canvas
33-
const int screenHeight = 450;
34-
Vector2 messagePosition = { 160, 7 };
30+
// Global Variables Definition
31+
//--------------------------------------------------------------------------------------
32+
static int screenWidth = 800; // Update depending on web canvas
33+
static const int screenHeight = 450;
34+
static Vector2 messagePosition = { 160, 7 };
3535

3636
// Last gesture variables definitions
37-
//--------------------------------------------------------------------------------------
38-
int lastGesture = 0;
39-
Vector2 lastGesturePosition = { 165, 130 };
37+
static int lastGesture = 0;
38+
static Vector2 lastGesturePosition = { 165, 130 };
39+
40+
// Gesture log variables definitions
41+
// NOTE: The gesture log uses an array (as an inverted circular queue) to store the performed gestures
42+
static char gestureLog[GESTURE_LOG_SIZE][12] = { "" };
43+
// NOTE: The index for the inverted circular queue (moving from last to first direction, then looping around)
44+
static int gestureLogIndex = GESTURE_LOG_SIZE;
45+
static int previousGesture = 0;
46+
47+
// Log mode values:
48+
// - 0 shows repeated events
49+
// - 1 hides repeated events
50+
// - 2 shows repeated events but hide hold events
51+
// - 3 hides repeated events and hide hold events
52+
static int logMode = 1;
53+
54+
static Color gestureColor = { 0, 0, 0, 255 };
55+
static Rectangle logButton1 = { 53, 7, 48, 26 };
56+
static Rectangle logButton2 = { 108, 7, 36, 26 };
57+
static Vector2 gestureLogPosition = { 10, 10 };
4058

41-
// Gesture log variables definitions and functions declarations
42-
//--------------------------------------------------------------------------------------
43-
#define GESTURE_LOG_SIZE 20
44-
char gestureLog[GESTURE_LOG_SIZE][12] = { "" }; // The gesture log uses an array (as an inverted circular queue) to store the performed gestures
45-
int gestureLogIndex = GESTURE_LOG_SIZE; // The index for the inverted circular queue (moving from last to first direction, then looping around)
46-
int previousGesture = 0;
59+
// Protractor variables definitions
60+
static float angleLength = 90.0f;
61+
static float currentAngleDegrees = 0.0f;
62+
static Vector2 finalVector = { 0.0f, 0.0f };
63+
static char currentAngleStr[7] = "";
64+
static Vector2 protractorPosition = { 266.0f, 315.0f };
65+
66+
//----------------------------------------------------------------------------------
67+
// Module Functions Declaration
68+
//----------------------------------------------------------------------------------
69+
static void UpdateDrawFrame(void); // Update and Draw one frame
70+
static char const *GetGestureName(int i);
71+
static Color GetGestureColor(int i);
4772

48-
char const *GetGestureName(int i)
73+
//------------------------------------------------------------------------------------
74+
// Program main entry point
75+
//------------------------------------------------------------------------------------
76+
int main(void)
4977
{
50-
switch (i) {
51-
case 0: return "None"; break;
52-
case 1: return "Tap"; break;
53-
case 2: return "Double Tap"; break;
54-
case 4: return "Hold"; break;
55-
case 8: return "Drag"; break;
56-
case 16: return "Swipe Right"; break;
57-
case 32: return "Swipe Left"; break;
58-
case 64: return "Swipe Up"; break;
59-
case 128: return "Swipe Down"; break;
60-
case 256: return "Pinch In"; break;
61-
case 512: return "Pinch Out"; break;
62-
default: return "Unknown"; break;
63-
}
64-
}
78+
// Initialization
79+
//--------------------------------------------------------------------------------------
80+
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures testbed");
6581

66-
Color GetGestureColor(int i)
67-
{
68-
switch (i) {
69-
case 0: return BLACK; break;
70-
case 1: return BLUE; break;
71-
case 2: return SKYBLUE; break;
72-
case 4: return BLACK; break;
73-
case 8: return LIME; break;
74-
case 16: return RED; break;
75-
case 32: return RED; break;
76-
case 64: return RED; break;
77-
case 128: return RED; break;
78-
case 256: return VIOLET; break;
79-
case 512: return ORANGE; break;
80-
default: return BLACK; break;
81-
}
82-
}
82+
#if defined(PLATFORM_WEB)
83+
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
84+
#else
85+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
86+
//--------------------------------------------------------------------------------------
8387

84-
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
88+
// Main game loop
89+
while (!WindowShouldClose()) // Detect window close button or ESC key
90+
{
91+
UpdateDrawFrame();
92+
}
93+
#endif
8594

86-
Color gestureColor = { 0, 0, 0, 255 };
87-
Rectangle logButton1 = { 53, 7, 48, 26 };
88-
Rectangle logButton2 = { 108, 7, 36, 26 };
89-
Vector2 gestureLogPosition = { 10, 10 };
95+
// De-Initialization
96+
//--------------------------------------------------------------------------------------
97+
CloseWindow(); // Close window and OpenGL context
98+
//--------------------------------------------------------------------------------------
9099

91-
// Protractor variables definitions
92-
//--------------------------------------------------------------------------------------
93-
float angleLength = 90.0f;
94-
float currentAngleDegrees = 0.0f;
95-
Vector2 finalVector = { 0.0f, 0.0f };
96-
char currentAngleStr[7] = "";
97-
Vector2 protractorPosition = { 266.0f, 315.0f };
100+
return 0;
101+
}
98102

99-
// Update
100-
//--------------------------------------------------------------------------------------
101-
void Update(void)
103+
//----------------------------------------------------------------------------------
104+
// Module Functions Definition
105+
//----------------------------------------------------------------------------------
106+
static void UpdateDrawFrame(void)
102107
{
103-
// Handle common
108+
// Update
104109
//--------------------------------------------------------------------------------------
110+
// Handle common gestures data
105111
int i, ii; // Iterators that will be reused by all for loops
106112
const int currentGesture = GetGestureDetected();
107113
const float currentDragDegrees = GetGestureDragAngle();
108114
const float currentPitchDegrees = GetGesturePinchAngle();
109115
const int touchCount = GetTouchPointCount();
110116

111117
// Handle last gesture
112-
//--------------------------------------------------------------------------------------
113-
if ((currentGesture != 0) && (currentGesture != 4) && (currentGesture != previousGesture)) lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display
118+
if ((currentGesture != 0) && (currentGesture != 4) && (currentGesture != previousGesture))
119+
lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display
114120

115121
// Handle gesture log
116-
//--------------------------------------------------------------------------------------
117122
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
118123
{
119124
if (CheckCollisionPointRec(GetMousePosition(), logButton1))
@@ -171,7 +176,6 @@ void Update(void)
171176
}
172177

173178
// Handle protractor
174-
//--------------------------------------------------------------------------------------
175179
if (currentGesture > 255) // aka Pinch In and Pinch Out
176180
{
177181
currentAngleDegrees = currentPitchDegrees;
@@ -189,9 +193,6 @@ void Update(void)
189193
finalVector = (Vector2){ (angleLength*sinf(currentAngleRadians)) + protractorPosition.x, (angleLength*cosf(currentAngleRadians)) + protractorPosition.y }; // Calculate the final vector for display
190194

191195
// Handle touch and mouse pointer points
192-
//--------------------------------------------------------------------------------------
193-
#define MAX_TOUCH_COUNT 32
194-
195196
Vector2 touchPosition[MAX_TOUCH_COUNT] = { 0 };
196197
Vector2 mousePosition = {0, 0};
197198
if (currentGesture != GESTURE_NONE)
@@ -202,22 +203,20 @@ void Update(void)
202203
}
203204
else mousePosition = GetMousePosition();
204205
}
206+
//--------------------------------------------------------------------------------------
205207

206208
// Draw
207209
//--------------------------------------------------------------------------------------
208210
BeginDrawing();
209-
210211
ClearBackground(RAYWHITE);
211212

212-
// Draw common
213-
//--------------------------------------------------------------------------------------
213+
// Draw common elements
214214
DrawText("*", messagePosition.x + 5, messagePosition.y + 5, 10, BLACK);
215215
DrawText("Example optimized for Web/HTML5\non Smartphones with Touch Screen.", messagePosition.x + 15, messagePosition.y + 5, 10, BLACK);
216216
DrawText("*", messagePosition.x + 5, messagePosition.y + 35, 10, BLACK);
217217
DrawText("While running on Desktop Web Browsers,\ninspect and turn on Touch Emulation.", messagePosition.x + 15, messagePosition.y + 35, 10, BLACK);
218218

219219
// Draw last gesture
220-
//--------------------------------------------------------------------------------------
221220
DrawText("Last gesture", lastGesturePosition.x + 33, lastGesturePosition.y - 47, 20, BLACK);
222221
DrawText("Swipe Tap Pinch Touch", lastGesturePosition.x + 17, lastGesturePosition.y - 18, 10, BLACK);
223222
DrawRectangle(lastGesturePosition.x + 20, lastGesturePosition.y, 20, 20, lastGesture == GESTURE_SWIPE_UP ? RED : LIGHTGRAY);
@@ -235,7 +234,6 @@ void Update(void)
235234
for (i = 0; i < 4; i++) DrawCircle(lastGesturePosition.x + 180, lastGesturePosition.y + 7 + i*15, 5, touchCount <= i? LIGHTGRAY : gestureColor);
236235

237236
// Draw gesture log
238-
//--------------------------------------------------------------------------------------
239237
DrawText("Log", gestureLogPosition.x, gestureLogPosition.y, 20, BLACK);
240238

241239
// 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)
256254
DrawText("Hold", logButton1.x + 62, logButton1.y + 13, 10, WHITE);
257255

258256
// Draw protractor
259-
//--------------------------------------------------------------------------------------
260257
DrawText("Angle", protractorPosition.x + 55, protractorPosition.y + 76, 10, BLACK);
261258
const char *angleString = TextFormat("%f", currentAngleDegrees);
262259
const int angleStringDot = TextFindIndex(angleString, ".");
@@ -278,7 +275,6 @@ void Update(void)
278275
if (currentAngleDegrees != 0.0f) DrawLineEx(protractorPosition, finalVector, 3.0f, gestureColor);
279276

280277
// Draw touch and mouse pointer points
281-
//--------------------------------------------------------------------------------------
282278
if (currentGesture != GESTURE_NONE)
283279
{
284280
if ( touchCount != 0 )
@@ -300,33 +296,42 @@ void Update(void)
300296

301297
EndDrawing();
302298
//--------------------------------------------------------------------------------------
303-
304299
}
305300

306-
//------------------------------------------------------------------------------------
307-
// Program main entry point
308-
//------------------------------------------------------------------------------------
309-
int main(void)
301+
static char const *GetGestureName(int i)
310302
{
311-
// Initialization
312-
//--------------------------------------------------------------------------------------
313-
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures web");
314-
//--------------------------------------------------------------------------------------
315-
316-
// Main game loop
317-
//--------------------------------------------------------------------------------------
318-
#if defined(PLATFORM_WEB)
319-
emscripten_set_main_loop(Update, 0, 1);
320-
#else
321-
SetTargetFPS(60);
322-
while (!WindowShouldClose()) Update(); // Detect window close button or ESC key
323-
#endif
324-
//--------------------------------------------------------------------------------------
325-
326-
// De-Initialization
327-
//--------------------------------------------------------------------------------------
328-
CloseWindow(); // Close window and OpenGL context
329-
//--------------------------------------------------------------------------------------
303+
switch (i)
304+
{
305+
case 0: return "None"; break;
306+
case 1: return "Tap"; break;
307+
case 2: return "Double Tap"; break;
308+
case 4: return "Hold"; break;
309+
case 8: return "Drag"; break;
310+
case 16: return "Swipe Right"; break;
311+
case 32: return "Swipe Left"; break;
312+
case 64: return "Swipe Up"; break;
313+
case 128: return "Swipe Down"; break;
314+
case 256: return "Pinch In"; break;
315+
case 512: return "Pinch Out"; break;
316+
default: return "Unknown"; break;
317+
}
318+
}
330319

331-
return 0;
320+
static Color GetGestureColor(int i)
321+
{
322+
switch (i)
323+
{
324+
case 0: return BLACK; break;
325+
case 1: return BLUE; break;
326+
case 2: return SKYBLUE; break;
327+
case 4: return BLACK; break;
328+
case 8: return LIME; break;
329+
case 16: return RED; break;
330+
case 32: return RED; break;
331+
case 64: return RED; break;
332+
case 128: return RED; break;
333+
case 256: return VIOLET; break;
334+
case 512: return ORANGE; break;
335+
default: return BLACK; break;
336+
}
332337
}
File renamed without changes.

examples/examples_list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ core;core_basic_screen_manager;⭐️☆☆☆;4.0;4.0;"Ramon Santamaria";@raysa
3939
core;core_custom_frame_control;⭐️⭐️⭐️⭐️;4.0;4.0;"Ramon Santamaria";@raysan5
4040
core;core_smooth_pixelperfect;⭐️⭐️⭐️☆;3.7;4.0;"Giancamillo Alessandroni";@NotManyIdeasDev
4141
core;core_random_sequence;⭐️☆☆☆;5.0;5.0;"Dalton Overmyer";@REDl3east
42-
core;core_input_gestures_web;⭐️⭐️☆☆;4.6-dev;4.6-dev;"ubkp";@ubkp
42+
core;core_input_gestures_testbed;⭐️⭐️☆☆;4.6-dev;4.6-dev;"ubkp";@ubkp
4343
core;core_automation_events;⭐️⭐️⭐️☆;5.0;5.0;"Ramon Santamaria";@raysan5
4444
core;core_high_dpi;⭐️☆☆☆;5.0;5.0;"Jonathan Marler";@marler8997
4545
shapes;shapes_basic_shapes;⭐️☆☆☆;1.0;4.2;"Ramon Santamaria";@raysan5

projects/VS2022/examples/core_input_gestures_web.vcxproj renamed to projects/VS2022/examples/core_input_gestures_testbed.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
<PropertyGroup Label="Globals">
5454
<ProjectGuid>{0981CA98-E4A5-4DF1-987F-A41D09131EFC}</ProjectGuid>
5555
<Keyword>Win32Proj</Keyword>
56-
<RootNamespace>core_input_gestures_web</RootNamespace>
56+
<RootNamespace>core_input_gestures_testbed</RootNamespace>
5757
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
58-
<ProjectName>core_input_gestures_web</ProjectName>
58+
<ProjectName>core_input_gestures_testbed</ProjectName>
5959
</PropertyGroup>
6060
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
6161
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -553,7 +553,7 @@
553553
</PostBuildEvent>
554554
</ItemDefinitionGroup>
555555
<ItemGroup>
556-
<ClCompile Include="..\..\..\examples\core\core_input_gestures_web.c" />
556+
<ClCompile Include="..\..\..\examples\core\core_input_gestures_testbed.c" />
557557
</ItemGroup>
558558
<ItemGroup>
559559
<ResourceCompile Include="..\..\..\examples\examples.rc" />

0 commit comments

Comments
 (0)