示例#1
0
 public EffectColorFunction(EffectFunction function, ColorSpectrum colorspectrum, int size = 1)
 {
     this.function      = function;
     this.colorspectrum = colorspectrum;
     this.size          = size;
     this.origin        = function.GetOrigin();
 }
示例#2
0
        /// <summary>
        /// Draws a percent effect on the layer bitmap using DeviceKeys keys and a ColorSpectrum.
        /// </summary>
        /// <param name="spectrum">The ColorSpectrum to be used as a "Progress bar"</param>
        /// <param name="keys">The array of keys that the percent effect will be drawn on</param>
        /// <param name="value">The current progress value</param>
        /// <param name="total">The maxiumum progress value</param>
        /// <param name="percentEffectType">The percent effect type</param>
        /// <returns>Itself</returns>
        public EffectLayer PercentEffect(ColorSpectrum spectrum, Devices.DeviceKeys[] keys, double value, double total, PercentEffectType percentEffectType = PercentEffectType.Progressive, double flash_past = 0.0, bool flash_reversed = false)
        {
            double progress_total = value / total;

            if (progress_total < 0.0)
            {
                progress_total = 0.0;
            }
            else if (progress_total > 1.0)
            {
                progress_total = 1.0;
            }

            double progress = progress_total * keys.Count();

            double flash_amount = 1.0;

            if (flash_past > 0.0)
            {
                if ((flash_reversed && progress_total >= flash_past) || (!flash_reversed && progress_total <= flash_past))
                {
                    flash_amount = Math.Sin((Utils.Time.GetMillisecondsSinceEpoch() % 1000.0D) / 1000.0D * Math.PI);
                }
            }

            for (int i = 0; i < keys.Count(); i++)
            {
                Devices.DeviceKeys current_key = keys[i];

                switch (percentEffectType)
                {
                case (PercentEffectType.AllAtOnce):
                    SetOneKey(current_key, spectrum.GetColorAt((float)progress_total, 1.0f, flash_amount));
                    break;

                case (PercentEffectType.Progressive_Gradual):
                    if (i == (int)progress)
                    {
                        double percent = (double)progress - i;
                        SetOneKey(current_key,
                                  Utils.ColorUtils.MultiplyColorByScalar(spectrum.GetColorAt((float)i / (float)(keys.Count() - 1), 1.0f, flash_amount), percent)
                                  );
                    }
                    else if (i < (int)progress)
                    {
                        SetOneKey(current_key, spectrum.GetColorAt((float)i / (float)(keys.Count() - 1), 1.0f, flash_amount));
                    }
                    break;

                default:
                    if (i < (int)progress)
                    {
                        SetOneKey(current_key, spectrum.GetColorAt((float)i / (float)(keys.Count() - 1), 1.0f, flash_amount));
                    }
                    break;
                }
            }

            return(this);
        }
示例#3
0
        /// <summary>
        /// Blends two EffectBrushes together by a specified amount
        /// </summary>
        /// <param name="otherBrush">The foreground EffectBrush (When percent is at 1.0D, only this EffectBrush is shown)</param>
        /// <param name="percent">The blending percent value</param>
        /// <returns>The blended EffectBrush</returns>
        public EffectBrush BlendEffectBrush(EffectBrush otherBrush, double percent)
        {
            if (percent <= 0.0)
            {
                return(new EffectBrush(this));
            }
            else if (percent >= 1.0)
            {
                return(new EffectBrush(otherBrush));
            }

            ColorSpectrum currentSpectrum = new ColorSpectrum(GetColorSpectrum());
            ColorSpectrum newSpectrum     = new ColorSpectrum(currentSpectrum).MultiplyByScalar(1.0 - percent);

            foreach (var kvp in otherBrush.colorGradients)
            {
                System.Drawing.Color bgColor = currentSpectrum.GetColorAt(kvp.Key);
                System.Drawing.Color fgColor = kvp.Value;

                newSpectrum.SetColorAt(kvp.Key, Utils.ColorUtils.BlendColors(bgColor, fgColor, percent));
            }

            EffectBrush returnBrush = new EffectBrush(newSpectrum);

            returnBrush.SetBrushType(type).SetWrap(wrap);

            returnBrush.start  = new System.Drawing.PointF((float)(start.X * (1.0 - percent) + otherBrush.start.X * (percent)), (float)(start.Y * (1.0 - percent) + otherBrush.start.Y * (percent)));
            returnBrush.end    = new System.Drawing.PointF((float)(end.X * (1.0 - percent) + otherBrush.end.X * (percent)), (float)(end.Y * (1.0 - percent) + otherBrush.end.Y * (percent)));
            returnBrush.center = new System.Drawing.PointF((float)(center.X * (1.0 - percent) + otherBrush.center.X * (percent)), (float)(center.Y * (1.0 - percent) + otherBrush.center.Y * (percent)));

            return(returnBrush);
        }
