예제 #1
0
bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) {
    /* Don't handle anything during switch from/to fullscreen */
    if(flags & Flag::FullscreenSwitchInProgress) return false;

    Flags tmpFlags = flags;

    switch(event.GetType()) {
        case PP_INPUTEVENT_TYPE_KEYDOWN:
        case PP_INPUTEVENT_TYPE_KEYUP: {
            pp::KeyboardInputEvent keyEvent(event);
            KeyEvent e(static_cast<KeyEvent::Key>(keyEvent.GetKeyCode()), static_cast<InputEvent::Modifier>(keyEvent.GetModifiers()));
            event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e);
            if(!e.isAccepted()) return false;
            break;
        }

        case PP_INPUTEVENT_TYPE_MOUSEDOWN:
        case PP_INPUTEVENT_TYPE_MOUSEUP: {
            pp::MouseInputEvent mouseEvent(event);
            MouseEvent e(static_cast<MouseEvent::Button>(mouseEvent.GetButton()), {mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()}, static_cast<InputEvent::Modifier>(mouseEvent.GetModifiers()));
            event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN ? mousePressEvent(e) : mouseReleaseEvent(e);
            if(!e.isAccepted()) return false;
            break;
        }

        case PP_INPUTEVENT_TYPE_WHEEL: {
            pp::WheelInputEvent wheelEvent(event);
            if(Math::TypeTraits<Float>::equals(wheelEvent.GetDelta().y(), 0.0f)) return false;
            MouseEvent e(wheelEvent.GetDelta().y() > 0 ? MouseEvent::Button::WheelUp : MouseEvent::Button::WheelDown, {}, static_cast<InputEvent::Modifier>(wheelEvent.GetModifiers()));
            mousePressEvent(e);
            if(!e.isAccepted()) return false;
            break;
        }

        case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
            pp::MouseInputEvent mouseEvent(event);
            MouseMoveEvent e({mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()},  {mouseEvent.GetMovement().x(), mouseEvent.GetMovement().y()}, static_cast<InputEvent::Modifier>(mouseEvent.GetModifiers()));
            mouseMoveEvent(e);
            if(!e.isAccepted()) return false;
            break;
        }

        default: return false;
    }

    /* Assume everything is properly sequential here */
    CORRADE_INTERNAL_ASSERT((tmpFlags & Flag::SwapInProgress) == (flags & Flag::SwapInProgress));

    /* Redraw, if it won't be handled after swap automatically */
    if((flags & Flag::Redraw) && !(flags & Flag::SwapInProgress)) {
        flags &= ~Flag::Redraw;
        drawEvent();
    }

    return true;
}
bool eUSPInstance::HandleInputEvent(const pp::InputEvent& ev)
{
	switch(ev.GetType())
	{
	case PP_INPUTEVENT_TYPE_KEYDOWN:
		{
			pp::KeyboardInputEvent event(ev);
			if(SpecialKeyDown(event))
				return true;
			int key = event.GetKeyCode();
			dword flags = KF_DOWN|OpJoyKeyFlags();
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, flags);
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_KEYUP:
		{
			pp::KeyboardInputEvent event(ev);
			int key = event.GetKeyCode();
			dword flags = 0;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, OpJoyKeyFlags());
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEMOVE:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			pp::Point delta = event.GetMovement();
			Handler()->OnMouse(MA_MOVE, delta.x(), -delta.y());
			return true;
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEDOWN:
	case PP_INPUTEVENT_TYPE_MOUSEUP:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			Handler()->OnMouse(MA_BUTTON, event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT, ev.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
			return true;
		}
		break;
	default:
		break;
	}
	return false;
}
예제 #3
0
 virtual bool HandleInputEvent(const pp::InputEvent &event) {
     if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE) {
         pp::MouseInputEvent ev(event);
         Point p = ev.GetPosition();
         mouse_x = p.x();
         mouse_y = p.y();
         return true;
     }
     return false;
 }
