Example #1
0
int
SDL_SendProximity(int id, int x, int y, int type)
{
    int index = SDL_GetMouseIndexId(id);
    SDL_Mouse *mouse = SDL_GetMouse(index);
    int posted = 0;

    if (!mouse) {
        return 0;
    }

    mouse->last_x = x;
    mouse->last_y = y;
    if (SDL_GetEventState(type) == SDL_ENABLE) {
        SDL_Event event;
        event.proximity.which = (Uint8) index;
        event.proximity.x = x;
        event.proximity.y = y;
        event.proximity.cursor = mouse->current_end;
        event.proximity.type = type;
        /* FIXME: is this right? */
        event.proximity.windowID = mouse->focus ? mouse->focus->id : 0;
        posted = (SDL_PushEvent(&event) > 0);
        if (type == SDL_PROXIMITYIN) {
            mouse->proximity = SDL_TRUE;
        } else {
            mouse->proximity = SDL_FALSE;
        }
    }
    return posted;
}
Example #2
0
int
SDL_SendProximity(int id, int x, int y, int type)
{
    int index = SDL_GetMouseIndexId(id);
    SDL_Mouse *mouse = SDL_GetMouse(index);
    int posted = 0;

    if (!mouse) {
        return 0;
    }

    mouse->last_x = x;
    mouse->last_y = y;
    if (SDL_ProcessEvents[type] == SDL_ENABLE) {
        SDL_Event event;
        event.proximity.which = (Uint8) index;
        event.proximity.x = x;
        event.proximity.y = y;
        event.proximity.cursor = mouse->current_end;
        event.proximity.type = type;
        posted = (SDL_PushEvent(&event) > 0);
        if (type == SDL_PROXIMITYIN) {
            mouse->proximity = SDL_TRUE;
        } else {
            mouse->proximity = SDL_FALSE;
        }
    }
    return posted;
}
Example #3
0
int
SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max,
             int pressure_min, int ends)
{
    SDL_Mouse **mice;
    int selected_mouse;
    int index;
    size_t length;

    if (SDL_GetMouseIndexId(mouse->id) != -1) {
        SDL_SetError("Mouse ID already in use");
    }

    /* Add the mouse to the list of mice */
    mice = (SDL_Mouse **) SDL_realloc(SDL_mice,
                                      (SDL_num_mice + 1) * sizeof(*mice));
    if (!mice) {
        SDL_OutOfMemory();
        return -1;
    }

    SDL_mice = mice;
    index = SDL_num_mice++;

    SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
    if (!SDL_mice[index]) {
        SDL_OutOfMemory();
        return -1;
    }
    *SDL_mice[index] = *mouse;

    /* we're setting the mouse properties */
    length = 0;
    length = SDL_strlen(name);
    SDL_mice[index]->focus = 0;
    SDL_mice[index]->name = SDL_malloc((length + 2) * sizeof(char));
    SDL_strlcpy(SDL_mice[index]->name, name, length + 1);
    SDL_mice[index]->pressure_max = pressure_max;
    SDL_mice[index]->pressure_min = pressure_min;
    SDL_mice[index]->cursor_shown = SDL_TRUE;
    selected_mouse = SDL_SelectMouse(index);
    SDL_mice[index]->cur_cursor = NULL;
    SDL_mice[index]->def_cursor =
        SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
                         DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
    SDL_SetCursor(SDL_mice[index]->def_cursor);
    /* we're assuming that all mice are in the computer sensing zone */
    SDL_mice[index]->proximity = SDL_TRUE;
    /* we're assuming that all mice are working in the absolute position mode
       thanx to that, the users that don't want to use many mice don't have to
       worry about anything */
    SDL_mice[index]->relative_mode = SDL_FALSE;
    SDL_mice[index]->current_end = 0;
    SDL_mice[index]->total_ends = ends;
    SDL_SelectMouse(selected_mouse);

    return index;
}
Example #4
0
void
SDL_ChangeEnd(int id, int end)
{
    int index = SDL_GetMouseIndexId(id);
    SDL_Mouse *mouse = SDL_GetMouse(index);

    if (mouse) {
        mouse->current_end = end;
    }
}
Example #5
0
int
SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
{
    int index = SDL_GetMouseIndexId(id);
    SDL_Mouse *mouse = SDL_GetMouse(index);
    int posted;
    Uint32 type;

    if (!mouse) {
        return 0;
    }

    /* Figure out which event to perform */
    switch (state) {
    case SDL_PRESSED:
        if (mouse->buttonstate & SDL_BUTTON(button)) {
            /* Ignore this event, no state change */
            return 0;
        }
        type = SDL_MOUSEBUTTONDOWN;
        mouse->buttonstate |= SDL_BUTTON(button);
        break;
    case SDL_RELEASED:
        if (!(mouse->buttonstate & SDL_BUTTON(button))) {
            /* Ignore this event, no state change */
            return 0;
        }
        type = SDL_MOUSEBUTTONUP;
        mouse->buttonstate &= ~SDL_BUTTON(button);
        break;
    default:
        /* Invalid state -- bail */
        return 0;
    }

    /* Post the event, if desired */
    posted = 0;
    if (SDL_GetEventState(type) == SDL_ENABLE) {
        SDL_Event event;
        event.type = type;
        event.button.which = (Uint8) index;
        event.button.state = state;
        event.button.button = button;
        event.button.x = mouse->x;
        event.button.y = mouse->y;
        event.button.windowID = mouse->focus ? mouse->focus->id : 0;
        posted = (SDL_PushEvent(&event) > 0);
    }
    return posted;
}
Example #6
0
void
SDL_SetMouseFocus(int id, SDL_Window * window)
{
    int index = SDL_GetMouseIndexId(id);
    SDL_Mouse *mouse = SDL_GetMouse(index);
    int i;
    SDL_bool focus;

    if (!mouse || (mouse->focus == window)) {
        return;
    }

    /* See if the current window has lost focus */
    if (mouse->focus) {
        focus = SDL_FALSE;
        for (i = 0; i < SDL_num_mice; ++i) {
            SDL_Mouse *check;
            if (i != index) {
                check = SDL_GetMouse(i);
                if (check && check->focus == mouse->focus) {
                    focus = SDL_TRUE;
                    break;
                }
            }
        }
        if (!focus) {
            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
        }
    }

    mouse->focus = window;

    if (mouse->focus) {
        focus = SDL_FALSE;
        for (i = 0; i < SDL_num_mice; ++i) {
            SDL_Mouse *check;
            if (i != index) {
                check = SDL_GetMouse(i);
                if (check && check->focus == mouse->focus) {
                    focus = SDL_TRUE;
                    break;
                }
            }
        }
        if (!focus) {
            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
        }
    }
}
Example #7
0
int
SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
{
    int index = SDL_GetMouseIndexId(id);
    SDL_Mouse *mouse = SDL_GetMouse(index);
    int posted;
    int xrel;
    int yrel;
    int x_max = 0, y_max = 0;

    if (!mouse || mouse->flush_motion) {
        return 0;
    }

    /* if the mouse is out of proximity we don't to want to have any motion from it */
    if (mouse->proximity == SDL_FALSE) {
        mouse->last_x = x;
        mouse->last_y = y;
        return 0;
    }

    /* the relative motion is calculated regarding the system cursor last position */
    if (relative) {
        xrel = x;
        yrel = y;
        x = (mouse->last_x + x);
        y = (mouse->last_y + y);
    } else {
        xrel = x - mouse->last_x;
        yrel = y - mouse->last_y;
    }

    /* Drop events that don't change state */
    if (!xrel && !yrel) {
#if 0
        printf("Mouse event didn't change state - dropped!\n");
#endif
        return 0;
    }

    /* Update internal mouse coordinates */
    if (mouse->relative_mode == SDL_FALSE) {
        mouse->x = x;
        mouse->y = y;
    } else {
        mouse->x += xrel;
        mouse->y += yrel;
    }

    SDL_GetWindowSize(mouse->focus, &x_max, &y_max);

    /* make sure that the pointers find themselves inside the windows */
    /* only check if mouse->xmax is set ! */
    if (x_max && mouse->x > x_max) {
        mouse->x = x_max;
    } else if (mouse->x < 0) {
        mouse->x = 0;
    }

    if (y_max && mouse->y > y_max) {
        mouse->y = y_max;
    } else if (mouse->y < 0) {
        mouse->y = 0;
    }

    mouse->xdelta += xrel;
    mouse->ydelta += yrel;
    mouse->pressure = pressure;

    /* Move the mouse cursor, if needed */
    if (mouse->cursor_shown && !mouse->relative_mode &&
        mouse->MoveCursor && mouse->cur_cursor) {
        mouse->MoveCursor(mouse->cur_cursor);
    }

    /* Post the event, if desired */
    posted = 0;
    if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE &&
        mouse->proximity == SDL_TRUE) {
        SDL_Event event;
        event.motion.type = SDL_MOUSEMOTION;
        event.motion.which = (Uint8) index;
        event.motion.state = mouse->buttonstate;
        event.motion.x = mouse->x;
        event.motion.y = mouse->y;
        event.motion.z = mouse->z;
        event.motion.pressure = mouse->pressure;
        event.motion.pressure_max = mouse->pressure_max;
        event.motion.pressure_min = mouse->pressure_min;
        event.motion.rotation = 0;
        event.motion.tilt_x = 0;
        event.motion.tilt_y = 0;
        event.motion.cursor = mouse->current_end;
        event.motion.xrel = xrel;
        event.motion.yrel = yrel;
        event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
        posted = (SDL_PushEvent(&event) > 0);
    }
    mouse->last_x = mouse->x;
    mouse->last_y = mouse->y;
    return posted;
}