示例#4
0
        /// <summary>
        ///  Draws a percent effect on the layer bitmap using a FreeFormObject and a ColorSpectrum.
        /// </summary>
        /// <param name="spectrum">The ColorSpectrum to be used as a "Progress bar"</param>
        /// <param name="freeform">The FreeFormObject that the progress effect will be drawn on</param>
        /// <param name="value">The current progress value</param>
        /// <param name="total">The maxiumum progress value</param>
        /// <param name="percentEffectType">The percent effect type</param>
        public void PercentEffect(ColorSpectrum spectrum, Settings.FreeFormObject freeform, double value, double total, PercentEffectType percentEffectType = PercentEffectType.Progressive)
        {
            double progress_total = value / total;

            if (progress_total < 0.0)
            {
                progress_total = 0.0;
            }
            else if (progress_total > 1.0)
            {
                progress_total = 1.0;
            }

            using (Graphics g = Graphics.FromImage(colormap))
            {
                float x_pos  = (float)Math.Round((freeform.X + Effects.grid_baseline_x) * Effects.editor_to_canvas_width);
                float y_pos  = (float)Math.Round((freeform.Y + Effects.grid_baseline_y) * Effects.editor_to_canvas_height);
                float width  = (float)(freeform.Width * Effects.editor_to_canvas_width);
                float height = (float)(freeform.Height * Effects.editor_to_canvas_height);

                if (width < 3)
                {
                    width = 3;
                }
                if (height < 3)
                {
                    height = 3;
                }

                if (percentEffectType == PercentEffectType.AllAtOnce)
                {
                    Rectangle rect = new Rectangle((int)x_pos, (int)y_pos, (int)width, (int)height);

                    PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));

                    Matrix myMatrix = new Matrix();
                    myMatrix.RotateAt(freeform.Angle, rotatePoint, MatrixOrder.Append);

                    g.Transform = myMatrix;
                    g.FillRectangle(new SolidBrush(spectrum.GetColorAt((float)progress_total)), rect);
                }
                else
                {
                    double progress = progress_total * width;

                    Rectangle rect = new Rectangle((int)x_pos, (int)y_pos, (int)progress, (int)height);

                    PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));

                    Matrix myMatrix = new Matrix();
                    myMatrix.RotateAt(freeform.Angle, rotatePoint, MatrixOrder.Append);

                    g.Transform = myMatrix;
                    LinearGradientBrush brush = spectrum.ToLinearGradient(width, 0, x_pos, 0);
                    g.FillRectangle(brush, rect);
                }
            }
        }
示例#5
0
 /// <summary>
 /// Draws a percent effect on the layer bitmap using a KeySequence and a ColorSpectrum.
 /// </summary>
 /// <param name="spectrum">The ColorSpectrum to be used as a "Progress bar"</param>
 /// <param name="sequence">The sequence of keys that the percent effect will be drawn on</param>
 /// <param name="value">The current progress value</param>
 /// <param name="total">The maxiumum progress value</param>
 /// <param name="percentEffectType">The percent effect type</param>
 public void PercentEffect(ColorSpectrum spectrum, Settings.KeySequence sequence, double value, double total = 1.0D, PercentEffectType percentEffectType = PercentEffectType.Progressive)
 {
     if (sequence.type == KeySequenceType.Sequence)
     {
         PercentEffect(spectrum, sequence.keys.ToArray(), value, total, percentEffectType);
     }
     else
     {
         PercentEffect(spectrum, sequence.freeform, value, total, percentEffectType);
     }
 }
