Merge branch 'master' of github.com:raysan5/raylib

This commit is contained in:
Jeffery Myers 2024-05-18 17:47:39 -07:00
commit 661004a731
6 changed files with 42 additions and 13 deletions

3
.gitignore vendored
View File

@ -56,6 +56,9 @@ packages/
*.so.* *.so.*
*.dll *.dll
# Emscripten
emsdk
# Ignore wasm data in examples/ # Ignore wasm data in examples/
examples/**/*.wasm examples/**/*.wasm
examples/**/*.data examples/**/*.data

View File

@ -189,7 +189,7 @@
#define SUPPORT_DEFAULT_FONT 1 #define SUPPORT_DEFAULT_FONT 1
// Selected desired font fileformats to be supported for loading // Selected desired font fileformats to be supported for loading
#define SUPPORT_FILEFORMAT_TTF 1 #define SUPPORT_FILEFORMAT_TTF 1
//#define SUPPORT_FILEFORMAT_FNT 1 #define SUPPORT_FILEFORMAT_FNT 1
//#define SUPPORT_FILEFORMAT_BDF 1 //#define SUPPORT_FILEFORMAT_BDF 1
// Support text management functions // Support text management functions

View File

@ -100,6 +100,8 @@ static const char cursorLUT[11][12] = {
"not-allowed" // 10 MOUSE_CURSOR_NOT_ALLOWED "not-allowed" // 10 MOUSE_CURSOR_NOT_ALLOWED
}; };
Vector2 lockedMousePos = { 0 };
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Internal Functions Declaration // Module Internal Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -131,6 +133,7 @@ static EM_BOOL EmscriptenWindowResizedCallback(int eventType, const EmscriptenUi
static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData); static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData);
// Emscripten input callback events // Emscripten input callback events
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData); static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData);
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData); static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData);
@ -862,6 +865,8 @@ void SetMousePosition(int x, int y)
CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y }; CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
if (CORE.Input.Mouse.cursorHidden) lockedMousePos = CORE.Input.Mouse.currentPosition;
// NOTE: emscripten not implemented // NOTE: emscripten not implemented
glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y); glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y);
} }
@ -1270,6 +1275,9 @@ int InitPlatform(void)
emscripten_set_click_callback("#canvas", NULL, 1, EmscriptenMouseCallback); emscripten_set_click_callback("#canvas", NULL, 1, EmscriptenMouseCallback);
emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenPointerlockCallback); emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenPointerlockCallback);
// Following the mouse delta when the mouse is locked
emscripten_set_mousemove_callback("#canvas", NULL, 1, EmscriptenMouseMoveCallback);
// Support touch events // Support touch events
emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback); emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback); emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback);
@ -1477,9 +1485,13 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
// GLFW3 Cursor Position Callback, runs on mouse move // GLFW3 Cursor Position Callback, runs on mouse move
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y) static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
{ {
// If the pointer is not locked, follow the position
if (!CORE.Input.Mouse.cursorHidden)
{
CORE.Input.Mouse.currentPosition.x = (float)x; CORE.Input.Mouse.currentPosition.x = (float)x;
CORE.Input.Mouse.currentPosition.y = (float)y; CORE.Input.Mouse.currentPosition.y = (float)y;
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
}
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES) #if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
// Process mouse events as touches to be able to use mouse-gestures // Process mouse events as touches to be able to use mouse-gestures
@ -1505,6 +1517,18 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
#endif #endif
} }
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
{
// To emulate the GLFW_RAW_MOUSE_MOTION property.
if (CORE.Input.Mouse.cursorHidden)
{
CORE.Input.Mouse.previousPosition.x = lockedMousePos.x - mouseEvent->movementX;
CORE.Input.Mouse.previousPosition.y = lockedMousePos.y - mouseEvent->movementY;
}
return 1; // The event was consumed by the callback handler
}
// GLFW3 Scrolling Callback, runs on mouse wheel // GLFW3 Scrolling Callback, runs on mouse wheel
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset) static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
{ {
@ -1598,6 +1622,12 @@ static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPoin
{ {
CORE.Input.Mouse.cursorHidden = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0); CORE.Input.Mouse.cursorHidden = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0);
if (CORE.Input.Mouse.cursorHidden)
{
lockedMousePos = CORE.Input.Mouse.currentPosition;
CORE.Input.Mouse.previousPosition = lockedMousePos;
}
return 1; // The event was consumed by the callback handler return 1; // The event was consumed by the callback handler
} }

View File

@ -1348,7 +1348,6 @@ Music LoadMusicStream(const char *fileName)
} }
else else
{ {
drwav_uninit(ctxWav);
RL_FREE(ctxWav); RL_FREE(ctxWav);
} }
} }

View File

@ -78,10 +78,6 @@
#endif #endif
#if defined(__cplusplus)
extern "C" { // Prevents name mangling of functions
#endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -2528,8 +2524,5 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
return result; return result;
} }
#if defined(__cplusplus)
}
#endif
#endif // RAYMATH_H #endif // RAYMATH_H

View File

@ -2240,7 +2240,11 @@ static Font LoadBMFont(const char *fileName)
// Fill character image data from full font data // Fill character image data from full font data
font.glyphs[i].image = ImageFromImage(fullFont, font.recs[i]); font.glyphs[i].image = ImageFromImage(fullFont, font.recs[i]);
} }
else TRACELOG(LOG_WARNING, "FONT: [%s] Some characters data not correctly provided", fileName); else
{
font.glyphs[i].image = GenImageColor(font.recs[i].width, font.recs[i].height, BLACK);
TRACELOG(LOG_WARNING, "FONT: [%s] Some characters data not correctly provided", fileName);
}
} }
UnloadImage(fullFont); UnloadImage(fullFont);