Hello! Sorry for my english, I am not native speaker.
Current code seems to contain several errors:
- SDL_GetDisplayOrientation( … ) returns 0 (UNKNOWN) after application start.
I do not know why, but:
// Get our current screen orientation and pass it down.
mCurrentOrientation = SDLActivity.getCurrentOrientation();
SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
in onCreate() doesn’t do anything. And later:
if ( SDLActivity.mCurrentOrientation) { SDLActivity.mCurrentOrientation = newOrientation; SDLActivity.onNativeOrientationChanged(newOrientation); }
mCurrentOrientation blocks event from C-code and it doesn’t see correct value of orientation until physical flip of device (generation of event after changed orientation).
I think it’s better to check cached value in C-code, not in Java.
- enum
typedef enum
{
SDL_ORIENTATION_UNKNOWN,
SDL_ORIENTATION_LANDSCAPE,
SDL_ORIENTATION_LANDSCAPE_FLIPPED,
SDL_ORIENTATION_PORTRAIT,
SDL_ORIENTATION_PORTRAIT_FLIPPED
} SDL_DisplayOrientation;
and (or?) it’s usage are misleading. These values are mapped to Android “rotation from default position” in SDLActivity.java:
switch (display.getRotation()) { case Surface.ROTATION_0: result = SDL_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: result = SDL_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: result = SDL_ORIENTATION_PORTRAIT_FLIPPED; break; case Surface.ROTATION_270: result = SDL_ORIENTATION_LANDSCAPE_FLIPPED; break; }
but this is wrong - default position (ROTATION_0) is vertical for smartphones and all these values become misleading. I think it’s better to change meaning of enum values to Android “rotation degrees” because this is important for accelerator orientation determination only.
Also mapping to joistick (also in SDLActivity.java):
switch (mDisplay.getRotation()) { case Surface.ROTATION_90: x = -event.values[1]; y = event.values[0]; newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_270: x = event.values[1]; y = -event.values[0]; newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE_FLIPPED; break; case Surface.ROTATION_180: x = -event.values[1]; y = -event.values[0]; newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT_FLIPPED; break; default: x = event.values[0]; y = event.values[1]; newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT; break; }
is wrong for direction ROTATION_180 - it must be opposite of ROTATION_0 (default here) by signs only, but x and y are swapped also. This is incorrect. Must be:
case Surface.ROTATION_180: x = -event.values[0]; y = -event.values[1];
Hope this helps to improve next version of SDL2.
I very appreciate your work! Super great job! Thank you very much!