示例#1
0
		//render using new style
		protected override void DrawSelectionFrame(PaintEventArgs e, Rectangle rct, ButtonState state)
		{
			if (state == ButtonState.Checked ||
			    state == ButtonState.Pushed) {
				e.Graphics.PixelOffsetMode = PixelOffsetMode.None;
				e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
				rct.Width--;
				rct.Height--;
				using (GraphicsPath pth = CreateRoundedRect(2, rct)) {
					using (LinearGradientBrush brs = new LinearGradientBrush(
						new Point(0, rct.Bottom), new Point(0, rct.Y),
						Color.Black, Color.White)) {
						ColorBlend colorblnd = new ColorBlend();
						colorblnd.Positions = new float[]
						                      	{
						                      		0F, 0.5F, 0.50F, 1F
						                      	};
						colorblnd.Colors = new Color[]
						                   	{
						                   		Color.FromArgb(255, 236, 181),
						                   		Color.FromArgb(255, 236, 181),
						                   		Color.FromArgb(255, 243, 207),
						                   		Color.FromArgb(255, 252, 242)
						                   	};
						//
						brs.InterpolationColors = colorblnd;
						e.Graphics.FillPath(brs, pth);
					}
					using (Pen pn = new Pen(Color.FromArgb(229, 195, 101)))
						e.Graphics.DrawPath(pn, pth);
				}
			}
		}
示例#2
0
        public BlackStyleCheckBox()
        {
            SpaceAfterCheckBox = 3;

            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);

            BackColor = Color.Transparent;
            ForeColor = Color.White;

            // http://connect.microsoft.com/VisualStudio/feedback/details/348321/bug-in-fillrectangle-using-lineargradientbrush
            backgroundBrush = new LinearGradientBrush(new Rectangle(2, 2, checkBoxSize - 4, checkBoxSize - 3), Color.FromArgb(105, 105, 105), Color.FromArgb(55, 55, 55), LinearGradientMode.Vertical);

            innerBorderBrush = new LinearGradientBrush(new Rectangle(1, 1, checkBoxSize - 2, checkBoxSize - 2), Color.FromArgb(125, 125, 125), Color.FromArgb(65, 75, 75), LinearGradientMode.Vertical);
            innerBorderPen = new Pen(innerBorderBrush);

            backgroundCheckedBrush = new LinearGradientBrush(new Rectangle(2, 2, checkBoxSize - 4, checkBoxSize - 3), Color.Black, Color.Black, LinearGradientMode.Vertical);
            ColorBlend cb = new ColorBlend();
            cb.Positions = new float[] { 0, 0.49f, 0.50f, 1 };
            cb.Colors = new Color[] { Color.FromArgb(102, 163, 226), Color.FromArgb(83, 135, 186), Color.FromArgb(75, 121, 175), Color.FromArgb(56, 93, 135) };
            backgroundCheckedBrush.InterpolationColors = cb;

            innerBorderCheckedBrush = new LinearGradientBrush(new Rectangle(1, 1, checkBoxSize - 2, checkBoxSize - 2), Color.FromArgb(133, 192, 241), Color.FromArgb(76, 119, 163), LinearGradientMode.Vertical);
            innerBorderCheckedPen = new Pen(innerBorderCheckedBrush);

            borderPen = new Pen(Color.FromArgb(30, 30, 30));

            Font = new Font("Arial", 8);
        }
示例#3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="drawRectF"></param>
        /// <param name="drawColor"></param>
        /// <param name="orientation"></param>
        public static void DrawAquaPill(Graphics g, RectangleF drawRectF, Color drawColor, Orientation orientation)
        {
            System.Drawing.Drawing2D.LinearGradientBrush gradientBrush;
            System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend();

            var color1 = ColorHelper.OpacityMix(Color.White, ColorHelper.SoftLightMix(drawColor, Color.Black, 100), 40);
            var color2 = ColorHelper.OpacityMix(Color.White, ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColorFromRGB(64, 64, 64), 100), 20);
            var color3 = ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColorFromRGB(128, 128, 128), 100);
            var color4 = ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColorFromRGB(192, 192, 192), 100);
            var color5 = ColorHelper.OverlayMix(ColorHelper.SoftLightMix(drawColor, Color.White, 100), Color.White, 75);

            //
            colorBlend.Colors = new Color[] { color1, color2, color3, color4, color5 };
            colorBlend.Positions = new float[] { 0, 0.25f, 0.5f, 0.75f, 1 };
            if (orientation == Orientation.Horizontal)
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top - 1), new Point((int)drawRectF.Left, (int)drawRectF.Top + (int)drawRectF.Height + 1), color1, color5);
            else
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left - 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + (int)drawRectF.Width + 1, (int)drawRectF.Top), color1, color5);
            gradientBrush.InterpolationColors = colorBlend;
            FillPill(gradientBrush, drawRectF, g);

            //
            color2 = Color.White;
            colorBlend.Colors = new Color[] { color2, color3, color4, color5 };
            colorBlend.Positions = new float[] { 0, 0.5f, 0.75f, 1 };
            if (orientation == Orientation.Horizontal)
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left + 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + 1, (int)drawRectF.Top + (int)drawRectF.Height - 1), color2, color5);
            else
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top + 1), new Point((int)drawRectF.Left + (int)drawRectF.Width - 1, (int)drawRectF.Top + 1), color2, color5);
            gradientBrush.InterpolationColors = colorBlend;
            FillPill(gradientBrush, RectangleF.Inflate(drawRectF, -3, -3), g);
        }
示例#4
0
        /// <summary>
        /// 绘制窗体主体部分白色透明层
        /// </summary>
        /// <param name="form"></param>
        /// <param name="g"></param>
        public static void DrawFromAlphaMainPart(Form form, Graphics g)
        {
            Color[] colors =
            {
                Color.FromArgb(5, Color.White),
                Color.FromArgb(30, Color.White),
                Color.FromArgb(145, Color.White),
                Color.FromArgb(150, Color.White),
                Color.FromArgb(30, Color.White),
                Color.FromArgb(5, Color.White)
            };

            float[] pos =
            {
                0.0f,
                0.04f,
                0.10f,
                0.90f,
                0.97f,
                1.0f
            };

            ColorBlend colorBlend = new ColorBlend(6);
            colorBlend.Colors = colors;
            colorBlend.Positions = pos;

            RectangleF destRect = new RectangleF(0, 0, form.Width, form.Height);
            using (LinearGradientBrush lBrush = new LinearGradientBrush(destRect, colors[0], colors[5], LinearGradientMode.Vertical))
            {
                lBrush.InterpolationColors = colorBlend;
                g.FillRectangle(lBrush, destRect);
            }
        }
