/// <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); }
/// <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); }
/// <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; } } }
/// <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); } } }
public Tuple <EffectPoint, Color>[] getPointMap() { //List<Tuple<EffectPoint, EffectColor>> points = new List<Tuple<EffectPoint, EffectColor>>(); List <EffectPoint[]> points = new List <EffectPoint[]>(); if (function is EffectCircle) { for (float t = 0.0f; t < Math.PI * 2.0f; t += 0.025f) { EffectPoint point = function.GetPoint(t); HashSet <EffectPoint> newpts = new HashSet <EffectPoint>(); if (!point.IsOutOfRange()) { newpts.Add(new EffectPoint(point.X, point.Y)); for (int offset = 0; offset < size; offset++) { newpts.Add(new EffectPoint(point.X + offset, point.Y)); newpts.Add(new EffectPoint(point.X, point.Y + offset)); newpts.Add(new EffectPoint(point.X - offset, point.Y)); newpts.Add(new EffectPoint(point.X, point.Y - offset)); newpts.Add(new EffectPoint(point.X + offset, point.Y + offset)); newpts.Add(new EffectPoint(point.X + offset, point.Y - offset)); newpts.Add(new EffectPoint(point.X - offset, point.Y + offset)); newpts.Add(new EffectPoint(point.X - offset, point.Y - offset)); } } if (newpts.Count != 0) { points.Add(newpts.ToArray()); } } } else { for (float x = 0.0f; x < Effects.canvas_width; x += 1.0f) { EffectPoint point = function.GetPoint(x); List <EffectPoint> newpts = new List <EffectPoint>(); if (!point.IsOutOfRange()) { newpts.Add(point); for (int offset = 0; offset < size; offset++) { newpts.Add(new EffectPoint(point.X + offset, point.Y)); newpts.Add(new EffectPoint(point.X, point.Y + offset)); newpts.Add(new EffectPoint(point.X - offset, point.Y)); newpts.Add(new EffectPoint(point.X, point.Y - offset)); newpts.Add(new EffectPoint(point.X + offset, point.Y + offset)); newpts.Add(new EffectPoint(point.X + offset, point.Y - offset)); newpts.Add(new EffectPoint(point.X - offset, point.Y + offset)); newpts.Add(new EffectPoint(point.X - offset, point.Y - offset)); } } if (newpts.Count != 0) { points.Add(newpts.ToArray()); } } } List <Tuple <EffectPoint, Color> > points_ret = new List <Tuple <EffectPoint, Color> >(); for (int pt_id = 0; pt_id < points.Count; pt_id++) { Color color = colorspectrum.GetColorAt((float)pt_id / points.Count); foreach (EffectPoint pt in points[pt_id]) { points_ret.Add(new Tuple <EffectPoint, Color>(pt, color)); } } return(points_ret.ToArray()); }
/// <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); } }