Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
HighlightBorderAdorner.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Windows;
4 using System.Windows.Documents;
5 using System.Windows.Media;
6 
7 namespace SiliconStudio.Presentation.Adorners
8 {
9  /// <summary>
10  /// An adorner that draw a rectangle with borders over the adorned element. It can multiple possible states: Hidden, Visible, HighlightAccept and HighlightRefuse.
11  /// </summary>
13  {
14  private Brush renderBrush;
15  private Pen renderPen;
16 
17  /// <summary>
18  /// Identifies the <see cref="AcceptBorderBrush"/> dependency property.
19  /// </summary>
20  public static readonly DependencyProperty AcceptBorderBrushProperty = DependencyProperty.Register("AcceptBorderBrush", typeof(Brush), typeof(HighlightBorderAdorner), new PropertyMetadata(Brushes.PaleGreen, PropertyChanged));
21 
22  /// <summary>
23  /// Identifies the <see cref="AcceptBorderBrush"/> dependency property.
24  /// </summary>
25  public static readonly DependencyProperty AcceptBorderThicknessProperty = DependencyProperty.Register("AcceptBorderThickness", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(2.0, PropertyChanged));
26 
27  /// <summary>
28  /// Identifies the <see cref="AcceptBorderBrush"/> dependency property.
29  /// </summary>
30  public static readonly DependencyProperty AcceptBorderCornerRadiusProperty = DependencyProperty.Register("AcceptBorderCornerRadius", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(3.0, PropertyChanged));
31 
32  /// <summary>
33  /// Identifies the <see cref="AcceptBorderBrush"/> dependency property.
34  /// </summary>
35  public static readonly DependencyProperty AcceptBackgroundBrushProperty = DependencyProperty.Register("AcceptBackgroundBrush", typeof(Brush), typeof(HighlightBorderAdorner), new PropertyMetadata(Brushes.MediumSeaGreen, PropertyChanged));
36 
37  /// <summary>
38  /// Identifies the <see cref="AcceptBorderBrush"/> dependency property.
39  /// </summary>
40  public static readonly DependencyProperty AcceptBackgroundOpacityProperty = DependencyProperty.Register("AcceptBackgroundOpacity", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(0.3, PropertyChanged));
41 
42  /// <summary>
43  /// Identifies the <see cref="RefuseBorderBrush"/> dependency property.
44  /// </summary>
45  public static readonly DependencyProperty RefuseBorderBrushProperty = DependencyProperty.Register("RefuseBorderBrush", typeof(Brush), typeof(HighlightBorderAdorner), new PropertyMetadata(Brushes.Red, PropertyChanged));
46 
47  /// <summary>
48  /// Identifies the <see cref="RefuseBorderBrush"/> dependency property.
49  /// </summary>
50  public static readonly DependencyProperty RefuseBorderThicknessProperty = DependencyProperty.Register("RefuseBorderThickness", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(2.0, PropertyChanged));
51 
52  /// <summary>
53  /// Identifies the <see cref="RefuseBorderBrush"/> dependency property.
54  /// </summary>
55  public static readonly DependencyProperty RefuseBorderCornerRadiusProperty = DependencyProperty.Register("RefuseBorderCornerRadius", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(3.0, PropertyChanged));
56 
57  /// <summary>
58  /// Identifies the <see cref="RefuseBorderBrush"/> dependency property.
59  /// </summary>
60  public static readonly DependencyProperty RefuseBackgroundBrushProperty = DependencyProperty.Register("RefuseBackgroundBrush", typeof(Brush), typeof(HighlightBorderAdorner), new PropertyMetadata(Brushes.IndianRed, PropertyChanged));
61 
62  /// <summary>
63  /// Identifies the <see cref="RefuseBorderBrush"/> dependency property.
64  /// </summary>
65  public static readonly DependencyProperty RefuseBackgroundOpacityProperty = DependencyProperty.Register("RefuseBackgroundOpacity", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(0.3, PropertyChanged));
66 
67  /// <summary>
68  /// Identifies the <see cref="BorderBrush"/> dependency property.
69  /// </summary>
70  public static readonly DependencyProperty BorderBrushProperty = DependencyProperty.Register("BorderBrush", typeof(Brush), typeof(HighlightBorderAdorner), new PropertyMetadata(Brushes.SteelBlue, PropertyChanged));
71 
72  /// <summary>
73  /// Identifies the <see cref="BorderThickness"/> dependency property.
74  /// </summary>
75  public static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register("BorderThickness", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(2.0, PropertyChanged));
76 
77  /// <summary>
78  /// Identifies the <see cref="BorderCornerRadius"/> dependency property.
79  /// </summary>
80  public static readonly DependencyProperty BorderCornerRadiusProperty = DependencyProperty.Register("BorderCornerRadius", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(3.0, PropertyChanged));
81 
82  /// <summary>
83  /// Identifies the <see cref="BackgroundBrush"/> dependency property.
84  /// </summary>
85  public static readonly DependencyProperty BackgroundBrushProperty = DependencyProperty.Register("BackgroundBrush", typeof(Brush), typeof(HighlightBorderAdorner), new PropertyMetadata(Brushes.LightSteelBlue, PropertyChanged));
86 
87  /// <summary>
88  /// Identifies the <see cref="BorderBrush"/> dependency property.
89  /// </summary>
90  public static readonly DependencyProperty BackgroundOpacityProperty = DependencyProperty.Register("BackgroundOpacity", typeof(double), typeof(HighlightBorderAdorner), new PropertyMetadata(0.3, PropertyChanged));
91 
92  /// <summary>
93  /// Identifies the <see cref="State"/> dependency property.
94  /// </summary>
95  public static readonly DependencyProperty StateProperty = DependencyProperty.Register("State", typeof(HighlightAdornerState), typeof(HighlightBorderAdorner), new PropertyMetadata(HighlightAdornerState.Hidden, PropertyChanged));
96 
97  /// <summary>
98  /// Initializes a new instance of the <see cref="HighlightBorderAdorner"/> class.
99  /// </summary>
100  /// <param name="adornedElement"></param>
101  public HighlightBorderAdorner(UIElement adornedElement)
102  : base(adornedElement)
103  {
104  }
105 
106  /// <summary>
107  /// Gets or sets the border brush when the adorner is Accepted.
108  /// </summary>
109  public Brush AcceptBorderBrush { get { return (Brush)GetValue(AcceptBorderBrushProperty); } set { SetValue(AcceptBorderBrushProperty, value); } }
110 
111  /// <summary>
112  /// Gets or sets the border thickness when the adorner is Accepted.
113  /// </summary>
114  public double AcceptBorderThickness { get { return (double)GetValue(AcceptBorderThicknessProperty); } set { SetValue(AcceptBorderThicknessProperty, value); } }
115 
116  /// <summary>
117  /// Gets or sets the border corner radius when the adorner is Accepted.
118  /// </summary>
119  public double AcceptBorderCornerRadius { get { return (double)GetValue(AcceptBorderCornerRadiusProperty); } set { SetValue(AcceptBorderCornerRadiusProperty, value); } }
120 
121  /// <summary>
122  /// Gets or sets the background brush when the adorner is Accepted.
123  /// </summary>
124  public Brush AcceptBackgroundBrush { get { return (Brush)GetValue(AcceptBackgroundBrushProperty); } set { SetValue(AcceptBackgroundBrushProperty, value); } }
125 
126  /// <summary>
127  /// Gets or sets the background opacity when the adorner is Accepted.
128  /// </summary>
129  public double AcceptBackgroundOpacity { get { return (double)GetValue(AcceptBackgroundOpacityProperty); } set { SetValue(AcceptBackgroundOpacityProperty, value); } }
130 
131  /// <summary>
132  /// Gets or sets the border brush when the adorner is Refuseed.
133  /// </summary>
134  public Brush RefuseBorderBrush { get { return (Brush)GetValue(RefuseBorderBrushProperty); } set { SetValue(RefuseBorderBrushProperty, value); } }
135 
136  /// <summary>
137  /// Gets or sets the border thickness when the adorner is Refuseed.
138  /// </summary>
139  public double RefuseBorderThickness { get { return (double)GetValue(RefuseBorderThicknessProperty); } set { SetValue(RefuseBorderThicknessProperty, value); } }
140 
141  /// <summary>
142  /// Gets or sets the border corner radius when the adorner is Refuseed.
143  /// </summary>
144  public double RefuseBorderCornerRadius { get { return (double)GetValue(RefuseBorderCornerRadiusProperty); } set { SetValue(RefuseBorderCornerRadiusProperty, value); } }
145 
146  /// <summary>
147  /// Gets or sets the background brush when the adorner is Refuseed.
148  /// </summary>
149  public Brush RefuseBackgroundBrush { get { return (Brush)GetValue(RefuseBackgroundBrushProperty); } set { SetValue(RefuseBackgroundBrushProperty, value); } }
150 
151  /// <summary>
152  /// Gets or sets the background opacity when the adorner is Refuseed.
153  /// </summary>
154  public double RefuseBackgroundOpacity { get { return (double)GetValue(RefuseBackgroundOpacityProperty); } set { SetValue(RefuseBackgroundOpacityProperty, value); } }
155 
156  /// <summary>
157  /// Gets or sets the border brush when the adorner visible but not highlighted.
158  /// </summary>
159  public Brush BorderBrush { get { return (Brush)GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } }
160 
161  /// <summary>
162  /// Gets or sets the border thickness when the adorner is visible but not highlighted.
163  /// </summary>
164  public double BorderThickness { get { return (double)GetValue(BorderThicknessProperty); } set { SetValue(BorderThicknessProperty, value); } }
165 
166  /// <summary>
167  /// Gets or sets the border corner radius when the adorner is visible but not highlighted.
168  /// </summary>
169  public double BorderCornerRadius { get { return (double)GetValue(BorderCornerRadiusProperty); } set { SetValue(BorderCornerRadiusProperty, value); } }
170 
171  /// <summary>
172  /// Gets or sets the background brush when the adorner is visible but not highlighted.
173  /// </summary>
174  public Brush BackgroundBrush { get { return (Brush)GetValue(BackgroundBrushProperty); } set { SetValue(BackgroundBrushProperty, value); } }
175 
176  /// <summary>
177  /// Gets or sets the background opacity when the adorner is visible but not highlighted.
178  /// </summary>
179  public double BackgroundOpacity { get { return (double)GetValue(BackgroundOpacityProperty); } set { SetValue(BackgroundOpacityProperty, value); } }
180 
181  /// <summary>
182  /// Gets or sets the state of the adorner.
183  /// </summary>
184  public HighlightAdornerState State { get { return (HighlightAdornerState)GetValue(StateProperty); } set { SetValue(StateProperty, value); } }
185 
186  /// <inheritdoc/>
187  protected override void OnRender(DrawingContext drawingContext)
188  {
189  var adornedElementRect = new Rect(AdornedElement.RenderSize);
190 
191  switch (State)
192  {
193  case HighlightAdornerState.HighlightAccept:
194  renderBrush = AcceptBackgroundBrush.Clone();
195  renderBrush.Opacity = AcceptBackgroundOpacity;
196  renderPen = new Pen(AcceptBorderBrush, AcceptBorderThickness);
197  drawingContext.DrawRoundedRectangle(renderBrush, renderPen, adornedElementRect, AcceptBorderCornerRadius, AcceptBorderCornerRadius);
198  break;
199  case HighlightAdornerState.HighlightRefuse:
200  renderBrush = RefuseBackgroundBrush.Clone();
201  renderBrush.Opacity = RefuseBackgroundOpacity;
202  renderPen = new Pen(RefuseBorderBrush, RefuseBorderThickness);
203  drawingContext.DrawRoundedRectangle(renderBrush, renderPen, adornedElementRect, RefuseBorderCornerRadius, RefuseBorderCornerRadius);
204  break;
205  case HighlightAdornerState.Visible:
206  renderBrush = BackgroundBrush.Clone();
207  renderBrush.Opacity = BackgroundOpacity;
208  renderPen = new Pen(BorderBrush, BorderThickness);
209  drawingContext.DrawRoundedRectangle(renderBrush, renderPen, adornedElementRect, BorderCornerRadius, BorderCornerRadius);
210  break;
211  }
212  }
213 
214  private static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
215  {
216  var adorner = (Adorner)d;
217  adorner.InvalidateVisual();
218  }
219  }
220 }
override void OnRender(DrawingContext drawingContext)
An adorner that draw a rectangle with borders over the adorned element. It can multiple possible stat...
HighlightBorderAdorner(UIElement adornedElement)
Initializes a new instance of the HighlightBorderAdorner class.