Skip to content

Commit

Permalink
Support color inner rectangle of RectangleAdorner (helix-toolkit#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauNguyenVan committed Dec 22, 2023
1 parent ff7dfc8 commit a704b48
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Source/HelixToolkit.Wpf.Shared/Adorners/RectangleAdorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class RectangleAdorner : Adorner
/// </summary>
private readonly Pen pen;

/// <summary>
/// The brush to color the inner rectangle
/// </summary>
private Brush fillBrush;

/// <summary>
/// The pen 2.
/// </summary>
Expand Down Expand Up @@ -58,6 +63,8 @@ public class RectangleAdorner : Adorner
/// <param name="crossHairSize">
/// Size of the cross hair.
/// </param>
///<exception cref="ArgumentNullException">
///</exception>
public RectangleAdorner(
UIElement adornedElement,
Rect rectangle,
Expand All @@ -66,7 +73,7 @@ public class RectangleAdorner : Adorner
double thickness1 = 1.0,
double thickness2 = 1.0,
double crossHairSize = 10)
: this(adornedElement, rectangle, color1, color2, thickness1, thickness2, crossHairSize, DashStyles.Dash)
: this(adornedElement, rectangle, color1, color2, thickness1, thickness2, crossHairSize, DashStyles.Dash, null)
{
}

Expand Down Expand Up @@ -97,6 +104,11 @@ public class RectangleAdorner : Adorner
/// <param name="dashStyle2">
/// The dash style2.
/// </param>
/// <param name="fillBrush">
/// The brush to color the inner rectangle
/// </param>
/// <exception cref="ArgumentNullException">
/// </exception>
public RectangleAdorner(
UIElement adornedElement,
Rect rectangle,
Expand All @@ -105,7 +117,8 @@ public class RectangleAdorner : Adorner
double thickness1,
double thickness2,
double crossHairSize,
DashStyle dashStyle2)
DashStyle dashStyle2,
Brush fillBrush = null)
: base(adornedElement)
{
if (adornedElement == null)
Expand Down Expand Up @@ -135,6 +148,7 @@ public class RectangleAdorner : Adorner
this.pen2 = new Pen(new SolidColorBrush(color2), thickness2 * dpiFactor);
this.pen2.DashStyle = dashStyle2;
this.crossHairSize = crossHairSize;
this.fillBrush = fillBrush;
}

/// <summary>
Expand Down Expand Up @@ -173,7 +187,7 @@ protected override void OnRender(DrawingContext dc)
guidelines.GuidelinesY.Add(my + halfPenWidth);
dc.PushGuidelineSet(guidelines);*/
dc.DrawRectangle(null, this.pen, rect);
dc.DrawRectangle(fillBrush, this.pen, rect);
dc.DrawRectangle(null, this.pen2, rect);

if (this.crossHairSize > 0)
Expand Down

0 comments on commit a704b48

Please sign in to comment.