示例#5
0
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            base.OnRenderToolStripBackground(e);

            if (e.ToolStrip is ToolStripDropDownMenu) return;
            using (LinearGradientBrush lgBrush = new LinearGradientBrush(Point.Empty, new PointF(0, e.ToolStrip.Height),
                    ToolStripColorTable.ToolStripBackgroundTop, ToolStripColorTable.ToolStripBackgroundBottom))
            {
                ColorBlend blend = new ColorBlend(3);
                blend.Colors = new Color[] { ToolStripColorTable.ToolStripBackgroundTop, 
                    ToolStripColorTable.ToolStripBackgroundMiddle,ToolStripColorTable.ToolStripBackgroundMiddle,
                    ToolStripColorTable.ToolStripBackgroundBottom};
                blend.Positions = new float[] { 0.0f, 0.33f,0.58f, 1.0f };

                lgBrush.InterpolationColors = blend;            

                using (GraphicsPath border = GetToolStripRectangle(e.ToolStrip))
                {
                    e.Graphics.FillPath(lgBrush, border);
                    e.Graphics.DrawLine(new Pen( ToolStripColorTable.ToolStripBackgroundTopLine), 0, 0, e.ToolStrip.Width, 0);
                    e.Graphics.DrawLine(new Pen( ToolStripColorTable.ToolStripBackgroundBottomLine), 0, e.ToolStrip.Height - 2,
                        e.ToolStrip.Width, e.ToolStrip.Height - 2);
                }
            }

        }
示例#6
0
文件: Form1.cs 项目: Mofsy/jinxbot
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                BniFileParser bni = new BniFileParser(@"C:\Projects\jinxbot\branches\mbncsutil\trunk\mbnftp\bin\Debug\icons.bni");
                this.pictureBox1.Image = bni.FullImage;

                foreach (BniIcon icon in bni.AllIcons)
                {
                    this.flowContainer.Controls.Add(new IconRep(icon));
                }
            }
            catch { }

            Bitmap bmp = new Bitmap(28, 12);
            Rectangle bounds = new Rectangle(0, 0, 28, 12);
            using (Graphics g = Graphics.FromImage(bmp))
            using (LinearGradientBrush b = new LinearGradientBrush(bounds, Color.Black, Color.Black, 0, false))
            {
                ColorBlend cb = new ColorBlend();
                cb.Colors = new Color[] { Color.LimeGreen, Color.Lime, Color.Yellow, Color.Orange, Color.OrangeRed, Color.Maroon };
                cb.Positions = new float[] { 0f, 0.1f, 0.4f, 0.6f, 0.9f, 1f };
                b.InterpolationColors = cb;

                g.FillRectangle(b, bounds);
            }
            pictureBox2.Image = bmp;
        }
示例#7
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            Graphics g = e.Graphics;
            Rectangle rect = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);

            using (LinearGradientBrush lgBrush = new LinearGradientBrush(Point.Empty, new PointF(0, Height),
                    ToolStripColorTable.ToolStripBackgroundTop, ToolStripColorTable.ToolStripBackgroundBottom))
            {
                ColorBlend blend = new ColorBlend(3);
                blend.Colors = new Color[] { ToolStripColorTable.ToolStripBackgroundTop, 
                    ToolStripColorTable.ToolStripBackgroundMiddle,ToolStripColorTable.ToolStripBackgroundMiddle,
                    ToolStripColorTable.ToolStripBackgroundBottom};
                blend.Positions = new float[] { 0.0f, 0.33f, 0.58f, 1.0f };

                lgBrush.InterpolationColors = blend;

                g.FillRectangle(lgBrush, rect);

                g.DrawLine(new Pen(ToolStripColorTable.ToolStripBackgroundBottomLine), 0, rect.Height - 2, rect.Width, rect.Height - 2);
                g.DrawLine(Pens.White, 0, Height, Width, Height);
            }

        }
示例#8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            Graphics g   = e.Graphics;
            Image    img = new Bitmap(this.Width, this.Height);

            g.DrawImage(img, new Point(0, 0));


            Graphics gc = e.Graphics;

            /// 定义好颜色格式
            System.Drawing.Drawing2D.LinearGradientBrush preyPlayBrush = new System.Drawing.Drawing2D.LinearGradientBrush(
                this._startTextPos, new Point(1500, 0), this.PlayedColor, this.PrevPlayColor);

            System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend(4);
            colorBlend.Colors = new Color[4] {
                this.PlayedColor, this.PlayedColor, PrevPlayColor, PrevPlayColor
            };
            float f = this._colorLine;

            f /= (1500 - this._startTextPos.Y);
            /// 设置颜色显示范围,三个区域: Blue区,Blue向Red过度区(过度区很短),Red区。
            colorBlend.Positions = new float[4] {
                0, f, f + 0.0001f, 1.0f
            };

            preyPlayBrush.InterpolationColors = colorBlend;
            gc.DrawString(this.MusicText, this.TextFont, preyPlayBrush, new PointF(0, 0));
        }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="drawRectF"></param>
        /// <param name="drawColor"></param>
        /// <param name="orientation"></param>
        public static void DrawAquaPillSingleLayer(Graphics g, RectangleF drawRectF, Color drawColor, Orientation orientation)
        {
            Color color1;
            Color color2;
            Color color3;
            Color color4;

            System.Drawing.Drawing2D.LinearGradientBrush gradientBrush;
            System.Drawing.Drawing2D.ColorBlend          colorBlend = new System.Drawing.Drawing2D.ColorBlend();

            color1 = drawColor;
            color2 = ControlPaint.Light(color1);
            color3 = ControlPaint.Light(color2);
            color4 = ControlPaint.Light(color3);

            colorBlend.Colors    = new Color[] { color1, color2, color3, color4 };
            colorBlend.Positions = new float[] { 0, 0.25f, 0.65f, 1 };

            if (orientation == Orientation.Horizontal)
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top), new Point((int)drawRectF.Left, (int)drawRectF.Top + (int)drawRectF.Height), color1, color4);
            }
            else
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top), new Point((int)drawRectF.Left + (int)drawRectF.Width, (int)drawRectF.Top), color1, color4);
            }
            gradientBrush.InterpolationColors = colorBlend;

            FillPill(gradientBrush, drawRectF, g);
        }
