forked from microsoft/WinAppDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
126 lines (107 loc) · 4.61 KB
/
Copy pathMainPage.xaml.cs
File metadata and controls
126 lines (107 loc) · 4.61 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
//******************************************************************************
//
// Copyright (c) 2017 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************
using System;
using Windows.Storage.Streams;
using Windows.UI.Input;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace Input
{
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
ConfigureDialRotation();
}
private void ConfigureDialRotation()
{
var iconRotate = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Rotate.png"));
var itemRotate = RadialControllerMenuItem.CreateFromIcon("Rotate", iconRotate);
var controller = RadialController.CreateForCurrentView();
controller.Menu.Items.Add(itemRotate);
controller.RotationChanged += ControllerOnRotationChanged;
var config = RadialControllerConfiguration.GetForCurrentView();
config.SetDefaultMenuItems(new RadialControllerSystemMenuItemKind[] { });
}
private void Log(string text)
{
if (ResultText.Text.Length > 0)
{
ResultText.Text += Environment.NewLine;
}
ResultText.Text += text;
}
private void Touchable_OnTapped(object sender, TappedRoutedEventArgs e)
{
Log("Tapped");
}
private void Touchable_OnDoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
Log("DoubleTapped");
}
private void Touchable_OnRightTapped(object sender, RightTappedRoutedEventArgs e)
{
Log("RightTapped");
}
private void Touchable_OnHolding(object sender, HoldingRoutedEventArgs e)
{
Log("Holding");
}
private void Clear_OnTapped(object sender, TappedRoutedEventArgs e)
{
ResultText.Text = string.Empty;
Touchable.Opacity = 1;
TouchableTransform.TranslateX = 0;
TouchableTransform.TranslateY = 0;
TouchableTransform.Rotation = 0;
TouchableTransform.ScaleX = 1;
TouchableTransform.ScaleY = 1;
}
private void Touchable_OnManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
Log("ManipulationStarted");
Touchable.Opacity = 0.5;
}
private void Touchable_OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
// Do some math to prevent the Touchable from being moved outside of the designated container.
var maxDistanceX = (ManipulationContainer.ActualWidth - Touchable.ActualWidth) / 2;
var maxDistanceY = (ManipulationContainer.ActualHeight - Touchable.ActualHeight) / 2;
var translationX = TouchableTransform.TranslateX + e.Delta.Translation.X;
var translationY = TouchableTransform.TranslateY + e.Delta.Translation.Y;
TouchableTransform.TranslateX = translationX > 0
? Math.Min(maxDistanceX, translationX)
: Math.Max(maxDistanceX * -1, translationX);
TouchableTransform.TranslateY = translationY > 0
? Math.Min(maxDistanceY, translationY)
: Math.Max(maxDistanceY * -1, translationY);
// Apply other manipulation deltas
TouchableTransform.Rotation += e.Delta.Rotation;
TouchableTransform.ScaleX *= e.Delta.Scale;
TouchableTransform.ScaleY *= e.Delta.Scale;
}
private void ControllerOnRotationChanged(RadialController sender, RadialControllerRotationChangedEventArgs e)
{
TouchableTransform.Rotation += e.RotationDeltaInDegrees;
}
private void Touchable_OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
Log("ManipulationCompleted");
Touchable.Opacity = 1;
}
}
}