示例#6
0
        public EffectBrush(ColorSpectrum spectrum)
        {
            type = BrushType.Linear;

            foreach (var color in spectrum.GetSpectrumColors())
            {
                color_gradients.Add(color.Key, color.Value);
            }

            start  = new System.Drawing.PointF(0, 0);
            end    = new System.Drawing.PointF(1, 0);
            center = new System.Drawing.PointF(0.0f, 0.0f);
        }
示例#7
0
        /// <summary>
        /// Draws a percent effect on the layer bitmap using a KeySequence and a ColorSpectrum.
        /// </summary>
        /// <param name="spectrum">The ColorSpectrum to be used as a "Progress bar"</param>
        /// <param name="sequence">The sequence of keys that the percent effect will be drawn on</param>
        /// <param name="value">The current progress value</param>
        /// <param name="total">The maxiumum progress value</param>
        /// <param name="percentEffectType">The percent effect type</param>
        /// <returns>Itself</returns>
        public EffectLayer PercentEffect(ColorSpectrum spectrum, Settings.KeySequence sequence, double value, double total = 1.0D, PercentEffectType percentEffectType = PercentEffectType.Progressive, double flash_past = 0.0, bool flash_reversed = false)
        {
            if (sequence.type == KeySequenceType.Sequence)
            {
                PercentEffect(spectrum, sequence.keys.ToArray(), value, total, percentEffectType, flash_past, flash_reversed);
            }
            else
            {
                PercentEffect(spectrum, sequence.freeform, value, total, percentEffectType, flash_past, flash_reversed);
            }

            return(this);
        }
示例#8
0
        public bool Equals(ColorSpectrum p)
        {
            if (ReferenceEquals(null, p))
            {
                return(false);
            }
            if (ReferenceEquals(this, p))
            {
                return(true);
            }

            return(shift == p.shift &&
                   colors.Equals(p.colors));
        }
示例#9
0
        /// <summary>
        /// Draws a percent effect on the layer bitmap using DeviceKeys keys and a ColorSpectrum.
        /// </summary>
        /// <param name="spectrum">The ColorSpectrum to be used as a "Progress bar"</param>
        /// <param name="keys">The array of keys that the percent effect will be drawn on</param>
        /// <param name="value">The current progress value</param>
        /// <param name="total">The maxiumum progress value</param>
        /// <param name="percentEffectType">The percent effect type</param>
        public void PercentEffect(ColorSpectrum spectrum, Devices.DeviceKeys[] keys, double value, double total, PercentEffectType percentEffectType = PercentEffectType.Progressive)
        {
            double progress_total = value / total;

            if (progress_total < 0.0)
            {
                progress_total = 0.0;
            }
            else if (progress_total > 1.0)
            {
                progress_total = 1.0;
            }

            double progress = progress_total * keys.Count();

            for (int i = 0; i < keys.Count(); i++)
            {
                Devices.DeviceKeys current_key = keys[i];

                switch (percentEffectType)
                {
                case (PercentEffectType.AllAtOnce):
                    SetOneKey(current_key, spectrum.GetColorAt((float)progress_total));
                    break;

                case (PercentEffectType.Progressive_Gradual):
                    if (i == (int)progress)
                    {
                        double percent = (double)progress - i;
                        SetOneKey(current_key, Utils.ColorUtils.MultiplyColorByScalar(spectrum.GetColorAt((float)i / (float)keys.Count()), percent));
                    }
                    else if (i < (int)progress)
                    {
                        SetOneKey(current_key, spectrum.GetColorAt((float)i / (float)keys.Count()));
                    }
                    break;

                default:
                    if (i < (int)progress)
                    {
                        SetOneKey(current_key, spectrum.GetColorAt((float)i / (float)keys.Count()));
                    }
                    break;
                }
            }
        }
