Exemplo n.º 1
0
void XWindow::handleEvent(XEvent& Event)
{
    switch (Event.type) 
    {
        case KeyPress:
            //produceKeyPressed(determineKey(wParam),getKeyModifiers());
            _LastKeyboardMouseButtonMask = Event.xkey.state;
            produceKeyPressed(determineKey(XLookupKeysym(&(Event.xkey), 0)),determineKeyModifiers(Event.xkey.state));
            break;
        case KeyRelease:
            //produceKeyReleased(determineKey(wParam),getKeyModifiers());
            _LastKeyboardMouseButtonMask = Event.xkey.state;
            produceKeyReleased(determineKey(XLookupKeysym(&(Event.xkey),0)),determineKeyModifiers(Event.xkey.state));
            break;
        case MotionNotify:
            {
                _LastKeyboardMouseButtonMask = Event.xmotion.state;
                _LastMousePosition.setValues(Event.xbutton.x, Event.xbutton.y);
                if(Event.xmotion.state & Button1MotionMask)
                {
                    produceMouseDragged(MouseEventDetails::BUTTON1,Pnt2f(Event.xmotion.x, Event.xmotion.y), Vec2f(0.0f,0.0f));
                }
                if(Event.xmotion.state & Button2MotionMask)
                {
                    produceMouseDragged(MouseEventDetails::BUTTON2,Pnt2f(Event.xmotion.x, Event.xmotion.y), Vec2f(0.0f,0.0f));
                }
                if(Event.xmotion.state & Button3MotionMask)
                {
                    produceMouseDragged(MouseEventDetails::BUTTON3,Pnt2f(Event.xmotion.x, Event.xmotion.y), Vec2f(0.0f,0.0f));
                }
                if(Event.xmotion.state & Button4MotionMask)
                {
                    produceMouseDragged(MouseEventDetails::BUTTON4,Pnt2f(Event.xmotion.x, Event.xmotion.y), Vec2f(0.0f,0.0f));
                }
                if(Event.xmotion.state & Button5MotionMask)
                {
                    produceMouseDragged(MouseEventDetails::BUTTON5,Pnt2f(Event.xmotion.x, Event.xmotion.y), Vec2f(0.0f,0.0f));
                }
                
                produceMouseMoved(Pnt2f(Event.xmotion.x, Event.xmotion.y), Vec2f(0.0f,0.0f));
                break;
            }
         case ButtonPress:
            {
                _LastKeyboardMouseButtonMask = Event.xbutton.state;
               _LastMousePosition.setValues(Event.xbutton.x, Event.xbutton.y);
               MouseEventDetails::MouseButton OSGButton(MouseEventDetails::NO_BUTTON);
               switch(Event.xbutton.button)
               {
               case  1:
                  OSGButton = MouseEventDetails::BUTTON1;
                  break;
               case  2:
                  OSGButton = MouseEventDetails::BUTTON2;
                  break;
               case  3:
                  OSGButton = MouseEventDetails::BUTTON3;
                  break;
               case   4:
				  produceMouseWheelMoved(1, Pnt2f(Event.xbutton.x, Event.xbutton.y));
                  break;
               case   5:
				  produceMouseWheelMoved(-1, Pnt2f(Event.xbutton.x, Event.xbutton.y));
                  break;
               case   6:
                  OSGButton = MouseEventDetails::BUTTON6;
                  break;
               case   7:
                  OSGButton = MouseEventDetails::BUTTON7;
                  break;
               case   8:
                  OSGButton = MouseEventDetails::BUTTON8;
                  break;
               case   9:
                  OSGButton = MouseEventDetails::BUTTON9;
                  break;
               case   10:
                  OSGButton = MouseEventDetails::BUTTON10;
                  break;
               default:
                  OSGButton = MouseEventDetails::NO_BUTTON;
                  break;
               }
               if(OSGButton != MouseEventDetails::NO_BUTTON)
               {
                   produceMousePressed(OSGButton, Pnt2f(Event.xbutton.x, Event.xbutton.y));
               }
               break;
            }

         case ButtonRelease:
            {
               _LastKeyboardMouseButtonMask = Event.xbutton.state;
               _LastMousePosition.setValues(Event.xbutton.x, Event.xbutton.y);
               MouseEventDetails::MouseButton OSGButton(MouseEventDetails::NO_BUTTON);
              switch(Event.xbutton.button)
              {
              case  1:
                 OSGButton = MouseEventDetails::BUTTON1;
                 break;
              case  2:
                 OSGButton = MouseEventDetails::BUTTON2;
                 break;
               case  3:
                  OSGButton = MouseEventDetails::BUTTON3;
                  break;
               case   6:
                  OSGButton = MouseEventDetails::BUTTON6;
                  break;
               case   7:
                  OSGButton = MouseEventDetails::BUTTON7;
                  break;
               case   8:
                  OSGButton = MouseEventDetails::BUTTON8;
                  break;
               case   9:
                  OSGButton = MouseEventDetails::BUTTON9;
                  break;
               case   10:
                  OSGButton = MouseEventDetails::BUTTON10;
                  break;
              default:
                 break;
              }
               if(OSGButton != MouseEventDetails::NO_BUTTON)
               {
                   produceMouseReleased(OSGButton, Pnt2f(Event.xbutton.x, Event.xbutton.y));
               }
              break;
            }
         case ConfigureNotify:
               this->resize( Event.xconfigure.width,
                            Event.xconfigure.height );

               internalReshape(Vec2f(Event.xconfigure.width, Event.xconfigure.height));
            break;
            
         case DestroyNotify:
            produceWindowClosing();
            produceWindowClosed();
            break;
         case EnterNotify:
            produceWindowEntered();
            break;
         case LeaveNotify:
            produceWindowExited();
            break;
         case UnmapNotify:
            produceWindowIconified();
            break;
         case MapNotify:
            produceWindowDeiconified();
            break;
         case FocusIn:
            produceWindowActivated();
            break;
         case FocusOut:
            produceWindowDeactivated();
            break;
         case Expose:
            internalDraw();
            break;
        case ClientMessage:
        {
            Atom wm_delete_window=XInternAtom(this->getDisplay(), "WM_DELETE_WINDOW", False);
            Atom wm_protocols=XInternAtom(this->getDisplay(), "WM_PROTOCOLS", False);
            if (Event.xclient.message_type == wm_protocols &&
                Event.xclient.data.l[0] == (long)wm_delete_window)
            {
                XDestroyWindow(this->getDisplay(),this->getWindow());
            }
            break;
        }
        default:
            //std::cout << "Event Type: " << Event.type << std::endl;
            break;
      }
}
Exemplo n.º 2
0
void TouchControls::update(int ptr, int action, int x, int y) {
	if (ptr > kNumPointers)
		return;

	TouchArea touchArea = (TouchArea) getTouchArea(x, y);

	switch (action) {
	case JACTION_POINTER_DOWN:
	case JACTION_DOWN:
		if (touchArea > kTouchAreaNone && -1 == pointerFor(touchArea)) {
			pointerFor(touchArea) = ptr;
			_pointers[ptr].active = true;
			_pointers[ptr].function = touchArea;
			_pointers[ptr].startX = _pointers[ptr].currentX = x;
			_pointers[ptr].startY = _pointers[ptr].currentY = y;
			// fall through to move case to initialize _{joy,center,right}Pressing
		} else {
			return;
		}

	case JACTION_MOVE: {
		_pointers[ptr].currentX = x;
		_pointers[ptr].currentY = y;
		int dX = x - _pointers[ptr].startX;
		int dY = y - _pointers[ptr].startY;

		switch (_pointers[ptr].function) {
		case kTouchAreaJoystick: {
			Common::KeyCode newPressing = determineKey(dX, dY);
			if (newPressing != _joystickPressing) {
				_key_receiver->keyPress(_joystickPressing, KeyReceiver::UP);
				_key_receiver->keyPress(newPressing, KeyReceiver::DOWN);
				_joystickPressing = newPressing;
			}
			return;
		}

		case kTouchAreaCenter:
			_centerPressing = determineKey(dX, dY, Common::KEYCODE_RETURN);
			return;

		case kTouchAreaRight:
			_rightPressing = determineKey(dX, dY, Common::KEYCODE_i);
			switch (_rightPressing) {
			case Common::KEYCODE_LEFT:
			case Common::KEYCODE_RIGHT:
				_rightPressing = _rightKeycodes[abs(dX / 100) % _numRightKeycodes];
				break;

			case Common::KEYCODE_UP:
				_rightPressing = Common::KEYCODE_PAGEUP;
				break;

			case Common::KEYCODE_DOWN:
				_rightPressing = Common::KEYCODE_PAGEDOWN;
				break;

			default:
				break;
			}

		default:
			return;
		}
		return;
	}

	case JACTION_UP:
	case JACTION_POINTER_UP: {
		switch (_pointers[ptr].function) {
		case kTouchAreaJoystick:
			pointerFor(kTouchAreaJoystick) = -1;
			if (_joystickPressing != Common::KEYCODE_INVALID) {
				_key_receiver->keyPress(_joystickPressing, KeyReceiver::UP);
				_joystickPressing = Common::KEYCODE_INVALID;
			}
			break;

		case kTouchAreaCenter:
			pointerFor(kTouchAreaCenter) = -1;
			_key_receiver->keyPress(_centerPressing);
			_centerPressing = Common::KEYCODE_INVALID;
			break;

		case kTouchAreaRight:
			pointerFor(kTouchAreaRight) = -1;
			_key_receiver->keyPress(_rightPressing);
			_rightPressing = Common::KEYCODE_INVALID;
			break;

		case kTouchAreaNone:
		default:
			break;
		}
		_pointers[ptr].active = false;
		_pointers[ptr].function = kTouchAreaNone;
		return;
	}
	}
}