Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
 private void CustomColorEditor_ColorChanged(object sender, EventArgs e)
 {
     if (UpdateLocked)
     {
         return;
     }
     _background = new C1SolidBrush(_customColorEditor.Value);
 }
Esempio n. 4
0
 private void SystemColorsEditor_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (UpdateLocked)
     {
         return;
     }
     _background = new C1SolidBrush(_systemColorsEditor.SelectedColor);
 }
Esempio n. 5
0
        private void OnChanged()
        {
            _background = GetBackground();

            if (Changed != null)
            {
                Changed(this, EventArgs.Empty);
            }
        }
Esempio n. 6
0
        public override void Init(
            GradientBackgroundEditor owner,
            C1Brush brush)
        {
            base.Init(owner, brush);

            var gradientBrush = (C1GradientBrush)brush;

            tcbeColors.Init();
            tcbeColors.SetGradientStops(gradientBrush.GradientStops);
        }
Esempio n. 7
0
 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()));
         }
     }
 }
Esempio n. 8
0
 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);
 }
Esempio n. 9
0
        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());
        }
Esempio n. 10
0
        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());
        }
Esempio n. 11
0
 public virtual void Init(
     GradientBackgroundEditor owner,
     C1Brush brush)
 {
     m_Owner = owner;
 }
Esempio n. 12
0
 private void GradientEditor_Changed(object sender, EventArgs e)
 {
     _background = _gradientEditor.Background;
 }
Esempio n. 13
0
 private void GradientEditor_BackgroundSelected(object sender, EventArgs e)
 {
     _background = _gradientEditor.Background;
     CloseDropDown();
 }
Esempio n. 14
0
        /// <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();
        }