protected override sealed void CreateImage(ImageGenerationContext context) { base.CreateImage(context); Rect bounds = new Rect(StrokeWidth / 2, StrokeWidth / 2, CalculatedWidth - StrokeWidth, CalculatedHeight - StrokeWidth); Brush brush = Fill.GetBrush(); Pen pen = GetPen(); DrawingVisual dv = new DrawingVisual(); DrawingContext dc = dv.RenderOpen(); if (Roundness == 0) { dc.DrawRectangle(brush, pen, bounds); } else { dc.DrawRoundedRectangle(brush, pen, bounds, Roundness, Roundness); } dc.Close(); RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(CalculatedWidth, CalculatedHeight); rtb.Render(dv); Bitmap = new FastBitmap(rtb); }
protected sealed override void CreateImage() { base.CreateImage(); Rect bounds = new Rect(StrokeWidth / 2, StrokeWidth / 2, CalculatedWidth - StrokeWidth, CalculatedHeight - StrokeWidth); Brush brush = Fill.GetBrush(); PointCollection points = GetPoints(bounds); PathGeometry geometry = CanonicalSplineHelper.CreateSpline(points, Roundness / 100.0, null, true, true, 0.25); Pen pen = GetPen(); DrawingVisual dv = new DrawingVisual(); DrawingContext dc = dv.RenderOpen(); // Draw polygon. dc.DrawGeometry(brush, pen, geometry); dc.Close(); RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(CalculatedWidth, CalculatedHeight); rtb.Render(dv); Bitmap = new FastBitmap(rtb); }
/// <summary> /// Paints the hook. /// </summary> /// <param name="e">The <see cref="PaintEventArgs" /> instance containing the event data.</param> /// <exception cref="System.ArgumentOutOfRangeException"></exception> protected override void PaintHook(PaintEventArgs e) { Bitmap B = new Bitmap(Width, Height); Graphics G = Graphics.FromImage(B); G.SmoothingMode = Smoothing; G.TextRenderingHint = TextRendering; G.Clear(Parent.BackColor); Rectangle rect = new Rectangle(0 + Convert.ToInt32(Border.Width), 0 + Convert.ToInt32(Border.Width), Width - Convert.ToInt32(Border.Width) * 2, Height - Convert.ToInt32(Border.Width) * 2); GraphicsPath shape = Draw.RoundRect(rect, Curves.UpperLeft, Curves.UpperRight, Curves.DownLeft, Curves.DownRight); if (EnableHatchAnimation) { G.RenderingOrigin = new Point(reactorOFS, 0); } switch (ControlType) { case ControlTypes.Polygon: G.FillPolygon(Fill.GetBrush(rect), Polygon.Points); G.DrawPolygon(Border.GetPen(), Polygon.Points); break; case ControlTypes.Rectangle: G.FillPath(Fill.GetBrush(rect), shape); G.FillPath(Fill.GetBrush(rect), shape); G.DrawPath(Border.GetPen(), shape); break; default: throw new ArgumentOutOfRangeException(); } //if (TextShadow) //{ // CenterString(G, Text, Font, Color.Black, rect); //} //CenterString(G, Text, Font, ForeColor, new Rectangle(2 + Convert.ToInt32(Border.Width), 2 + Convert.ToInt32(Border.Width), Width - 4 - Convert.ToInt32(Border.Width) * 2, Height - 4 - Convert.ToInt32(Border.Width) * 2)); DrawImage(G, ClientRectangle); e.Graphics.DrawImage(B, 0, 0); G.Dispose(); B.Dispose(); }
/// <summary> /// Renders the fill of the <see cref="SvgVisualElement"/> to the specified <see cref="ISvgRenderer"/> /// </summary> /// <param name="renderer">The <see cref="ISvgRenderer"/> object to render to.</param> protected internal virtual void RenderFill(ISvgRenderer renderer) { if (Fill != null) { using (var brush = Fill.GetBrush(this, renderer, Math.Min(Math.Max(FillOpacity, 0f), 1f))) { if (brush != null) { var path = Path(renderer); path.FillMode = FillRule == SvgFillRule.NonZero ? FillMode.Winding : FillMode.Alternate; renderer.FillPath(brush, path); } } } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Rectangle reflection = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height / 2); Rectangle bounds = this.ClientRectangle; bounds.Inflate(-2, -2); GraphicsPath shape = RoundRect(bounds, RectangleInfo.UpperLeft, RectangleInfo.UpperRight, RectangleInfo.DownLeft, RectangleInfo.DownRight); Bitmap B = new Bitmap(Width, Height); Graphics G = Graphics.FromImage(B); G.SmoothingMode = Smoothing; G.TextRenderingHint = TextRendering; G.CompositingQuality = CompositingQuality; G.InterpolationMode = InterpolationMode; if (EnableHatchAnimation) { G.RenderingOrigin = new Point(reactorOFS, 0); } if (AllowTransparency) { MakeTransparent(this, G); } switch (Shape) { case Shapes.Rectangle: if (RectangleInfo.Rounding) { switch (FillMode) { case PolygonInput.FillModes.Fill: G.FillPath(Fill.GetBrush(bounds), shape); break; case PolygonInput.FillModes.Border: G.DrawPath(Border.GetPen(), shape); break; case PolygonInput.FillModes.Both: G.FillPath(Fill.GetBrush(bounds), shape); G.DrawPath(Border.GetPen(), shape); break; default: break; } } else { switch (FillMode) { case PolygonInput.FillModes.Fill: G.FillRectangle(Fill.GetBrush(bounds), bounds); break; case PolygonInput.FillModes.Border: G.DrawRectangle(Border.GetPen(), bounds); break; case PolygonInput.FillModes.Both: G.FillRectangle(Fill.GetBrush(bounds), bounds); G.DrawRectangle(Border.GetPen(), bounds); break; default: break; } } break; case Shapes.Circle: switch (FillMode) { case PolygonInput.FillModes.Fill: G.FillEllipse(Fill.GetBrush(bounds), bounds); break; case PolygonInput.FillModes.Border: G.DrawEllipse(Border.GetPen(), bounds); break; case PolygonInput.FillModes.Both: G.FillEllipse(Fill.GetBrush(bounds), bounds); G.DrawEllipse(Border.GetPen(), bounds); break; default: break; } break; case Shapes.Pie: switch (FillMode) { case PolygonInput.FillModes.Fill: G.FillPie(Fill.GetBrush(bounds), bounds, Pie.StartAngle, Pie.SweepAngle); break; case PolygonInput.FillModes.Border: G.DrawPie(Border.GetPen(), bounds, Pie.StartAngle, Pie.SweepAngle); break; case PolygonInput.FillModes.Both: G.FillPie(Fill.GetBrush(bounds), bounds, Pie.StartAngle, Pie.SweepAngle); G.DrawPie(Border.GetPen(), bounds, Pie.StartAngle, Pie.SweepAngle); break; default: break; } break; case Shapes.Polygon: PolygonInput.DrawShape(G, Fill.GetBrush(ClientRectangle), Border.GetPen()); if (ShowReflection) { e.Graphics.DrawReflection(B, reflection, Reflection.Gap, Reflection.Height, Reflection.StartAlpha, Reflection.EndAlpha); } break; default: break; } //this.CreateDropShadow(); DrawImage(G, bounds); e.Graphics.DrawImage(B, 0, 0); G.Dispose(); B.Dispose(); if (!DesignMode) { GC.Collect(); } }