Reviewed C compilation issues and formatting
This commit is contained in:
parent
70286c7cdc
commit
86f95d7150
1 changed files with 66 additions and 58 deletions
|
@ -14,6 +14,7 @@
|
|||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include "math.h" // Required for the protractor angle graphic drawing
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
|
@ -26,7 +27,7 @@
|
|||
|
||||
// Common variables definitions
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenWidth = 800; // Update depending on web canvas
|
||||
const int screenHeight = 450;
|
||||
Vector2 messagePosition = { 160, 7 };
|
||||
|
||||
|
@ -41,6 +42,7 @@ Vector2 lastGesturePosition = {165, 130};
|
|||
char gestureLog[GESTURE_LOG_SIZE][12] = { "" }; // The gesture log uses an array (as an inverted circular queue) to store the performed gestures
|
||||
int gestureLogIndex = GESTURE_LOG_SIZE; // The index for the inverted circular queue (moving from last to first direction, then looping around)
|
||||
int previousGesture = 0;
|
||||
|
||||
char const *GetGestureName(int i)
|
||||
{
|
||||
switch (i) {
|
||||
|
@ -58,6 +60,7 @@ char const *GetGestureName(int i)
|
|||
default: return "Unknown"; break;
|
||||
}
|
||||
}
|
||||
|
||||
Color GetGestureColor(int i)
|
||||
{
|
||||
switch (i) {
|
||||
|
@ -75,8 +78,10 @@ Color GetGestureColor(int i)
|
|||
default: return BLACK; break;
|
||||
}
|
||||
}
|
||||
Color gestureColor = BLACK;
|
||||
|
||||
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 };
|
||||
|
@ -103,7 +108,7 @@ void Update(void)
|
|||
|
||||
// Handle last gesture
|
||||
//--------------------------------------------------------------------------------------
|
||||
if ( currentGesture != 0 && currentGesture != 4 && currentGesture != previousGesture ) lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display
|
||||
if ((currentGesture != 0) && (currentGesture != 4) && (currentGesture != previousGesture)) lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display
|
||||
|
||||
// Handle gesture log
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
@ -130,12 +135,13 @@ void Update(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fillLog = 0; // Gate variable to be used to allow or not the gesture log to be filled
|
||||
if (currentGesture !=0)
|
||||
{
|
||||
if (logMode == 3) // 3 hides repeated events and hide hold events
|
||||
{
|
||||
if ( ( currentGesture != 4 && currentGesture != previousGesture ) || currentGesture < 3 ) fillLog = 1;
|
||||
if (((currentGesture != 4) && (currentGesture != previousGesture)) || (currentGesture < 3)) fillLog = 1;
|
||||
}
|
||||
else if (logMode == 2) // 2 shows repeated events but hide hold events
|
||||
{
|
||||
|
@ -150,13 +156,16 @@ void Update(void)
|
|||
fillLog = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (fillLog) // If one of the conditions from logMode was met, fill the gesture log
|
||||
{
|
||||
previousGesture = currentGesture;
|
||||
gestureColor = GetGestureColor(currentGesture);
|
||||
if (gestureLogIndex <= 0) gestureLogIndex = GESTURE_LOG_SIZE;
|
||||
gestureLogIndex--;
|
||||
TextCopy( gestureLog[gestureLogIndex], GetGestureName(currentGesture) ); // Copy the gesture respective name to the gesture log array
|
||||
|
||||
// Copy the gesture respective name to the gesture log array
|
||||
TextCopy(gestureLog[gestureLogIndex], GetGestureName(currentGesture));
|
||||
}
|
||||
|
||||
// Handle protractor
|
||||
|
@ -173,12 +182,15 @@ void Update(void)
|
|||
{
|
||||
currentAngleDegrees = 0.0f;
|
||||
}
|
||||
|
||||
float currentAngleRadians = ((currentAngleDegrees +90.0f)*PI/180); // Convert the current angle to Radians
|
||||
finalVector = (Vector2){ (angleLength*sinf(currentAngleRadians)) + protractorPosition.x, (angleLength*cosf(currentAngleRadians)) + protractorPosition.y }; // Calculate the final vector for display
|
||||
|
||||
// Handle touch and mouse pointer points
|
||||
//--------------------------------------------------------------------------------------
|
||||
Vector2 touchPosition[touchCount];
|
||||
#define MAX_TOUCH_COUNT 32
|
||||
|
||||
Vector2 touchPosition[MAX_TOUCH_COUNT] = { 0 };
|
||||
Vector2 mousePosition = {0, 0};
|
||||
if (currentGesture != GESTURE_NONE)
|
||||
{
|
||||
|
@ -186,15 +198,13 @@ void Update(void)
|
|||
{
|
||||
for (i = 0; i < touchCount; i++) touchPosition[i] = GetTouchPosition(i); // Fill the touch positions
|
||||
}
|
||||
else
|
||||
{
|
||||
mousePosition = GetMousePosition();
|
||||
}
|
||||
else mousePosition = GetMousePosition();
|
||||
}
|
||||
|
||||
// Draw
|
||||
//--------------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw common
|
||||
|
@ -225,6 +235,7 @@ void Update(void)
|
|||
// Draw gesture log
|
||||
//--------------------------------------------------------------------------------------
|
||||
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)
|
||||
for (i = 0, ii = gestureLogIndex; i < GESTURE_LOG_SIZE; i++, ii = (ii + 1) % GESTURE_LOG_SIZE) DrawText(gestureLog[ii], gestureLogPosition.x, gestureLogPosition.y + 410 - i*20, 20, (i == 0 ? gestureColor : LIGHTGRAY));
|
||||
Color logButton1Color, logButton2Color;
|
||||
|
@ -275,7 +286,8 @@ void Update(void)
|
|||
DrawCircleV(touchPosition[i], 50.0f, Fade(gestureColor, 0.5f));
|
||||
DrawCircleV(touchPosition[i], 5.0f, gestureColor);
|
||||
}
|
||||
if (touchCount == 2) DrawLineEx( touchPosition[0], touchPosition[1], (currentGesture == 512 ? 8 : 12), gestureColor);
|
||||
|
||||
if (touchCount == 2) DrawLineEx(touchPosition[0], touchPosition[1], ((currentGesture == 512)? 8 : 12), gestureColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -297,15 +309,11 @@ int main(void)
|
|||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
#if defined( PLATFORM_WEB )
|
||||
const int canvasWidth = EM_ASM_INT( return document.getElementById('canvas').getBoundingClientRect().width; ); // Using Emscripten EM_ASM_INT macro, get the page canvas width
|
||||
if (canvasWidth > 400)
|
||||
{
|
||||
screenWidth = canvasWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
screenWidth = 400; // Set a minimum width for the screen
|
||||
}
|
||||
// Using Emscripten EM_ASM_INT macro, get the page canvas width
|
||||
const int canvasWidth = EM_ASM_INT( return document.getElementById('canvas').getBoundingClientRect().width; );
|
||||
|
||||
if (canvasWidth > 400) screenWidth = canvasWidth;
|
||||
else screenWidth = 400; // Set a minimum width for the screen
|
||||
#endif
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures web");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue