/// <summary>
        /// Perform any multi-touch actions
        /// </summary>
        public void Update()
        {
            if (this.AttachedCursors.Count > 0)
            {
                // Find the Behavior for the multitouch action
                var behaviorChain = this.Behavior;
                if (behaviorChain == null)
                {
                    //default to full multitouch
                    behaviorChain = Behaviors.FullMultitouchNode.PrincipalBehavior;
                }

                // Setup the arguments to perform the Behavior
                var performArguments = new Behaviors.PerformArguments
                {
                    Cursors = this.AttachedCursors
                };

                // If we have constraints, add the settings to the performArguments
                if (this.Constraint != null)
                {
                    var checkConstraintArguments = new Constraints.CheckConstraintArguments
                    {
                        Slide = this
                    };

                    performArguments.ValidateFunction = (Behaviors.ValidateFunctionArguments validateFunctionArguments) =>
                    {
                        return(this.Constraint.CheckConstraint(validateFunctionArguments, checkConstraintArguments));
                    };
                }

                // Perform the behavior chain (inside the chain it checks relevant Constraints and at
                // each point in the tree uses fallback behavior if Constraints are not met if any)
                {
                    Matrix4x4 newTransform = this.Transform;                     // this will always be overwritten - it's just the cheapest thing here to use as a dummy
                    if (behaviorChain.PerformAndValidate(performArguments, this.Transform, ref newTransform))
                    {
                        this.Transform = newTransform;
                    }
                    else
                    {
                        // No matching of behaviors and constraints could be met
                    }
                }
            }
        }
예제 #2
0
        public bool CheckConstraint(Behaviors.ValidateFunctionArguments validateFunctionArguments, CheckConstraintArguments checkConstraintArguments)
        {
            if (this.UpstreamConstraint != null)
            {
                if (!this.UpstreamConstraint.CheckConstraint(validateFunctionArguments, checkConstraintArguments))
                {
                    return(false);
                }
            }

            if (this.HitTestFunction != null)
            {
                var localCoordinates = new List <Vector2D>();
                var worldCoordinates = new List <Vector2D>();

                // Build local coordinates
                for (int i = 0; i < this.Resolution; i++)
                {
                    for (int j = 0; j < this.Resolution; j++)
                    {
                        localCoordinates.Add(new Vector2D(
                                                 ((double)i / (double)(Resolution - 1)) - 0.5,
                                                 ((double)j / (double)(Resolution - 1)) - 0.5
                                                 ));
                    }
                }

                // Build world coordinates
                foreach (var localCoordinate in localCoordinates)
                {
                    // Ignore local coordinate which doesn't pass slide hit test
                    if (checkConstraintArguments.Slide.DragHitTest(localCoordinate))
                    {
                        var localCoordinate3 = new Vector3D(localCoordinate);
                        var worldCoordinate3 = validateFunctionArguments.Transform * localCoordinate3;
                        var worldCoordinate  = new Vector2D(worldCoordinate3.x, worldCoordinate3.y);
                        worldCoordinates.Add(worldCoordinate);
                    }
                }

                // Check if any world coordinates fail hit test
                foreach (var worldCoordinate in worldCoordinates)
                {
                    var worldCoordinateInHitTest = worldCoordinate;

                    if (this.HitTestFunction is HitTestImageFileNode.Function)
                    {
                        worldCoordinateInHitTest /= 2.0;
                    }

                    if (!this.HitTestFunction.TestHit(worldCoordinateInHitTest))                     // Full screen hit test rather than default quad size
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public bool CheckConstraint(Behaviors.ValidateFunctionArguments validateFunctionArguments, CheckConstraintArguments checkConstraintArguments)
        {
            if (this.UpstreamConstraint != null)
            {
                if (!this.UpstreamConstraint.CheckConstraint(validateFunctionArguments, checkConstraintArguments))
                {
                    return(false);
                }
            }

            if (!validateFunctionArguments.ActionsApplied.Contains(Behaviors.ActionsApplied.Translate))
            {
                // Ignore if no translate applied
                return(true);
            }

            Vector3D rotation, scale, translation;

            Matrix4x4Utils.Decompose(validateFunctionArguments.Transform
                                     , out scale
                                     , out rotation
                                     , out translation);

            var translation2 = new Vector2D(translation.x, translation.y);

            var result = translation2.x >= this.Minimum.x &&
                         translation2.y >= this.Minimum.y &&
                         translation2.x <= this.Maximum.x &&
                         translation2.y <= this.Maximum.y;

            return(result);
        }
        public bool CheckConstraint(Behaviors.ValidateFunctionArguments validateFunctionArguments, CheckConstraintArguments checkConstraintArguments)
        {
            if (this.UpstreamConstraint != null)
            {
                if (!this.UpstreamConstraint.CheckConstraint(validateFunctionArguments, checkConstraintArguments))
                {
                    return(false);
                }
            }

            if (!validateFunctionArguments.ActionsApplied.Contains(Behaviors.ActionsApplied.Rotate))
            {
                // Ignore if no rotation applied
                return(true);
            }

            Vector3D rotation, scale, translation;

            Matrix4x4Utils.Decompose(validateFunctionArguments.Transform
                                     , out scale
                                     , out rotation
                                     , out translation);

            return(rotation.z / (Math.PI * 2.0) >= this.Minimum && rotation.z / (Math.PI * 2.0) <= this.Maximum);
        }