예제 #1
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);
                }
            }
        }
예제 #2
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);
            }
        }