public override void Render(DrawingContext context) { var geometry = RenderedGeometry; if (geometry != null) { var stroke = Stroke; ImmutablePen?pen = null; if (stroke != null) { var strokeDashArray = StrokeDashArray; ImmutableDashStyle?dashStyle = null; if (strokeDashArray != null && strokeDashArray.Count > 0) { dashStyle = new ImmutableDashStyle(strokeDashArray, StrokeDashOffset); } pen = new ImmutablePen( stroke.ToImmutable(), StrokeThickness, dashStyle, StrokeLineCap, StrokeJoin); } context.DrawGeometry(Fill, pen, geometry); } }
public ImmutableTextDecoration(TextDecorationLocation location, ImmutablePen pen, TextDecorationUnit penThicknessUnit, double penOffset, TextDecorationUnit penOffsetUnit) { Location = location; Pen = pen; PenThicknessUnit = penThicknessUnit; PenOffset = penOffset; PenOffsetUnit = penOffsetUnit; }
void RenderCore(DrawingContext context, IBrush background, IBrush borderBrush, BoxShadows boxShadows, double borderDashOffset, PenLineCap borderLineCap, PenLineJoin borderLineJoin, AvaloniaList <double> borderDashArray) { if (_useComplexRendering) { var backgroundGeometry = _backgroundGeometryCache; if (backgroundGeometry != null) { context.DrawGeometry(background, null, backgroundGeometry); } var borderGeometry = _borderGeometryCache; if (borderGeometry != null) { context.DrawGeometry(borderBrush, null, borderGeometry); } } else { var borderThickness = _borderThickness.Top; IPen pen = null; ImmutableDashStyle?dashStyle = null; if (borderDashArray != null && borderDashArray.Count > 0) { dashStyle = new ImmutableDashStyle(borderDashArray, borderDashOffset); } if (borderBrush != null && borderThickness > 0) { pen = new ImmutablePen( borderBrush.ToImmutable(), borderThickness, dashStyle, borderLineCap, borderLineJoin); } var rect = new Rect(_size); if (!MathUtilities.IsZero(borderThickness)) { rect = rect.Deflate(borderThickness * 0.5); } var rrect = new RoundedRect(rect, _cornerRadius.TopLeft, _cornerRadius.TopRight, _cornerRadius.BottomRight, _cornerRadius.BottomLeft); context.PlatformImpl.DrawRectangle(background, pen, rrect, boxShadows); } }
public void Equality_Is_Implemented_Between_Mutable_And_Immutable_DashStyles() { var brush = new SolidColorBrush(Colors.Red); var target1 = new ImmutablePen( brush: brush, thickness: 2, dashStyle: new ImmutableDashStyle(new[] { 0.1, 0.2 }, 5), lineCap: PenLineCap.Round, lineJoin: PenLineJoin.Round, miterLimit: 21); var target2 = new Pen( brush: brush, thickness: 2, dashStyle: new DashStyle(new[] { 0.1, 0.2 }, 5), lineCap: PenLineCap.Round, lineJoin: PenLineJoin.Round, miterLimit: 21); Assert.True(Equals(target1, target2)); }
void RenderCore(DrawingContext context, IBrush background, IBrush borderBrush, BoxShadows boxShadows) { if (_useComplexRendering) { var backgroundGeometry = _backgroundGeometryCache; if (backgroundGeometry != null) { context.DrawGeometry(background, null, backgroundGeometry); } var borderGeometry = _borderGeometryCache; if (borderGeometry != null) { context.DrawGeometry(borderBrush, null, borderGeometry); } } else { var borderThickness = _borderThickness.Top; IPen pen = null; if (borderBrush != null && borderThickness > 0) { pen = new ImmutablePen(borderBrush.ToImmutable(), borderThickness); } var rect = new Rect(_size); if (!MathUtilities.IsZero(borderThickness)) { rect = rect.Deflate(borderThickness * 0.5); } var rrect = new RoundedRect(rect, _cornerRadius.TopLeft, _cornerRadius.TopRight, _cornerRadius.BottomRight, _cornerRadius.BottomLeft); context.PlatformImpl.DrawRectangle(background, pen, rrect, boxShadows); } }
public SpectrumControl() { _data = new float[NumBins]; _auraSpectrumDataSource = new AuraSpectrumDataSource(NumBins); _splashEffectDataSource = new SplashEffectDataSource(NumBins); _sources = new SpectrumDataSource[] { _auraSpectrumDataSource, _splashEffectDataSource }; _lineBrush = SolidColorBrush.Parse("#97D234").ToImmutable(); _linePen = new(_lineBrush); Background = new RadialGradientBrush() { GradientStops = { new GradientStop { Color = Color.Parse("#00000D21"), Offset = 0 }, new GradientStop { Color = Color.Parse("#FF000D21"), Offset = 1 } } }; }
/// <summary> /// Draw ticks. /// Ticks can be draw in 8 different ways depends on Placement property and IsDirectionReversed property. /// /// This function also draw selection-tick(s) if IsSelectionRangeEnabled is 'true' and /// SelectionStart and SelectionEnd are valid. /// /// The primary ticks (for Mininum and Maximum value) height will be 100% of TickBar's render size (use Width or Height /// depends on Placement property). /// /// The secondary ticks (all other ticks, including selection-tics) height will be 75% of TickBar's render size. /// /// Brush that use to fill ticks is specified by Fill property. /// </summary> public override void Render(DrawingContext dc) { var size = new Size(Bounds.Width, Bounds.Height); var range = Maximum - Minimum; var tickLen = 0.0d; // Height for Primary Tick (for Mininum and Maximum value) var tickLen2 = 0.0d; // Height for Secondary Tick var logicalToPhysical = 1.0; var startPoint = new Point(); var endPoint = new Point(); var rSpace = Orientation == Orientation.Horizontal ? ReservedSpace.Width : ReservedSpace.Height; // Take Thumb size in to account double halfReservedSpace = rSpace * 0.5; switch (Placement) { case TickBarPlacement.Top: if (MathUtilities.GreaterThanOrClose(rSpace, size.Width)) { return; } size = new Size(size.Width - rSpace, size.Height); tickLen = -size.Height; startPoint = new Point(halfReservedSpace, size.Height); endPoint = new Point(halfReservedSpace + size.Width, size.Height); logicalToPhysical = size.Width / range; break; case TickBarPlacement.Bottom: if (MathUtilities.GreaterThanOrClose(rSpace, size.Width)) { return; } size = new Size(size.Width - rSpace, size.Height); tickLen = size.Height; startPoint = new Point(halfReservedSpace, 0d); endPoint = new Point(halfReservedSpace + size.Width, 0d); logicalToPhysical = size.Width / range; break; case TickBarPlacement.Left: if (MathUtilities.GreaterThanOrClose(rSpace, size.Height)) { return; } size = new Size(size.Width, size.Height - rSpace); tickLen = -size.Width; startPoint = new Point(size.Width, size.Height + halfReservedSpace); endPoint = new Point(size.Width, halfReservedSpace); logicalToPhysical = size.Height / range * -1; break; case TickBarPlacement.Right: if (MathUtilities.GreaterThanOrClose(rSpace, size.Height)) { return; } size = new Size(size.Width, size.Height - rSpace); tickLen = size.Width; startPoint = new Point(0d, size.Height + halfReservedSpace); endPoint = new Point(0d, halfReservedSpace); logicalToPhysical = size.Height / range * -1; break; } ; tickLen2 = tickLen * 0.75; // Invert direciton of the ticks if (IsDirectionReversed) { logicalToPhysical *= -1; // swap startPoint & endPoint var pt = startPoint; startPoint = endPoint; endPoint = pt; } var pen = new ImmutablePen(Fill?.ToImmutable(), 1.0d); // Is it Vertical? if (Placement == TickBarPlacement.Left || Placement == TickBarPlacement.Right) { // Reduce tick interval if it is more than would be visible on the screen double interval = TickFrequency; if (interval > 0.0) { double minInterval = (Maximum - Minimum) / size.Height; if (interval < minInterval) { interval = minInterval; } } // Draw Min & Max tick dc.DrawLine(pen, startPoint, new Point(startPoint.X + tickLen, startPoint.Y)); dc.DrawLine(pen, new Point(startPoint.X, endPoint.Y), new Point(startPoint.X + tickLen, endPoint.Y)); // This property is rarely set so let's try to avoid the GetValue // caching of the mutable default value var ticks = Ticks ?? null; // Draw ticks using specified Ticks collection if (ticks?.Count > 0) { for (int i = 0; i < ticks.Count; i++) { if (MathUtilities.LessThanOrClose(ticks[i], Minimum) || MathUtilities.GreaterThanOrClose(ticks[i], Maximum)) { continue; } double adjustedTick = ticks[i] - Minimum; double y = adjustedTick * logicalToPhysical + startPoint.Y; dc.DrawLine(pen, new Point(startPoint.X, y), new Point(startPoint.X + tickLen2, y)); } } // Draw ticks using specified TickFrequency else if (interval > 0.0) { for (double i = interval; i < range; i += interval) { double y = i * logicalToPhysical + startPoint.Y; dc.DrawLine(pen, new Point(startPoint.X, y), new Point(startPoint.X + tickLen2, y)); } } } else // Placement == Top || Placement == Bottom { // Reduce tick interval if it is more than would be visible on the screen double interval = TickFrequency; if (interval > 0.0) { double minInterval = (Maximum - Minimum) / size.Width; if (interval < minInterval) { interval = minInterval; } } // Draw Min & Max tick dc.DrawLine(pen, startPoint, new Point(startPoint.X, startPoint.Y + tickLen)); dc.DrawLine(pen, new Point(endPoint.X, startPoint.Y), new Point(endPoint.X, startPoint.Y + tickLen)); // This property is rarely set so let's try to avoid the GetValue // caching of the mutable default value var ticks = Ticks ?? null; // Draw ticks using specified Ticks collection if (ticks?.Count > 0) { for (int i = 0; i < ticks.Count; i++) { if (MathUtilities.LessThanOrClose(ticks[i], Minimum) || MathUtilities.GreaterThanOrClose(ticks[i], Maximum)) { continue; } double adjustedTick = ticks[i] - Minimum; double x = adjustedTick * logicalToPhysical + startPoint.X; dc.DrawLine(pen, new Point(x, startPoint.Y), new Point(x, startPoint.Y + tickLen2)); } } // Draw ticks using specified TickFrequency else if (interval > 0.0) { for (double i = interval; i < range; i += interval) { double x = i * logicalToPhysical + startPoint.X; dc.DrawLine(pen, new Point(x, startPoint.Y), new Point(x, startPoint.Y + tickLen2)); } } } }