/// <summary> /// Make the bitmap for the wheel. /// </summary> private void _makeBitmap() { // If there already is a bitmap then dispose it. if (null != _bitmap) { _bitmap.Dispose(); } // Get the size. int w = this.ClientRectangle.Width; int h = this.ClientRectangle.Height; // If the size is too small then punt. if (w <= 0 || h <= 0) { return; } // The number of points we use is a function of radius. int num = (360 * this.Radius) / 100; // Never go below this many points. num = System.Math.Max(num, 10); // Make the points around the perimeter. float radius = this.RadiusF; System.Drawing.PointF[] points = CadKit.Color.Wheel._makePoints(this.CenterF, radius, num); // Make the circle. using (System.Drawing.Drawing2D.PathGradientBrush brush = new System.Drawing.Drawing2D.PathGradientBrush(points)) { CadKit.Color.HSV currentHSV = new HSV(this.Color); RGB grayscale = new RGB(new HSV(0, 0, currentHSV.v)); brush.CenterColor = System.Drawing.Color.FromArgb(255, grayscale.r, grayscale.g, grayscale.b); brush.CenterPoint = this.CenterF; brush.SurroundColors = CadKit.Color.Wheel._makeColors(num, currentHSV.v); // Make new bitmap. float diameter = radius * 2; _bitmap = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // Make a new graphic from the bitmap. using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(_bitmap)) { // This writes to the bitmap. graphic.FillEllipse(brush, this.ClientRectangle); } } }
private static readonly Dictionary <int, PointF[]> g_RadialPoints = new Dictionary <int, PointF[]>(); // key is the size of the rectangle; value is the list of points needed for a gradient brush private static Brush CreateGradientBrush(int size, Color light, Color dark) { if (!g_RadialPoints.ContainsKey(size)) { PointF[] points = CreateRadialPoints(new PointF(size / 3 + INSET, size / 3 + INSET), size / 2); g_RadialPoints.Add(size, points); } System.Drawing.Drawing2D.PathGradientBrush br = new System.Drawing.Drawing2D.PathGradientBrush(g_RadialPoints[size]); // Create new color blend to tell the PathGradientBrush what colors to use and where to put them System.Drawing.Drawing2D.ColorBlend gradientSpecifications = new System.Drawing.Drawing2D.ColorBlend(3); // Define positions of gradient colors gradientSpecifications.Positions = new float[] { 0, 1 }; // Define gradient colors and their alpha values, adjust alpha of gradient colors to match intensity gradientSpecifications.Colors = new Color[] { dark, light }; // Pass off color blend to PathGradientBrush to instruct it how to generate the gradient br.InterpolationColors = gradientSpecifications; return(br); }
internal static void SetBrushMatrix(System.Drawing.Brush brush, System.Drawing.Drawing2D.Matrix matrix) { if (brush == null) { throw new System.ArgumentNullException("brush"); } if (brush.GetType() == typeof(System.Drawing.TextureBrush)) { System.Drawing.TextureBrush textureBrush = (System.Drawing.TextureBrush)brush; textureBrush.Transform = matrix; } else if (brush.GetType() == typeof(System.Drawing.Drawing2D.LinearGradientBrush)) { System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush = (System.Drawing.Drawing2D.LinearGradientBrush)brush; linearGradientBrush.Transform = matrix; } else if (brush.GetType() == typeof(System.Drawing.Drawing2D.PathGradientBrush)) { System.Drawing.Drawing2D.PathGradientBrush pathGradientBrush = (System.Drawing.Drawing2D.PathGradientBrush)brush; pathGradientBrush.Transform = matrix; } }
private static void CreateLights() { //Optimize? Lights = new List <Texture>(); for (int I = 1; I < 15; I++) { using (MemoryStream MStream = new MemoryStream()) { using (Bitmap B = new Bitmap(65 * I, 50 * I, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { using (System.Drawing.Graphics G = System.Drawing.Graphics.FromImage(B)) { using (System.Drawing.Drawing2D.GraphicsPath P = new System.Drawing.Drawing2D.GraphicsPath()) { P.AddEllipse(new Rectangle(0, 0, 65 * I, 50 * I)); using (System.Drawing.Drawing2D.PathGradientBrush Br = new System.Drawing.Drawing2D.PathGradientBrush(P)) { G.Clear(Color.Black); G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Br.SurroundColors = new Color[] { Color.Black }; Br.CenterColor = Color.Gray; G.FillPath(Br, P); Br.CenterColor = Color.White; Br.FocusScales = new PointF(0.2f, 0.2f); G.TranslateTransform(0, 0); G.FillPath(Br, P); G.Save(); B.Save(MStream, System.Drawing.Imaging.ImageFormat.Bmp); MStream.Position = 0; Lights.Add(TextureLoader.FromStream(Device, MStream, 65 * I, 50 * I, 1, Usage.RenderTarget, Format.A8B8G8R8, Pool.Default, Filter.None, Filter.None, 0)); } } } } } } }
/// <summary> /// Evaluates the DrawStyle of the control and calls the appropriate /// drawing function for content /// </summary> protected void DrawContent() { Graphics g = Graphics.FromImage(m_Output); Rectangle Rect = new Rectangle(4, 11, Width - 8, Height - 21); // Draw a nice checker box System.Drawing.Drawing2D.HatchBrush Checker = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard, Color.Gray, Color.DarkGray); g.FillRectangle(Checker, Rect); Checker.Dispose(); // Draw a gradient box System.Drawing.Drawing2D.GraphicsPath Path = new System.Drawing.Drawing2D.GraphicsPath(); Path.AddRectangle(Rect); System.Drawing.Drawing2D.PathGradientBrush Gradient = new System.Drawing.Drawing2D.PathGradientBrush(Path); Gradient.SurroundColors = new Color[] { Color.FromArgb(0, Color.White), Color.FromArgb(255, Color.White), Color.FromArgb(255, Color.White), Color.FromArgb(0, Color.White) }; Gradient.CenterPoint = new PointF(0.5f * (Rect.Left + Rect.Right), .5f * (Rect.Bottom + Rect.Top)); Gradient.CenterColor = Color.FromArgb(128, Color.White); g.FillRectangle(Gradient, Rect); Gradient.Dispose(); }
public EffectBrush(System.Drawing.Brush brush) { if (brush is System.Drawing.SolidBrush) { type = BrushType.Solid; color_gradients.Add(0.0f, (brush as System.Drawing.SolidBrush).Color); color_gradients.Add(1.0f, (brush as System.Drawing.SolidBrush).Color); wrap = BrushWrap.Repeat; } else if (brush is System.Drawing.Drawing2D.LinearGradientBrush) { type = BrushType.Linear; System.Drawing.Drawing2D.LinearGradientBrush lgb = (brush as System.Drawing.Drawing2D.LinearGradientBrush); start = lgb.Rectangle.Location; end = new System.Drawing.PointF(lgb.Rectangle.Width, lgb.Rectangle.Height); switch (lgb.WrapMode) { case (System.Drawing.Drawing2D.WrapMode.Clamp): wrap = BrushWrap.None; break; case (System.Drawing.Drawing2D.WrapMode.Tile): wrap = BrushWrap.Repeat; break; case (System.Drawing.Drawing2D.WrapMode.TileFlipXY): wrap = BrushWrap.Reflect; break; } try { if (lgb.InterpolationColors != null && lgb.InterpolationColors.Colors.Length == lgb.InterpolationColors.Positions.Length) { for (int x = 0; x < lgb.InterpolationColors.Colors.Length; x++) { if (!color_gradients.ContainsKey(lgb.InterpolationColors.Positions[x]) && (lgb.InterpolationColors.Positions[x] >= 0.0f && lgb.InterpolationColors.Positions[x] <= 1.0f)) { color_gradients.Add( lgb.InterpolationColors.Positions[x], lgb.InterpolationColors.Colors[x] ); } } } } catch (Exception exc) { color_gradients.Clear(); for (int x = 0; x < lgb.LinearColors.Length; x++) { float pos = x / (float)(lgb.LinearColors.Length - 1); if (!color_gradients.ContainsKey(pos)) { color_gradients.Add( pos, lgb.LinearColors[x] ); } } } } else if (brush is System.Drawing.Drawing2D.PathGradientBrush) { type = BrushType.Radial; System.Drawing.Drawing2D.PathGradientBrush pgb = (brush as System.Drawing.Drawing2D.PathGradientBrush); center = new System.Drawing.PointF( pgb.CenterPoint.X, pgb.CenterPoint.Y ); start = pgb.Rectangle.Location; end = new System.Drawing.PointF(pgb.Rectangle.Width, pgb.Rectangle.Height); switch (pgb.WrapMode) { case (System.Drawing.Drawing2D.WrapMode.Clamp): wrap = BrushWrap.None; break; case (System.Drawing.Drawing2D.WrapMode.Tile): wrap = BrushWrap.Repeat; break; case (System.Drawing.Drawing2D.WrapMode.TileFlipXY): wrap = BrushWrap.Reflect; break; } try { if (pgb.InterpolationColors != null && pgb.InterpolationColors.Colors.Length == pgb.InterpolationColors.Positions.Length) { for (int x = 0; x < pgb.InterpolationColors.Colors.Length; x++) { if (!color_gradients.ContainsKey(pgb.InterpolationColors.Positions[x]) && (pgb.InterpolationColors.Positions[x] >= 0.0f && pgb.InterpolationColors.Positions[x] <= 1.0f)) { color_gradients.Add( pgb.InterpolationColors.Positions[x], pgb.InterpolationColors.Colors[x] ); } } } } catch (Exception exc) { color_gradients.Clear(); for (int x = 0; x < pgb.SurroundColors.Length; x++) { float pos = x / (float)(pgb.SurroundColors.Length - 1); if (!color_gradients.ContainsKey(pos)) { color_gradients.Add( pos, pgb.SurroundColors[x] ); } } } } else { } if (color_gradients.Count > 0) { bool firstFound = false; System.Drawing.Color first_color = new System.Drawing.Color(); System.Drawing.Color last_color = new System.Drawing.Color(); foreach (var kvp in color_gradients) { if (!firstFound) { first_color = kvp.Value; firstFound = true; } last_color = kvp.Value; } if (!color_gradients.ContainsKey(0.0f)) { color_gradients.Add(0.0f, first_color); } if (!color_gradients.ContainsKey(1.0f)) { color_gradients.Add(1.0f, last_color); } } else { if (!color_gradients.ContainsKey(0.0f)) { color_gradients.Add(0.0f, System.Drawing.Color.Transparent); } if (!color_gradients.ContainsKey(1.0f)) { color_gradients.Add(1.0f, System.Drawing.Color.Transparent); } } }
public System.Drawing.Brush GetDrawingBrush() { if (true /*_drawingbrush == null*/) { if (type == BrushType.Solid) { _drawingbrush = new System.Drawing.SolidBrush(color_gradients[0.0f]); } else if (type == BrushType.Linear) { System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush( start, end, System.Drawing.Color.Red, System.Drawing.Color.Red ); List <System.Drawing.Color> brush_colors = new List <System.Drawing.Color>(); List <float> brush_positions = new List <float>(); foreach (var kvp in color_gradients) { brush_positions.Add(kvp.Key); brush_colors.Add(kvp.Value); } System.Drawing.Drawing2D.ColorBlend color_blend = new System.Drawing.Drawing2D.ColorBlend(); color_blend.Colors = brush_colors.ToArray(); color_blend.Positions = brush_positions.ToArray(); brush.InterpolationColors = color_blend; switch (wrap) { //case BrushWrap.None: // brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; // break; case BrushWrap.Repeat: brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; break; case BrushWrap.Reflect: brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY; break; } _drawingbrush = brush; } else if (type == BrushType.Radial) { System.Drawing.Drawing2D.GraphicsPath g_path = new System.Drawing.Drawing2D.GraphicsPath(); g_path.AddEllipse( new System.Drawing.RectangleF( start.X, start.Y, end.X, end.Y )); System.Drawing.Drawing2D.PathGradientBrush brush = new System.Drawing.Drawing2D.PathGradientBrush( g_path ); switch (wrap) { //// Clamp causes an exception, it's a bug in the Drawing Brush. //case BrushWrap.None: // brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; // break; case BrushWrap.Repeat: brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; break; case BrushWrap.Reflect: brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY; break; } List <System.Drawing.Color> brush_colors = new List <System.Drawing.Color>(); List <float> brush_positions = new List <float>(); foreach (var kvp in color_gradients) { brush_positions.Add(1.0f - kvp.Key); brush_colors.Add(kvp.Value); } brush.CenterPoint = center; //brush.CenterColor = brush_colors[0]; //brush.SurroundColors = brush_colors.ToArray(); brush_colors.Reverse(); brush_positions.Reverse(); System.Drawing.Drawing2D.ColorBlend color_blend = new System.Drawing.Drawing2D.ColorBlend(); color_blend.Colors = brush_colors.ToArray(); color_blend.Positions = brush_positions.ToArray(); brush.InterpolationColors = color_blend; _drawingbrush = brush; } else { _drawingbrush = new System.Drawing.SolidBrush(System.Drawing.Color.Transparent); } } return(_drawingbrush); }
protected override void PaintControlBackground(ItemPaintArgs pa) { bool resetClip = false; eDotNetBarStyle effectiveStyle = this.EffectiveStyle; bool isGlassEnabled = this.IsGlassEnabled; if (isGlassEnabled) { RibbonForm f = this.FindForm() as RibbonForm; if (f != null) { pa.Graphics.SetClip(new Rectangle(0, 0, this.Width, f.GlassHeight - ((effectiveStyle == eDotNetBarStyle.Office2010 || effectiveStyle == eDotNetBarStyle.Metro) && pa.GlassEnabled ? Office2010GlassExcludeTopPart : 1)), System.Drawing.Drawing2D.CombineMode.Exclude); resetClip = true; } } if (isGlassEnabled && (effectiveStyle == eDotNetBarStyle.Office2010 || effectiveStyle == eDotNetBarStyle.Metro)) { ElementStyle style = GetBackgroundStyle(); if (style != null) { Rectangle r = new Rectangle(0, Office2010GlassExcludeTopPart - 2, this.Width, this.Height + 8); using (System.Drawing.Drawing2D.GraphicsPath fillPath = new System.Drawing.Drawing2D.GraphicsPath()) { //if (StyleManager.Style == eStyle.Office2010Black) //{ // fillPath.AddRectangle(r); // using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(r, style.BackColor2, style.BackColor, 90)) // pa.Graphics.FillPath(brush, fillPath); //} //else { fillPath.AddEllipse(r); using (System.Drawing.Drawing2D.PathGradientBrush brush = new System.Drawing.Drawing2D.PathGradientBrush(fillPath)) { brush.CenterColor = style.BackColor; brush.SurroundColors = new Color[] { style.BackColor2 }; brush.CenterPoint = new PointF(r.Width / 2, r.Bottom - Office2010GlassExcludeTopPart / 2); System.Drawing.Drawing2D.Blend blend = new System.Drawing.Drawing2D.Blend(); blend.Factors = new float[] { 0f, .85f, 1f, }; blend.Positions = new float[] { 0f, .65f, 1f }; brush.Blend = blend; pa.Graphics.FillPath(brush, fillPath); } } } } } else base.PaintControlBackground(pa); if (resetClip) pa.Graphics.ResetClip(); m_QuickToolbarBounds = Rectangle.Empty; m_CaptionBounds = Rectangle.Empty; m_SystemCaptionItemBounds = Rectangle.Empty; Rendering.BaseRenderer renderer = GetRenderer(); if (renderer != null && this.Parent is RibbonControl) { RibbonControlRendererEventArgs rargs = new RibbonControlRendererEventArgs(pa.Graphics, this.Parent as RibbonControl, pa.GlassEnabled); rargs.ItemPaintArgs = pa; renderer.DrawRibbonControlBackground(rargs); if (m_CaptionVisible) renderer.DrawQuickAccessToolbarBackground(new RibbonControlRendererEventArgs(pa.Graphics, this.Parent as RibbonControl, pa.GlassEnabled)); } if (m_TabGroupsVisible) { PaintTabGroups(pa); } // Paint form caption text if (renderer != null && m_CaptionVisible) { RibbonControlRendererEventArgs rer = new RibbonControlRendererEventArgs(pa.Graphics, this.Parent as RibbonControl, pa.GlassEnabled); rer.ItemPaintArgs = pa; renderer.DrawRibbonFormCaptionText(rer); } #if TRIAL if (NativeFunctions.ColorExpAlt()) { pa.Graphics.Clear(Color.White); TextDrawing.DrawString(pa.Graphics, "Trial Version Expired :-(", this.Font, Color.FromArgb(128, Color.Black), this.ClientRectangle, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter); } //else //{ // TextDrawing.DrawString(pa.Graphics, "Trial Version", this.Font, Color.FromArgb(128, Color.Black), new Rectangle(0, 0, this.Width - 12, this.Height-4), eTextFormat.Right | eTextFormat.Bottom); //} #endif }
public static System.Drawing.Brush MediaBrushToDrawingBrush(System.Windows.Media.Brush in_brush) { if (in_brush is System.Windows.Media.SolidColorBrush) { System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush( ColorUtils.MediaColorToDrawingColor((in_brush as System.Windows.Media.SolidColorBrush).Color) ); return(brush); } else if (in_brush is System.Windows.Media.LinearGradientBrush) { System.Windows.Media.LinearGradientBrush lgb = (in_brush as System.Windows.Media.LinearGradientBrush); System.Drawing.PointF starting_point = new System.Drawing.PointF( (float)lgb.StartPoint.X, (float)lgb.StartPoint.Y ); System.Drawing.PointF ending_point = new System.Drawing.PointF( (float)lgb.EndPoint.X, (float)lgb.EndPoint.Y ); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush( starting_point, ending_point, System.Drawing.Color.Red, System.Drawing.Color.Red ); /* * switch(lgb.SpreadMethod) * { * case System.Windows.Media.GradientSpreadMethod.Pad: * brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; * break; * case System.Windows.Media.GradientSpreadMethod.Reflect: * brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY; * break; * case System.Windows.Media.GradientSpreadMethod.Repeat: * brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; * break; * } */ SortedDictionary <float, System.Drawing.Color> brush_blend = new SortedDictionary <float, System.Drawing.Color>(); foreach (var grad_stop in lgb.GradientStops) { if (!brush_blend.ContainsKey((float)grad_stop.Offset)) { brush_blend.Add((float)grad_stop.Offset, ColorUtils.MediaColorToDrawingColor(grad_stop.Color)); } } List <System.Drawing.Color> brush_colors = new List <System.Drawing.Color>(); List <float> brush_positions = new List <float>(); foreach (var kvp in brush_blend) { brush_colors.Add(kvp.Value); brush_positions.Add(kvp.Key); } System.Drawing.Drawing2D.ColorBlend color_blend = new System.Drawing.Drawing2D.ColorBlend(); color_blend.Colors = brush_colors.ToArray(); color_blend.Positions = brush_positions.ToArray(); brush.InterpolationColors = color_blend; return(brush); } else if (in_brush is System.Windows.Media.RadialGradientBrush) { System.Windows.Media.RadialGradientBrush rgb = (in_brush as System.Windows.Media.RadialGradientBrush); System.Drawing.RectangleF brush_region = new System.Drawing.RectangleF( 0.0f, 0.0f, 2.0f * (float)rgb.RadiusX, 2.0f * (float)rgb.RadiusY ); System.Drawing.PointF center_point = new System.Drawing.PointF( (float)rgb.Center.X, (float)rgb.Center.Y ); System.Drawing.Drawing2D.GraphicsPath g_path = new System.Drawing.Drawing2D.GraphicsPath(); g_path.AddEllipse(brush_region); System.Drawing.Drawing2D.PathGradientBrush brush = new System.Drawing.Drawing2D.PathGradientBrush(g_path); brush.CenterPoint = center_point; /* * switch (rgb.SpreadMethod) * { * case System.Windows.Media.GradientSpreadMethod.Pad: * brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; * break; * case System.Windows.Media.GradientSpreadMethod.Reflect: * brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY; * break; * case System.Windows.Media.GradientSpreadMethod.Repeat: * brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; * break; * } */ SortedDictionary <float, System.Drawing.Color> brush_blend = new SortedDictionary <float, System.Drawing.Color>(); foreach (var grad_stop in rgb.GradientStops) { if (!brush_blend.ContainsKey((float)grad_stop.Offset)) { brush_blend.Add((float)grad_stop.Offset, ColorUtils.MediaColorToDrawingColor(grad_stop.Color)); } } List <System.Drawing.Color> brush_colors = new List <System.Drawing.Color>(); List <float> brush_positions = new List <float>(); foreach (var kvp in brush_blend) { brush_colors.Add(kvp.Value); brush_positions.Add(kvp.Key); } System.Drawing.Drawing2D.ColorBlend color_blend = new System.Drawing.Drawing2D.ColorBlend(); color_blend.Colors = brush_colors.ToArray(); color_blend.Positions = brush_positions.ToArray(); brush.InterpolationColors = color_blend; return(brush); } else { return(new System.Drawing.SolidBrush(System.Drawing.Color.Red)); //Return error color } }
public static System.Windows.Media.Brush DrawingBrushToMediaBrush(System.Drawing.Brush in_brush) { if (in_brush is System.Drawing.SolidBrush) { System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush( ColorUtils.DrawingColorToMediaColor((in_brush as System.Drawing.SolidBrush).Color) ); return(brush); } else if (in_brush is System.Drawing.Drawing2D.LinearGradientBrush) { System.Drawing.Drawing2D.LinearGradientBrush lgb = (in_brush as System.Drawing.Drawing2D.LinearGradientBrush); System.Windows.Point starting_point = new System.Windows.Point( lgb.Rectangle.X, lgb.Rectangle.Y ); System.Windows.Point ending_point = new System.Windows.Point( lgb.Rectangle.Right, lgb.Rectangle.Bottom ); System.Windows.Media.GradientStopCollection collection = new System.Windows.Media.GradientStopCollection(); try { if (lgb.InterpolationColors != null && lgb.InterpolationColors.Colors.Length == lgb.InterpolationColors.Positions.Length) { for (int x = 0; x < lgb.InterpolationColors.Colors.Length; x++) { collection.Add( new System.Windows.Media.GradientStop( ColorUtils.DrawingColorToMediaColor(lgb.InterpolationColors.Colors[x]), lgb.InterpolationColors.Positions[x] ) ); } } } catch (Exception exc) { for (int x = 0; x < lgb.LinearColors.Length; x++) { collection.Add( new System.Windows.Media.GradientStop( ColorUtils.DrawingColorToMediaColor(lgb.LinearColors[x]), x / (double)(lgb.LinearColors.Length - 1) ) ); } } System.Windows.Media.LinearGradientBrush brush = new System.Windows.Media.LinearGradientBrush( collection, starting_point, ending_point ); return(brush); } else if (in_brush is System.Drawing.Drawing2D.PathGradientBrush) { System.Drawing.Drawing2D.PathGradientBrush pgb = (in_brush as System.Drawing.Drawing2D.PathGradientBrush); System.Windows.Point starting_point = new System.Windows.Point( pgb.CenterPoint.X, pgb.CenterPoint.Y ); System.Windows.Media.GradientStopCollection collection = new System.Windows.Media.GradientStopCollection(); if (pgb.InterpolationColors != null && pgb.InterpolationColors.Colors.Length == pgb.InterpolationColors.Positions.Length) { for (int x = 0; x < pgb.InterpolationColors.Colors.Length; x++) { collection.Add( new System.Windows.Media.GradientStop( ColorUtils.DrawingColorToMediaColor(pgb.InterpolationColors.Colors[x]), pgb.InterpolationColors.Positions[x] ) ); } } System.Windows.Media.RadialGradientBrush brush = new System.Windows.Media.RadialGradientBrush( collection ); brush.Center = starting_point; return(brush); } else { return(new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0))); //Return error color } }
internal PathGradientBrush(System.Drawing.Drawing2D.PathGradientBrush pathGradientBrush) { WrappedPathGradientBrush = pathGradientBrush; }
/// <summary> /// Initializes a new instance of the <see cref="T:Common.Drawing.Drawing2D.PathGradientBrush" /> class with the /// specified path. /// </summary> /// <param name="path"> /// The <see cref="T:Common.Drawing.Drawing2D.GraphicsPath" /> that defines the area filled by this /// <see cref="T:Common.Drawing.Drawing2D.PathGradientBrush" />. /// </param> public PathGradientBrush(GraphicsPath path) { WrappedPathGradientBrush = new System.Drawing.Drawing2D.PathGradientBrush(path); }
/// <summary> /// Initializes a new instance of the <see cref="T:Common.Drawing.Drawing2D.PathGradientBrush" /> class with the /// specified points and wrap mode. /// </summary> /// <param name="points"> /// An array of <see cref="T:Common.Drawing.Point" /> structures that represents the points that make /// up the vertices of the path. /// </param> /// <param name="wrapMode"> /// A <see cref="T:Common.Drawing.Drawing2D.WrapMode" /> that specifies how fills drawn with this /// <see cref="T:Common.Drawing.Drawing2D.PathGradientBrush" /> are tiled. /// </param> public PathGradientBrush(Point[] points, WrapMode wrapMode) { WrappedPathGradientBrush = new System.Drawing.Drawing2D.PathGradientBrush( points.Convert <System.Drawing.Point>().ToArray(), (System.Drawing.Drawing2D.WrapMode)wrapMode); }
/// <summary> /// Initializes a new instance of the <see cref="T:Common.Drawing.Drawing2D.PathGradientBrush" /> class with the /// specified points. /// </summary> /// <param name="points"> /// An array of <see cref="T:Common.Drawing.Point" /> structures that represents the points that make /// up the vertices of the path. /// </param> public PathGradientBrush(Point[] points) { WrappedPathGradientBrush = new System.Drawing.Drawing2D.PathGradientBrush(points.Convert <System.Drawing.Point>().ToArray()); }
/// <summary> /// Repaints the form with cool background and stuff /// </summary> /// <param name="graph">The graphics object to paint to, the element will be drawn to 0,0</param> public virtual void Paint(Graphics graph) { //Sets up the colors to use Pen outlinePen = new Pen(MapWindow.Main.Global.ColorFromHSL(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 0.6 * Highlight), 1.75F); Color gradientTop = MapWindow.Main.Global.ColorFromHSL(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 0.7 * Highlight); Color gradientBottom = MapWindow.Main.Global.ColorFromHSL(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 1.0 * Highlight); //The path used for drop shadows System.Drawing.Drawing2D.GraphicsPath shadowPath = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend(3); colorBlend.Colors = new Color[] { Color.Transparent, Color.FromArgb(180, Color.DarkGray), Color.FromArgb(180, Color.DimGray) }; colorBlend.Positions = new float[] { 0f, 0.125f,1f}; //Draws Rectangular Shapes if (Shape == ModelShapes.Rectangle) { //Draws the shadow shadowPath.AddPath(GetRoundedRect(new Rectangle(5, 5, this.Width, this.Height), 10), true); System.Drawing.Drawing2D.PathGradientBrush shadowBrush = new System.Drawing.Drawing2D.PathGradientBrush(shadowPath); shadowBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; shadowBrush.InterpolationColors = colorBlend; graph.FillPath(shadowBrush, shadowPath); //Draws the basic shape System.Drawing.Rectangle fillRectange = new Rectangle(0, 0, this.Width - 5, this.Height - 5); System.Drawing.Drawing2D.GraphicsPath fillArea = GetRoundedRect(fillRectange, 5); System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(fillRectange, gradientBottom, gradientTop, System.Drawing.Drawing2D.LinearGradientMode.Vertical); graph.FillPath(myBrush, fillArea); graph.DrawPath(outlinePen, fillArea); //Draws the status light drawStatusLight(graph); //Draws the text SizeF textSize = graph.MeasureString(Name, Font, this.Width); RectangleF textRect; if ((textSize.Width < this.Width) || (textSize.Height < this.Height)) textRect = new RectangleF((this.Width - textSize.Width) / 2, (this.Height - textSize.Height) / 2, textSize.Width, textSize.Height); else textRect = new RectangleF(0, (this.Height - textSize.Height) / 2, this.Width, textSize.Height); graph.DrawString(Name, Font, new SolidBrush(Color.FromArgb(50, Color.Black)), textRect); textRect.X = textRect.X - 1; textRect.Y = textRect.Y - 1; graph.DrawString(Name, Font, System.Drawing.Brushes.Black, textRect); //Garbage collection fillArea.Dispose(); myBrush.Dispose(); } //Draws Ellipse Shapes if (_shape == ModelShapes.Ellipse) { //Draws the shadow shadowPath.AddEllipse(0, 5, this.Width+5, this.Height); System.Drawing.Drawing2D.PathGradientBrush shadowBrush = new System.Drawing.Drawing2D.PathGradientBrush(shadowPath); shadowBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; shadowBrush.InterpolationColors = colorBlend; graph.FillPath(shadowBrush, shadowPath); //Draws the Ellipse System.Drawing.Rectangle fillArea = new Rectangle(0, 0, this.Width, this.Height); System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(fillArea, gradientBottom, gradientTop, System.Drawing.Drawing2D.LinearGradientMode.Vertical); graph.FillEllipse(myBrush, 1, 1, this.Width - 5, this.Height - 5); graph.DrawEllipse(outlinePen, 1, 1, this.Width - 5, this.Height - 5); //Draws the text SizeF textSize = graph.MeasureString(_name, _font, this.Width); RectangleF textRect; if ((textSize.Width < this.Width) || (textSize.Height < this.Height)) textRect = new RectangleF((this.Width - textSize.Width) / 2, (this.Height - textSize.Height) / 2, textSize.Width, textSize.Height); else textRect = new RectangleF(0, (this.Height - textSize.Height) / 2, this.Width, textSize.Height); graph.DrawString(Name, Font, new SolidBrush(Color.FromArgb(50, Color.Black)), textRect); textRect.X = textRect.X - 1; textRect.Y = textRect.Y - 1; graph.DrawString(Name, Font, System.Drawing.Brushes.Black, textRect); //Garbage collection myBrush.Dispose(); } //Draws Triangular Shapes if (_shape == ModelShapes.Triangle) { //Draws the shadow Point[] ptShadow = new Point[4]; ptShadow[0] = new Point(5, 5); ptShadow[1] = new Point(this.Width + 5, ((this.Height - 5) / 2) + 5); ptShadow[2] = new Point(5, this.Height+2); ptShadow[3] = new Point(5, 5); shadowPath.AddLines(ptShadow); System.Drawing.Drawing2D.PathGradientBrush shadowBrush = new System.Drawing.Drawing2D.PathGradientBrush(shadowPath); shadowBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; shadowBrush.InterpolationColors = colorBlend; graph.FillPath(shadowBrush, shadowPath); //Draws the shape Point[] pt = new Point[4]; pt[0] = new Point(0, 0); pt[1] = new Point(this.Width - 5, (this.Height-5) / 2); pt[2] = new Point(0, this.Height-5); pt[3] = new Point(0, 0); System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath(); myPath.AddLines(pt); System.Drawing.Rectangle fillArea = new Rectangle(1, 1, this.Width - 5, this.Height - 5); System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(fillArea, gradientBottom, gradientTop, System.Drawing.Drawing2D.LinearGradientMode.Vertical); graph.FillPath(myBrush, myPath); graph.DrawPath(outlinePen, myPath); //Draws the text SizeF textSize = graph.MeasureString(Name, Font, this.Width); RectangleF textRect; if ((textSize.Width < this.Width) || (textSize.Height < this.Height)) textRect = new RectangleF((this.Width - textSize.Width) / 2, (this.Height - textSize.Height) / 2, textSize.Width, textSize.Height); else textRect = new RectangleF(0, (this.Height - textSize.Height) / 2, this.Width, textSize.Height); graph.DrawString(Name, Font, System.Drawing.Brushes.Black, textRect); //Garbage collection myBrush.Dispose(); } //Garbage collection shadowPath.Dispose(); outlinePen.Dispose(); }