Mercurial > silverbladetech
annotate MetroWpf/MetroWpf.Xaml/Adorners/NotesAdorner.cs @ 121:8f94475d3146 tip
final code
author | stevenh7776 |
---|---|
date | Thu, 31 May 2012 15:35:26 +0100 |
parents | 060f02cd4591 |
children |
rev | line source |
---|---|
15
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
1 using System.Globalization; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
2 using System.Windows; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
3 using System.Windows.Documents; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
4 using System.Windows.Media; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
5 using MetroWpf.Xaml.Styles; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
6 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
7 namespace MetroWpf.Xaml.Adorners |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
8 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
9 public class NotesAdorner : Adorner |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
10 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
11 public NotesAdorner(UIElement adornedElement) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
12 : base(adornedElement) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
13 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
14 NoteBrush = new SolidColorBrush(AccentColors.Black); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
15 NoteWidth = 70; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
16 NoteHeight = 30; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
17 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
18 TextBrush = new SolidColorBrush(AccentColors.White); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
19 Text = "Adorner!"; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
20 TextTypeface = new Typeface("Segoe UI"); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
21 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
22 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
23 public SolidColorBrush NoteBrush { get; set; } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
24 public double NoteWidth { get; set; } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
25 public double NoteHeight { get; set; } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
26 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
27 public SolidColorBrush TextBrush { get; set; } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
28 public string Text { get; set; } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
29 public Typeface TextTypeface { get; set; } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
30 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
31 protected override void OnRender(DrawingContext drawingContext) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
32 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
33 Rect adornedElementRect = |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
34 new Rect(this.AdornedElement.DesiredSize); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
35 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
36 var noteContainer = |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
37 DrawContainer(drawingContext, adornedElementRect); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
38 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
39 DrawMessageText( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
40 drawingContext, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
41 noteContainer.Left, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
42 noteContainer.Top); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
43 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
44 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
45 private Rect DrawContainer( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
46 DrawingContext drawingContext, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
47 Rect adornedElementRect) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
48 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
49 // border and fill color |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
50 SolidColorBrush renderBrush = NoteBrush; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
51 renderBrush.Opacity = 0.2; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
52 Pen renderPen = new Pen(NoteBrush, 1.5); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
53 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
54 // location and sizing |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
55 double xOffset = 20; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
56 double yOffset = 0; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
57 double renderRadius = 5.0; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
58 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
59 Point topLeftPosition = new Point( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
60 adornedElementRect.Right + xOffset, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
61 adornedElementRect.Top + yOffset); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
62 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
63 Point bottomRightPosition = new Point( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
64 adornedElementRect.Right + xOffset + NoteWidth, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
65 adornedElementRect.Top + NoteHeight); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
66 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
67 Rect noteContainer = new Rect( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
68 topLeftPosition, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
69 bottomRightPosition); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
70 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
71 //Add to visual tree (should we add to logical tree as well?) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
72 drawingContext.DrawRoundedRectangle( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
73 renderBrush, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
74 renderPen, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
75 noteContainer, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
76 renderRadius, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
77 renderRadius); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
78 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
79 return noteContainer; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
80 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
81 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
82 private void DrawMessageText( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
83 DrawingContext drawingContext, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
84 double left, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
85 double top) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
86 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
87 FormattedText formattedText = new FormattedText( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
88 Text, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
89 CultureInfo.InvariantCulture, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
90 FlowDirection.LeftToRight, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
91 TextTypeface, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
92 12, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
93 TextBrush); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
94 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
95 Point topLeftPosition = new Point( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
96 left + 8, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
97 top + 4); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
98 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
99 drawingContext.DrawText( |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
100 formattedText, |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
101 topLeftPosition); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
102 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
103 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
104 } |