fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14.  
  15. namespace WpfApplication1
  16. {
  17. /// <summary>
  18. /// MainWindow.xaml の相互作用ロジック
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. bool _leftIsDragging;
  23. bool _rightIsDragging;
  24. bool _middleIsDragging;
  25. Point _leftDragOffset;
  26. Point _rightDragOffset;
  27. Point _middleDragOffset;
  28.  
  29. TranslateTransform _pan;
  30. ScaleTransform _zoom;
  31. RotateTransform _turn;
  32.  
  33. public MainWindow()
  34. {
  35. InitializeComponent();
  36.  
  37. _pan = new TranslateTransform();
  38. _zoom = new ScaleTransform(1.0,1.0,controlTarget.Height/2,controlTarget.Width/2);
  39. _turn = new RotateTransform();
  40.  
  41. TransformGroup tGroup = new TransformGroup();
  42. tGroup.Children.Add(_zoom);
  43. tGroup.Children.Add(_turn);
  44. tGroup.Children.Add(_pan);
  45. controlTarget.RenderTransform = tGroup;
  46.  
  47. controlTarget.MouseDown += new MouseButtonEventHandler(controlTarget_MouseDown);
  48. controlTarget.MouseMove += new MouseEventHandler(controlTarget_MouseMove);
  49. controlTarget.MouseUp += new MouseButtonEventHandler(controlTarget_MouseUp);
  50.  
  51. this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);
  52. }
  53.  
  54. void MainWindow_KeyDown(object sender, KeyEventArgs e)
  55. {
  56. if (e.Key == Key.Escape)
  57. {
  58. _pan.X = 0;
  59. _pan.Y = 0;
  60. _zoom.ScaleX = 1;
  61. _zoom.ScaleY = 1;
  62. _zoom.CenterX = controlTarget.Height/2;
  63. _zoom.CenterY = controlTarget.Width / 2;
  64. }
  65. }
  66.  
  67. void controlTarget_MouseDown(object sender, MouseButtonEventArgs e)
  68. {
  69. if (e.ChangedButton == MouseButton.Left)
  70. {
  71. var s = sender as UIElement;
  72. s.CaptureMouse();
  73. _leftDragOffset = e.GetPosition(this);
  74. _leftIsDragging = true;
  75. }
  76. else
  77. {
  78. if (e.ChangedButton == MouseButton.Right)
  79. {
  80. var s = sender as UIElement;
  81. s.CaptureMouse();
  82. _rightDragOffset = e.GetPosition(this);
  83. _rightIsDragging = true;
  84. //Point center = e.GetPosition(s);
  85. //_zoom.CenterX = center.X;
  86. //_zoom.CenterY = center.Y;
  87. }
  88. }
  89. }
  90.  
  91. void controlTarget_MouseMove(object sender, MouseEventArgs e)
  92. {
  93. if (_leftIsDragging)
  94. {
  95. var s = sender as UIElement;
  96. Point p = e.GetPosition(this);
  97. _pan.X += p.X - _leftDragOffset.X;
  98. _pan.Y += p.Y - _leftDragOffset.Y;
  99. _leftDragOffset = p;
  100. }
  101. else
  102. {
  103. if (_rightIsDragging)
  104. {
  105. var s = sender as UIElement;
  106. Point p = e.GetPosition(this);
  107. double delta = (_rightDragOffset.Y - p.Y) * 0.01;
  108. _zoom.ScaleX += delta;
  109. _zoom.ScaleY += delta;
  110. _rightDragOffset = p;
  111. }
  112. }
  113. }
  114.  
  115. void controlTarget_MouseUp(object sender, MouseButtonEventArgs e)
  116. {
  117. if (e.ChangedButton == MouseButton.Left)
  118. {
  119. var s = sender as UIElement;
  120. s.ReleaseMouseCapture();
  121. _leftIsDragging = false;
  122. }
  123. if (e.ChangedButton == MouseButton.Right)
  124. {
  125. var s = sender as UIElement;
  126. s.ReleaseMouseCapture();
  127. _rightIsDragging = false;
  128. }
  129. }
  130. }
  131. }
  132.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty