/// <summary>
        /// Updates position until stopDragging completes.
        /// </summary>
        public static async Task <IBehavior> DragRelative(this IBehavior self,
                                                          V2d initialPosition, IEvent <V2d> moves, IAwaitable stopDragging, CancellationToken ct
                                                          )
        {
            var obj = self as IBehaviorTransform2d;

            if (obj == null)
            {
                throw new InvalidOperationException("DragRelative requires IBehaviorTransform2d.");
            }

            var lastPos = initialPosition;
            await stopDragging.RepeatUntilCompleted(
                async delegate
            {
                var p = await moves.Next.WithCancellation(ct);
                obj.Transform(M33d.Translation(p - lastPos));
                lastPos = p;
            });

            return(self);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates position until stopDragging completes.
        /// </summary>
        public static async Task <IBehavior> DragAbsolute(this IBehavior self,
                                                          IEvent <V2d> positions, IAwaitable stopDragging, CancellationToken ct
                                                          )
        {
            var obj = self as IBehaviorPosition2d;

            if (obj == null)
            {
                throw new InvalidOperationException("DragAbsolute requires IBehaviorPosition2d.");
            }

            await stopDragging.RepeatUntilCompleted(async delegate
            {
                var p = await positions.Next.WithCancellation(ct);
                if (stopDragging.IsCompleted)
                {
                    return;
                }
                obj.Position = p;
            });

            return(self);
        }