Deep Zoom Composerが生成したプロジェクトのソース・コードをそのまま流用してしまってもよいのだが、基本的なユーザー・インターフェイスの処理をここで確認しておこう。ultiScaleImageコントロールを制御するための基本的な手段は、ZoomAboutLogicalPointメソッドとViewportOriginプロパティだ。
public partial class Page : UserControl
{
Point lastMouseDownPos = new Point();
Point lastMouseViewPort = new Point();
bool mouseDown = false;
bool duringDrag = false;
double scale = 1.0;
// ズームイン
private void Button_Click(object sender, RoutedEventArgs e)
{
double newscale = scale * 2;
double y = msi.ActualHeight / 2;
double x = msi.ActualWidth / 2; // 表示エリアの中心
Point point = msi.ElementToLogicalPoint(new Point(x, y));
zoom(newscale, point);
}
// ズームアウト
private void Button_Click_1(object sender, RoutedEventArgs e)
{
double newscale = scale / 2;
double y = msi.ActualHeight / 2;
double x = msi.ActualWidth / 2; // 表示エリアの中心
Point point = msi.ElementToLogicalPoint(new Point(x, y));
zoom(newscale, point);
}
Private lastMouseDownPos As New Point()
Private lastMouseViewPort As New Point()
Private mouseDown As Boolean = False
Private duringDrag As Boolean = False
Private scale As Double = 1.0
' ズームイン
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim newscale As Double = scale * 2
Dim y As Double = msi.ActualHeight / 2
Dim x As Double = msi.ActualWidth / 2 ' 表示エリアの中心
Dim point As Point = msi.ElementToLogicalPoint(New Point(x, y))
zoom(newscale, point)
End Sub
' ズームアウト
Private Sub Button_Click_1(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim newscale As Double = scale / 2
Dim y As Double = msi.ActualHeight / 2
Dim x As Double = msi.ActualWidth / 2 ' 表示エリアの中心
Dim point As Point = msi.ElementToLogicalPoint(New Point(x, y))
zoom(newscale, point)
End Sub
' ZoomAboutLogicalPointメソッド
Private Sub zoom(ByVal newscale As Double, ByVal p As Point)
msi.ZoomAboutLogicalPoint(newscale / scale, p.X, p.Y)
scale = newscale
End Sub
End Class
' 左ボタンのクリック
Private Sub msi_MouseLeftButtonDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
lastMouseDownPos = e.GetPosition(msi)
lastMouseViewPort = msi.ViewportOrigin
mouseDown = True
msi.CaptureMouse()
End Sub
' マウスの移動
Private Sub msi_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs)
Dim lastMousePos As Point = e.GetPosition(msi)
If mouseDown AndAlso Not duringDrag Then
duringDrag = True
End If
If duringDrag Then
' 表示位置を移動
Dim newPoint As Point = lastMouseViewPort
' 左ボタンが離された
Private Sub msi_MouseLeftButtonUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
duringDrag = False ' ドラッグ終了
mouseDown = False 'ボタンが押されている状態も終わり
msi.ReleaseMouseCapture()
End Sub
' 初期状態の表示に戻す
Private Sub Button_Click_2(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Me.msi.ViewportWidth = 1
Me.msi.ViewportOrigin = New Point(0, 0)
scale = 1 ' 拡大率をリセットする
End Sub
// 画像を切り替える
private void Button_Click_3(object sender, RoutedEventArgs e)
{
// 現在表示しているイメージ・ピラミッドのURI
string src = ((DeepZoomImageTileSource)msi.Source)
.UriSource.OriginalString;
if (src.IndexOf("vb") >= 0)
{
msi.Source = new DeepZoomImageTileSource(
new Uri("cs_poster/dzc_output.xml",UriKind.Relative));
}
else
{
msi.Source = new DeepZoomImageTileSource(
new Uri("vb_poster/dzc_output.xml",UriKind.Relative));
}
}
Private Sub Button_Click_3(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
' 現在表示しているイメージ・ピラミッドのURI
Dim src As String = CType(msi.Source, DeepZoomImageTileSource).UriSource.OriginalString
If src.IndexOf("vb") >= 0 Then
msi.Source = New DeepZoomImageTileSource(_
New Uri("cs_poster/dzc_output.xml", UriKind.Relative))
Else
msi.Source = New DeepZoomImageTileSource(_
New Uri("vb_poster/dzc_output.xml", UriKind.Relative))
End If
End Sub