示例#1
0
jint
render(JNIEnv *env, jobject thiz, jint touchX, jint touchY, jdouble turnFactor, jint keyCode, jboolean keySpecial, jboolean keyReleased) {

    turnFact = turnFactor;

    if (initDone) {

        if (mouse_func != NULL && touchX != oldX && touchY != oldY && prevX == -1 && prevY == -1) {
            mouse_func(WS_LEFT_BUTTON, WS_MOUSE_DOWN, touchX, touchY);
            prevX = touchX; prevY = touchY;
        } else if (mouse_func != NULL && touchX != oldX && touchY != oldY) {
            oldX = prevX; oldY = prevY;            
            mouse_func(WS_LEFT_BUTTON, WS_MOUSE_UP, prevX, prevY);
            prevX = -1; prevY = -1;
        }

        if (keyboard_func != NULL && keyCode != -1) {
            keyboard_func(keyCode, keySpecial, keyReleased, 1/*x*/, 1/*y*/);
        }

        if (idle_func != NULL) {
            idle_func();
        }
    
    }

    if (forceExit)
        return(NO_MODE);
    else
        return(g_game.mode);

}
static void 
__glutInputEvent( DFBInputEvent *e, DFBInputEvent *p )
{
     __glutAssert( g_game != NULL );
     
     switch (e->type) {
          case DIET_KEYPRESS:
               g_game->modifiers = __glutModifiers( e->modifiers );
               if (g_ignore_key_repeat && p) {
                    if (p->type       == DIET_KEYPRESS &&
                        p->key_symbol == e->key_symbol)
                         break;
               }
               if (DFB_KEY_IS_ASCII( e->key_symbol )) {
                    if (keyboard_func) {
                         __glutSetWindow( g_game );
                         keyboard_func( e->key_symbol, g_game->cx, g_game->cy );
                    }
               }
               else {
                    int key = __glutSpecialKey( e->key_symbol );
                    if (key && special_func) {
                         __glutSetWindow( g_game );
                         special_func( key, g_game->cx, g_game->cy );
                    }
               }
               break;
          case DIET_KEYRELEASE:
               g_game->modifiers = __glutModifiers( e->modifiers ); 
               if (DFB_KEY_IS_ASCII( e->key_symbol )) {
                    if (keyboard_up_func) {
                         __glutSetWindow( g_game );
                         keyboard_up_func( e->key_symbol, g_game->cx, g_game->cy );
                    }
               }
               else {
                    int key = __glutSpecialKey( e->key_symbol );
                    if (key && special_up_func) {
                         __glutSetWindow( g_game );
                         special_up_func( key, g_game->cx, g_game->cy );
                    }
               }
               break;
          case DIET_BUTTONPRESS:
               if (e->device_id == DIDID_JOYSTICK) {
                    g_game->buttons = e->buttons;
                    if (joystick_func) {
                         __glutSetWindow( g_game );
                         joystick_func( g_game->buttons,
                                        g_game->jx, g_game->jy, g_game->jz );
                    }
               }
               else {
                    if (mouse_func) {
                         __glutSetWindow( g_game );
                         mouse_func( __glutButton( e->button ), 
                                     GLUT_DOWN, g_game->cx, g_game->cy );
                    }
               }
               break;
          case DIET_BUTTONRELEASE:
               if (e->device_id == DIDID_JOYSTICK) {
                    g_game->buttons = e->buttons;
                    if (joystick_func) {
                         __glutSetWindow( g_game );
                         joystick_func( g_game->buttons,
                                        g_game->jx, g_game->jy, g_game->jz );
                    }
               }
               else {
                    if (mouse_func) {
                         __glutSetWindow( g_game );
                         mouse_func( __glutButton( e->button ), 
                                     GLUT_UP, g_game->cx, g_game->cy );
                    }
               }
               break;
          case DIET_AXISMOTION:
               if (e->device_id == DIDID_JOYSTICK) {
                    switch (e->axis) {
                         case DIAI_X:
                              if (e->flags & DIEF_AXISABS)
                                   g_game->jx = e->axisabs;
                              else if (e->flags & DIEF_AXISREL)
                                   g_game->jx += e->axisrel;
                              break;
                         case DIAI_Y:
                              if (e->flags & DIEF_AXISABS)
                                   g_game->jy = e->axisabs;
                              else if (e->flags & DIEF_AXISREL)
                                   g_game->jy += e->axisrel;
                              break;
                         case DIAI_Z:
                              if (e->flags & DIEF_AXISABS)
                                   g_game->jz = e->axisabs;
                              else if (e->flags & DIEF_AXISREL)
                                   g_game->jz += e->axisrel;
                              break;
                         default:
                              break;
                    } 
                    if (joystick_func) {
                         __glutSetWindow( g_game );
                         joystick_func( g_game->buttons,
                                        g_game->jx, g_game->jy, g_game->jz );
                    }
               }
               else {
                    switch (e->axis) {
                         case DIAI_X:
                              if (e->flags & DIEF_AXISABS)
                                   g_game->cx = e->axisabs;
                              else if (e->flags & DIEF_AXISREL)
                                   g_game->cx += e->axisrel;
                              break;
                         case DIAI_Y:
                              if (e->flags & DIEF_AXISABS)
                                   g_game->cy = e->axisabs;
                              else if (e->flags & DIEF_AXISREL)
                                   g_game->cy += e->axisrel;
                              break;
                         default:
                              return;
                    }
                    if (e->buttons && motion_func) {
                         __glutSetWindow( g_game );
                         motion_func( g_game->cx, g_game->cy );
                    }
                    else if (!e->buttons && passive_motion_func) {
                         __glutSetWindow( g_game );
                         passive_motion_func( g_game->cx, g_game->cy );
                    }
               }
               break;
          default:
               break;
     }
}
static void 
__glutWindowEvent( DFBWindowEvent *e, DFBWindowEvent *p )
{
     __GlutWindow *window;
     
     window = __glutFindWindow( e->window_id );
     if (!window) /* window was destroyed */
          return;
     
     switch (e->type) {
          case DWET_KEYDOWN:
               window->modifiers = __glutModifiers( e->modifiers );
               if (g_ignore_key_repeat && p) {
                    if (p->type       == DWET_KEYDOWN &&
                        p->window_id  == e->window_id &&
                        p->key_symbol == e->key_symbol)
                         break;
               }
               if (DFB_KEY_IS_ASCII( e->key_symbol )) {
                    if (keyboard_func) {
                         __glutSetWindow( window );
                         keyboard_func( e->key_symbol, e->x, e->y );
                    }
               }
               else {
                    int key = __glutSpecialKey( e->key_symbol );
                    if (key && special_func) {
                         __glutSetWindow( window );
                         special_func( key, e->x, e->y );
                    }
               }
               break;
          case DWET_KEYUP:
               window->modifiers = __glutModifiers( e->modifiers );
               if (DFB_KEY_IS_ASCII( e->key_symbol )) {
                    if (keyboard_up_func) {
                         __glutSetWindow( window );
                         keyboard_up_func( e->key_symbol, e->x, e->y );
                    }
               }
               else {
                    int key = __glutSpecialKey( e->key_symbol );
                    if (key && special_up_func) {
                         __glutSetWindow( window );
                         special_up_func( key, e->x, e->y );
                    }
               }
               break;
          case DWET_BUTTONDOWN:
               if (mouse_func) {
                    __glutSetWindow( window );
                    mouse_func( __glutButton( e->button ), GLUT_DOWN, e->x, e->y );
               }
               break;
          case DWET_BUTTONUP:
               if (mouse_func) {
                    __glutSetWindow( window );
                    mouse_func( __glutButton( e->button ), GLUT_UP, e->x, e->y );
               }
               break;
          case DWET_MOTION:
               if (e->buttons) {
                    if (motion_func) {
                         __glutSetWindow( window );
                         motion_func( e->cx, e->cy );
                    }
               }
               else {
                    if (passive_motion_func) {
                         __glutSetWindow( window );
                         passive_motion_func( e->cx, e->cy );
                    }
               }
               break;
          case DWET_ENTER:
               if (entry_func) {
                    __glutSetWindow( window );
                    entry_func( GLUT_ENTERED );
               }
               break;
          case DWET_LEAVE:
               if (entry_func) {
                    __glutSetWindow( window );
                    entry_func( GLUT_LEFT );
               }
               break;
          case DWET_SIZE:
               window->reshape = GL_TRUE;
               window->redisplay = GL_TRUE;
               break;
          default:
               break;
     }
}