Пример #1
0
        public Type0 GetColorAnimation(Type0.Parameter parameter, Type0.Component component)
        {
            foreach (var anim in Type0)
            {
                if (anim.I_00 == parameter && anim.I_01_a == component)
                {
                    return(anim);
                }
            }

            return(null);
        }
Пример #2
0
        private void ChangeHueForAnimations(double hue, double saturation, double lightness, Type0.Parameter parameter, List <IUndoRedo> undos, bool hueSet = false, int variance = 0)
        {
            Type0 r = Type0.FirstOrDefault(e => e.I_01_a == ECF.Type0.Component.R && e.I_00 == parameter);
            Type0 g = Type0.FirstOrDefault(e => e.I_01_a == ECF.Type0.Component.G && e.I_00 == parameter);
            Type0 b = Type0.FirstOrDefault(e => e.I_01_a == ECF.Type0.Component.B && e.I_00 == parameter);

            if (r == null || g == null || b == null)
            {
                return;
            }

            foreach (var r_frame in r.Keyframes)
            {
                float g_frame = g.GetValue(r_frame.Index);
                float b_frame = b.GetValue(r_frame.Index);

                if (r_frame.Float != 0.0 || g_frame != 0.0 || b_frame != 0.0)
                {
                    HslColor.HslColor color = new RgbColor(r_frame.Float, g_frame, b_frame).ToHsl();
                    RgbColor          convertedColor;

                    if (hueSet)
                    {
                        color.SetHue(hue, variance);
                    }
                    else
                    {
                        color.ChangeHue(hue);
                        color.ChangeSaturation(saturation);
                        color.ChangeLightness(lightness);
                    }

                    convertedColor = color.ToRgb();

                    r.SetValue(r_frame.Index, (float)convertedColor.R, undos);
                    g.SetValue(r_frame.Index, (float)convertedColor.G, undos);
                    b.SetValue(r_frame.Index, (float)convertedColor.B, undos);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Ensures that an animation exists for each color component.
        /// </summary>
        public void InitColorAnimations(Type0.Parameter parameter, float defaultR, float defaultG, float defaultB)
        {
            if (Type0 == null)
            {
                return;
            }

            var r = GetColorAnimation(parameter, ECF.Type0.Component.R);
            var g = GetColorAnimation(parameter, ECF.Type0.Component.G);
            var b = GetColorAnimation(parameter, ECF.Type0.Component.B);

            //Create missing animations
            if (r != null || g != null || b != null)
            {
                if (r == null)
                {
                    var newR = ECF.Type0.GetNew(defaultR);
                    newR.I_01_a = ECF.Type0.Component.R;
                    newR.I_00   = parameter;
                    Type0.Add(newR);
                }

                if (g == null)
                {
                    var newG = ECF.Type0.GetNew(defaultG);
                    newG.I_01_a = ECF.Type0.Component.G;
                    newG.I_00   = parameter;
                    Type0.Add(newG);
                }

                if (b == null)
                {
                    var newB = ECF.Type0.GetNew(defaultB);
                    newB.I_01_a = ECF.Type0.Component.B;
                    newB.I_00   = parameter;
                    Type0.Add(newB);
                }
            }

            r = GetColorAnimation(parameter, ECF.Type0.Component.R);
            g = GetColorAnimation(parameter, ECF.Type0.Component.G);
            b = GetColorAnimation(parameter, ECF.Type0.Component.B);

            if (r != null && g != null && b != null)
            {
                //Add keyframe at frame 0, if it doesn't exist
                if (r.GetKeyframe(0) == null)
                {
                    r.SetValue(0, defaultR);
                }

                if (g.GetKeyframe(0) == null)
                {
                    g.SetValue(0, defaultG);
                }

                if (b.GetKeyframe(0) == null)
                {
                    b.SetValue(0, defaultB);
                }
            }

            //Add missing keyframes
            foreach (var anim in Type0)
            {
                foreach (var anim2 in Type0)
                {
                    if (anim.I_00 == parameter && anim2.I_00 == parameter && !anim.IsAlpha && !anim2.IsAlpha)
                    {
                        anim.AddKeyframesFromAnim(anim2);
                    }
                }
            }
        }