Exemplo n.º 1
0
        /// <summary>Runs the current frame.</summary>
        private void Run()
        {
            // Get the frame:
            KeyframesKeyframe frame = RawAnimation.GetFrame(CurrentFrame);

            float duration;

            if (Backwards)
            {
                duration = Duration * frame.AfterDelay;
            }
            else
            {
                duration = Duration * frame.BeforeDelay;
            }

            // The function to use:
            Blaze.VectorPath path = null;

            if (TimingFunction != null)
            {
                // Get the defined vector path:
                path = TimingFunction.GetPath(
                    Style.RenderData,
                    Css.Properties.AnimationTimingFunction.GlobalProperty
                    );
            }

            if (path == null)
            {
                // Use ease:
                path = Css.Keywords.Ease.SharedPath;
            }

            // Create the UI animation:
            Animation = new UIAnimation(Style.Element, frame.Style, duration, path);

            // Add ondone callback:
            Animation.OnDone(Advance);
        }
Exemplo n.º 2
0
        public KeyframesRule(StyleSheet sheet, Css.Value rawValue, string name, List <Rule> frames)
        {
            Name        = name;
            ParentSheet = sheet;
            RawValue    = rawValue;

            SortedDictionary <float, KeyframesKeyframe> sortedSet = new SortedDictionary <float, KeyframesKeyframe>();

            // Sort the set by % order. Exceptions for from and to.
            foreach (Rule rule in frames)
            {
                StyleRule styleRule = rule as StyleRule;

                if (styleRule == null)
                {
                    continue;
                }

                // Create the frame:
                KeyframesKeyframe frame = new KeyframesKeyframe(styleRule.Style);

                if (frame.Style == null)
                {
                    // Empty keyframe - ignore it.
                    continue;
                }

                // What is its percentage position?
                Css.Value cssValue = styleRule.Selector.Value[0];

                float percF = 0f;

                if (cssValue.Type == ValueType.Text)
                {
                    // Get as text:
                    string text = cssValue.Text.ToLower();

                    if (text == "from")
                    {
                        percF = 0f;
                    }
                    else if (text == "to")
                    {
                        percF = 1f;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    percF = cssValue.GetRawDecimal() / 100f;
                }

                // Apply the time:
                frame.Time = percF;

                // Add to Frames set in order of percF.
                sortedSet[percF] = frame;
            }

            // Create the frames set:
            FrameCount = sortedSet.Count;
            Frames     = new KeyframesKeyframe[FrameCount];
            int index = 0;

            foreach (KeyValuePair <float, KeyframesKeyframe> kvp in sortedSet)
            {
                if (index != 0)
                {
                    // Get the frame before:
                    KeyframesKeyframe before = Frames[index - 1];

                    // Figure out the gap between them:
                    float delay = kvp.Value.Time - before.Time;

                    // Update the delay that occurs after it:
                    before.AfterDelay = delay;

                    // And update the delay that occurs before this:
                    kvp.Value.BeforeDelay = delay;
                }
                else
                {
                    // Apply before:
                    kvp.Value.BeforeDelay = kvp.Value.Time;
                }

                Frames[index] = kvp.Value;
                index++;
            }
        }