示例#10
0
        public ColorSpectrum GetColorSpectrum()
        {
            ColorSpectrum spectrum = new ColorSpectrum();

            if (type == BrushType.Solid)
            {
                spectrum = new ColorSpectrum(color_gradients[0.0f]);
            }
            else if (type == BrushType.Linear)
            {
                foreach (var color in color_gradients)
                {
                    spectrum.SetColorAt(color.Key, color.Value);
                }
            }

            return(spectrum);
        }
示例#11
0
 /// <summary>
 /// Copy constructor, Creates a new ColorSpectrum instance with data from the passed ColorSpectrum.
 /// </summary>
 /// <param name="otherspectrum">The passed ColorSpectrum</param>
 public ColorSpectrum(ColorSpectrum otherspectrum)
 {
     colors = otherspectrum.colors;
 }
示例#12
0
        /// <summary>
        ///  Draws a percent effect on the layer bitmap using a FreeFormObject and a ColorSpectrum.
        /// </summary>
        /// <param name="spectrum">The ColorSpectrum to be used as a "Progress bar"</param>
        /// <param name="freeform">The FreeFormObject that the progress effect will be drawn on</param>
        /// <param name="value">The current progress value</param>
        /// <param name="total">The maxiumum progress value</param>
        /// <param name="percentEffectType">The percent effect type</param>
        /// <returns>Itself</returns>
        public EffectLayer PercentEffect(ColorSpectrum spectrum, Settings.FreeFormObject freeform, double value, double total, PercentEffectType percentEffectType = PercentEffectType.Progressive, double flash_past = 0.0, bool flash_reversed = false)
        {
            double progress_total = value / total;

            if (progress_total < 0.0)
            {
                progress_total = 0.0;
            }
            else if (progress_total > 1.0)
            {
                progress_total = 1.0;
            }

            double flash_amount = 1.0;

            if (flash_past > 0.0)
            {
                if ((flash_reversed && progress_total >= flash_past) || (!flash_reversed && progress_total <= flash_past))
                {
                    flash_amount = Math.Sin((Utils.Time.GetMillisecondsSinceEpoch() % 1000.0D) / 1000.0D * Math.PI);
                }
            }

            using (Graphics g = Graphics.FromImage(colormap))
            {
                float x_pos  = (float)Math.Round((freeform.X + Effects.grid_baseline_x) * Effects.editor_to_canvas_width);
                float y_pos  = (float)Math.Round((freeform.Y + Effects.grid_baseline_y) * Effects.editor_to_canvas_height);
                float width  = (float)(freeform.Width * Effects.editor_to_canvas_width);
                float height = (float)(freeform.Height * Effects.editor_to_canvas_height);

                if (width < 3)
                {
                    width = 3;
                }
                if (height < 3)
                {
                    height = 3;
                }

                if (percentEffectType == PercentEffectType.AllAtOnce)
                {
                    Rectangle rect = new Rectangle((int)x_pos, (int)y_pos, (int)width, (int)height);

                    PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));

                    Matrix myMatrix = new Matrix();
                    myMatrix.RotateAt(freeform.Angle, rotatePoint, MatrixOrder.Append);

                    g.Transform = myMatrix;
                    g.FillRectangle(new SolidBrush(spectrum.GetColorAt((float)progress_total, 1.0f, flash_amount)), rect);
                }
                else
                {
                    double progress = progress_total * width;

                    Rectangle rect = new Rectangle((int)x_pos, (int)y_pos, (int)progress, (int)height);

                    PointF rotatePoint = new PointF(x_pos + (width / 2.0f), y_pos + (height / 2.0f));

                    Matrix myMatrix = new Matrix();
                    myMatrix.RotateAt(freeform.Angle, rotatePoint, MatrixOrder.Append);

                    g.Transform = myMatrix;
                    LinearGradientBrush brush = spectrum.ToLinearGradient(width, 0, x_pos, 0, flash_amount);
                    g.FillRectangle(brush, rect);
                }

                return(this);
            }
        }