示例#10
0
        public VerticalMeterData()
        {
            Inverted = false;
            DecayTime = 1500;
            AttackTime = 50;
            Normalize = true;
            Gain = 0;
            Range = 10;
            RedColorPosition = 95;
            GreenColorPosition = 25;
            MeterColorStyle = MeterColorTypes.Linear;

            LowPass = false;
            LowPassFreq = 100;
            HighPass = false;
            HighPassFreq = 500;

            Color[] myColors = { Color.Lime, Color.Yellow, Color.Red };
            float[] myPositions = { 0, (float)GreenColorPosition / 100, (float)RedColorPosition / 100 };
            ColorBlend linearBlend = new ColorBlend();
            linearBlend.Colors = myColors;
            linearBlend.Positions = myPositions;

            ColorGradient linearGradient = new ColorGradient(linearBlend);

            IntensityCurve = new Curve();
            IntensityCurve.Points.Clear();
            IntensityCurve.Points.Add(new ZedGraph.PointPair(0, 100));
            IntensityCurve.Points.Add(new ZedGraph.PointPair(100, 100));

            MeterColorGradient = linearGradient;

            DepthOfEffect = 0;
        }
        public static void DrawAquaPill(Graphics g, RectangleF drawRectF, Color drawColor, Orientation orientation)
        {
            var colorBlend = new ColorBlend();

            var color1 = OpacityMix(Color.White, SoftLightMix(drawColor, Color.Black, 100), 40);
            var color2 = OpacityMix(Color.White, SoftLightMix(drawColor, CreateColorFromRgb(64, 64, 64), 100), 20);
            var color3 = SoftLightMix(drawColor, CreateColorFromRgb(128, 128, 128), 100);
            var color4 = SoftLightMix(drawColor, CreateColorFromRgb(192, 192, 192), 100);
            var color5 = OverlayMix(SoftLightMix(drawColor, Color.White, 100), Color.White, 75);

            //
            colorBlend.Colors = new[] { color1, color2, color3, color4, color5 };
            colorBlend.Positions = new[] { 0, 0.25f, 0.5f, 0.75f, 1 };
            var gradientBrush = orientation == Orientation.Horizontal ? new LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top - 1), new Point((int)drawRectF.Left, (int)drawRectF.Top + (int)drawRectF.Height + 1), color1, color5) :
                new LinearGradientBrush(new Point((int)drawRectF.Left - 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + (int)drawRectF.Width + 1, (int)drawRectF.Top), color1, color5);
            gradientBrush.InterpolationColors = colorBlend;
            FillPill(gradientBrush, drawRectF, g);

            //
            color2 = Color.White;
            colorBlend.Colors = new[] { color2, color3, color4, color5 };
            colorBlend.Positions = new[] { 0, 0.5f, 0.75f, 1 };
            gradientBrush = orientation == Orientation.Horizontal ? new LinearGradientBrush(new Point((int)drawRectF.Left + 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + 1, (int)drawRectF.Top + (int)drawRectF.Height - 1), color2, color5) :
                                                                    new LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top + 1), new Point((int)drawRectF.Left + (int)drawRectF.Width - 1, (int)drawRectF.Top + 1), color2, color5);
            gradientBrush.InterpolationColors = colorBlend;
            FillPill(gradientBrush, RectangleF.Inflate(drawRectF, -3, -3), g);
        }
示例#12
0
        public void DrawFormBackgroud(Graphics g, Rectangle r)
        {
            drawing = new Bitmap(this.Width, AnimSize, g);
            gg = Graphics.FromImage(drawing);

            Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10);
            Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, AnimSize-9);
            LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 61), Color.FromArgb(47, colorR, colorR), LinearGradientMode.Vertical);
            //LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical);
            LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical);
            //LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical);
            ColorBlend blend = new ColorBlend();

            // Set multi-color gradient
            blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 0.95f,1f };
            blend.Colors = new[] { Color.FromArgb(47, colorR, colorR), Color.FromArgb(64, colorR + 22, colorR + 32), Color.FromArgb(66, colorR + 20, colorR + 35), Color.FromArgb(64, colorR + 20, colorR + 32), Color.FromArgb(49, colorR, colorR + 1), SystemColors.Control };
            //blend.Colors = new[] { Color.FromArgb(47, colorR, 64), Color.FromArgb(64, colorR + 32, 88), Color.FromArgb(66, colorR + 35, 90), Color.FromArgb(64, colorR + 32, 88), Color.FromArgb(49, colorR + 1, 66),SystemColors.Control };
            grad.InterpolationColors = blend;
            Font myf = new System.Drawing.Font(this.Font.FontFamily, 16);
            // Draw basic gradient and shadow
            //gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            gg.FillRectangle(grad, gradRect);
            gg.FillRectangle(shadow, shadowRect);
            gg.TextRenderingHint = TextRenderingHint.AntiAlias;
            gg.DrawString("Поиск по ресурсам сети", myf, Brushes.GhostWhite, new PointF(55, 15));
            gg.DrawImage(Properties.Resources.search1.ToBitmap(), 10, 10,32,32);

            g.DrawImageUnscaled(drawing, 0, 0);
            gg.Dispose();

            // Draw checkers
            //g.FillRectangle(checkers, r);
        }
示例#13
0
        protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
        {
            // base.OnRenderSeparator(e);
            if (!e.Item.IsOnDropDown)
            {
                int top = 9;
                int left = e.Item.Width / 2; left--;
                int height = e.Item.Height - top  * 2;
                RectangleF separator = new RectangleF(left, top, 0.5f, height);

                using (LinearGradientBrush b = new LinearGradientBrush(
                    separator.Location,
                    new Point(Convert.ToInt32(separator.Left), Convert.ToInt32(separator.Bottom)),
                    Color.Red, Color.Black))
                {
                    ColorBlend blend = new ColorBlend();
                    blend.Colors = new Color[] { ToolStripColorTable.ToolStripSplitButtonTop, ToolStripColorTable.ToolStripSplitButtonMiddle, ToolStripColorTable.ToolStripSplitButtonMiddle, ToolStripColorTable.ToolStripSplitButtonBottom };
                    blend.Positions = new float[] { 0.0f, 0.22f, 0.78f, 1.0f };

                    b.InterpolationColors = blend;

                    e.Graphics.FillRectangle(b, separator);
                }
            }
        }
示例#14
0
        public void DrawFormBackgroud(Graphics g, Rectangle r)
        {
            drawing = new Bitmap(this.Width, this.Height, g);
            gg = Graphics.FromImage(drawing);

            Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10);
            Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, 42);
            //LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 41, 61), Color.FromArgb(47, 64, 94), LinearGradientMode.Vertical);
            LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical);
            //LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical);
            LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical);
            ColorBlend blend = new ColorBlend();

            // Set multi-color gradient
            blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 1.0f };
            //blend.Colors = new[] { Color.FromArgb(47, 64, 94), Color.FromArgb(64, 88, 126), Color.FromArgb(66, 90, 129), Color.FromArgb(64, 88, 126), Color.FromArgb(49, 66, 95) };
            blend.Colors = new[] { Color.FromArgb(47,colorR, 64), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(66, colorR+35, 90), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(49, colorR+1, 66) };
            grad.InterpolationColors = blend;
            Font myf=new System.Drawing.Font(this.Font.FontFamily,16);
            // Draw basic gradient and shadow
            //gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            gg.FillRectangle(grad, gradRect);
            gg.FillRectangle(shadow, shadowRect);
            gg.DrawString("Добавить один ПК", myf, Brushes.GhostWhite, new PointF(55, 15));
            gg.DrawImage(Properties.Resources.singleAdd1.ToBitmap(), 10, 10,32,32);

            g.DrawImageUnscaled(drawing, 0, 0);
            gg.Dispose();

            // Draw checkers
            //g.FillRectangle(checkers, r);
        }
