Esempio n. 1
0
/*
 * @note Scrolling by `:pixel` may not actually be by real pixels, but instead
 *       correspond to Cocoa co-ords (I don't have a retina display, so I
 *       haven't checked it out yet).
 *
 * Generate `amount` scroll events at the current cursor position
 *
 * Returns number of lines/pixels scrolled, default `units` are by `line`.
 * A positive `amount` will scroll up and a negative `amount` will scroll down.
 *
 * An animation duration can also be specified, which defaults to 0.2 seconds.
 *
 * @overload scroll(amount)
 *   @param amount [Number]
 *   @return [Number]
 * @overload scroll(amount, units)
 *   @param amount [Number]
 *   @param units [Symbol] `:pixel` or `:line`
 *   @return [Number]
 * @overload scroll(amount, units, duration)
 *   @param amount [Number]
 *   @param units [Symbol] `:pixel` or `:line`
 *   @param duration [Number] animation time, in seconds
 *   @return [Number]
 */
static
VALUE
rb_mouse_scroll(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (argc == 0 || argc > 3)
        rb_raise(rb_eArgError,
                 "scroll requires 1..3 arguments, you gave %d",
                 argc);

    const int amt = NUM2INT(argv[0]);

    if (argc == 1) {
        mouse_scroll(amt);

    } else {
        const VALUE input_units = argv[1];
        CGScrollEventUnit units = kCGScrollEventUnitLine;

        if (input_units == sym_pixel)
            units = kCGScrollEventUnitPixel;
        else if (input_units == sym_line)
            units = kCGScrollEventUnitLine;
        else
            rb_raise(rb_eArgError,
                     "unknown units `%s'",
                     rb_id2name(SYM2ID(input_units)));

        if (argc == 2)
            mouse_scroll2(amt, units);
        else
            mouse_scroll3(amt, units, NUM2DBL(argv[2]));
    }

    return argv[0];
}
Esempio n. 2
0
void
mouse_scroll(int amount)
{
  mouse_scroll2(amount, kCGScrollEventUnitLine);
}