private void shadowToolStripButton_Click(object sender, EventArgs e) { if (diagram1.View.SelectionList != null && diagram1.View.SelectionList.Count > 0) { ShadowStyleDialog ssd = new ShadowStyleDialog(); ShadowStyle fs = null; if (DialogResult.OK == ssd.ShowDialog()) { diagram1.BeginUpdate(); foreach (Node node in this.diagram1.View.SelectionList) { if (!(node is ConnectorBase) && !(node is TextNode)) { fs = (ShadowStyle)TypeDescriptor.GetProperties(node, false)["ShadowStyle"].GetValue(node); if (fs != null) { fs.Color = ssd.ShadowStyle.Color; fs.ForeColor = ssd.ShadowStyle.ForeColor; fs.ColorAlphaFactor = ssd.ShadowStyle.ColorAlphaFactor; fs.ForeColorAlphaFactor = ssd.ShadowStyle.ForeColorAlphaFactor; fs.PathBrushStyle = ssd.ShadowStyle.PathBrushStyle; fs.OffsetX = ssd.ShadowStyle.OffsetX; fs.OffsetY = ssd.ShadowStyle.OffsetY; fs.Visible = ssd.ShadowStyle.Visible; } } } diagram1.EndUpdate(); } } }
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name = "boundingRect"> /// Bounding rectangle used to draw the top surface of the slice. /// </param> /// <param name = "sliceHeight"> /// Pie slice height. /// </param> /// <param name = "startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name = "sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name = "surfaceColor"> /// Color used to render pie slice surface. /// </param> /// <param name = "shadowStyle"> /// Shadow style used in rendering. /// </param> /// <param name = "edgeColorType"> /// Edge color type used for rendering. /// </param> public PieSlice(RectangleF boundingRect, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType) : this( boundingRect.X, boundingRect.Y, boundingRect.Width, boundingRect.Height, sliceHeight, startAngle, sweepAngle, surfaceColor, shadowStyle, edgeColorType) { }
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name = "xBoundingRect"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name = "yBoundingRect"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name = "widthBoundingRect"> /// Width of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name = "heightBoundingRect"> /// Height of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name = "sliceHeight"> /// Height of the pie slice. /// </param> /// <param name = "startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name = "sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name = "surfaceColor"> /// Color used to render pie slice surface. /// </param> /// <param name = "shadowStyle"> /// Shadow style used in rendering. /// </param> /// <param name = "edgeColorType"> /// Edge color type used for rendering. /// </param> /// <param name = "edgeLineWidth"> /// Edge line width. /// </param> public PieSlice(float xBoundingRect, float yBoundingRect, float widthBoundingRect, float heightBoundingRect, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) : this(xBoundingRect, yBoundingRect, widthBoundingRect, heightBoundingRect, sliceHeight, startAngle, sweepAngle, surfaceColor, shadowStyle, edgeColorType) { Pen.Width = edgeLineWidth; }
/// <summary> /// Creates a <c>PieSlice</c> object. /// </summary> /// <param name = "boundingRectLeft"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name = "boundingRectTop"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name = "boundingRectWidth"> /// Width of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name = "boundingRectHeight"> /// Height of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name = "sliceHeight"> /// Slice height. /// </param> /// <param name = "startAngle"> /// Starting angle. /// </param> /// <param name = "sweepAngle"> /// Sweep angle. /// </param> /// <param name = "color"> /// Color used for slice rendering. /// </param> /// <param name = "shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name = "edgeColorType"> /// Edge lines color type. /// </param> /// <param name = "edgeLineWidth"> /// Edge lines width. /// </param> /// <returns> /// <c>PieSlice</c> object with given values. /// </returns> protected virtual PieSlice CreatePieSlice(float boundingRectLeft, float boundingRectTop, float boundingRectWidth, float boundingRectHeight, float sliceHeight, float startAngle, float sweepAngle, Color color, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) { return(new PieSlice(boundingRectLeft, boundingRectTop, boundingRectWidth, boundingRectHeight, sliceHeight, startAngle % 360, sweepAngle, color, shadowStyle, edgeColorType, edgeLineWidth)); }
/// <summary> /// Creates highlighted <c>PieSlice</c> object. /// </summary> /// <param name="boundingRectLeft"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectTop"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectWidth"> /// Width of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="boundingRectHeight"> /// Height of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="sliceHeight"> /// Slice height. /// </param> /// <param name="startAngle"> /// Starting angle. /// </param> /// <param name="sweepAngle"> /// Sweep angle. /// </param> /// <param name="color"> /// Color used for slice rendering. /// </param> /// <param name="shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name="edgeColorType"> /// Edge lines color type. /// </param> /// <param name="edgeLineWidth"> /// Edge lines width. /// </param> /// <returns> /// <c>PieSlice</c> object with given values. /// </returns> private static PieSlice CreatePieSliceHighlighted(float boundingRectLeft, float boundingRectTop, float boundingRectWidth, float boundingRectHeight, float sliceHeight, float startAngle, float sweepAngle, Color color, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) { Color highLightedColor = ColorUtil.CreateColorWithCorrectedLightness(color, ColorUtil.BrightnessEnhancementFactor1); return(new PieSlice(boundingRectLeft, boundingRectTop, boundingRectWidth, boundingRectHeight, sliceHeight, startAngle, sweepAngle, highLightedColor, shadowStyle, edgeColorType, edgeLineWidth)); }
/// <summary> /// Creates a new instance of form /// </summary> public Form() { SetBounds(0, 0, 22, 12); fg = ConsoleColor.Cyan; bg = ConsoleColor.Blue; sfg = ConsoleColor.Gray; sbg = ConsoleColor.Black; tfg = ConsoleColor.White; border = Form.BorderStyle.Single; shadow = Form.ShadowStyle.Med; ConsoleBase.forms.Add(this); }
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name = "xBoundingRect"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name = "yBoundingRect"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name = "widthBoundingRect"> /// Width of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name = "heightBoundingRect"> /// Height of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name = "sliceHeight"> /// Height of the pie slice. /// </param> /// <param name = "startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name = "sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name = "surfaceColor"> /// Color used to paint the pie slice. /// </param> /// <param name = "shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name = "edgeColorType"> /// Edge color style used for slice rendering. /// </param> public PieSlice(float xBoundingRect, float yBoundingRect, float widthBoundingRect, float heightBoundingRect, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType) { // set some persistent values _actualStartAngle = startAngle; _actualSweepAngle = sweepAngle; _surfaceColor = surfaceColor; _shadowStyle = shadowStyle; // create pens for rendering var edgeLineColor = EdgeColor.GetRenderingColor(edgeColorType, surfaceColor); Pen = new Pen(edgeLineColor) { LineJoin = LineJoin.Round }; InitializePieSlice(xBoundingRect, yBoundingRect, widthBoundingRect, heightBoundingRect, sliceHeight); }
/// <summary> /// Creates brushes used to render the pie slice. /// </summary> /// <param name = "surfaceColor"> /// Color used for rendering. /// </param> /// <param name = "shadowStyle"> /// Shadow style used for rendering. /// </param> protected virtual void CreateSurfaceBrushes(Color surfaceColor, ShadowStyle shadowStyle) { DisposeBrushes(); BrushSurface = new SolidBrush(surfaceColor); BrushSurfaceHighlighted = new SolidBrush( ColorUtil.CreateColorWithCorrectedLightness( surfaceColor, ColorUtil.BrightnessEnhancementFactor1)); switch (shadowStyle) { case ShadowStyle.NoShadow: BrushStartSide = BrushEndSide = BrushPeripherySurface = new SolidBrush(surfaceColor); break; case ShadowStyle.UniformShadow: BrushStartSide = BrushEndSide = BrushPeripherySurface = new SolidBrush( ColorUtil.CreateColorWithCorrectedLightness( surfaceColor, -ColorUtil.BrightnessEnhancementFactor1)); break; case ShadowStyle.GradualShadow: double angle = StartAngle - 180 - ShadowAngle; if (angle < 0) { angle += 360; } BrushStartSide = CreateBrushForSide(surfaceColor, angle); angle = StartAngle + SweepAngle - ShadowAngle; if (angle < 0) { angle += 360; } BrushEndSide = CreateBrushForSide(surfaceColor, angle); BrushPeripherySurface = CreateBrushForPeriphery(surfaceColor); break; } }
//################################ // Private Members. //################################ /// <summary> /// Append shadow vertices. /// * It is similar to Shadow component implementation. /// </summary> void _ApplyShadow(List <UIVertex> verts, ref int start, ref int end, ShadowStyle mode, float toneLevel, float blur, Vector2 effectDistance, Color color, bool useGraphicAlpha) { if (ShadowStyle.None == mode) { return; } var factor = new Vector2( Packer.ToFloat(toneLevel, 0, blur, 0), Packer.ToFloat(color.r, color.g, color.b, 1) ); // Append Shadow. _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha); // Append Shadow3. if (ShadowStyle.Shadow3 == mode) { _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, effectDistance.x, 0, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, 0, effectDistance.y, factor, color, useGraphicAlpha); } // Append Outline. else if (ShadowStyle.Outline == mode) { _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, -effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, -effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha); } // Append Outline8. else if (ShadowStyle.Outline8 == mode) { _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, -effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, -effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, -effectDistance.x, 0, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, 0, -effectDistance.y, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, effectDistance.x, 0, factor, color, useGraphicAlpha); _ApplyShadowZeroAlloc(tempVerts, ref start, ref end, 0, effectDistance.y, factor, color, useGraphicAlpha); } }
/// <summary> /// Append shadow vertices. /// * It is similar to Shadow component implementation. /// </summary> private void ApplyShadow(List <UIVertex> verts, Color color, ref int start, ref int end, Vector2 distance, ShadowStyle style, bool alpha) { if (style == ShadowStyle.None || color.a <= 0) { return; } var x = distance.x; var y = distance.y; // Append Shadow. ApplyShadowZeroAlloc(verts, color, ref start, ref end, x, y, alpha); switch (style) { // Append Shadow3. case ShadowStyle.Shadow3: ApplyShadowZeroAlloc(verts, color, ref start, ref end, x, 0, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, 0, y, alpha); break; // Append Outline. case ShadowStyle.Outline: ApplyShadowZeroAlloc(verts, color, ref start, ref end, x, -y, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, -x, y, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, -x, -y, alpha); break; // Append Outline8. case ShadowStyle.Outline8: ApplyShadowZeroAlloc(verts, color, ref start, ref end, x, -y, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, -x, y, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, -x, -y, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, -x, 0, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, 0, -y, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, x, 0, alpha); ApplyShadowZeroAlloc(verts, color, ref start, ref end, 0, y, alpha); break; } }
private static int ShadowStyleToPos(ShadowStyle style) { switch (style) { case ShadowStyle.None: return(0); case ShadowStyle.Light: return(1); case ShadowStyle.Medium: return(2); case ShadowStyle.Dark: return(3); case ShadowStyle.Block: return(4); default: throw new ArgumentOutOfRangeException(nameof(style), style, null); } }
/// <summary> /// Initializes an empty instance of <c>PieChart3D</c>. /// </summary> private PieChart3D() { m_fitToBoundingRectangle = true; m_shadowStyle = ShadowStyle.NoShadow; m_colors = new[] { Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Purple, Color.Olive, Color.Navy, Color.Aqua, Color.Lime, Color.Maroon, Color.Teal, Color.Fuchsia }; m_font = System.Windows.Forms.Control.DefaultFont; m_foreColor = SystemColors.WindowText; m_edgeColorType = EdgeColorType.SystemColor; m_edgeLineWidth = 1F; }
/// <summary> /// Sets the shadow style. /// </summary> public void StyleOfShadow(ShadowStyle shadowStyle) { m_shadowStyle = shadowStyle; Invalidate(); }
/// <summary> /// Sets the shadow style. /// </summary> public void SetShadowStyle(ShadowStyle value) { _shadowStyle = value; Invalidate(); }
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name="xBoundingRect"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="yBoundingRect"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="widthBoundingRect"> /// Width of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="heightBoundingRect"> /// Height of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="sliceHeight"> /// Height of the pie slice. /// </param> /// <param name="startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name="sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name="surfaceColor"> /// Color used to paint the pie slice. /// </param> /// <param name="shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name="edgeColorType"> /// Edge color style used for slice rendering. /// </param> public PieSlice(float xBoundingRect, float yBoundingRect, float widthBoundingRect, float heightBoundingRect, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType) : this() { // set some persistent values m_actualStartAngle = startAngle; m_actualSweepAngle = sweepAngle; m_surfaceColor = surfaceColor; m_shadowStyle = shadowStyle; m_edgeColorType = edgeColorType; // create pens for rendering Color edgeLineColor = EdgeColor.GetRenderingColor(edgeColorType, surfaceColor); m_pen = new Pen(edgeLineColor); m_pen.LineJoin = LineJoin.Round; InitializePieSlice(xBoundingRect, yBoundingRect, widthBoundingRect, heightBoundingRect, sliceHeight); }
/// <summary> /// Sets the shadowing style used. /// </summary> public void StyleOfShadow(ShadowStyle shadowStyle) { m_shadowStyle = shadowStyle; }
internal static string GetShadow(ShadowStyle style) => " ░▒▓█"[ShadowStyleToPos(style)].ToString();
internal static ConsoleCharBuffer DrawBlockOutline(ConsoleCharBuffer buffer, DisplayObject owner, bool focusable, int x, int y, int w, int h, ConsoleColor backgroundColor, ConsoleColor foregroundColor, BorderStyle style, ShadowStyle shadow) { // Border buffer.DrawString(owner, GetTopLeftCornerBorder(style) + new string(GetHorizontalBorder(style)[0], w - 2) + GetTopRightCornerBorder(style), focusable, x, y, backgroundColor, foregroundColor); for (int i = y + 1; i < y + h - 1; i++) { buffer.DrawString(owner, GetVerticalBorder(style), focusable, x, i, backgroundColor, foregroundColor); buffer.DrawString(owner, GetVerticalBorder(style), focusable, x + w, i, backgroundColor, foregroundColor); } buffer.DrawString(owner, GetBottomLeftCornerBorder(style) + new string(GetHorizontalBorder(style)[0], w - 2) + GetBottomRightCornerBorder(style), focusable, x, y + h - 1, backgroundColor, foregroundColor); buffer = DrawShadow(buffer, owner, focusable, x, y, w, h, foregroundColor, shadow); return(buffer); }
internal static ConsoleCharBuffer DrawShadow(ConsoleCharBuffer buffer, DisplayObject owner, bool focusable, int x, int y, int w, int h, ConsoleColor foregroundColor, ShadowStyle shadow) { if (shadow != ShadowStyle.None) { for (int i = y + 1; i < y + h; i++) { buffer.DrawString(owner, GetShadow(shadow), focusable, x + w, i, null, foregroundColor); } buffer.DrawString(owner, new string(GetShadow(shadow)[0], w), focusable, x + 1, y + h, null, foregroundColor); } return(buffer); }
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name="boundingRectX"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="boundingRectY"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="boundingRectWidth"> /// Width of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="boundingRectHeight"> /// Height of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="sliceHeight"> /// Height of the pie slice. /// </param> /// <param name="startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name="sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name="surfaceColor"> /// Color used to render pie slice surface. /// </param> /// <param name="shadowStyle"> /// Shadow style used in rendering. /// </param> /// <param name="edgeColorType"> /// Edge color type used for rendering. /// </param> /// <param name="edgeLineWidth"> /// Edge line width. /// </param> public PieSlice(float boundingRectX, float boundingRectY, float boundingRectWidth, float boundingRectHeight, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) : this( boundingRectX, boundingRectY, boundingRectWidth, boundingRectHeight, sliceHeight, startAngle, sweepAngle, surfaceColor, shadowStyle, edgeColorType) { m_pen.Width = edgeLineWidth; }
/// <summary> /// Creates a <c>PieSlice</c> object. /// </summary> /// <param name="boundingRectLeft"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectTop"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectWidth"> /// Width of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="boundingRectHeight"> /// Height of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="sliceHeight"> /// Slice height. /// </param> /// <param name="startAngle"> /// Starting angle. /// </param> /// <param name="sweepAngle"> /// Sweep angle. /// </param> /// <param name="color"> /// Color used for slice rendering. /// </param> /// <param name="shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name="edgeColorType"> /// Edge lines color type. /// </param> /// <param name="edgeLineWidth"> /// Edge lines width. /// </param> /// <returns> /// <c>PieSlice</c> object with given values. /// </returns> private static PieSlice CreatePieSlice(float boundingRectLeft, float boundingRectTop, float boundingRectWidth, float boundingRectHeight, float sliceHeight, float startAngle, float sweepAngle, Color color, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) => new PieSlice(boundingRectLeft, boundingRectTop, boundingRectWidth, boundingRectHeight, sliceHeight, startAngle, sweepAngle, color, shadowStyle, edgeColorType, edgeLineWidth);
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name="boundingRectX"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="boundingRectY"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="boundingRectWidth"> /// Width of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="boundingRectHeight"> /// Height of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="sliceHeight"> /// Height of the pie slice. /// </param> /// <param name="startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name="sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name="surfaceColor"> /// Color used to paint the pie slice. /// </param> /// <param name="shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name="edgeColorType"> /// Edge color style used for slice rendering. /// </param> public PieSlice(float boundingRectX, float boundingRectY, float boundingRectWidth, float boundingRectHeight, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType) : this() { // set some persistent values m_actualStartAngle = startAngle; m_actualSweepAngle = sweepAngle; m_surfaceColor = surfaceColor; m_shadowStyle = shadowStyle; m_edgeColorType = edgeColorType; // create pens for rendering Color edgeLineColor = EdgeColor.GetRenderingColor(edgeColorType, surfaceColor); using (Pen pen = new Pen(edgeLineColor)) { pen.LineJoin = LineJoin.Round; m_pen = (Pen)pen.Clone(); } InitializePieSlice(boundingRectX, boundingRectY, boundingRectWidth, boundingRectHeight, sliceHeight); }
/// <summary> /// Creates a <c>PieSlice</c> object. /// </summary> /// <param name="boundingRectLeft"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectTop"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectWidth"> /// Width of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="boundingRectHeight"> /// Height of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="sliceHeight"> /// Slice height. /// </param> /// <param name="startAngle"> /// Starting angle. /// </param> /// <param name="sweepAngle"> /// Sweep angle. /// </param> /// <param name="color"> /// Color used for slice rendering. /// </param> /// <param name="shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name="edgeColorType"> /// Edge lines color type. /// </param> /// <param name="edgeLineWidth"> /// Edge lines width. /// </param> /// <returns> /// <c>PieSlice</c> object with given values. /// </returns> protected virtual PieSlice CreatePieSlice(float boundingRectLeft, float boundingRectTop, float boundingRectWidth, float boundingRectHeight, float sliceHeight, float startAngle, float sweepAngle, Color color, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) { return new PieSlice(boundingRectLeft, boundingRectTop, boundingRectWidth, boundingRectHeight, sliceHeight, (float)(startAngle % 360), sweepAngle, color, shadowStyle, edgeColorType, edgeLineWidth); }
#pragma warning disable 0612 protected override void UpgradeIfNeeded() { // Upgrade for v3.0.0 if (IsShouldUpgrade(300)) { if (m_ColorMode != ColorMode.Multiply) { Color col = targetGraphic.color; col.r = m_EffectColor.r; col.g = m_EffectColor.g; col.b = m_EffectColor.b; targetGraphic.color = col; m_ColorFactor = m_EffectColor.a; } if (m_ShadowStyle != ShadowStyle.None || m_AdditionalShadows.Any(x => x.style != ShadowStyle.None)) { if (m_ShadowStyle != ShadowStyle.None) { var shadow = gameObject.GetComponent <UIShadow>() ?? gameObject.AddComponent <UIShadow>(); shadow.style = m_ShadowStyle; shadow.effectDistance = m_EffectDistance; shadow.effectColor = m_ShadowColor; shadow.useGraphicAlpha = m_UseGraphicAlpha; shadow.blurFactor = m_ShadowBlur; } foreach (var s in m_AdditionalShadows) { if (s.style == ShadowStyle.None) { continue; } var shadow = gameObject.AddComponent <UIShadow>(); shadow.style = s.style; shadow.effectDistance = s.effectDistance; shadow.effectColor = s.effectColor; shadow.useGraphicAlpha = s.useGraphicAlpha; shadow.blurFactor = s.blur; } m_ShadowStyle = ShadowStyle.None; m_AdditionalShadows = null; if (m_EffectMode == EffectMode.None && m_ColorMode == ColorMode.Multiply && m_BlurMode == BlurMode.None) { DestroyImmediate(this, true); } } int tone = (int)m_EffectMode; const int Mono = 5; const int Cutoff = 6; const int Hue = 7; if (tone == Hue) { var go = gameObject; var hue = m_EffectFactor; DestroyImmediate(this, true); var hsv = go.GetComponent <UIHsvModifier>() ?? go.AddComponent <UIHsvModifier>(); hsv.hue = hue; hsv.range = 1; } // Cutoff/Mono if (tone == Cutoff || tone == Mono) { var go = gameObject; var factor = m_EffectFactor; var transitionMode = tone == Cutoff ? UITransitionEffect.EffectMode.Cutoff : UITransitionEffect.EffectMode.Fade; DestroyImmediate(this, true); var trans = go.GetComponent <UITransitionEffect>() ?? go.AddComponent <UITransitionEffect>(); trans.effectFactor = factor; var sp = new SerializedObject(trans).FindProperty("m_EffectMode"); sp.intValue = (int)transitionMode; sp.serializedObject.ApplyModifiedProperties(); } } }
/// <summary> /// Append shadow vertices. /// * It is similar to Shadow component implementation. /// </summary> void _ApplyShadow(List <UIVertex> verts, Color color, ref int start, ref int end, Vector2 effectDistance, ShadowStyle style, bool useGraphicAlpha) { if (style == ShadowStyle.None || color.a <= 0) { return; } // Append Shadow. _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, effectDistance.y, useGraphicAlpha); // Append Shadow3. if (ShadowStyle.Shadow3 == style) { _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, 0, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, 0, effectDistance.y, useGraphicAlpha); } // Append Outline. else if (ShadowStyle.Outline == style) { _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, -effectDistance.y, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, effectDistance.y, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, -effectDistance.y, useGraphicAlpha); } // Append Outline8. else if (ShadowStyle.Outline8 == style) { _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, -effectDistance.y, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, effectDistance.y, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, -effectDistance.y, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, 0, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, 0, -effectDistance.y, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, 0, useGraphicAlpha); _ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, 0, effectDistance.y, useGraphicAlpha); } }
/// <summary> /// 绘制特效文字图片 /// </summary> /// <param name="drawStr">绘制的字符串</param> /// <param name="drawFont">绘制的字体</param> /// <param name="drawFontBrush">字体的笔刷</param> /// <param name="drawBackBrush">背景的笔刷</param> /// <param name="shadowImage">投影的类型</param> /// <returns></returns> private static Bitmap DrawSpeciallyFont(string drawStr, string fontStyleSrt, string drawFontBrushSrt, string drawBackBrushStr, ShadowStyle shadowStyle) { //绘制的字体 Font drawFont = GetFont(fontStyleSrt); if (drawFont == null) { return(null); } #region 获取绘制字符串的大小 Bitmap temp_bit = new Bitmap(1, 1); Graphics temp_g = Graphics.FromImage(temp_bit); SizeF bitsize = temp_g.MeasureString(drawStr, drawFont); //释放资源 temp_bit.Dispose(); temp_g.Dispose(); #endregion int img_w = (int)bitsize.Width; int img_h = (int)bitsize.Height; #region 对文字的位置进行调整 int adjust_w = (int)(bitsize.Height * 0.00F);//R int adjust_h = (int)(bitsize.Height * 0.06F); if (drawFont.Italic) { adjust_w = (int)(bitsize.Height * 0.10F);//I adjust_h = (int)(bitsize.Height * 0.06F); } Point sPoint = new Point(-adjust_w, adjust_h);//绘制文字的起始点 #endregion Bitmap fontimg = new Bitmap(img_w, img_h); Graphics g = Graphics.FromImage(fontimg); //字体笔刷 Brush drawFontBrush = GetDrawBrush(drawFontBrushSrt, img_w, img_h); //背景笔刷 Brush drawBackBrush = GetDrawBrush(drawBackBrushStr, img_w, img_h); //设置绘制文字的抗锯齿效果 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; #region 绘制背景 if (drawBackBrush != null) { g.FillRectangle(drawBackBrush, 0, 0, img_w, img_h); drawBackBrush.Dispose(); } #endregion #region 绘制阴影效果 if (shadowStyle != ShadowStyle.None) { Bitmap shadowImage = DrawShadowImage(drawStr, drawFont, img_w, img_h, sPoint, shadowStyle); if (shadowImage != null) { g.DrawImage(shadowImage, new Point(0, 0)); } } #endregion //绘制字符串 if (drawFontBrush != null) { g.DrawString(drawStr, drawFont, drawFontBrush, sPoint); drawFontBrush.Dispose(); } //释放资源 g.Dispose(); return(fontimg); }
internal static ConsoleCharBuffer DrawBlockFull(ConsoleCharBuffer buffer, DisplayObject owner, bool focusable, int x, int y, int w, int h, ConsoleColor?backgroundColor, ConsoleColor foregroundColor, BorderStyle style, ShadowStyle shadow) { // Border buffer.DrawString(owner, GetTopLeftCornerBorder(style) + new string(GetHorizontalBorder(style)[0], w - 2) + GetTopRightCornerBorder(style), focusable, x, y, backgroundColor, foregroundColor); for (int i = y + 1; i < y + h - 1; i++) { buffer.DrawString(owner, GetVerticalBorder(style) + new string(' ', w - 2) + GetVerticalBorder(style), focusable, x, i, backgroundColor, foregroundColor); } buffer.DrawString(owner, GetBottomLeftCornerBorder(style) + new string(GetHorizontalBorder(style)[0], w - 2) + GetBottomRightCornerBorder(style), focusable, x, y + h - 1, backgroundColor, foregroundColor); if (shadow != ShadowStyle.None) { for (int i = y + 1; i < y + h; i++) { buffer.DrawString(owner, GetShadow(shadow), focusable, x + w, i, null, foregroundColor); } buffer.DrawString(owner, new string(GetShadow(shadow)[0], w), focusable, x + 1, y + h, null, foregroundColor); } return(buffer); }
/// <summary> /// Creates highlighted <c>PieSlice</c> object. /// </summary> /// <param name="boundingRectLeft"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectTop"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the slice. /// </param> /// <param name="boundingRectWidth"> /// Width of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="boundingRectHeight"> /// Height of the rectangle that is used to draw the top surface of /// the slice. /// </param> /// <param name="sliceHeight"> /// Slice height. /// </param> /// <param name="startAngle"> /// Starting angle. /// </param> /// <param name="sweepAngle"> /// Sweep angle. /// </param> /// <param name="color"> /// Color used for slice rendering. /// </param> /// <param name="shadowStyle"> /// Shadow style used for slice rendering. /// </param> /// <param name="edgeColorType"> /// Edge lines color type. /// </param> /// <param name="edgeLineWidth"> /// Edge lines width. /// </param> /// <returns> /// <c>PieSlice</c> object with given values. /// </returns> protected virtual PieSlice CreatePieSliceHighlighted(float boundingRectLeft, float boundingRectTop, float boundingRectWidth, float boundingRectHeight, float sliceHeight, float startAngle, float sweepAngle, Color color, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) { Color highLightedColor = ColorUtil.CreateColorWithCorrectedLightness(color, ColorUtil.BrightnessEnhancementFactor1); return new PieSlice(boundingRectLeft, boundingRectTop, boundingRectWidth, boundingRectHeight, sliceHeight, (float)(startAngle % 360), sweepAngle, highLightedColor, shadowStyle, edgeColorType, edgeLineWidth); }
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name="boundingRect"> /// Bounding rectangle used to draw the top surface of the pie slice. /// </param> /// <param name="sliceHeight"> /// Pie slice height. /// </param> /// <param name="startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name="sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name="surfaceColor"> /// Color used to render pie slice surface. /// </param> /// <param name="shadowStyle"> /// Shadow style used in rendering. /// </param> /// <param name="edgeColorType"> /// Edge color type used for rendering. /// </param> /// <param name="edgeLineWidth"> /// Edge line width. /// </param> public PieSlice(Rectangle boundingRect, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) : this(boundingRect.X, boundingRect.Y, boundingRect.Width, boundingRect.Height, sliceHeight, startAngle, sweepAngle, surfaceColor, shadowStyle, edgeColorType, edgeLineWidth) { }
/// <summary> /// Creates brushes used to render the pie slice. /// </summary> /// <param name="surfaceColor"> /// Color used for rendering. /// </param> /// <param name="shadowStyle"> /// Shadow style used for rendering. /// </param> protected virtual void CreateSurfaceBrushes(Color surfaceColor, ShadowStyle shadowStyle) { m_brushSurface = new SolidBrush(surfaceColor); m_brushSurfaceHighlighted = new SolidBrush(ColorUtil.CreateColorWithCorrectedLightness(surfaceColor, ColorUtil.BrightnessEnhancementFactor1)); switch (shadowStyle) { case ShadowStyle.NoShadow: m_brushStartSide = m_brushEndSide = m_brushPeripherySurface = new SolidBrush(surfaceColor); break; case ShadowStyle.UniformShadow: m_brushStartSide = m_brushEndSide = m_brushPeripherySurface = new SolidBrush(ColorUtil.CreateColorWithCorrectedLightness(surfaceColor, -ColorUtil.BrightnessEnhancementFactor1)); break; case ShadowStyle.GradualShadow: double angle = m_startAngle - 180 - s_shadowAngle; if (angle < 0) angle += 360; m_brushStartSide = CreateBrushForSide(surfaceColor, angle); angle = m_startAngle + m_sweepAngle - s_shadowAngle; if (angle < 0) angle += 360; m_brushEndSide = CreateBrushForSide(surfaceColor, angle); m_brushPeripherySurface = CreateBrushForPeriphery(surfaceColor); break; } }
/// <summary> /// 绘制阴影图案 /// </summary> /// <param name="drawtxt">字符串</param> /// <param name="drawFont">字体</param> /// <param name="w">图片宽度</param> /// <param name="h">图片高度</param> /// <param name="startPoint">绘制起始点</param> /// <param name="x">偏移X</param> /// <param name="y">偏移Y</param> /// <param name="distance">偏移距离</param> /// <returns></returns> private static Bitmap DrawShadowImage(string drawtxt, Font drawFont, int w, int h, Point startPoint, ShadowStyle shadowStyle) { int x = 0; int y = 0; int distance = 0; bool is3D = false; switch (shadowStyle) { case ShadowStyle.None: return(null); case ShadowStyle.LeftTop1: x = -1; y = -1; distance = distance_1; break; case ShadowStyle.LeftTop2: x = -1; y = -1; distance = distance_2; break; case ShadowStyle.LeftTop3: x = -1; y = -1; distance = distance_3; break; case ShadowStyle.LeftBottom1: x = -1; y = 1; distance = distance_1; break; case ShadowStyle.LeftBottom2: x = -1; y = 1; distance = distance_2; break; case ShadowStyle.LeftBottom3: x = -1; y = 1; distance = distance_3; break; case ShadowStyle.RightTop1: x = 1; y = -1; distance = distance_1; break; case ShadowStyle.RightTop2: x = 1; y = -1; distance = distance_2; break; case ShadowStyle.RightTop3: x = 1; y = -1; distance = distance_3; break; case ShadowStyle.RightBottom1: x = 1; y = 1; distance = distance_1; break; case ShadowStyle.RightBottom2: x = 1; y = 1; distance = distance_2; break; case ShadowStyle.RightBottom3: x = 1; y = 1; distance = distance_3; break; case ShadowStyle.LeftTop3D1: x = -1; y = -1; distance = distance_1; is3D = true; break; case ShadowStyle.LeftTop3D2: x = -1; y = -1; distance = distance_2; is3D = true; break; case ShadowStyle.LeftTop3D3: x = -1; y = -1; distance = distance_3; is3D = true; break; case ShadowStyle.LeftBottom3D1: x = -1; y = 1; distance = distance_1; is3D = true; break; case ShadowStyle.LeftBottom3D2: x = -1; y = 1; distance = distance_2; is3D = true; break; case ShadowStyle.LeftBottom3D3: x = -1; y = 1; distance = distance_3; is3D = true; break; case ShadowStyle.RightTop3D1: x = 1; y = -1; distance = distance_1; is3D = true; break; case ShadowStyle.RightTop3D2: x = 1; y = -1; distance = distance_2; is3D = true; break; case ShadowStyle.RightTop3D3: x = 1; y = -1; distance = distance_3; is3D = true; break; case ShadowStyle.RightBottom3D1: x = 1; y = 1; distance = distance_1; is3D = true; break; case ShadowStyle.RightBottom3D2: x = 1; y = 1; distance = distance_2; is3D = true; break; case ShadowStyle.RightBottom3D3: x = 1; y = 1; distance = distance_3; is3D = true; break; default: break; } return(DrawShadow(drawtxt, drawFont, w, h, startPoint, x, y, distance, is3D)); }
/// <summary> /// Initializes a new instance of <c>PieSlice</c> class with given /// bounds and visual style. /// </summary> /// <param name="xBoundingRect"> /// x-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="yBoundingRect"> /// y-coordinate of the upper-left corner of the rectangle that is /// used to draw the top surface of the pie slice. /// </param> /// <param name="widthBoundingRect"> /// Width of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="heightBoundingRect"> /// Height of the rectangle that is used to draw the top surface of /// the pie slice. /// </param> /// <param name="sliceHeight"> /// Height of the pie slice. /// </param> /// <param name="startAngle"> /// Starting angle (in degrees) of the pie slice. /// </param> /// <param name="sweepAngle"> /// Sweep angle (in degrees) of the pie slice. /// </param> /// <param name="surfaceColor"> /// Color used to render pie slice surface. /// </param> /// <param name="shadowStyle"> /// Shadow style used in rendering. /// </param> /// <param name="edgeColorType"> /// Edge color type used for rendering. /// </param> /// <param name="edgeLineWidth"> /// Edge line width. /// </param> public PieSlice(float xBoundingRect, float yBoundingRect, float widthBoundingRect, float heightBoundingRect, float sliceHeight, float startAngle, float sweepAngle, Color surfaceColor, ShadowStyle shadowStyle, EdgeColorType edgeColorType, float edgeLineWidth) : this (xBoundingRect, yBoundingRect, widthBoundingRect, heightBoundingRect, sliceHeight, startAngle, sweepAngle, surfaceColor, shadowStyle, edgeColorType) { m_pen.Width = edgeLineWidth; }