Beispiel #1
0
boolean B_ParseMouseTypeAndId(const char* desc, ddeventtype_t* type, int* id)
{
    // Maybe it's one of the buttons?
    *id = I_GetKeyByName(I_GetDevice(IDEV_MOUSE, false), desc);
    if(*id >= 0)
    {
        // Got it.
        *type = E_TOGGLE;
        return true;
    }

    if(!strncasecmp(desc, "button", 6) && strlen(desc) > 6) // generic button
    {
        *type = E_TOGGLE;
        *id = strtoul(desc + 6, NULL, 10) - 1;
        if(*id < 0 || (uint)*id >= I_GetDevice(IDEV_MOUSE, false)->numKeys)
        {
            Con_Message("B_ParseMouseTypeAndId: Button %i does not exist.", *id);
            return false;
        }
    }
    else
    {
        // Try to find the axis.
        *type = E_AXIS;
        *id = I_GetAxisByName(I_GetDevice(IDEV_MOUSE, false), desc);
        if(*id < 0)
        {
            Con_Message("B_ParseMouseTypeAndId: Axis \"%s\" is not defined.", desc);
            return false;
        }
    }
    return true;
}
Beispiel #2
0
dd_bool B_ParseMouseTypeAndId(const char* desc, ddeventtype_t* type, int* id)
{
    // Maybe it's one of the buttons?
    *id = I_GetKeyByName(I_GetDevice(IDEV_MOUSE), desc);
    if(*id >= 0)
    {
        // Got it.
        *type = E_TOGGLE;
        return true;
    }

    if(!strncasecmp(desc, "button", 6) && strlen(desc) > 6) // generic button
    {
        *type = E_TOGGLE;
        *id = strtoul(desc + 6, NULL, 10) - 1;
        if(*id < 0 || (uint)*id >= I_GetDevice(IDEV_MOUSE)->numKeys)
        {
            LOG_INPUT_WARNING("Mouse button %i does not exist") << *id;
            return false;
        }
    }
    else
    {
        // Try to find the axis.
        *type = E_AXIS;
        *id = I_GetAxisByName(I_GetDevice(IDEV_MOUSE), desc);
        if(*id < 0)
        {
            LOG_INPUT_WARNING("Mouse axis \"%s\" does not exist") << desc;
            return false;
        }
    }
    return true;
}
Beispiel #3
0
boolean B_ParseJoystickTypeAndId(uint device, const char* desc, ddeventtype_t* type, int* id)
{
    if(!strncasecmp(desc, "button", 6) && strlen(desc) > 6)
    {
        *type = E_TOGGLE;
        *id = strtoul(desc + 6, NULL, 10) - 1;
        if(*id < 0 || (uint)*id >= I_GetDevice(device, false)->numKeys)
        {
            Con_Message("B_ParseJoystickTypeAndId: Button %i does not exist in joystick.", *id);
            return false;
        }
    }
    else if(!strncasecmp(desc, "hat", 3) && strlen(desc) > 3)
    {
        *type = E_ANGLE;
        *id = strtoul(desc + 3, NULL, 10) - 1;
        if(*id < 0 || (uint)*id >= I_GetDevice(device, false)->numHats)
        {
            Con_Message("B_ParseJoystickTypeAndId: Hat %i does not exist in joystick.", *id);
            return false;
        }
    }
    else if(!strcasecmp(desc, "hat"))
    {
        *type = E_ANGLE;
        *id = 0;
    }
    else
    {
        // Try to find the axis.
        *type = E_AXIS;
        *id = I_GetAxisByName(I_GetDevice(device, false), desc);
        if(*id < 0)
        {
            Con_Message("B_ParseJoystickTypeAndId: Axis \"%s\" is not defined in joystick.", desc);
            return false;
        }
    }
    return true;
}
Beispiel #4
0
dd_bool B_ParseDeviceAxisTypeAndId(uint device, const char* desc, ddeventtype_t* type, int* id)
{
    inputdev_t *dev = I_GetDevice(device);

    *type = E_AXIS;
    *id = I_GetAxisByName(dev, desc);
    if(*id < 0)
    {
        LOG_INPUT_WARNING("Axis \"%s\" is not defined in device '%s'") << desc << dev->name;
        return false;
    }
    return true;
}
Beispiel #5
0
dd_bool B_ParseJoystickTypeAndId(uint device, const char* desc, ddeventtype_t* type, int* id)
{
    if(!strncasecmp(desc, "button", 6) && strlen(desc) > 6)
    {
        *type = E_TOGGLE;
        *id = strtoul(desc + 6, NULL, 10) - 1;
        if(*id < 0 || (uint)*id >= I_GetDevice(device)->numKeys)
        {
            LOG_INPUT_WARNING("Joystick button %i does not exist") << *id;
            return false;
        }
    }
    else if(!strncasecmp(desc, "hat", 3) && strlen(desc) > 3)
    {
        *type = E_ANGLE;
        *id = strtoul(desc + 3, NULL, 10) - 1;
        if(*id < 0 || (uint)*id >= I_GetDevice(device)->numHats)
        {
            LOG_INPUT_WARNING("Joystick hat %i does not exist") << *id;
            return false;
        }
    }
    else if(!strcasecmp(desc, "hat"))
    {
        *type = E_ANGLE;
        *id = 0;
    }
    else
    {
        // Try to find the axis.       
        if(!B_ParseDeviceAxisTypeAndId(device, desc, type, id))
        {
            return false;
        }
    }
    return true;
}
Beispiel #6
0
void B_AppendDeviceDescToString(uint device, ddeventtype_t type, int id, ddstring_t* str)
{
    inputdev_t* dev = I_GetDevice(device, false);
    const char* name;

    if(type != E_SYMBOLIC)
    {
        // Name of the device.
        Str_Append(str, dev->name);
        Str_Append(str, "-");
    }

    switch(type)
    {
    case E_TOGGLE:
        if(dev->keys[id].name)
        {
            Str_Append(str, dev->keys[id].name);
        }
        else if(device == IDEV_KEYBOARD)
        {
            name = B_ShortNameForKey(id);
            if(name)
                Str_Append(str, name);
            else
                Str_Appendf(str, "code%03i", id);
        }
        else
            Str_Appendf(str, "button%i",id + 1);
        break;

    case E_AXIS:
        Str_Append(str, dev->axes[id].name);
        break;

    case E_ANGLE:
        Str_Appendf(str, "hat%i", id + 1);
        break;

    case E_SYMBOLIC:
        Str_Append(str, "sym");
        break;

    default:
        Con_Error("B_AppendDeviceDescToString: Invalid value, type = %i.",
                  (int) type);
        break;
    }
}
Beispiel #7
0
boolean B_CheckCondition(statecondition_t* cond, int localNum, bcontext_t* context)
{
    boolean fulfilled = !cond->flags.negate;
    inputdev_t* dev = I_GetDevice(cond->device, false);

    switch(cond->type)
    {
    case SCT_STATE:
        if(cond->flags.multiplayer && netGame)
            return fulfilled;
        break;

    case SCT_MODIFIER_STATE:
        if(context)
        {
            // Evaluate the current state of the modifier (in this context).
            float pos = 0, relative = 0;
            dbinding_t* binds = &B_GetControlBinding(context, cond->id)->deviceBinds[localNum];
            B_EvaluateDeviceBindingList(localNum, binds, &pos, &relative, context, false /*no triggered*/);
            if((cond->state == EBTOG_DOWN && fabs(pos) > .5) ||
               (cond->state == EBTOG_UP && fabs(pos) < .5))
                return fulfilled;
        }
        break;

    case SCT_TOGGLE_STATE:
    {
        int isDown = (dev->keys[cond->id].isDown != 0);
        if((isDown && cond->state == EBTOG_DOWN) ||
           (!isDown && cond->state == EBTOG_UP))
            return fulfilled;
        break;
    }

    case SCT_AXIS_BEYOND:
        if(B_CheckAxisPos(cond->state, cond->pos, dev->axes[cond->id].position))
            return fulfilled;
        break;

    case SCT_ANGLE_AT:
        if(dev->hats[cond->id].pos == cond->pos)
            return fulfilled;
        break;
    }
    return !fulfilled;
}
Beispiel #8
0
de::Action *EventBinding_ActionForEvent(evbinding_t *eb, ddevent_t const *event,
                                        struct bcontext_s *eventClass,
                                        bool respectHigherAssociatedContexts)
{
    int         i;
    inputdev_t* dev = 0;
    ddstring_t  command;

    if(eb->device != event->device || eb->type != event->type)
        return 0;

    if(event->type != E_SYMBOLIC)
    {
        dev = I_GetDevice(eb->device, true);
        if(!dev)
        {
            // The device is not active, there is no way this could get executed.
            return 0;
        }
    }

    switch(event->type)
    {
    case E_TOGGLE:
        if(eb->id != event->toggle.id)
            return 0;

        if(respectHigherAssociatedContexts)
        {
            if(eventClass && dev->keys[eb->id].assoc.bContext != eventClass)
                return 0; // Shadowed by a more important active class.
        }

        // We're checking it, so clear the triggered flag.
        dev->keys[eb->id].assoc.flags &= ~IDAF_TRIGGERED;

        // Is the state as required?
        switch(eb->state)
        {
            case EBTOG_UNDEFINED:
                // Passes no matter what.
                break;

            case EBTOG_DOWN:
                if(event->toggle.state != ETOG_DOWN)
                    return 0;
                break;

            case EBTOG_UP:
                if(event->toggle.state != ETOG_UP)
                    return 0;
                break;

            case EBTOG_REPEAT:
                if(event->toggle.state != ETOG_REPEAT)
                    return 0;
                break;

            case EBTOG_PRESS:
                if(event->toggle.state == ETOG_UP)
                    return 0;
                break;

            default:
                return 0;
        }
        break;

    case E_AXIS:
        if(eb->id != event->axis.id)
            return 0;
        if(eventClass && dev->axes[eb->id].assoc.bContext != eventClass)
            return 0; // Shadowed by a more important active class.

        // Is the position as required?
        if(!B_CheckAxisPos(eb->state, eb->pos,
                           I_TransformAxis(I_GetDevice(event->device, false),
                                           event->axis.id, event->axis.pos)))
            return 0;
        break;

    case E_ANGLE:
        if(eb->id != event->angle.id)
            return 0;
        if(eventClass && dev->hats[eb->id].assoc.bContext != eventClass)
            return 0; // Shadowed by a more important active class.
        // Is the position as required?
        if(event->angle.pos != eb->pos)
            return 0;
        break;

    case E_SYMBOLIC:
        if(strcmp(event->symbolic.name, eb->symbolicName))
            return 0;
        break;

    default:
        return 0;
    }

    // Any conditions on the current state of the input devices?
    for(i = 0; i < eb->numConds; ++i)
    {
        if(!B_CheckCondition(&eb->conds[i], 0, NULL))
            return 0;
    }

    // Substitute parameters in the command.
    Str_Init(&command);
    Str_Reserve(&command, strlen(eb->command));
    B_SubstituteInCommand(eb->command, event, eb, &command);

    de::Action *act = new CommandAction(Str_Text(&command), CMDS_BIND);

    Str_Free(&command);
    return act;
}