示例#15
0
 public void ComputeColors(float hue, float saturation, float start, float start2, float end2, float end, float edge, int border)
 {
     this.border = border;
     this.colorStart = new Color[border];
     this.colorEnd = new Color[border];
     float num = (start2 - start) / (float)border;
     float num2 = (end2 - end) / (float)border;
     float num3 = start;
     float num4 = end;
     for (int i = 0; i < border; i++)
     {
         this.colorStart[i] = ColorUtils.HSLToRGB(hue, saturation, num3);
         this.colorEnd[i] = ColorUtils.HSLToRGB(hue, saturation, num4);
         num3 += num;
         num4 += num2;
     }
     this.colorEdge = ColorUtils.HSLToRGB(hue, saturation, edge);
     float num5 = (end2 - start2) / 9f;
     float num6 = start2;
     this.colorMiddle = new ColorBlend(10);
     for (int j = 0; j < 10; j++)
     {
         this.colorMiddle.Positions[j] = (float)j / 9f;
         this.colorMiddle.Colors[j] = ColorUtils.HSLToRGB(hue, saturation, num6);
         num6 += num5;
     }
 }
示例#16
0
        public static ColorBlend[] ReadGradient(BinaryFlashReader reader, bool bWithAlpha, bool morph)
        {
            ColorBlend[] clrs = new ColorBlend[2];

            int nNumRecords = reader.ReadByte();
            ColorBlend clrBlend = new ColorBlend(nNumRecords);
            ColorBlend clrBlendEnd = null;
            if (morph)
                clrBlendEnd = new ColorBlend(nNumRecords);

            for (int i = 0; i < nNumRecords; i++)
            {
                Color clr;
                byte ratio;
                ReadRecord(reader, bWithAlpha, out clr, out ratio);
                clrBlend.Colors[i] = clr;
                clrBlend.Positions[i] = (float)ratio/255;

                if (morph)
                {
                    ReadRecord(reader, bWithAlpha, out clr, out ratio);
                    clrBlendEnd.Colors[i] = clr;
                    clrBlendEnd.Positions[i] = (float)ratio/255;
                }
            }
            return clrs;
        }
        public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)
        {
            try
            {
                p.Width = 6;
                Rectangle r = this.ClientRectangle;
                // r.Width--; r.Height--;
                using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
                {
                    using (System.Drawing.Drawing2D.LinearGradientBrush gradBrush = new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 90, false))
                    {

                        ColorBlend cb = new ColorBlend();
                        cb.Positions = new[] { 0, 1f };
                        cb.Colors = new[] { Color.Transparent, Color.Transparent };
                        gradBrush.InterpolationColors = cb;
                        // rotate
                        gradBrush.RotateTransform(0);
                        // paint
                        //g.FillPath(gradBrush, rr);
                        g.DrawPath(p, rr);
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
示例#18
0
        /// <summary>
        /// Draws the aqua pull single layer
        /// </summary>
        /// <param name="graphicsDevice">Graphics device</param>
        /// <param name="drawRectF">Float rectangle</param>
        /// <param name="drawColor">A Color</param>
        /// <param name="orientation">Enumeration Orientation</param>
        public static void DrawAquaPillSingleLayer(Graphics graphicsDevice, RectangleF drawRectF, Color drawColor, Orientation orientation)
        {
            Color color1;
            Color color2;
            Color color3;
            Color color4;
            System.Drawing.Drawing2D.LinearGradientBrush gradientBrush;
            System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend();
            color1 = drawColor;
            color2 = ControlPaint.Light(color1);
            color3 = ControlPaint.Light(color2);
            color4 = ControlPaint.Light(color3);
            colorBlend.Colors = new Color[] { color1, color2, color3, color4 };
            colorBlend.Positions = new float[] { 0, 0.25f, 0.65f, 1 };
            if (orientation == Orientation.Horizontal)
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top), new Point((int)drawRectF.Left, (int)drawRectF.Top + (int)drawRectF.Height), color1, color4);
            }
            else
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top), new Point((int)drawRectF.Left + (int)drawRectF.Width, (int)drawRectF.Top), color1, color4);
            }

            gradientBrush.InterpolationColors = colorBlend;
            FillPill(gradientBrush, drawRectF, graphicsDevice);
        }
