src/video/android/SDL_androidmouse.c
changeset 12007 ecfb6a793c30
parent 11932 a05a909eeddb
child 12025 39a92b19f99e
equal deleted inserted replaced
12006:1b7ed3438a7f 12007:ecfb6a793c30
   135         }
   135         }
   136     }
   136     }
   137     return 0;
   137     return 0;
   138 }
   138 }
   139 
   139 
       
   140 static int
       
   141 Android_SetRelativeMouseMode(SDL_bool enabled)
       
   142 {
       
   143     if (!Android_JNI_SupportsRelativeMouse()) {
       
   144         return SDL_Unsupported();
       
   145     }
       
   146 
       
   147     if (!Android_JNI_SetRelativeMouseEnabled(enabled)) {
       
   148         return SDL_Unsupported();
       
   149     }
       
   150 
       
   151     return 0;
       
   152 }
       
   153 
   140 void
   154 void
   141 Android_InitMouse(void)
   155 Android_InitMouse(void)
   142 {
   156 {
   143     SDL_Mouse *mouse = SDL_GetMouse();
   157     SDL_Mouse *mouse = SDL_GetMouse();
   144 
   158 
   145     mouse->CreateCursor = Android_CreateCursor;
   159     mouse->CreateCursor = Android_CreateCursor;
   146     mouse->CreateSystemCursor = Android_CreateSystemCursor;
   160     mouse->CreateSystemCursor = Android_CreateSystemCursor;
   147     mouse->ShowCursor = Android_ShowCursor;
   161     mouse->ShowCursor = Android_ShowCursor;
   148     mouse->FreeCursor = Android_FreeCursor;
   162     mouse->FreeCursor = Android_FreeCursor;
       
   163     mouse->SetRelativeMouseMode = Android_SetRelativeMouseMode;
   149 
   164 
   150     SDL_SetDefaultCursor(Android_CreateDefaultCursor());
   165     SDL_SetDefaultCursor(Android_CreateDefaultCursor());
   151 
   166 
   152     last_state = 0;
   167     last_state = 0;
   153 }
   168 }
   170         return 0;
   185         return 0;
   171     }
   186     }
   172 }
   187 }
   173 
   188 
   174 void
   189 void
   175 Android_OnMouse(int state, int action, float x, float y)
   190 Android_OnMouse(int state, int action, float x, float y, SDL_bool relative)
   176 {
   191 {
   177     int changes;
   192     int changes;
   178     Uint8 button;
   193     Uint8 button;
   179 
   194 
   180     if (!Android_Window) {
   195     if (!Android_Window) {
   184     switch(action) {
   199     switch(action) {
   185         case ACTION_DOWN:
   200         case ACTION_DOWN:
   186             changes = state & ~last_state;
   201             changes = state & ~last_state;
   187             button = TranslateButton(changes);
   202             button = TranslateButton(changes);
   188             last_state = state;
   203             last_state = state;
   189             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
   204             SDL_SendMouseMotion(Android_Window, 0, relative, x, y);
   190             SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, button);
   205             SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, button);
   191             break;
   206             break;
   192 
   207 
   193         case ACTION_UP:
   208         case ACTION_UP:
   194             changes = last_state & ~state;
   209             changes = last_state & ~state;
   195             button = TranslateButton(changes);
   210             button = TranslateButton(changes);
   196             last_state = state;
   211             last_state = state;
   197             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
   212             SDL_SendMouseMotion(Android_Window, 0, relative, x, y);
   198             SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, button);
   213             SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, button);
   199             break;
   214             break;
   200 
   215 
   201         case ACTION_MOVE:
   216         case ACTION_MOVE:
   202         case ACTION_HOVER_MOVE:
   217         case ACTION_HOVER_MOVE:
   203             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
   218             SDL_SendMouseMotion(Android_Window, 0, relative, x, y);
   204             break;
   219             break;
   205 
   220 
   206         case ACTION_SCROLL:
   221         case ACTION_SCROLL:
   207             SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
   222             SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
   208             break;
   223             break;