コード例 #1
0
ファイル: InputSystem.cs プロジェクト: xposure/zSprite_Old
        private void processMouseInput(float delta)
        {
            if (!engine.hasFocus())
            {
                return;
            }

            Vector2i deltaMouse = mouse.getDelta();

            //process mouse movement x axis
            if (deltaMouse.x != 0)
            {
                MouseAxisEvent @event = new MouseXAxisEvent(deltaMouse.x * config.getInput().getMouseSensitivity(), delta);
                setupTarget(@event);
                for (EntityRef entity : getInputEntities())
                {
                    entity.send(@event);
                    if (@event.isConsumed())
                    {
                        break;
                    }
                }
            }

            //process mouse movement y axis
            if (deltaMouse.y != 0)
            {
                MouseAxisEvent @event = new MouseYAxisEvent(deltaMouse.y * config.getInput().getMouseSensitivity(), delta);
                setupTarget(@event);
                for (EntityRef entity : getInputEntities())
                {
                    entity.send(@event);
                    if (@event.isConsumed())
                    {
                        break;
                    }
                }
            }

            //process mouse clicks
            for (InputAction action : mouse.getInputQueue())
            {
                switch (action.getInput().getType())
                {
                case MOUSE_BUTTON:
                    int id = action.getInput().getId();
                    if (id != -1)
                    {
                        MouseInput button   = MouseInput.find(action.getInput().getType(), action.getInput().getId());
                        bool       consumed = sendMouseEvent(button, action.getState().isDown(), action.getMousePosition(), delta);

                        BindableButtonImpl bind = mouseButtonBinds.get(button);
                        if (bind != null)
                        {
                            bind.updateBindState(
                                action.getInput(),
                                action.getState().isDown(),
                                delta,
                                getInputEntities(),
                                targetSystem.getTarget(),
                                targetSystem.getTargetBlockPosition(),
                                targetSystem.getHitPosition(),
                                targetSystem.getHitNormal(),
                                consumed
                                );
                        }
                    }
                    break;

                case MOUSE_WHEEL:
                    int dir = action.getInput().getId();
                    if (dir != 0 && action.getTurns() != 0)
                    {
                        bool consumed = sendMouseWheelEvent(action.getMousePosition(), dir * action.getTurns(), delta);

                        BindableButtonImpl bind = (dir == 1) ? mouseWheelUpBind : mouseWheelDownBind;
                        if (bind != null)
                        {
                            for (int i = 0; i < action.getTurns(); ++i)
                            {
                                bind.updateBindState(
                                    action.getInput(),
                                    true,
                                    delta,
                                    getInputEntities(),
                                    targetSystem.getTarget(),
                                    targetSystem.getTargetBlockPosition(),
                                    targetSystem.getHitPosition(),
                                    targetSystem.getHitNormal(),
                                    consumed
                                    );
                                bind.updateBindState(
                                    action.getInput(),
                                    false,
                                    delta,
                                    getInputEntities(),
                                    targetSystem.getTarget(),
                                    targetSystem.getTargetBlockPosition(),
                                    targetSystem.getHitPosition(),
                                    targetSystem.getHitNormal(),
                                    consumed
                                    );
                            }
                        }
                    }
                    break;

                case KEY:
                    break;
                }
            }
        }