示例#19
0
        public override void Render(Graphics g)
        {
            //theCode, love theVariableNames :D [Xylem]
            //Set the hue shades with the correct saturation and luminance
            Color[] theColors =
                {
                    new ColorManager.HSVColor(0, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(),
                    new ColorManager.HSVColor(60, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(),
                    new ColorManager.HSVColor(120, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(),
                    new ColorManager.HSVColor(180, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(),
                    new ColorManager.HSVColor(240, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(),
                    new ColorManager.HSVColor(300, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(),
                    new ColorManager.HSVColor(360, CurrentColor.HSV.S, CurrentColor.HSV.V).ToColor(),
                };

            //Calculate positions
            float percent = 1.0f / 6;
            float[] thePositions = {0.0f, percent, percent * 2, percent * 3, percent * 4, percent * 5, 1.0f};
            //Set blend
            var theBlend = new ColorBlend();
            theBlend.Colors = theColors;
            theBlend.Positions = thePositions;
            //Get rectangle
            var colorRect = new Rectangle(0, (Slider.Height / 2) - 3, Slider.Width - 6, 4);
            //Make the linear brush and assign the custom blend to it
            var theBrush = new LinearGradientBrush(colorRect,
                                                   Color.Red,
                                                   Color.Red, 0, false);
            theBrush.InterpolationColors = theBlend;
            //Draw rectangle
            g.FillRectangle(theBrush, colorRect);
            //Draw border and trackbar
            g.DrawRectangle(Pens.Black, new Rectangle(0, (Slider.Height / 2) - 3, Slider.Width - 6, 4));
            DrawThumb(g);
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="g"></param>
		/// <param name="drawRectF"></param>
		/// <param name="drawColor"></param>
		/// <param name="orientation"></param>
		public static void DrawAquaPillSingleLayer(Graphics g, RectangleF drawRectF, Color drawColor, Orientation orientation, BrushStyle brushStyle)
		{
		    if (brushStyle == BrushStyle.LinearGradient)
		    {
		        var colorBlend = new ColorBlend();
		        var color1 = drawColor;
                var color2 = ControlPaint.Light(color1);
                var color3 = ControlPaint.Light(color2);
                var color4 = ControlPaint.Light(color3);

		        colorBlend.Colors = new[] {color1, color2, color3, color4};
		        colorBlend.Positions = new[] {0, 0.25f, 0.65f, 1};

		        var gradientBrush = orientation == Orientation.Horizontal
		                                                ? new LinearGradientBrush(
		                                                      new Point((int) drawRectF.Left, (int) drawRectF.Top),
		                                                      new Point((int) drawRectF.Left,
		                                                                (int) drawRectF.Top + (int) drawRectF.Height), color1,
		                                                      color4)
		                                                : new LinearGradientBrush(
		                                                      new Point((int) drawRectF.Left, (int) drawRectF.Top),
		                                                      new Point((int) drawRectF.Left + (int) drawRectF.Width,
		                                                                (int) drawRectF.Top), color1, color4);
		        gradientBrush.InterpolationColors = colorBlend;

		        FillPill(gradientBrush, drawRectF, g);
		    }
		    else
		    {
                FillPill(new SolidBrush(drawColor), drawRectF, g);
		    }
		}
      /// <summary>
      /// Draws the background of the rectangle containing the small buttons on the bottom 
      /// of the NavigationBar
      /// </summary>
      /// <param name="g">The graphics surface to draw on</param>
      /// <param name="bounds">The bounds of the small rectangle</param>
      public override void DrawNaviBarOverFlowPanelBg(Graphics g, Rectangle bounds)
      {
         // Background
         Color[] EndColors = { ColorTable.ButtonNormalColor2, ColorTable.ButtonNormalColor1 };
         float[] ColorPositions = { 0.0f, 1.0f };

         ColorBlend blend = new ColorBlend();

         blend.Colors = EndColors;
         blend.Positions = ColorPositions;

         if (bounds.Height == 0)
            bounds.Height = 1; // its to prevent an out of memory exception
         if (bounds.Width == 0)
            bounds.Width = 1;

         // Make the linear brush and assign the custom blend to it
         using (LinearGradientBrush brush = new LinearGradientBrush(new Point(bounds.Left, bounds.Bottom),
                                                           new Point(bounds.Left, bounds.Top),
                                                           Color.White,
                                                           Color.Black))
         {
            brush.InterpolationColors = blend;
            g.FillRectangle(brush, bounds);
         }

         using (Pen p = new Pen(ColorTable.Border))
         {
            g.DrawLine(p, bounds.Left, bounds.Top, bounds.Right, bounds.Top);
         }
      }
示例#22
0
 private void SetColorBlend(ColorBlend colorBlend)
 {
     for (var i = 0; i < colorBlend.Positions.Length; i++)
     {
         colorListBox.Items.Add(colorBlend.Colors[i]);
     }
 }
示例#23
0
		public void ColorBlend_Empty ()
		{
			ColorBlend cb = new ColorBlend ();
			Assert.AreEqual (1, cb.Colors.Length, "Colors");
			Assert.IsTrue (cb.Colors[0].IsEmpty, "C0");
			Assert.AreEqual (1, cb.Positions.Length, "Positions");
			Assert.AreEqual (0f, cb.Positions[0], "P0");
		}
示例#24
0
        public static System.Drawing.Drawing2D.ColorBlend Convert(this AGS.API.IColorBlend blend)
        {
            var result = new System.Drawing.Drawing2D.ColorBlend(blend.Colors.Length);

            result.Colors    = blend.Colors.Convert();
            result.Positions = blend.Positions;
            return(result);
        }
 /// <summary>
 /// Creates a 2-colour colour blend
 /// </summary>
 public static ColorBlend CreateColourBlend( Color c0, float t0, Color c1, float t1 )
 {
     ColorBlend blend = new ColorBlend( 2 );
     blend.Colors[ 0 ] = c0;
     blend.Colors[ 1 ] = c1;
     blend.Positions[ 0 ] = t0;
     blend.Positions[ 1 ] = t1;
     return blend;
 }
示例#26
0
        /// <summary>
        /// Converts the color blend to a gradient brush
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="angle"></param>
        /// <returns></returns>
        public System.Drawing.Drawing2D.LinearGradientBrush ToBrush(Rectangle rectangle, float angle)
        {
            LinearGradientBrush br = new LinearGradientBrush(rectangle, Color.Black, Color.Black, angle, true);

            System.Drawing.Drawing2D.ColorBlend cb = new System.Drawing.Drawing2D.ColorBlend();
            cb.Colors              = _Colors;
            cb.Positions           = _Positions;
            br.InterpolationColors = cb;
            return(br);
        }
示例#27
0
 public static ColorBlend GetGradient(ColorBlend originalBlend)
 {
     using (GradientDialog gradientDialog = new GradientDialog())
       {
     gradientDialog.SetColorBlend(originalBlend);
     if (gradientDialog.ShowDialog() == DialogResult.OK)
       return gradientDialog.GetColorBlend();
       }
       return (ColorBlend) null;
 }
示例#28
0
 private void panel1_Click(object sender, EventArgs e)
 {
     LinearGradientBrush lgb = new LinearGradientBrush(new Point(20,20),new Point(20,70),Color.Black,Color.Red);
     Graphics g = panel1.CreateGraphics();
     ColorBlend cb = new ColorBlend();
     cb.Colors = new Color[] { Color.Black,Color.Blue,Color.White};
     //float array diff between two number be equal .5 between each number.
     cb.Positions = new float[] { 0, .5F,1F};//float array, postions center of color, black,blue,white, F to convert to float.
     lgb.InterpolationColors = cb;
     g.FillRectangle(lgb,20,20,50,50);
 }
示例#29
0
        static ColorBlend BuildBlend(List <GradientStop> stops, bool reverse = false)
        {
            if (stops.Count < 2)
            {
                return(null);
            }

            var s1 = stops[0];
            var s2 = stops[stops.Count - 1];

            // Build the blend
            var n  = stops.Count;
            var an = 0;

            if (s1.Offset != 0)
            {
                an++;
            }
            if (s2.Offset != 1)
            {
                an++;
            }
            var blend = new System.Drawing.Drawing2D.ColorBlend(n + an);
            var o     = 0;

            if (s1.Offset != 0)
            {
                blend.Colors[0]    = GetColor(s1.Color);
                blend.Positions[0] = 0;
                o = 1;
            }
            for (var i = 0; i < n; i++)
            {
                blend.Colors[i + o]    = GetColor(stops[i].Color);
                blend.Positions[i + o] = (float)stops[i].Offset;
            }
            if (s2.Offset != 1)
            {
                blend.Colors[n + an - 1]    = GetColor(s1.Color);
                blend.Positions[n + an - 1] = 1;
            }

            if (reverse)
            {
                for (var i = 0; i < blend.Positions.Length; i++)
                {
                    blend.Positions[i] = 1 - blend.Positions[i];
                }
                Array.Reverse(blend.Positions);
                Array.Reverse(blend.Colors);
            }

            return(blend);
        }
示例#30
0
        private ColorBlend GetColorBlend()
        {
            var result = new ColorBlend(colorListBox.Items.Count);
            var distance = 1f / (result.Positions.Length - 1);
            for (var i = 0; i < result.Positions.Length; i++)
            {
                result.Positions[i] = i * distance;
                result.Colors[i] = (Color)colorListBox.Items[i];
            }

            return result;
        }
示例#31
0
 public static ColorBlend GetGradient(ColorBlend originalBlend)
 {
     using (var form = new GradientDialog())
     {
         form.SetColorBlend(originalBlend);
         if (form.ShowDialog() == DialogResult.OK)
         {
             return form.GetColorBlend();
         }
     }
     return null;
 }
示例#32
0
 private void DrawBar(GraphicsContext context, LinearGradientBrush brush, RectangleF rect)
 {
     var blend = new ColorBlend (Colors.Length);
     var step = 1f / (Colors.Length - 1);
     for (int i = 0; i < Colors.Length; i++)
     {
         blend.Colors [i] = Colors [i];
         blend.Positions [i] = i * step;
     }
     brush.InterpolationColors = blend;
     context.Graphics.FillRectangle (brush, rect);
 }
示例#33
0
文件: Utils.cs 项目: zloiia/sdrsrc
 public static ColorBlend GetGradientBlend(int alpha, string settingName)
 {
     ColorBlend colorBlend = new ColorBlend();
       string str1;
       try
       {
     str1 = ConfigurationManager.AppSettings[settingName] ?? string.Empty;
       }
       catch
       {
     str1 = string.Empty;
       }
       string[] strArray = str1.Split(',');
       if (strArray.Length < 2)
       {
     colorBlend.Colors = new Color[6]
     {
       Color.White,
       Color.LightBlue,
       Color.DodgerBlue,
       Color.FromArgb(0, 0, 80),
       Color.Black,
       Color.Black
     };
     for (int index = 0; index < colorBlend.Colors.Length; ++index)
       colorBlend.Colors[index] = Color.FromArgb(alpha, colorBlend.Colors[index]);
       }
       else
       {
     colorBlend.Colors = new Color[strArray.Length];
     for (int index = 0; index < strArray.Length; ++index)
     {
       string str2 = strArray[index];
       int red = int.Parse(str2.Substring(0, 2), NumberStyles.HexNumber);
       int green = int.Parse(str2.Substring(2, 2), NumberStyles.HexNumber);
       int blue = int.Parse(str2.Substring(4, 2), NumberStyles.HexNumber);
       colorBlend.Colors[index] = Color.FromArgb(red, green, blue);
     }
       }
       float[] numArray = new float[colorBlend.Colors.Length];
       float num = 1f / (float) (numArray.Length - 1);
       for (int index = 0; index < numArray.Length; ++index)
       {
     byte r = colorBlend.Colors[index].R;
     byte g = colorBlend.Colors[index].G;
     byte b = colorBlend.Colors[index].B;
     colorBlend.Colors[index] = Color.FromArgb(alpha, (int) r, (int) g, (int) b);
     numArray[index] = (float) index * num;
       }
       colorBlend.Positions = numArray;
       return colorBlend;
 }
 /// <summary>
 /// Creates a 4-colour colour blend
 /// </summary>
 public static ColorBlend CreateColourBlend( Color c0, float t0, Color c1, float t1, Color c2, float t2, Color c3, float t3 )
 {
     ColorBlend blend = new ColorBlend( 4 );
     blend.Colors[ 0 ] = c0;
     blend.Colors[ 1 ] = c1;
     blend.Colors[ 2 ] = c2;
     blend.Colors[ 3 ] = c3;
     blend.Positions[ 0 ] = t0;
     blend.Positions[ 1 ] = t1;
     blend.Positions[ 2 ] = t2;
     blend.Positions[ 3 ] = t3;
     return blend;
 }
示例#35
0
        public static ColorBlend GetGradientBlend(int alpha, string settingName)
        {
            var colorBlend = new ColorBlend();

            string colorString;
            try
            {
                colorString = ConfigurationManager.AppSettings[settingName] ?? string.Empty;
            }
            catch
            {
                colorString = string.Empty;
            }
            var colorPatterns = colorString.Split(',');
            if (colorPatterns.Length < 2)
            {
                //colorBlend.Colors = new[] { Color.White, Color.Yellow, Color.Red, Color.FromArgb(56, 3, 2), Color.Black };
                colorBlend.Colors = new[] { Color.White, Color.LightBlue, Color.DodgerBlue, Color.FromArgb(0, 0, 80), Color.Black, Color.Black };
                //colorBlend.Colors = new[] { Color.Red, Color.Orange, Color.Yellow, Color.Lime, Color.DodgerBlue, Color.DarkBlue, Color.Black, Color.Black };
                for (var i = 0; i < colorBlend.Colors.Length; i++)
                {
                    colorBlend.Colors[i] = Color.FromArgb(alpha, colorBlend.Colors[i]);
                }
            }
            else
            {
                colorBlend.Colors = new Color[colorPatterns.Length];
                for (var i = 0; i < colorPatterns.Length; i++)
                {
                    var colorPattern = colorPatterns[i];
                    var r = int.Parse(colorPattern.Substring(0, 2), NumberStyles.HexNumber);
                    var g = int.Parse(colorPattern.Substring(2, 2), NumberStyles.HexNumber);
                    var b = int.Parse(colorPattern.Substring(4, 2), NumberStyles.HexNumber);
                    colorBlend.Colors[i] = Color.FromArgb(r, g, b);
                }
            }

            var positions = new float[colorBlend.Colors.Length];
            var distance = 1f / (positions.Length - 1);
            for (var i = 0; i < positions.Length; i++)
            {
                var r = colorBlend.Colors[i].R;
                var g = colorBlend.Colors[i].G;
                var b = colorBlend.Colors[i].B;

                colorBlend.Colors[i] = Color.FromArgb(alpha, r, g, b);
                positions[i] = i * distance;
            }
            colorBlend.Positions = positions;
            return colorBlend;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="drawRectF"></param>
        /// <param name="drawColor"></param>
        /// <param name="orientation"></param>
        public static void DrawAquaPillSingleLayer(Graphics g, RectangleF drawRectF, Color drawColor, Orientation orientation, RectangleF bufferedRect, Color bufferedColor)
        {
            Color color1;
            Color color2;
            Color color3;
            Color color4;

            System.Drawing.Drawing2D.LinearGradientBrush gradientBrush;
            System.Drawing.Drawing2D.ColorBlend          colorBlend = new System.Drawing.Drawing2D.ColorBlend();

            g.FillRectangle(new SolidBrush(drawColor), drawRectF);
            if (!bufferedRect.IsEmpty)
            {
                g.FillRectangle(new SolidBrush(bufferedColor), bufferedRect);

                /*color1 = bufferedColor;
                 * color2 = ControlPaint.Light(color1);
                 * color3 = ControlPaint.Light(color2);
                 * color4 = ControlPaint.Light(color3);
                 *
                 * colorBlend.Colors = new Color[] { color1, color2, color3, color4 };
                 * colorBlend.Positions = new float[] { 0, 0.25f, 0.65f, 1 };
                 *
                 * if (orientation == Orientation.Horizontal)
                 *  gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)bufferedRect.Left, (int)bufferedRect.Top), new Point((int)bufferedRect.Left, (int)bufferedRect.Top + (int)bufferedRect.Height), color1, color4);
                 * else
                 *  gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)bufferedRect.Left, (int)bufferedRect.Top), new Point((int)bufferedRect.Left + (int)bufferedRect.Width, (int)bufferedRect.Top), color1, color4);
                 * gradientBrush.InterpolationColors = colorBlend;
                 *
                 * FillPill(gradientBrush, bufferedRect, g);*/
            }

            //g.FillRectangle(new SolidBrush(drawColor), drawRectF);

            /*color1 = drawColor;
             * color2 = ControlPaint.Light(color1);
             * color3 = ControlPaint.Light(color2);
             * color4 = ControlPaint.Light(color3);
             *
             * colorBlend.Colors = new Color[]{color1, color2, color3, color4};
             * colorBlend.Positions = new float[]{0, 0.25f, 0.65f, 1};
             *
             * if(orientation == Orientation.Horizontal)
             *      gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top), new Point((int)drawRectF.Left, (int)drawRectF.Top + (int)drawRectF.Height), color1, color4);
             * else
             *      gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top), new Point((int)drawRectF.Left + (int)drawRectF.Width, (int)drawRectF.Top), color1, color4);
             * gradientBrush.InterpolationColors = colorBlend;
             *
             * FillPill(gradientBrush, drawRectF, g);*/
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="drawRectF"></param>
        /// <param name="drawColor"></param>
        /// <param name="orientation"></param>
        ///
        public static void DrawAquaPill(Graphics g, RectangleF drawRectF, Color drawColor, Orientation orientation, Color fillColor)

        {
            Color color1;
            Color color2;
            Color color3;
            Color color4;
            Color color5;

            System.Drawing.Drawing2D.LinearGradientBrush gradientBrush;
            System.Drawing.Drawing2D.ColorBlend          colorBlend = new System.Drawing.Drawing2D.ColorBlend();

            color1 = ColorHelper.OpacityMix(Color.White, ColorHelper.SoftLightMix(drawColor, Color.Black, 100), 40);
            color2 = ColorHelper.OpacityMix(Color.White, ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColorFromRGB(64, 64, 64), 100), 20);
            color3 = ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColorFromRGB(128, 128, 128), 100);
            color4 = ColorHelper.SoftLightMix(drawColor, ColorHelper.CreateColorFromRGB(192, 192, 192), 100);
            color5 = ColorHelper.OverlayMix(ColorHelper.SoftLightMix(drawColor, Color.White, 100), Color.White, 75);

            //
            colorBlend.Colors    = new Color[] { fillColor, fillColor, fillColor, fillColor, fillColor /*color1, color2, color3, color4, color5*/ };
            colorBlend.Positions = new float[] { 0, 0.25f, 0.5f, 0.75f, 1 };
            if (orientation == Orientation.Horizontal)
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top - 1), new Point((int)drawRectF.Left, (int)drawRectF.Top + (int)drawRectF.Height + 1), color1, color5);
            }
            else
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left - 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + (int)drawRectF.Width + 1, (int)drawRectF.Top), color1, color5);
            }
            gradientBrush.InterpolationColors = colorBlend;
            FillPill(gradientBrush, drawRectF, g);

            //
            color2 = Color.White;

            colorBlend.Colors    = new Color[] { drawColor, drawColor, drawColor, drawColor };
            colorBlend.Positions = new float[] { 0, 0.5f, 0.75f, 1 };
            if (orientation == Orientation.Horizontal)
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left + 1, (int)drawRectF.Top), new Point((int)drawRectF.Left + 1, (int)drawRectF.Top + (int)drawRectF.Height - 1), color2, color5);
            }
            else
            {
                gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point((int)drawRectF.Left, (int)drawRectF.Top + 1), new Point((int)drawRectF.Left + (int)drawRectF.Width - 1, (int)drawRectF.Top + 1), color2, color5);
            }
            gradientBrush.InterpolationColors = colorBlend;
            FillPill(gradientBrush, RectangleF.Inflate(drawRectF, -4, -4), g);
        }
