/
CampusMapPage.xaml.cs
146 lines (133 loc) · 5.8 KB
/
CampusMapPage.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
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
//
// Copyright (c) 2011 Microsoft Corporation. All rights reserved.
// Use of this sample source code is subject to the terms of the Microsoft license
// agreement under which you licensed this sample source code and is provided AS-IS.
// If you did not accept the terms of the license agreement, you are not authorized
// to use this sample source code. For the terms of the license, please see the
// license agreement between you and Microsoft.
//
//
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace MySchoolApp
{
public partial class CampusMapPage : PhoneApplicationPage
{
private PageOrientation previousOrientation;
private double initialScale;
public CampusMapPage()
{
this.InitializeComponent();
this.initialScale = 1.0;
this.previousOrientation = base.Orientation;
base.OrientationChanged += FullImage_OrientationChanged;
}
private void FullImage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
RotateTransition rotateTransition = new RotateTransition();
PhoneApplicationPage element = (PhoneApplicationPage)((PhoneApplicationFrame)Application.Current.RootVisual).Content;
switch (e.Orientation)
{
case PageOrientation.LandscapeLeft:
switch (this.previousOrientation)
{
case PageOrientation.PortraitUp:
rotateTransition.Mode = RotateTransitionMode.In90Clockwise;
break;
case PageOrientation.LandscapeRight:
rotateTransition.Mode = RotateTransitionMode.In180Clockwise;
break;
}
break;
case PageOrientation.LandscapeRight:
switch (this.previousOrientation)
{
case PageOrientation.PortraitUp:
rotateTransition.Mode = RotateTransitionMode.In90Counterclockwise;
break;
case PageOrientation.LandscapeLeft:
rotateTransition.Mode = RotateTransitionMode.In180Counterclockwise;
break;
}
break;
case PageOrientation.Portrait:
switch (this.previousOrientation)
{
case PageOrientation.LandscapeLeft:
rotateTransition.Mode = RotateTransitionMode.In90Counterclockwise;
break;
case PageOrientation.LandscapeRight:
rotateTransition.Mode = RotateTransitionMode.In90Clockwise;
break;
}
break;
}
ITransition transition = rotateTransition.GetTransition(element);
transition.Completed += delegate
{
transition.Stop();
};
transition.Begin();
this.previousOrientation = e.Orientation;
}
private void OnGestureListenerDragDelta(object sender, DragDeltaGestureEventArgs args)
{
if (this.initialScale > 1.0)
{
this.transform.TranslateX = this.ComputeTranslateX(this.transform.TranslateX + args.HorizontalChange, this.initialScale);
this.transform.TranslateY = this.ComputeTranslateY(this.transform.TranslateY + args.VerticalChange, this.initialScale);
}
}
private void OnGestureListenerPinchStarted(object sender, PinchStartedGestureEventArgs args)
{
this.initialScale = this.transform.ScaleX;
this.transform.CenterX = this.MyImage.ActualWidth / 2.0;
this.transform.CenterY = this.MyImage.ActualHeight / 2.0;
}
private void OnGestureListenerPinchDelta(object sender, PinchGestureEventArgs args)
{
this.transform.ScaleY = this.transform.ScaleX = this.initialScale * args.DistanceRatio;
if (this.transform.ScaleX > 1.0)
{
this.transform.TranslateX = this.ComputeTranslateX(this.transform.TranslateX, this.transform.ScaleX);
this.transform.TranslateY = this.ComputeTranslateY(this.transform.TranslateY, this.transform.ScaleY);
}
}
private void OnGestureListenerPinchCompleted(object sender, PinchGestureEventArgs args)
{
if (this.transform.ScaleX < 1.0)
{
this.transform.ScaleX = this.transform.ScaleY = 1.0;
this.transform.TranslateX = this.transform.TranslateY = 0.0;
}
}
private double ComputeTranslateX(double translate, double ratio)
{
if (this.MyImage.ActualWidth * ratio > this.pageImage.ActualWidth)
{
var amp = this.MyImage.ActualWidth * ratio / 2;
return (translate > amp) ? amp : (translate < -amp) ? -amp : translate;
}
return 0.0;
}
private double ComputeTranslateY(double translate, double ratio)
{
if (this.MyImage.ActualHeight * ratio > this.pageImage.ActualHeight)
{
var amp = this.MyImage.ActualHeight * ratio / 2;
return (translate > amp) ? amp : (translate < -amp) ? -amp : translate;
}
return 0.0;
}
}
}