Added support for additional mouse buttons (#1753)

* Added support for additional mouse buttons

* Renamed mouse button enum

Co-authored-by: Lambert Wang <lambert.ww@gmail.com>
This commit is contained in:
Lambert Wang 2021-05-08 09:26:24 -07:00 committed by GitHub
parent 2565c01158
commit 2545f62565
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 81 additions and 65 deletions

View file

@ -71,7 +71,7 @@ int main(void)
// Sample mouse input.
mousePosition = GetMousePosition();
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{
float fp = (float)(mousePosition.y);
frequency = 40.0f + (float)(fp);

View file

@ -47,7 +47,7 @@ int main(void)
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
if (!collision)
{

View file

@ -33,9 +33,13 @@ int main(void)
//----------------------------------------------------------------------------------
ballPosition = GetMousePosition();
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
else if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) ballColor = LIME;
else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) ballColor = DARKBLUE;
else if (IsMouseButtonPressed(MOUSE_BUTTON_SIDE)) ballColor = PURPLE;
else if (IsMouseButtonPressed(MOUSE_BUTTON_EXTRA)) ballColor = YELLOW;
else if (IsMouseButtonPressed(MOUSE_BUTTON_FORWARD)) ballColor = ORANGE;
else if (IsMouseButtonPressed(MOUSE_BUTTON_BACK)) ballColor = BEIGE;
//----------------------------------------------------------------------------------
// Draw

View file

@ -42,13 +42,13 @@ int main(void)
ballColor = BEIGE;
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
if (IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)) ballColor = LIME;
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) ballColor = DARKBLUE;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) touchCounter = 10;
if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) touchCounter = 10;
if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) touchCounter = 10;
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) touchCounter = 10;
if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) touchCounter = 10;
if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) touchCounter = 10;
if (touchCounter > 0) touchCounter--;
//----------------------------------------------------------------------------------

View file

@ -95,7 +95,7 @@ int main(void)
}
// Select model on mouse click
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
// Check collision between ray and box
if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected;

View file

@ -113,7 +113,7 @@ int main(void)
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update internal camera and our camera
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures
}

View file

@ -63,8 +63,8 @@ int main(void)
}
// Physics body creation inputs
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10);
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10);
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10);
else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10);
// Destroy falling physics bodies
int bodiesCount = GetPhysicsBodiesCount();

View file

@ -53,7 +53,7 @@ int main(void)
CreatePhysicsBodyPolygon((Vector2){ screenWidth/2.0f, screenHeight/2.0f }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
}
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) // Physics shatter input
{
int count = GetPhysicsBodiesCount();
for (int i = count - 1; i >= 0; i--)

View file

@ -67,7 +67,7 @@ int main(void)
SetShaderValue(shader, mouseLoc, mousePos, SHADER_UNIFORM_VEC2);
// Hot shader reloading
if (shaderAutoReloading || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
if (shaderAutoReloading || (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)))
{
long currentFragShaderModTime = GetFileModTime(TextFormat(fragShaderFileName, GLSL_VERSION));

View file

@ -115,10 +115,10 @@ int main(void)
// TODO: The idea is to zoom and move around with mouse
// Probably offset movement should be proportional to zoom level
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) || IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) || IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) zoom += zoom*0.003f;
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) zoom -= zoom*0.003f;
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) zoom += zoom*0.003f;
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) zoom -= zoom*0.003f;
Vector2 mousePos = GetMousePosition();

View file

@ -32,8 +32,8 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) start = GetMousePosition();
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) end = GetMousePosition();
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) start = GetMousePosition();
else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) end = GetMousePosition();
//----------------------------------------------------------------------------------
// Draw

View file

@ -45,7 +45,7 @@ int main(void)
CheckCollisionPointRec(mousePosition, (Rectangle){ rec.x + rec.width - MOUSE_SCALE_MARK_SIZE, rec.y + rec.height - MOUSE_SCALE_MARK_SIZE, MOUSE_SCALE_MARK_SIZE, MOUSE_SCALE_MARK_SIZE }))
{
mouseScaleReady = true;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) mouseScaleMode = true;
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) mouseScaleMode = true;
}
else mouseScaleReady = false;
@ -59,7 +59,7 @@ int main(void)
if (rec.width < MOUSE_SCALE_MARK_SIZE) rec.width = MOUSE_SCALE_MARK_SIZE;
if (rec.height < MOUSE_SCALE_MARK_SIZE) rec.height = MOUSE_SCALE_MARK_SIZE;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) mouseScaleMode = false;
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) mouseScaleMode = false;
}
//----------------------------------------------------------------------------------