示例#38
0
        public LinearGradientBrush ToBrush(Rectangle rectangle, float angle)
        {
            LinearGradientBrush br = new LinearGradientBrush(rectangle, Color.Black, Color.Black, angle, true);

            System.Drawing.Drawing2D.ColorBlend cb = new System.Drawing.Drawing2D.ColorBlend();
            cb.Colors = _Colors;
            float[] positions = new float[_Positions.Length];
            float   range     = _maximum - _minimum;

            for (int i = 0; i < _Positions.Length; i++)
            {
                positions[i] = (_Positions[i] - _minimum) / range;
            }
            cb.Positions           = positions;
            br.InterpolationColors = cb;
            return(br);
        }
示例#39
0
        /*
         * Preset Color Blend
         */

        private ColorBlend _GetInterpolationColors()
        {
            ColorBlend blend;

            // Figure out the size of blend factor array
            int retval = 0;
            int status = SafeNativeMethods.Gdip.GdipGetPathGradientPresetBlendCount(new HandleRef(this, this.NativeBrush), out retval);

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }

            // If retVal is 0, then there is nothing to marshal.
            // In this case, we'll return an empty ColorBlend...
            //
            if (retval == 0)
            {
                return(new ColorBlend());
            }

            // Allocate temporary native memory buffer

            int count = retval;

            IntPtr colors    = IntPtr.Zero;
            IntPtr positions = IntPtr.Zero;

            try {
                int size = checked (4 * count);
                colors    = Marshal.AllocHGlobal(size);
                positions = Marshal.AllocHGlobal(size);

                // Retrieve horizontal blend factors

                status = SafeNativeMethods.Gdip.GdipGetPathGradientPresetBlend(new HandleRef(this, this.NativeBrush), colors, positions, count);

                if (status != SafeNativeMethods.Gdip.Ok)
                {
                    throw SafeNativeMethods.Gdip.StatusException(status);
                }

                // Return the result in a managed array

                blend = new ColorBlend(count);

                int[] argb = new int[count];
                Marshal.Copy(colors, argb, 0, count);
                Marshal.Copy(positions, blend.Positions, 0, count);

                // copy ARGB values into Color array of ColorBlend
                blend.Colors = new Color[argb.Length];

                for (int i = 0; i < argb.Length; i++)
                {
                    blend.Colors[i] = Color.FromArgb(argb[i]);
                }
            }
            finally {
                if (colors != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(colors);
                }
                if (positions != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(positions);
                }
            }

            return(blend);
        }