예제 #4
0
파일: gbox.cpp 프로젝트: dale6john/dj_nacl
  bool GboxInstance::HandleInputEvent(const pp::InputEvent &event) {
    bool ret = false; // handled?

    switch (event.GetType()) {
    case PP_INPUTEVENT_TYPE_KEYDOWN:
    case PP_INPUTEVENT_TYPE_KEYUP:
    case PP_INPUTEVENT_TYPE_CHAR:
    case PP_INPUTEVENT_TYPE_CONTEXTMENU:
      {
        pp::KeyboardInputEvent key_event(event);
        ret = HandleKeyboard(key_event);
      }
      break;

    case PP_INPUTEVENT_TYPE_MOUSEDOWN:
    case PP_INPUTEVENT_TYPE_MOUSEMOVE:
    case PP_INPUTEVENT_TYPE_MOUSEUP:
    case PP_INPUTEVENT_TYPE_MOUSEENTER:
    case PP_INPUTEVENT_TYPE_MOUSELEAVE:
    case PP_INPUTEVENT_TYPE_WHEEL:
      {
        pp::MouseInputEvent mouse_event(event);
        ret = HandleMouse(mouse_event);
      }
      break;

    case PP_INPUTEVENT_TYPE_UNDEFINED:
    case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
      ret = false;

    default:
      break;
    }

#if 1
    if (!ret && sca() == 0x3)
      theLog.info("_Input Event: (%s a) et:%d handled:%d count:%d",
        kVersion, event.GetType(), ret, ++m_mc);
#endif
    return ret;
  }
예제 #5
0
bool Fuji::HandleInputEvent(const pp::InputEvent& event)
{
	if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEUP)
	{
		// By notifying the browser mouse clicks are handled, the application window
		// is able to get focus and receive key events.
		return true;
	}
	else if (event.GetType() == PP_INPUTEVENT_TYPE_KEYUP)
	{
		pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event);
		//...
		return true;
	}
	else if (event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN)
	{
		pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event);
		//...
		return true;
	}
	return false;
}
예제 #6
0
    virtual bool HandleInputEvent(const pp::InputEvent &event) {
        if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE) {
            pp::MouseInputEvent ev(event);
            Point p = ev.GetPosition();
            for (int dy = -4; dy <= 4; dy++) {
                int y = p.y() + dy;
                if (y < MARGIN) y = MARGIN;
                if (y > HEIGHT - MARGIN - 1) y = HEIGHT - MARGIN - 1;
                for (int dx = -4; dx <= 4; dx++) {
                    int x = p.x() + dx;
                    if (x < MARGIN) x = MARGIN;
                    if (x > WIDTH - MARGIN - 1) x = WIDTH - MARGIN - 1;
                    if (dx*dx + dy*dy < 4*4) {                        
                        uint32_t col;
                        switch (rand() & 3) {
                        case 0:
                            col = 0x000000ff;
                            break;
                        case 1:
                            col = 0x0000ffff;
                            break;
                        case 2:
                            col = 0x00ff00ff;
                            break;
                        case 3:
                            col = 0xff0000ff;
                        }
                        Point q(x, y);
                        *(im1.GetAddr32(q)) = col;
                        *(im2.GetAddr32(q)) = col;
                    }
                }
            }

            return true;
        }
        return false;
    }