View file

@ -186,7 +186,7 @@ int main(void)
}
// Handle clicking the cube
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
Ray ray = GetMouseRay(GetMousePosition(), camera);

View file

@ -61,7 +61,7 @@ tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet ris
// Container resizing logic
if (resizing)
{
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) resizing = false;
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) resizing = false;
float width = container.width + (mouse.x - lastMouse.x);
container.width = (width > minWidth)? ((width < maxWidth)? width : maxWidth) : minWidth;
@ -72,7 +72,7 @@ tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet ris
else
{
// Check if we're resizing
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mouse, resizer)) resizing = true;
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && CheckCollisionPointRec(mouse, resizer)) resizing = true;
}
// Move resizer rectangle properly

View file

@ -180,7 +180,7 @@ int main(int argc, char **argv)
if (IsKeyPressed(KEY_SPACE)) RandomizeEmoji();
// Set the selected emoji and copy its text to clipboard
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && (hovered != -1) && (hovered != selected))
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && (hovered != -1) && (hovered != selected))
{
selected = hovered;
selectedPos = hoveredPos;

View file

@ -49,7 +49,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{
// Create more bunnies
for (int i = 0; i < 100; i++)

View file

@ -75,7 +75,7 @@ int main(int argc, char **argv)
screenHeight = GetScreenHeight();
// Handle mouse
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
const Vector2 mouse = GetMousePosition();

View file

@ -59,7 +59,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsKeyPressed(KEY_RIGHT))
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_RIGHT))
{
currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures
}

View file

@ -80,7 +80,7 @@ int main(void)
{
mouseHoverRec = i;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
{
currentProcess = i;
textureReload = true;

View file

@ -88,7 +88,7 @@ int main(void)
else colorMouseHover = -1;
}
if ((colorMouseHover >= 0) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if ((colorMouseHover >= 0) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
colorSelected = colorMouseHover;
colorSelectedPrev = colorSelected;
@ -107,7 +107,7 @@ int main(void)
EndTextureMode();
}
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) || (GetGestureDetected() == GESTURE_DRAG))
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) || (GetGestureDetected() == GESTURE_DRAG))
{
// Paint circle into render texture
// NOTE: To avoid discontinuous circles, we could store
@ -117,7 +117,7 @@ int main(void)
EndTextureMode();
}
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{
if (!mouseWasPressed)
{
@ -132,7 +132,7 @@ int main(void)
if (mousePos.y > 50) DrawCircle((int)mousePos.x, (int)mousePos.y, brushSize, colors[0]);
EndTextureMode();
}
else if (IsMouseButtonReleased(MOUSE_RIGHT_BUTTON) && mouseWasPressed)
else if (IsMouseButtonReleased(MOUSE_BUTTON_RIGHT) && mouseWasPressed)
{
colorSelected = colorSelectedPrev;
mouseWasPressed = false;
@ -144,7 +144,7 @@ int main(void)
// Image saving logic
// NOTE: Saving painted texture to a default named image
if ((btnSaveMouseHover && IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) || IsKeyPressed(KEY_S))
if ((btnSaveMouseHover && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) || IsKeyPressed(KEY_S))
{
Image image = GetTextureData(target.texture);
ImageFlipVertical(&image);
@ -177,7 +177,7 @@ int main(void)
// Draw drawing circle for reference
if (mousePos.y > 50)
{
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) DrawCircleLines((int)mousePos.x, (int)mousePos.y, brushSize, GRAY);
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) DrawCircleLines((int)mousePos.x, (int)mousePos.y, brushSize, GRAY);
else DrawCircle(GetMouseX(), GetMouseY(), brushSize, colors[colorSelected]);
}

View file

@ -53,10 +53,10 @@ int main(void)
// Check button state
if (CheckCollisionPointRec(mousePoint, btnBounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) btnState = 2;
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) btnState = 2;
else btnState = 1;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) btnAction = true;
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) btnAction = true;
}
else btnState = 0;

View file

@ -53,7 +53,7 @@ int main(void)
//----------------------------------------------------------------------------------
// Check for mouse button pressed and activate explosion (if not active)
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !active)
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !active)
{
position = GetMousePosition();
active = true;