void DesertStrikeScenario::WinLoseScreen::closeEvent(Tempest::CloseEvent &e) {
  e.ignore();
  }
Beispiel #2
0
void MainMenu::closeEvent(Tempest::CloseEvent &e) {
  e.ignore();
  }
Beispiel #3
0
int AndroidAPI::nextEvent(bool &quit) {  
  /*
  static const int ACTION_DOWN = 0,
                   ACTION_UP   = 1,
                   ACTION_MOVE = 2;
  */

  bool hasWindow = true;
  Android::Message msg = Android::MSG_NONE;
  {
  Guard g(android.appMutex);
  (void)g;
  hasWindow = android.window;

  if( android.msg.size() ){
    msg = android.msg[0];

    if( !hasWindow && msg.msg!=Android::MSG_RENDER_LOOP_EXIT ){
      android.sleep();
      return 0;
      }

    android.msg.erase( android.msg.begin() );
    } else {
    if( !android.isPaused && hasWindow )
      render(); else
      android.sleep();
    return 0;
    }
  }

  if( android.wnd==0 )
    return 0;

  switch( msg.msg ) {
    case Android::MSG_SURFACE_RESIZE:
      break;

    case Android::MSG_RENDER_LOOP_EXIT:
      quit = true;
      break;

    case Android::MSG_CHAR:
    {
       Tempest::KeyEvent e = Tempest::KeyEvent( uint32_t(msg.data1) );

       int wrd[3] = {
         AKEYCODE_DEL,
         AKEYCODE_BACK,
         0
         };

       if( 0 == *std::find( wrd, wrd+2, msg.data1) ){
         Tempest::KeyEvent ed( e.key, e.u16, Event::KeyDown );
         SystemAPI::emitEvent( android.wnd, ed);

         Tempest::KeyEvent eu( e.key, e.u16, Event::KeyUp );
         SystemAPI::emitEvent( android.wnd, eu);
         }
    }

    case Android::MSG_KEYDOWN_EVENT:{
      SystemAPI::emitEvent( android.wnd,
                            makeKeyEvent(msg.data1),
                            makeKeyEvent(msg.data1, true),
                            Event::KeyDown );
      }
      break;

    case Android::MSG_KEYUP_EVENT:{
      Tempest::KeyEvent e = makeKeyEvent(msg.data1);

      Tempest::KeyEvent eu( e.key, e.u16, Event::KeyUp );
      SystemAPI::emitEvent( android.wnd, eu);
      }
      break;

    case Android::MSG_TOUCH: {
      int id = android.pointerId( msg.data2 );

      if( msg.data1==0 ){
        MouseEvent e( msg.data.x, msg.data.y,
                      MouseEvent::ButtonLeft, 0, id,
                      Event::MouseDown );
        android.pointerPos(id) = Point(msg.data.x, msg.data.y);
        SystemAPI::emitEvent(android.wnd, e);
        }

      if( msg.data1==1 ){
        MouseEvent e( msg.data.x, msg.data.y,
                      MouseEvent::ButtonLeft, 0, id,
                      Event::MouseUp );
        SystemAPI::emitEvent(android.wnd, e);
        android.unsetPointer(msg.data2);
        }

      if( msg.data1==2 ){
        MouseEvent e( msg.data.x, msg.data.y,
                      MouseEvent::ButtonLeft, 0, id,
                      Event::MouseMove );
        if( android.pointerPos(id) != Point(msg.data.x, msg.data.y) ){
          android.pointerPos(id) = Point(msg.data.x, msg.data.y);
          SystemAPI::emitEvent(android.wnd, e);
          }
        }
      }
      break;

    case Android::MSG_CLOSE:  {
      Tempest::CloseEvent e;
      SystemAPI::emitEvent(android.wnd, e);
      if( !e.isAccepted() ){
        android.pushMsg( Android::MSG_RENDER_LOOP_EXIT );
        }
      }
      break;

    case Android::MSG_START:
      SystemAPI::setShowMode(android.wnd, Tempest::Window::Maximized);
      break;

    case Android::MSG_STOP:
      SystemAPI::setShowMode(android.wnd, Tempest::Window::Minimized);
      break;

    case Android::MSG_PAUSE:
      android.destroy(false);
      break;

    case Android::MSG_RESUME:
      android.initialize();
      break;

    case Android::MSG_NONE:
      if( !android.isPaused && hasWindow )
        render();
      break;

    default:
      break;
    }

  return 0;
  }
