Пример #1
0
static void mouseMotion(int x, int y)
{
	static int last_x = 0, last_y = 0;
	const int dx = x - last_x;
	const int dy = y - last_y;
	last_x = x;
	last_y = y;

	if (rotating_camera)
		camera.orientation = mouse_rotate(camera.orientation, dx, dy, 0.25);
}
Пример #2
0
/*
 * Perform a rotation gesture in the given `direction` the given `angle` degrees
 *
 * Possible directions are:
 *
 *   - `:cw`, ':clockwise`, ':clock_wise` to rotate in the clockwise
 *     direction
 *   - `:ccw`, ':counter_clockwise`, `:counter_clock_wise` to rotate in
 *     the the counter clockwise direction
 *
 * The `angle` parameter is a number of degrees to rotate. There are 360
 * degrees in a full rotation, as you would expect in Euclidian geometry.
 *
 * You can also optionally specify a point on screen for the mouse
 * pointer to be moved to before the gesture begins. The movement will
 * be instantaneous. Default `point` is {#current_position}.
 *
 * An animation duration can also be specified. The default is 0.2 seconds.
 *
 * @overload rotate(direction, angle)
 *   @param direction [Symbol]
 *   @param angle [Float]
 *   @return [CGPoint]
 * @overload rotate(direction, angle, point)
 *   @param direction [Symbol]
 *   @param angle [Float]
 *   @param point [CGPoint]
 *   @return [CGPoint]
 * @overload rotate(direction, angle, point, duration)
 *   @param direction [Symbol]
 *   @param angle [Float]
 *   @param point [CGPoint]
 *   @param duration [Float]
 *   @return [CGPoint]
 */
static
VALUE
rb_mouse_rotate(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (argc < 2)
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);


    const VALUE input_dir = argv[0];
    CGRotateDirection direction = kCGRotateNone;

    if      (input_dir == sym_cw ||
             input_dir == sym_clockwise ||
             input_dir == sym_clock_wise)
        direction = kCGRotateClockwise;

    else if (input_dir == sym_ccw ||
             input_dir == sym_counter_clockwise ||
             input_dir == sym_counter_clock_wise)
        direction = kCGRotateCounterClockwise;
    else
        rb_raise(rb_eArgError,
                 "invalid rotation direction `%s'",
                 rb_id2name(SYM2ID(input_dir)));

    const double angle = NUM2DBL(argv[1]);

    if (argc == 2) {
        mouse_rotate(direction, angle);
        return CURRENT_POSITION;
    }

    const CGPoint point = rb_mouse_unwrap_point(argv[2]);
    if (argc == 3) {
        mouse_rotate2(direction, angle, point);
        return CURRENT_POSITION;
    }

    mouse_rotate3(direction, angle, point, NUM2DBL(argv[3]));
    return CURRENT_POSITION;
}