示例#40
0
        private ColorBlend _GetInterpolationColors()
        {
            ColorBlend blend;

            if (!_interpolationColorsWasSet)
            {
                throw new ArgumentException(SR.Format(SR.InterpolationColorsCommon,
                                                      SR.Format(SR.InterpolationColorsColorBlendNotSet), ""));
            }
            // Figure out the size of blend factor array

            int status = SafeNativeMethods.Gdip.GdipGetLinePresetBlendCount(new HandleRef(this, NativeBrush), out int retval);

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }

            // Allocate temporary native memory buffer

            int count = retval;

            IntPtr colors    = IntPtr.Zero;
            IntPtr positions = IntPtr.Zero;

            try
            {
                int size = checked (4 * count);
                colors    = Marshal.AllocHGlobal(size);
                positions = Marshal.AllocHGlobal(size);

                // Retrieve horizontal blend factors

                status = SafeNativeMethods.Gdip.GdipGetLinePresetBlend(new HandleRef(this, NativeBrush), colors, positions, count);

                if (status != SafeNativeMethods.Gdip.Ok)
                {
                    throw SafeNativeMethods.Gdip.StatusException(status);
                }

                // Return the result in a managed array

                blend = new ColorBlend(count);

                int[] argb = new int[count];
                Marshal.Copy(colors, argb, 0, count);
                Marshal.Copy(positions, blend.Positions, 0, count);

                // copy ARGB values into Color array of ColorBlend
                blend.Colors = new Color[argb.Length];

                for (int i = 0; i < argb.Length; i++)
                {
                    blend.Colors[i] = Color.FromArgb(argb[i]);
                }
            }
            finally
            {
                if (colors != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(colors);
                }
                if (positions != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(positions);
                }
            }

            return(blend);
        }