Beispiel #4
0
void xProc( XEvent& xev, HWND &hWnd, bool &quit ) {
    Tempest::Window* w = 0;
    std::unordered_map<HWND, Tempest::Window*>::iterator i
        = wndWx.find( hWnd );

    if( i!= wndWx.end() )
        w = i->second;

    if( !w )
        return;

    {
        HWND root;
        int x, y;
        unsigned ww, hh, border, depth;

        if( XGetGeometry(dpy, hWnd, &root, &x, &y, &ww, &hh, &border, &depth) ) {
            SystemAPI::moveEvent( w, x, y );
            SystemAPI::sizeEvent( w, ww, hh );
        }
    }

    switch( xev.type ) {
    case Expose:
        if( xev.xexpose.count == 0 ) {
            render( w );
        }
        break;

    /*
      case WM_CHAR:
      {
         Tempest::KeyEvent e = Tempest::KeyEvent( uint32_t(wParam) );

         DWORD wrd[3] = {
           VK_RETURN,
           VK_BACK,
           0
           };

         if( 0 == *std::find( wrd, wrd+2, wParam) ){
           Tempest::KeyEvent ed( e.key, e.u16, Event::KeyDown );
           SystemAPI::emitEvent(w, ed);

           Tempest::KeyEvent eu( e.key, e.u16, Event::KeyUp );
           SystemAPI::emitEvent(w, eu);
           }
      }
      break;*/

    case KeyPress:
    {
        SystemAPI::emitEvent( w,
                              makeKeyEvent( xev.xkey ),
                              makeKeyEvent( xev.xkey, true),
                              Event::KeyDown );
    }
    break;

    case KeyRelease:
    {
        SystemAPI::emitEvent( w,
                              makeKeyEvent( xev.xkey ),
                              makeKeyEvent( xev.xkey, true),
                              Event::KeyUp );
    }
    break;


    case ButtonPress:
    case ButtonRelease: {
        bool isWheel = false;
        if( xev.type==ButtonPress && XPending(dpy) &&
                (xev.xbutton.button == Button4 || xev.xbutton.button == Button5) ) {
            XEvent ev;
            XNextEvent(dpy, &ev);
            isWheel = (ev.type==ButtonRelease);
        }

        if( isWheel ) {
            int ticks = 0;
            if( xev.xbutton.button == Button4 ) {
                ticks = 100;
            }
            else if ( xev.xbutton.button == Button5 ) {
                ticks = -100;
            }
            Tempest::MouseEvent e( xev.xbutton.x,
                                   xev.xbutton.y,
                                   Tempest::Event::ButtonNone,
                                   ticks,
                                   0,
                                   Event::MouseWheel );
            SystemAPI::emitEvent(w, e);
        } else {
            MouseEvent e( xev.xbutton.x,
                          xev.xbutton.y,
                          toButton( xev.xbutton ),
                          0,
                          0,
                          xev.type==ButtonPress ? Event::MouseDown : Event::MouseUp );
            SystemAPI::emitEvent(w, e);
        }
    }
    break;

    case MotionNotify: {
        MouseEvent e( xev.xmotion.x,
                      xev.xmotion.y,
                      Event::ButtonNone,
                      0,
                      0,
                      Event::MouseMove  );
        SystemAPI::emitEvent(w, e);
    }
    break;
    /*
          case WM_ACTIVATEAPP:
          {
              bool a = (wParam==TRUE);
              SystemAPI::activateEvent(w,a);

              if( !a && w->isFullScreenMode() ){
                ShowWindow( hWnd, SW_MINIMIZE );
                }
          }
          break;*/

    case ClientMessage: {
        if( xev.xclient.data.l[0] == long(wmDeleteMessage()) ) {
            Tempest::CloseEvent e;
            SystemAPI::emitEvent(w, e);
            if( !e.isAccepted() )
                quit = true;
        }
    }
    break;

    case DestroyNotify: {
        quit = true;
    }
    break;

    default:
        break;
    }

    return;
}
Beispiel #5
0
LRESULT CALLBACK WindowProc( HWND   hWnd,
                             UINT   msg,
                             const WPARAM wParam,
                             const LPARAM lParam ) {
    //return DefWindowProc( hWnd, msg, wParam, lParam );

    Tempest::Window* w = 0;
    std::unordered_map<WindowsAPI::Window*, Tempest::Window*>::iterator i
        = wndWx.find( (WindowsAPI::Window*)hWnd );

    if( i!= wndWx.end() )
      w = i->second;

    if( !w )
      return DefWindowProc( hWnd, msg, wParam, lParam );

    if(msg==WM_CHAR || msg==WM_KEYDOWN || msg==WM_KEYUP){
      if(wParam==0x7 || (wParam>0xe && wParam<0xf))
        return DefWindowProc( hWnd, msg, wParam, lParam );//undefined keys
      }

    switch( msg ) {
      case WM_CHAR:
      {
         Tempest::KeyEvent e = Tempest::KeyEvent( uint32_t(wParam) );

         DWORD wrd[4] = {
           VK_RETURN,
           VK_BACK,
           VK_CONTROL,
           0
           };

         if( 0 == *std::find( wrd, wrd+3, wParam) ){
           Tempest::KeyEvent ed( e.key, e.u16, Event::KeyDown );
           SystemAPI::emitEvent(w, ed);

           Tempest::KeyEvent eu( e.key, e.u16, Event::KeyUp );
           SystemAPI::emitEvent(w, eu);
           }
      }
      break;

      case WM_KEYDOWN:
      {
         SystemAPI::emitEvent( w,
                               makeKeyEvent(wParam),
                               makeKeyEvent(wParam, true),
                               Event::KeyDown );
      }
      break;

      case WM_KEYUP:
      {
         SystemAPI::emitEvent( w,
                               makeKeyEvent(wParam),
                               makeKeyEvent(wParam, true),
                               Event::KeyUp );
      }
      break;


      case WM_LBUTTONDOWN:
      case WM_MBUTTONDOWN:
      case WM_RBUTTONDOWN: {
        SetCapture(hWnd);
        MouseEvent e( GET_X_LPARAM(lParam),
                      GET_Y_LPARAM(lParam),
                      toButton(msg),
                      0,
                      0,
                      Event::MouseDown );
        SystemAPI::emitEvent(w, e);
        }
        break;

      case WM_LBUTTONUP:
      case WM_RBUTTONUP:
      case WM_MBUTTONUP: {
        ReleaseCapture();
        MouseEvent e( GET_X_LPARAM(lParam),
                      GET_Y_LPARAM(lParam),
                      toButton(msg),
                      0,
                      0,
                      Event::MouseUp  );
        SystemAPI::emitEvent(w, e);
        }
        break;

      case WM_MOUSELEAVE:{

        }
        break;

      case WM_MOUSEMOVE: {
        MouseEvent e( GET_X_LPARAM(lParam),
                      GET_Y_LPARAM(lParam),
                      Event::ButtonNone,
                      0,
                      0,
                      Event::MouseMove  );
        SystemAPI::emitEvent(w, e);
        }
        break;

       case WM_MOUSEWHEEL:{
          POINT p;
          p.x = GET_X_LPARAM(lParam);
          p.y = GET_Y_LPARAM(lParam);

          ScreenToClient(hWnd, &p);

          Tempest::MouseEvent e( p.x, p.y,
                                 Tempest::Event::ButtonNone,
                                 GET_WHEEL_DELTA_WPARAM(wParam),
                                 0,
                                 Event::MouseWheel );
          SystemAPI::emitEvent(w, e);
          //w->mouseWheelEvent(e);
          }
        break;

      case WM_MOVING:
        if( w ){
          RECT rpos = {0,0,0,0};
          GetWindowRect( hWnd, &rpos );
          SystemAPI::moveEvent( w, rpos.left, rpos.top );
          }
        break;
      case WM_SIZE:{
          RECT rpos = {0,0,0,0};
          GetWindowRect( hWnd, &rpos );

          RECT rectWindow;
          GetClientRect( HWND(hWnd), &rectWindow);
          int cW = rectWindow.right  - rectWindow.left;
          int cH = rectWindow.bottom - rectWindow.top;

          if( w ){
            int smode = int( w->showMode() );

            if( wParam==SIZE_RESTORED )
              smode = Window::Normal;

            if( wParam==SIZE_MAXIMIZED ||
                wParam==SIZE_MAXSHOW   )
              smode = Window::Maximized;

            if( wParam==SIZE_MINIMIZED )
              smode = Window::Minimized;

            if( !w->isFullScreenMode() )
              SystemAPI::setShowMode( w, smode);

            if( wParam!=SIZE_MINIMIZED ){
              SystemAPI::sizeEvent( w, cW, cH );
              //GetWindowRect( HWND(hWnd), &rectWindow );
              SystemAPI::moveEvent( w, rpos.left, rpos.top );
              }
            }
          }
        break;

      case WM_ACTIVATEAPP:
      {
          bool a = (wParam==TRUE);
          SystemAPI::activateEvent(w,a);

          WindowsAPI& api = (WindowsAPI&)SystemAPI::instance();
          api.clearPressedImpl();

          if( !a && w->isFullScreenMode() ){
            ShowWindow( hWnd, SW_MINIMIZE );
            }

          if( !a ){
            if( w->isFullScreenMode() )
              changeDisplaySettings(nullptr, 0);
            } else {
            if( w->isFullScreenMode() ){
              changeDisplaySettings(&appMode, appDevModeFlg);
              UpdateWindow((HWND)w);
              }
            }
      }
      break;

      case WM_CLOSE:{
        Tempest::CloseEvent e;
        SystemAPI::emitEvent(w, e);
        if( !e.isAccepted() )
          PostQuitMessage(0);
        }
        break;

      case WM_DESTROY: {
        PostQuitMessage(0);
        }
        break;

      default: {
        return DefWindowProc( hWnd, msg, wParam, lParam );
        }
      }

    return 0;
  }