Accelerometer events
This commit is contained in:
@@ -18,6 +18,7 @@ namespace lime {
|
||||
std::map<int, std::map<int, int> > gamepadsAxisMap;
|
||||
const int analogAxisDeadZone = 1000;
|
||||
|
||||
|
||||
SDLApplication::SDLApplication () {
|
||||
|
||||
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) {
|
||||
@@ -45,10 +46,15 @@ namespace lime {
|
||||
KeyEvent keyEvent;
|
||||
MouseEvent mouseEvent;
|
||||
RenderEvent renderEvent;
|
||||
SensorEvent sensorEvent;
|
||||
TextEvent textEvent;
|
||||
TouchEvent touchEvent;
|
||||
WindowEvent windowEvent;
|
||||
|
||||
#if defined(IOS) || defined(ANDROID)
|
||||
SDL_JoystickOpen (0);
|
||||
#endif
|
||||
|
||||
#ifdef HX_MACOS
|
||||
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ());
|
||||
char path[PATH_MAX];
|
||||
@@ -145,6 +151,16 @@ namespace lime {
|
||||
break;
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
|
||||
#if defined(IOS) || defined(ANDROID)
|
||||
if (event->jaxis.which == 0) {
|
||||
|
||||
ProcessSensorEvent (event);
|
||||
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SDL_JOYBALLMOTION:
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
@@ -392,6 +408,26 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void SDLApplication::ProcessSensorEvent (SDL_Event* event) {
|
||||
|
||||
if (SensorEvent::callback) {
|
||||
|
||||
switch (event->jaxis.axis) {
|
||||
|
||||
case 0: sensorEvent.x = event->jaxis.value; break;
|
||||
case 1: sensorEvent.y = event->jaxis.value; break;
|
||||
case 2: sensorEvent.z = event->jaxis.value; break;
|
||||
default: break;
|
||||
|
||||
}
|
||||
|
||||
SensorEvent::Dispatch (&sensorEvent);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SDLApplication::ProcessTextEvent (SDL_Event* event) {
|
||||
|
||||
if (TextEvent::callback) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <app/Application.h>
|
||||
#include <app/ApplicationEvent.h>
|
||||
#include <graphics/RenderEvent.h>
|
||||
#include <system/SensorEvent.h>
|
||||
#include <ui/GamepadEvent.h>
|
||||
#include <ui/KeyEvent.h>
|
||||
#include <ui/MouseEvent.h>
|
||||
@@ -39,6 +40,7 @@ namespace lime {
|
||||
void ProcessGamepadEvent (SDL_Event* event);
|
||||
void ProcessKeyEvent (SDL_Event* event);
|
||||
void ProcessMouseEvent (SDL_Event* event);
|
||||
void ProcessSensorEvent (SDL_Event* event);
|
||||
void ProcessTextEvent (SDL_Event* event);
|
||||
void ProcessTouchEvent (SDL_Event* event);
|
||||
void ProcessWindowEvent (SDL_Event* event);
|
||||
@@ -58,6 +60,7 @@ namespace lime {
|
||||
MouseEvent mouseEvent;
|
||||
double nextUpdate;
|
||||
RenderEvent renderEvent;
|
||||
SensorEvent sensorEvent;
|
||||
TextEvent textEvent;
|
||||
TouchEvent touchEvent;
|
||||
WindowEvent windowEvent;
|
||||
|
||||
Reference in New Issue
Block a user