summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Makefile15
-rw-r--r--src/core.c129
-rw-r--r--src/shell.html4
3 files changed, 105 insertions, 43 deletions
diff --git a/src/Makefile b/src/Makefile
index e7086e55..3a790789 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -291,9 +291,16 @@ endif
ifeq ($(RAYLIB_BUILD_MODE),DEBUG)
CFLAGS += -g
+ ifeq ($(PLATFORM),PLATFORM_WEB)
+ CFLAGS += -s ASSERTIONS=1 --profiling
+ endif
endif
ifeq ($(RAYLIB_BUILD_MODE),RELEASE)
- CFLAGS += -O1
+ ifeq ($(PLATFORM),PLATFORM_WEB)
+ CFLAGS += -Os
+ else
+ CFLAGS += -s -O1
+ endif
endif
# Additional flags for compiler (if desired)
@@ -311,18 +318,12 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
# -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL!
# -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
# -s USE_PTHREADS=1 # multithreading support
- # -s WASM=0 # disable Web Assembly, emitted by default
- # -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow)
- # -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter
# -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data
# -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
# --profiling # include information for code profiling
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
# --preload-file resources # specify a resources folder for data compilation
CFLAGS += -s USE_GLFW=3
- ifeq ($(RAYLIB_BUILD_MODE),DEBUG)
- CFLAGS += -s ASSERTIONS=1 --profiling
- endif
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Compiler flags for arquitecture
diff --git a/src/core.c b/src/core.c
index 814ed9f5..111b2be6 100644
--- a/src/core.c
+++ b/src/core.c
@@ -867,9 +867,9 @@ bool IsWindowHidden(void)
// Toggle fullscreen mode (only PLATFORM_DESKTOP)
void ToggleFullscreen(void)
{
-#if defined(PLATFORM_DESKTOP)
CORE.Window.fullscreen = !CORE.Window.fullscreen; // Toggle fullscreen flag
+#if defined(PLATFORM_DESKTOP)
// NOTE: glfwSetWindowMonitor() doesn't work properly (bugs)
if (CORE.Window.fullscreen)
{
@@ -893,7 +893,10 @@ void ToggleFullscreen(void)
}
else glfwSetWindowMonitor(CORE.Window.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
#endif
-
+#if defined(PLATFORM_WEB)
+ if (CORE.Window.fullscreen) EM_ASM(Module.requestFullscreen(false, false););
+ else EM_ASM(document.exitFullscreen(););
+#endif
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
TRACELOG(LOG_WARNING, "Could not toggle to windowed mode");
#endif
@@ -2511,7 +2514,11 @@ bool IsMouseButtonReleased(int button)
{
bool released = false;
-#if !defined(PLATFORM_ANDROID)
+#if defined(PLATFORM_ANDROID)
+ # if defined(SUPPORT_GESTURES_SYSTEM)
+ released = GetGestureDetected() == GESTURE_TAP;
+ # endif
+#else
if ((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) &&
(GetMouseButtonStatus(button) == 0)) released = true;
#endif
@@ -4230,37 +4237,84 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
{
// If additional inputs are required check:
// https://developer.android.com/ndk/reference/group/input
+ // https://developer.android.com/training/game-controllers/controller-input
int type = AInputEvent_getType(event);
+ int source = AInputEvent_getSource(event);
if (type == AINPUT_EVENT_TYPE_MOTION)
{
- // Get first touch position
- CORE.Input.Touch.position[0].x = AMotionEvent_getX(event, 0);
- CORE.Input.Touch.position[0].y = AMotionEvent_getY(event, 0);
+ if ((source & AINPUT_SOURCE_JOYSTICK) == AINPUT_SOURCE_JOYSTICK || (source & AINPUT_SOURCE_GAMEPAD) == AINPUT_SOURCE_GAMEPAD)
+ {
+ // Get first touch position
+ CORE.Input.Touch.position[0].x = AMotionEvent_getX(event, 0);
+ CORE.Input.Touch.position[0].y = AMotionEvent_getY(event, 0);
- // Get second touch position
- CORE.Input.Touch.position[1].x = AMotionEvent_getX(event, 1);
- CORE.Input.Touch.position[1].y = AMotionEvent_getY(event, 1);
+ // Get second touch position
+ CORE.Input.Touch.position[1].x = AMotionEvent_getX(event, 1);
+ CORE.Input.Touch.position[1].y = AMotionEvent_getY(event, 1);
- // Useful functions for gamepad inputs:
- //AMotionEvent_getAction()
- //AMotionEvent_getAxisValue()
- //AMotionEvent_getButtonState()
+ int32_t keycode = AKeyEvent_getKeyCode(event);
+ if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN)
+ {
+ CORE.Input.Keyboard.currentKeyState[keycode] = 1; // Key down
- // Gamepad dpad button presses capturing
- // TODO: That's weird, key input (or button)
- // shouldn't come as a TYPE_MOTION event...
- int32_t keycode = AKeyEvent_getKeyCode(event);
- if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN)
- {
- CORE.Input.Keyboard.currentKeyState[keycode] = 1; // Key down
+ CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode;
+ CORE.Input.Keyboard.keyPressedQueueCount++;
+ }
+ else CORE.Input.Keyboard.currentKeyState[keycode] = 0; // Key up
- CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode;
- CORE.Input.Keyboard.keyPressedQueueCount++;
+ // Stop processing gamepad buttons
+ return 1;
}
- else CORE.Input.Keyboard.currentKeyState[keycode] = 0; // Key up
+ int32_t action = AMotionEvent_getAction(event);
+ unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
+
+ // Simple touch position
+ if (flags == AMOTION_EVENT_ACTION_DOWN)
+ {
+ // Get first touch position
+ CORE.Input.Touch.position[0].x = AMotionEvent_getX(event, 0);
+ CORE.Input.Touch.position[0].y = AMotionEvent_getY(event, 0);
+ }
+
+#if defined(SUPPORT_GESTURES_SYSTEM)
+ GestureEvent gestureEvent;
+
+ // Register touch actions
+ if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_DOWN;
+ else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_UP;
+ else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
+
+ // Register touch points count
+ // NOTE: Documentation says pointerCount is Always >= 1,
+ // but in practice it can be 0 or over a million
+ gestureEvent.pointCount = AMotionEvent_getPointerCount(event);
+
+ // Only enable gestures for 1-3 touch points
+ if ((gestureEvent.pointCount > 0) && (gestureEvent.pointCount < 4))
+ {
+ // Register touch points id
+ // NOTE: Only two points registered
+ gestureEvent.pointerId[0] = AMotionEvent_getPointerId(event, 0);
+ gestureEvent.pointerId[1] = AMotionEvent_getPointerId(event, 1);
+
+ // Register touch points position
+ gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
+ gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) };
+
+ // Normalize gestureEvent.position[x] for screenWidth and screenHeight
+ gestureEvent.position[0].x /= (float)GetScreenWidth();
+ gestureEvent.position[0].y /= (float)GetScreenHeight();
+
+ gestureEvent.position[1].x /= (float)GetScreenWidth();
+ gestureEvent.position[1].y /= (float)GetScreenHeight();
+
+ // Gesture data is sent to gestures system for processing
+ ProcessGestureEvent(gestureEvent);
+ }
+#endif
}
else if (type == AINPUT_EVENT_TYPE_KEY)
{
@@ -4297,11 +4351,29 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Set default OS behaviour
return 0;
}
+
+ return 0;
}
int32_t action = AMotionEvent_getAction(event);
unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
+ // Support only simple touch position
+ if (flags == AMOTION_EVENT_ACTION_DOWN)
+ {
+ // Get first touch position
+ CORE.Input.Touch.position[0].x = AMotionEvent_getX(event, 0);
+ CORE.Input.Touch.position[0].y = AMotionEvent_getY(event, 0);
+ }
+ else if (flags == AMOTION_EVENT_ACTION_UP)
+ {
+ // Get first touch position
+ CORE.Input.Touch.position[0].x = 0;
+ CORE.Input.Touch.position[0].y = 0;
+ }
+ else // TODO:Not sure what else should be handled
+ return 0;
+
#if defined(SUPPORT_GESTURES_SYSTEM)
GestureEvent gestureEvent = { 0 };
@@ -4337,17 +4409,6 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Gesture data is sent to gestures system for processing
ProcessGestureEvent(gestureEvent);
}
-#else
- // Support only simple touch position
- if (flags == AMOTION_EVENT_ACTION_DOWN)
- {
- // Get first touch position
- CORE.Input.Touch.position[0].x = AMotionEvent_getX(event, 0);
- CORE.Input.Touch.position[0].y = AMotionEvent_getY(event, 0);
-
- CORE.Input.Touch.position[0].x /= (float)GetScreenWidth();
- CORE.Input.Touch.position[0].y /= (float)GetScreenHeight();
- }
#endif
return 0;
diff --git a/src/shell.html b/src/shell.html
index 7db891be..507b35ac 100644
--- a/src/shell.html
+++ b/src/shell.html
@@ -241,8 +241,8 @@ jwE50AGjLCVuS8Yt4H7OgZLKK5EKOsLviEWJSL/+0uMi7gLUSBseYwqEbXvSHCec1CJvZPyHCmYQffaB
canvas: (function() {
var canvas = document.querySelector('#canvas');
- // As a default initial behavior, pop up an alert when webgl context is lost. To make your
- // application robust, you may want to override this behavior before shipping!
+ // As a default initial behavior, pop up an alert when webgl context is lost.
+ // To make your application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);