示例#41
0
        private void _SetInterpolationColors(ColorBlend blend)
        {
            _interpolationColorsWasSet = true;

            // Validate the ColorBlend object.
            if (blend == null)
            {
                throw new ArgumentException(SR.Format(SR.InterpolationColorsCommon,
                                                      SR.Format(SR.InterpolationColorsInvalidColorBlendObject), ""));
            }
            else if (blend.Colors.Length < 2)
            {
                throw new ArgumentException(SR.Format(SR.InterpolationColorsCommon,
                                                      SR.Format(SR.InterpolationColorsInvalidColorBlendObject),
                                                      SR.Format(SR.InterpolationColorsLength)));
            }
            else if (blend.Colors.Length != blend.Positions.Length)
            {
                throw new ArgumentException(SR.Format(SR.InterpolationColorsCommon,
                                                      SR.Format(SR.InterpolationColorsInvalidColorBlendObject),
                                                      SR.Format(SR.InterpolationColorsLengthsDiffer)));
            }
            else if (blend.Positions[0] != 0.0f)
            {
                throw new ArgumentException(SR.Format(SR.InterpolationColorsCommon,
                                                      SR.Format(SR.InterpolationColorsInvalidColorBlendObject),
                                                      SR.Format(SR.InterpolationColorsInvalidStartPosition)));
            }
            else if (blend.Positions[blend.Positions.Length - 1] != 1.0f)
            {
                throw new ArgumentException(SR.Format(SR.InterpolationColorsCommon,
                                                      SR.Format(SR.InterpolationColorsInvalidColorBlendObject),
                                                      SR.Format(SR.InterpolationColorsInvalidEndPosition)));
            }


            // Allocate temporary native memory buffer
            // and copy input blend factors into it.

            int count = blend.Colors.Length;

            IntPtr colors    = IntPtr.Zero;
            IntPtr positions = IntPtr.Zero;

            try
            {
                int size = checked (4 * count);
                colors    = Marshal.AllocHGlobal(size);
                positions = Marshal.AllocHGlobal(size);

                int[] argbs = new int[count];
                for (int i = 0; i < count; i++)
                {
                    argbs[i] = blend.Colors[i].ToArgb();
                }

                Marshal.Copy(argbs, 0, colors, count);
                Marshal.Copy(blend.Positions, 0, positions, count);

                // Set blend factors

                int status = SafeNativeMethods.Gdip.GdipSetLinePresetBlend(new HandleRef(this, NativeBrush), new HandleRef(null, colors), new HandleRef(null, positions), count);

                if (status != SafeNativeMethods.Gdip.Ok)
                {
                    throw SafeNativeMethods.Gdip.StatusException(status);
                }
            }
            finally
            {
                if (colors != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(colors);
                }
                if (positions != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(positions);
                }
            }
        }
示例#42
0
        /// <summary>
        /// Draws a linestring using a gradient brush with colors
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="strokes">An array of coordinates to draw </param>
        /// <param name="width">with of the line to be drawn. There no support for multiple widths</param>
        /// <param name="colors">The colors to use in the brush</param>
        /// <param name="positions">The relative positions of the colors in the brush. Should be in range [0..1]</param>
        private static void DrawStrokesLinear(Graphics graphics, PointF[] strokes, int width, Color[] colors, float[] positions)
        {
            var    totalLength   = TotalDistance(strokes);
            double currentLength = 0;

            for (var i = 1; i < strokes.Length; i++)
            {
                // a LinearGradientBrush can only interpolate between two locations. To draw a line
                // with multliple colors we must split the linestring into straight segments and
                // create a brush for each segment.
                // strokes are in device coordinates; linearGradientBrush will fail if points overlap.
                if (Distance(strokes[i - 1], strokes[i]) > 2)
                {
                    var startOffset = (float)(currentLength / totalLength);
                    currentLength += Distance(strokes[i - 1], strokes[i]);
                    var endOffset = (float)(currentLength / totalLength);

                    var           startColor          = InterpolateColor(colors, positions, startOffset, false);
                    var           endColor            = InterpolateColor(colors, positions, endOffset, true);
                    var           linearGradientBrush = new LinearGradientBrush(strokes[i - 1], strokes[i], startColor, endColor);
                    IList <Color> localColors         = new List <Color>();
                    IList <float> localPositions      = new List <float>();
                    localColors.Add(startColor);
                    localPositions.Add(0.0f);
                    for (var c = 0; c < positions.Length; c++)
                    {
                        if ((positions[c] <= startOffset) || (positions[c] >= endOffset))
                        {
                            continue;
                        }
                        localColors.Add(colors[c]);
                        localPositions.Add((positions[c] - startOffset) / (endOffset - startOffset));
                        if (localPositions[localPositions.Count - 1] == localPositions[localPositions.Count - 2])
                        {
                            localPositions[localPositions.Count - 1] = localPositions[localPositions.Count - 2] + 1.0e-6F;
                        }
                    }
                    localColors.Add(endColor);
                    localPositions.Add(1.0f);

                    var colorBlend = new ColorBlend {
                        Colors = localColors.ToArray(), Positions = localPositions.ToArray()
                    };

                    linearGradientBrush.InterpolationColors = colorBlend;
                    var pen = new Pen(linearGradientBrush, width);
                    if (i != (strokes.Length - 1))
                    {
                        using (var solidBrush = new SolidBrush(endColor))
                        {
                            graphics.FillEllipse(solidBrush, strokes[i].X - pen.Width / 2, strokes[i].Y - pen.Width / 2,
                                                 pen.Width, pen.Width);
                        }
                    }
                    graphics.DrawLine(pen, strokes[i - 1], strokes[i]);
                    pen.Dispose();
                    linearGradientBrush.Dispose();
                }
                else
                {
                    using (var solidBrush = new SolidBrush(colors[0]))
                    {
                        using (var pen = new Pen(solidBrush, width))
                        {
                            graphics.DrawLine(pen, strokes[i - 1], strokes[i]);
                        }
                    }
                }
            }
        }