-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShortCutSetter.xaml.cs
187 lines (157 loc) · 5.96 KB
/
ShortCutSetter.xaml.cs
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Drawing;
namespace AP_HA
{
/// <summary>
/// Interaktionslogik für ShortCutSetter.xaml
/// </summary>
public partial class ShortCutSetter : Window
{
private ShortCut sc;
private StackPanel sPanel;
private TextBlock header;
private TextBox scText;
private StackPanel btnPanel;
private Button reset;
private Button ok;
private ComboBox mouseMoveCB;
private Button btnDownSection;
public ShortCutSetter(ShortCut sc)
{
this.sc = sc;
InitializeComponent();
InitializePresentation();
}
public void InitializePresentation()
{
sc.reset(); // Werte des Shortcuts zurücksetzen
sPanel = new StackPanel();
sPanel.Orientation = Orientation.Vertical;
header = new TextBlock();
header.FontWeight = FontWeights.Bold;
header.Text = "Neuer Shortcut:";
StackPanel scsPanel = new StackPanel();
scsPanel.Orientation = Orientation.Horizontal;
scText = new TextBox();
scText.FontSize = 30;
scText.Margin = new Thickness(5,20,5,20);
scText.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
scText.IsManipulationEnabled = false;
btnDownSection = new Button();
btnDownSection.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.WhiteSmoke);
btnDownSection.Width = 40;
btnDownSection.Height = 40;
btnDownSection.IsEnabled = true;
Label mmLbl = new Label();
mmLbl.Content = "Maus Bewegung: ";
mouseMoveCB = new ComboBox();
mouseMoveCB.Items.Add(MouseMoveDirection.None);
mouseMoveCB.Items.Add(MouseMoveDirection.Up);
mouseMoveCB.Items.Add(MouseMoveDirection.Down);
mouseMoveCB.Items.Add(MouseMoveDirection.Left);
mouseMoveCB.Items.Add(MouseMoveDirection.Right);
mouseMoveCB.SelectedIndex = 0;
scsPanel.Children.Add(mmLbl);
scsPanel.Children.Add(mouseMoveCB);
btnPanel = new StackPanel();
btnPanel.Orientation = Orientation.Horizontal;
reset = new Button();
reset.Content = "Zurücksetzen";
ok = new Button();
ok.Content = "OK";
reset.Click += OnReset;
ok.Click += OnOk;
btnPanel.Children.Add(reset);
btnPanel.Children.Add(ok);
sPanel.Children.Add(header);
sPanel.Children.Add(scText);
sPanel.Children.Add(btnDownSection);
sPanel.Children.Add(scsPanel);
sPanel.Children.Add(btnPanel);
this.AddChild(sPanel);
this.PreviewKeyDown += new KeyEventHandler(OnKeyDown);
btnDownSection.PreviewMouseDown += new MouseButtonEventHandler(OnMouseDown);
this.PreviewMouseWheel += new MouseWheelEventHandler(OnPreviewMouseWheel);
//this.PreviewMouseMove += new MouseEventHandler(OnPreviewMouseMove);
mouseMoveCB.SelectionChanged += new SelectionChangedEventHandler(OnMmSelectChanged);
}
private void OnMmSelectChanged(object sender, SelectionChangedEventArgs e)
{
sc.register((MouseMoveDirection) mouseMoveCB.SelectedItem);
scText.Text = sc.ToString();
}
private void OnReset(object sender, RoutedEventArgs e)
{
sc.reset();
mouseMoveCB.SelectedIndex = 0;
scText.Text = sc.ToString();
}
private void OnOk(object sender, RoutedEventArgs e)
{
Close();
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
sc.register(e.Key);
scText.Text = sc.ToString();
}
private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
sc.register(e.ChangedButton);
scText.Text = sc.ToString();
}
private void OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta > 0)
sc.register(Wheel.Up);
else if (e.Delta < 0)
sc.register(Wheel.Down);
else
sc.register(Wheel.None);
scText.Text = sc.ToString();
}
private System.Windows.Point? lastMovePoint;
private void OnPreviewMouseMove(object sender, MouseEventArgs e)
{
System.Windows.Point mousePos = e.GetPosition(this);
if (lastMovePoint != null)
{
double deltaX = mousePos.X - lastMovePoint.Value.X;
double deltaY = mousePos.Y - lastMovePoint.Value.Y;
MouseMoveDirection moveDir = MouseMoveDirection.None;
if (Math.Abs(deltaX) > Math.Abs(deltaY)) // Maus ist eher zur Seite gegangen
{
if (deltaX < 0)
moveDir = MouseMoveDirection.Left;
else
moveDir = MouseMoveDirection.Right;
}
else if (Math.Abs(deltaX) < Math.Abs(deltaY))
{
if (deltaY < 0)
moveDir = MouseMoveDirection.Up;
else
moveDir = MouseMoveDirection.Down;
}
sc.register(moveDir);
scText.Text = sc.ToString();
lastMovePoint = mousePos;
}
else
{
lastMovePoint = mousePos;
}
}
}
}