Esempio n. 1
0
void
Joystick::update()
{
  struct js_event event;

  ssize_t len = read(fd, &event, sizeof(event));

  if (len < 0)
    {
      std::ostringstream str;
      str << filename << ": " << strerror(errno);
      throw std::runtime_error(str.str());
    }
  else if (len == sizeof(event))
    { // ok
      if (event.type & JS_EVENT_AXIS)
        {
          //std::cout << "Axis: " << (int)event.number << " -> " << (int)event.value << std::endl;
          axis_state[event.number] = event.value;
          axis_move(event.number, event.value);
        }
      else if (event.type & JS_EVENT_BUTTON)
        {
          //std::cout << "Button: " << (int)event.number << " -> " << (int)event.value << std::endl;
          button_move(event.number, event.value);
        }
    }
  else
    {
      throw std::runtime_error("Joystick::update(): unknown read error");
    }
}
Component *button_new(
    Uint32        id,
    Word        name,
    RectFloat   rect,
    RectFloat        bounds,
    char         * buttonText,
    Uint32        fontSize,
    Uint32        buttonType,
    int         buttonHotkey,
    Uint32        buttonHotkeymod,
    int        center,
    int         justify,
    char         * buttonFileUp,
    char         * buttonFileHigh,
    char         * buttonFileDown,
    Vec3D       backgroundColor,
    float       backgroundAlpha,
    Vec3D       highlightColor,
    Vec3D       pressColor
)
{
    int i;
    ComponentButton *button = NULL;
    Component *component = NULL;
    component = component_new();
    if (!component)return NULL;
    component_make_button(
        component,
        buttonText,
        justify,
        buttonType,
        buttonHotkey,
        buttonHotkeymod,
        buttonFileUp,
        buttonFileHigh,
        buttonFileDown,
        backgroundColor,
        backgroundAlpha,
        highlightColor,
        pressColor,
        fontSize
    );
    rect_copy(&component->rect,rect);
    button = component_get_button_data(component);
    if (button == NULL)
    {
        component_free(&component);
        return NULL;
    }
    button->centered = center;
    component->id = id;
    strncpy(component->name,name,WORDLEN);
    component->type = ButtonComponent;
    component->data_move = button_move;
    for (i = 0; i < ButtonStateMax; i++)
    {
        vec3d_cpy(button->textColor[i],__component_button_color[i]);
    }
    button_move(component,bounds);
    component_button_set_activation(component,
                                    __component_button_release_active,
                                    __component_button_press_active,
                                    __component_button_hold_active);
    return component;
}