예제 #7
0
void OSNacl::handle_event(const pp::InputEvent& p_event) {

	int type = p_event.GetType();
	switch (type) {

	case PP_INPUTEVENT_TYPE_MOUSEDOWN:
	case PP_INPUTEVENT_TYPE_MOUSEUP:
	case PP_INPUTEVENT_TYPE_WHEEL: {

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::MOUSE_BUTTON;
		event.device=0;

		pp::MouseInputEvent mevent(p_event);
		if (type == PP_INPUTEVENT_TYPE_WHEEL) {

			pp::WheelInputEvent wevent(p_event);;
			float ticks = wevent.GetTicks().y();
			if (ticks == 0)
				break; // whut?

			event.mouse_button.pressed = true;
			event.mouse_button.button_index = ticks > 0 ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN;
			event.mouse_button.doubleclick = false;

		} else {

			event.mouse_button.pressed = (type == PP_INPUTEVENT_TYPE_MOUSEDOWN);
			event.mouse_button.button_index = mouse_button(mevent.GetButton());
			event.mouse_button.doubleclick = (mevent.GetClickCount() % 2) == 0;

			mouse_mask &= ~(1<< (event.mouse_button.button_index - 1));
			mouse_mask |= (event.mouse_button.pressed << (event.mouse_button.button_index - 1));
		};
		pp::Point pos = mevent.GetPosition();
		event.mouse_button.button_mask = mouse_mask;
		event.mouse_button.global_x = pos.x();
		event.mouse_button.x = pos.x();
		event.mouse_button.global_y = pos.y();
		event.mouse_button.y = pos.y();
		event.mouse_button.pointer_index = 0;
		event.mouse_button.mod = modifier(p_event.GetModifiers());
		queue_event(event);

	} break;

	case PP_INPUTEVENT_TYPE_MOUSEMOVE: {

		pp::MouseInputEvent mevent(p_event);
		pp::Point pos = mevent.GetPosition();

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::MOUSE_MOTION;
		event.mouse_motion.pointer_index = 0;
		event.mouse_motion.global_x = pos.x();
		event.mouse_motion.global_y = pos.y();
		event.mouse_motion.x = pos.x();
		event.mouse_motion.y = pos.y();
		event.mouse_motion.button_mask = mouse_mask;
		event.mouse_motion.mod = modifier(p_event.GetModifiers());

		event.mouse_motion.relative_x = pos.x() - mouse_last_x;
		event.mouse_motion.relative_y = pos.y() - mouse_last_y;
		mouse_last_x = pos.x();
		mouse_last_y = pos.y();

		queue_event(event);

	} break;

	case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
	case PP_INPUTEVENT_TYPE_KEYDOWN:
	case PP_INPUTEVENT_TYPE_KEYUP: {

		pp::KeyboardInputEvent kevent(p_event);
		bool is_char;
		uint32_t key = godot_key(kevent.GetKeyCode(), is_char);
		if (type != PP_INPUTEVENT_TYPE_KEYUP && is_char) {

			last_scancode = key;
			break;
		};

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::KEY;
		event.key.pressed = (type != PP_INPUTEVENT_TYPE_KEYUP);
		event.key.scancode = key;
		event.key.unicode = key;

		event.key.echo = p_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT;
		event.key.mod = modifier(p_event.GetModifiers());
		queue_event(event);
	} break;

	case PP_INPUTEVENT_TYPE_CHAR: {

		pp::KeyboardInputEvent kevent(p_event);
		InputEvent event;
		event.ID = ++event_id;
		event.type = InputEvent::KEY;
		event.key.pressed = true;
		event.key.scancode = last_scancode;
		event.key.unicode = kevent.GetCharacterText().AsString().c_str()[0];
		event.key.mod = modifier(p_event.GetModifiers());
		event.key.echo = p_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT;
		queue_event(event);

	} break;

	/*
	case NPEventType_Minimize: {

		minimized = p_event->u.minimize.value == 1;

	} break;


	case NPEventType_Focus: {

		if (p_event->u.focus.value == 1) {
			main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
		} else {
			main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
		};
	} break;

	*/

	default:
		;
	};
};
예제 #8
0
bool eUSPInstance::HandleInputEvent(const pp::InputEvent& ev)
{
	switch(ev.GetType())
	{
	case PP_INPUTEVENT_TYPE_KEYDOWN:
		{
			pp::KeyboardInputEvent event(ev);
			if(SpecialKeyDown(event))
				return true;
			int key = event.GetKeyCode();
			dword flags = KF_DOWN|OpJoyKeyFlags();
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, flags);
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_KEYUP:
		{
			pp::KeyboardInputEvent event(ev);
			int key = event.GetKeyCode();
			dword flags = 0;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, OpJoyKeyFlags());
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEMOVE:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			float z = OpZoom();
			float sx, sy;
			GetScaleWithAspectRatio43(&sx, &sy, size.width(), size.height());
			float scale_x = 320.0f/size.width()/sx/z;
			float scale_y = 240.0f/size.height()/sy/z;
			mouse_delta += eMouseDelta(event.GetMovement(), scale_x, scale_y);
			int dx = mouse_delta.x;
			int dy = mouse_delta.y;
			if(dx || dy)
			{
				mouse_delta.x -= dx;
				mouse_delta.y -= dy;
				Handler()->OnMouse(MA_MOVE, dx, -dy);
			}
			return true;
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEDOWN:
		if(!mouse_locked)
		{
			LockMouse(callback.NewCallback(&eUSPInstance::DidLockMouse));
		}
		//no break
	case PP_INPUTEVENT_TYPE_MOUSEUP:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			Handler()->OnMouse(MA_BUTTON, event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT, ev.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
			return true;
		}
		break;
	default:
		break;
	}
	return false;
}