public static void DrawBackground( Graphics g, Color backcolor, C1Brush background, Rectangle bounds) { if (background == null) { return; } var tsb = background as C1SolidBrush; if (tsb != null) { if (tsb.Color == Color.Transparent || tsb.Color.IsEmpty) { DrawColorMark(g, tsb.Color, false, bounds); return; } } using ( var image = GetBrushImage(backcolor, background, new NSD.Size(bounds.Width, bounds.Height), new NSD.Point(g.DpiX, g.DpiY))) { g.DrawImageUnscaled(image, bounds.Left, bounds.Top); } }
public void Init(C1Brush background) { _background = background; BeginUpdate(); cbLinear.Checked = true; cbRadial.Checked = false; lgeLinear.Visible = true; rgeRadial.Visible = false; var linearBrush = ConvertToLinearBrush(background); lgeLinear.Init(this, linearBrush); var radialBrush = ConvertToRadialBrush(background); mceMultiColor.Init(this, radialBrush); rgeRadial.Init(this, radialBrush); var brushType = GetBrushType(background); if ((brushType & BrushType.Gradient) != 0) { ModeType = brushType & BrushType.Gradient; } else { ModeType = BrushType.LinearGradient; } UpdateColors(); EndUpdate(); }
private void CustomColorEditor_ColorChanged(object sender, EventArgs e) { if (UpdateLocked) { return; } _background = new C1SolidBrush(_customColorEditor.Value); }
private void SystemColorsEditor_SelectedIndexChanged(object sender, EventArgs e) { if (UpdateLocked) { return; } _background = new C1SolidBrush(_systemColorsEditor.SelectedColor); }
private void OnChanged() { _background = GetBackground(); if (Changed != null) { Changed(this, EventArgs.Empty); } }
public override void Init( GradientBackgroundEditor owner, C1Brush brush) { base.Init(owner, brush); var gradientBrush = (C1GradientBrush)brush; tcbeColors.Init(); tcbeColors.SetGradientStops(gradientBrush.GradientStops); }
public static Image GetBrushImage(Color backcolor, C1Brush brush, C1.Win.Interop.Size size, C1.Win.Interop.Point dpi) { using (var dxGraphics = new C1DXGraphics()) { dxGraphics.BeginGetImage(size, dpi); var bounds = new C1.Win.Interop.Rect(0, 0, size.Width, size.Height); dxGraphics.FillRectangle(backcolor, bounds); dxGraphics.FillRectangle(brush, bounds); using (C1Image image = dxGraphics.EndGetImage(false)) { return(Image.FromStream(image.GetData())); } } }
private BrushType GetBrushType(C1Brush brush) { if (brush == null) { return(BrushType.None); } if (brush is C1SolidBrush) { return(BrushType.Solid); } if (brush is C1LinearBrush) { return(BrushType.LinearGradient); } if (brush is C1RadialBrush) { return(BrushType.RadialGradient); } return(BrushType.None); }
private C1LinearBrush ConvertToLinearBrush(C1Brush brush) { if (brush == null) { return(new C1LinearBrush()); } var linearBrush = brush as C1LinearBrush; if (linearBrush != null) { return(linearBrush); } var solidBrush = brush as C1SolidBrush; if (solidBrush != null) { linearBrush = new C1LinearBrush { StartColor = solidBrush.Color, EndColor = solidBrush.Color }; return(linearBrush); } var radialBrush = brush as C1RadialBrush; if (radialBrush != null) { linearBrush = new C1LinearBrush(); foreach (var stop in radialBrush.GradientStops) { linearBrush.GradientStops.Add(stop); } return(linearBrush); } return(new C1LinearBrush()); }
private C1SolidBrush ConvertToSolidBrush(C1Brush brush) { if (brush == null) { return(new C1SolidBrush()); } var solidBrush = brush as C1SolidBrush; if (solidBrush != null) { return(solidBrush); } var gradientBrush = brush as C1GradientBrush; if (gradientBrush != null) { return(new C1SolidBrush(gradientBrush.Color1)); } return(new C1SolidBrush()); }
public virtual void Init( GradientBackgroundEditor owner, C1Brush brush) { m_Owner = owner; }
private void GradientEditor_Changed(object sender, EventArgs e) { _background = _gradientEditor.Background; }
private void GradientEditor_BackgroundSelected(object sender, EventArgs e) { _background = _gradientEditor.Background; CloseDropDown(); }
/// <summary> /// Initializes a control, should be called before using the control. /// </summary> /// <param name="background">The initial value to edit.</param> /// <param name="allowGradient">Indicates whether the gradient brush editor is visible.</param> /// <param name="allowEmpty">Indicates whether the solid brush with Color.Empty can be specified, this value showed as "Auto" in editor.</param> /// <param name="emptyAlias">The text for Color.Empty color, typically it is displayed as "Auto".</param> public void Init(C1Brush background, bool allowGradient, bool allowEmpty, string emptyAlias) { _background = background ?? new C1SolidBrush(); Color solidColor = ConvertToSolidBrush(_background).Color; // BeginUpdate(); // initialize editors _webColorsEditor = new ColorListBox { BorderStyle = BorderStyle.None, Dock = DockStyle.Fill, FormattingEnabled = true, Name = "clbWebColors", TabIndex = 0, ShowColors = ShowColors.Web, ShowEmpty = allowEmpty, EmptyColorAlias = emptyAlias, }; _webColorsEditor.SelectedIndexChanged += WebColorsEditor_SelectedIndexChanged; _webColorsEditor.MouseUp += WebColorsEditor_MouseUp; _systemColorsEditor = new ColorListBox { BorderStyle = BorderStyle.None, Dock = DockStyle.Fill, FormattingEnabled = true, Name = "clbSystemColors", TabIndex = 0, ShowColors = ShowColors.SystemColors, ShowEmpty = allowEmpty, EmptyColorAlias = emptyAlias, }; _systemColorsEditor.SelectedIndexChanged += SystemColorsEditor_SelectedIndexChanged; _systemColorsEditor.MouseUp += SystemColorsEditor_MouseUp; _customColorEditor = new CustomColorEditor { Dock = DockStyle.Fill, Name = "customColorEditor1", TabIndex = 0, AllowColorPicker = true, ShowEmpty = allowEmpty, EmptyColorAlias = emptyAlias, }; _customColorEditor.ColorSelected += CustomColorEditor_ColorSelected; _customColorEditor.ColorChanged += CustomColorEditor_ColorChanged; _webColorsEditor.SelectedColor = solidColor; _systemColorsEditor.SelectedColor = solidColor; _customColorEditor.OldValue = solidColor; _customColorEditor.Value = solidColor; // dtpGradient.TabVisible = allowGradient; if (!allowGradient) { if (!(_background is C1SolidBrush)) { _background = new C1SolidBrush(solidColor); } } else { _gradientEditor = new GradientBackgroundEditor { Dock = DockStyle.Fill, Name = "gbeEditor", TabIndex = 0 }; _gradientEditor.BackgroundSelected += GradientEditor_BackgroundSelected; _gradientEditor.Changed += GradientEditor_Changed; _gradientEditor.Init(_background); } // if (_background is C1SolidBrush) { if (_systemColorsEditor.SelectedIndex >= 0) { dtMain.SelectedTab = dtpSystemColors; } else if (_webColorsEditor.SelectedIndex >= 0) { dtMain.SelectedTab = dtpWebColors; } else { dtMain.SelectedTab = dtpCustom; } } else { dtMain.SelectedTab = dtpGradient; } // EnsureEditorAdded(dtMain.SelectedIndex); dtMain.SelectedIndexChanging += (s, e) => EnsureEditorAdded(e.NewIndex); // EndUpdate(); }