-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyoutCreator.cs
More file actions
147 lines (130 loc) · 3.81 KB
/
Copy pathFlyoutCreator.cs
File metadata and controls
147 lines (130 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System.Windows;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace PdfEater;
public class FlyoutCreator {
static public void CreateColorFlyout(ref Popup parentPopup) {
var panel = new StackPanel {
Orientation = Orientation.Horizontal,
Background = Brushes.White,
Margin = new Thickness(4)
};
Popup parentPopupVal = parentPopup;
foreach (Color col in Globals.colorOptions) {
AddColorButton(col, ref panel);
}
AddCustomColorButton(ref panel);
parentPopup = new Popup {
Child = panel,
Placement = PlacementMode.MousePoint,
StaysOpen = false
};
}
static void AddColorButton(Color c, ref StackPanel panel) {
Grid btnGrid = new Grid();
Button btn = new Button {
Width = 40,
Height = 40,
Margin = new Thickness(1),
Background = new SolidColorBrush(c),
BorderBrush = Brushes.Gray,
BorderThickness = new Thickness(1),
};
Button revokeBtn =
new Button {
Width = 10,
Height = 10,
BorderThickness = new Thickness(0),
Padding = new Thickness(-4),
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Right,
FontWeight = FontWeights.Bold,
Foreground = Brushes.White,
Background = Brushes.Red,
Margin = new Thickness(0, 2, 2, 0),
Content = "x"
};
btnGrid.Children.Add(btn);
btnGrid.Children.Add(revokeBtn);
btn.Click += (object s, RoutedEventArgs e) => {
Globals.selectedColor = (SolidColorBrush) btn.Background;
((Popup) ((StackPanel) ((Grid) btn.Parent).Parent).Parent).IsOpen = false;
};
revokeBtn.Click += (object s, RoutedEventArgs e) => {
Globals.colorOptions.Remove(((SolidColorBrush) btn.Background).Color);
Popup parentPopup = ((Popup) ((StackPanel) ((Grid) btn.Parent).Parent).Parent);
UpdateColorFlyout(ref parentPopup);
};
panel.Children.Add(btnGrid);
}
static private void AddCustomColorButton(ref StackPanel panel) {
Button addBtn = new Button {
Width = 40,
Height = 40,
Margin = new Thickness(1),
Background = Brushes.Lime,
BorderBrush = Brushes.Gray,
BorderThickness = new Thickness(1),
Content = new TextBlock {
Text = "+",
FontWeight = FontWeights.Bold,
FontSize = 40,
Foreground = Brushes.White,
Margin = new Thickness(2.5, -10, 0, 0)
},
};
addBtn.Click += (object s, RoutedEventArgs e) => {
ColorpickerWindow colWin = new ColorpickerWindow();
colWin.ShowDialog();
};
panel.Children.Add(addBtn);
}
static public void UpdateColorFlyout(ref Popup parentPopup) {
StackPanel panel = (StackPanel) parentPopup.Child;
panel.Children.Clear();
foreach (Color col in Globals.colorOptions) {
AddColorButton(col, ref panel);
}
AddCustomColorButton(ref panel);
}
static public void CreateThicknessFlyout(ref Popup parentPopup) {
var panel = new StackPanel {
Orientation = Orientation.Horizontal,
Background = Brushes.White,
Margin = new Thickness(4)
};
void AddButton(int dotThickness) {
var btn = new Button {
Width = 30,
Height = 30,
Margin = new Thickness(2),
Background = Brushes.White,
BorderBrush = Brushes.Gray,
BorderThickness = new Thickness(1),
Content = new Ellipse {
Width = dotThickness,
Height = dotThickness,
Fill = Brushes.Black,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
}
};
btn.Click += (object s, RoutedEventArgs e) => {
Globals.selectedThickness = (int) Math.Floor(((Ellipse) btn.Content).Width / 2);
((Popup)((StackPanel) btn.Parent).Parent).IsOpen = false;
};
panel.Children.Add(btn);
}
AddButton(4);
AddButton(6);
AddButton(10);
AddButton(16);
parentPopup = new Popup {
Child = panel,
Placement = PlacementMode.MousePoint,
StaysOpen = false
};
}
}