public static LinearGradientBrush CreateGradientBrush(Size size, BrushData gradientData) { IEnumerable <GradientStop> gradient = ParseGradientData(gradientData.Data); PointF startPoint = new PointF(0, 0); PointF endPoint = PointF.Empty; switch (gradientData.Direction) { case BrushData.GradientDirection.Horizontal: endPoint = new PointF(1, 0); break; case BrushData.GradientDirection.Vertical: endPoint = new PointF(0, 1); break; } Point start = new Point((int)(size.Width * startPoint.X), (int)(size.Height * startPoint.Y)); Point end = new Point((int)(size.Width * endPoint.X), (int)(size.Height * endPoint.Y)); LinearGradientBrush brush = new LinearGradientBrush(start, end, Color.Black, Color.Black); gradient = gradient.OrderBy(x => x.Offset); ColorBlend blend = new ColorBlend(); blend.Colors = gradient.Select(x => x.Color).ToArray(); blend.Positions = gradient.Select(x => x.Offset).ToArray(); brush.InterpolationColors = blend; return(brush); }
private BrushData GetNewBrushData() { BrushData bd = new BrushData(rtbCodes.Text, (BrushData.GradientDirection)cboGradientDirection.SelectedIndex); bd.Name = txtName.Text; return(bd); }
private bool ExistsBrushData(BrushData bd) { foreach (BrushData oBd in this.Options.BrushDataList) { if (bd.Name == oBd.Name) { return(true); } } return(false); }
private void btnAdd_Click(object sender, EventArgs e) { BrushData bd = new BrushData(); bd.Name = txtName.Text; if (!ExistsBrushData(bd)) { lbBrushData.Items.Add(bd); this.Options.BrushDataList.Add(bd); } else { MessageBox.Show("Brush data with the same name already exists.\n\nPlease change the name and try saving again.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } lbBrushData.SelectedIndex = lbBrushData.Items.Count - 1; }
private void UpdatePreview(BrushData bd) { try { using (LinearGradientBrush brush = CreateGradientBrush(pbPreview.ClientSize, bd)) { Bitmap bmp = new Bitmap(pbPreview.ClientSize.Width, pbPreview.ClientSize.Height); using (Graphics g = Graphics.FromImage(bmp)) { g.FillRectangle(brush, 0, 0, pbPreview.ClientSize.Width, pbPreview.ClientSize.Height); } pbPreview.Image = bmp; } } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
private void UpdateGUI(BrushData bd) { rtbCodes.Text = bd.Data; cboGradientDirection.SelectedIndex = (int)bd.Direction; }
private BrushData GetNewBrushData() { BrushData bd = new BrushData(rtbCodes.Text, (BrushData.GradientDirection)cboGradientDirection.SelectedIndex); bd.Name = txtName.Text; return bd; }
private bool ExistsBrushData(BrushData bd) { foreach (BrushData oBd in this.Options.BrushDataList) { if (bd.Name == oBd.Name) { return true; } } return false; }
public static LinearGradientBrush CreateGradientBrush(Size size, BrushData gradientData) { IEnumerable<GradientStop> gradient = ParseGradientData(gradientData.Data); PointF startPoint = new PointF(0, 0); PointF endPoint = PointF.Empty; switch (gradientData.Direction) { case BrushData.GradientDirection.Horizontal: endPoint = new PointF(1, 0); break; case BrushData.GradientDirection.Vertical: endPoint = new PointF(0, 1); break; } Point start = new Point((int)(size.Width * startPoint.X), (int)(size.Height * startPoint.Y)); Point end = new Point((int)(size.Width * endPoint.X), (int)(size.Height * endPoint.Y)); LinearGradientBrush brush = new LinearGradientBrush(start, end, Color.Black, Color.Black); gradient = gradient.OrderBy(x => x.Offset); ColorBlend blend = new ColorBlend(); blend.Colors = gradient.Select(x => x.Color).ToArray(); blend.Positions = gradient.Select(x => x.Offset).ToArray(); brush.InterpolationColors = blend; return brush; }