Esempio n. 1
0
        /// <summary>
        /// Applies this Affector's definition with parameters from given Animation Instance
        /// <para>This function is internal so unless you know what you're doing, don't touch!</para>
        /// </summary>
        /// <param name="instance"></param>
        /// <seealso cref="AnimationInstance"/>
        public void Apply(AnimationInstance instance)
        {
            var target   = instance.GetTarget();
            var position = instance.GetPosition();

            // special case
            if (_keyFrames.Count == 0)
            {
                return;
            }

            if (String.IsNullOrEmpty(_targetProperty))
            {
                System.GetSingleton().Logger.LogEvent("Affector can't be applied when target property is empty!", LoggingLevel.Warnings);
                return;
            }

            if (_interpolator == null)
            {
                System.GetSingleton().Logger.LogEvent("Affector can't be applied when no interpolator is set!", LoggingLevel.Warnings);
                return;
            }

            KeyFrame left  = null;
            KeyFrame right = null;

            // find 2 neighbouring keyframes
            foreach (var it in _keyFrames)
            {
                var current = it.Value;
                if (current.GetPosition() <= position)
                {
                    left = current;
                }

                if (current.GetPosition() >= position && right == null)
                {
                    right = current;
                }
            }

            float leftDistance, rightDistance;

            if (left != null)
            {
                leftDistance = position - left.GetPosition();
            }
            else
            {
                // if no keyframe is suitable for left neighbour, pick the first one
                left         = _keyFrames.First().Value;
                leftDistance = 0;
            }

            if (right != null)
            {
                rightDistance = right.GetPosition() - position;
            }
            else
            {
                // if no keyframe is suitable for the right neighbour, pick the last one
                right         = _keyFrames.Last().Value;
                rightDistance = 0;
            }

            // if there is just one keyframe and we are right on it
            if (leftDistance + rightDistance == 0f)
            {
                leftDistance = rightDistance = 0.5f;
            }

            // alter interpolation position using the right neighbours progression method
            var interpolationPosition = right.AlterInterpolationPosition(leftDistance / (leftDistance + rightDistance));

            // absolute application method
            if (_applicationMethod == ApplicationMethod.Absolute)
            {
                var result = _interpolator.InterpolateAbsolute(left.GetValueForAnimation(instance),
                                                               right.GetValueForAnimation(instance),
                                                               interpolationPosition);

                target.SetProperty(_targetProperty, result);
            }
            // relative application method
            else if (_applicationMethod == ApplicationMethod.Relative)
            {
                var @base = instance.GetSavedPropertyValue(GetTargetProperty());

                var result = _interpolator.InterpolateRelative(@base,
                                                               left.GetValueForAnimation(instance),
                                                               right.GetValueForAnimation(instance),
                                                               interpolationPosition);

                target.SetProperty(_targetProperty, result);
            }
            // relative multiply application method
            else if (_applicationMethod == ApplicationMethod.RelativeMultiply)
            {
                var @base = instance.GetSavedPropertyValue(GetTargetProperty());

                var result = _interpolator.InterpolateRelativeMultiply(@base,
                                                                       left.GetValueForAnimation(instance),
                                                                       right.GetValueForAnimation(instance),
                                                                       interpolationPosition);

                target.SetProperty(_targetProperty, result);
            }
            else
            {
                // todo: more application methods?
                global::System.Diagnostics.Debug.Assert(false);
            }
        }
Esempio n. 2
0
 private GlobalEventSet()
 {
     System.GetSingleton().Logger.
     LogEvent(String.Format("CEGUI::GlobalEventSet singleton created. ({0:X8})", GetHashCode()));
 }
Esempio n. 3
0
        private bool handlePasteRequest(SemanticInputEvent @event)
        {
            var target = GetInputTargetWindow();

            return(target != null && target.PerformPaste(System.GetSingleton().GetClipboard()));
        }