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. Point _leftDragOffset;
  23. Point _rightDragOffset;
  24. Point _middleDragOffset;
  25.  
  26. Point LPod = new Point();
  27. Point RPod = new Point();
  28. Point RHi = new Point();
  29. Point Rect = new Point();
  30. Point LastP = new Point();
  31.  
  32. TranslateTransform _pan;
  33. ScaleTransform _zoom;
  34. RotateTransform _turn;
  35.  
  36. public MainWindow()
  37. {
  38. InitializeComponent();
  39.  
  40. _pan = new TranslateTransform();
  41. _zoom = new ScaleTransform();
  42. _turn = new RotateTransform();
  43.  
  44. TransformGroup tGroup = new TransformGroup();
  45. tGroup.Children.Add(_zoom);
  46. tGroup.Children.Add(_turn);
  47. tGroup.Children.Add(_pan);
  48. controlTarget.RenderTransform = tGroup;
  49.  
  50. controlTarget.MouseDown += new MouseButtonEventHandler(controlTarget_MouseDown);
  51. controlTarget.MouseMove += new MouseEventHandler(controlTarget_MouseMove);
  52. controlTarget.MouseUp += new MouseButtonEventHandler(controlTarget_MouseUp);
  53.  
  54. this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);
  55. }
  56.  
  57. void MainWindow_KeyDown(object sender, KeyEventArgs e)
  58. {
  59. if (e.Key == Key.Escape)
  60. {
  61. _pan.X = 0;
  62. _pan.Y = 0;
  63. _zoom.ScaleX = 1;
  64. _zoom.ScaleY = 1;
  65. _zoom.CenterX = 0;
  66. _zoom.CenterY = 0;
  67. }
  68. }
  69.  
  70. void controlTarget_MouseDown(object sender, MouseButtonEventArgs e)
  71. {
  72. if (e.ChangedButton == MouseButton.Left)
  73. {
  74. var s = sender as UIElement;
  75. s.CaptureMouse();
  76. _leftDragOffset = e.GetPosition(this);
  77. LPod.X = Canvas.GetLeft(s) -_leftDragOffset.X;
  78. LPod.Y = Canvas.GetTop(s) -_leftDragOffset.Y;
  79. }
  80. if (e.ChangedButton == MouseButton.Right)
  81. {
  82. var s = sender as UIElement;
  83. s.CaptureMouse();
  84. _rightDragOffset = e.GetPosition(this);
  85. RPod.X = Canvas.GetLeft(s) -_leftDragOffset.X;
  86. RPod.Y = Canvas.GetTop(s) -_leftDragOffset.Y;
  87. Point Pos = e.GetPosition(s);
  88. RHi.X = (Pos.X / controlTarget.Width);
  89. RHi.Y = (Pos.Y / controlTarget.Height);
  90. Rect = new Point(controlTarget.Width, controlTarget.Height);
  91.  
  92. }
  93. }
  94.  
  95. void controlTarget_MouseMove(object sender, MouseEventArgs e)
  96. {
  97. if (e.LeftButton == MouseButtonState.Pressed)
  98. {
  99. var s = sender as UIElement;
  100. Point p = e.GetPosition(this);
  101. double X = _leftDragOffset.X + (p.X - _leftDragOffset.X) + LPod.X;
  102. double Y = _leftDragOffset.Y + (p.Y - _leftDragOffset.Y) + LPod.Y;
  103. Canvas.SetLeft(s, X);
  104. Canvas.SetTop(s, Y);
  105. }
  106. if (e.RightButton == MouseButtonState.Pressed)
  107. {
  108. //if (LastP == e.GetPosition(this)) return;
  109. LastP = e.GetPosition(this);
  110.  
  111. var s = sender as UIElement;
  112. Point p = e.GetPosition(this);
  113. //Point WP = new Point(Canvas.GetLeft(this), Canvas.GetTop(this));//マウスドラッグしながらウインドウをリサイズする鬼畜はいないだろう・・・。
  114. //Size WS = new Size(this.Width, this.Height);
  115. //Point RP = new Point(Canvas.GetLeft(controlTarget), Canvas.GetTop(controlTarget));
  116. Size RS = new Size(controlTarget.Width,controlTarget.Height);
  117. double MouseW = p.X-_rightDragOffset.X;
  118. double MouseH = p.Y-_rightDragOffset.Y;
  119.  
  120. double Recio = 0.005;
  121. Rect.X += (MouseW * Recio);
  122. Rect.Y += (MouseH * Recio);
  123. if (MouseW != 0 && Rect.Y>= 0) controlTarget.Width = Rect.Y;
  124. if (MouseH != 0 && Rect.Y >= 0) controlTarget.Height = Rect.Y;
  125. Size RS2 = new Size(controlTarget.Width, controlTarget.Height);
  126.  
  127. double DW = RS2.Width - RS.Width;
  128. double DH = RS2.Height - RS.Height;
  129.  
  130. double PX = (-RS.Width/2);
  131. double PY = (-RS.Width/2);
  132. Canvas.SetLeft(controlTarget, PX);
  133. Canvas.SetTop(controlTarget, PY);
  134. Point RP2 = new Point(Canvas.GetLeft(controlTarget), Canvas.GetTop(controlTarget));
  135. PX = RP2.X + _rightDragOffset.X-((RHi.X*RS2.Width)-(RS.Width/2));
  136. PY = RP2.Y + _rightDragOffset.Y-((RHi.Y*RS2.Height)-(RS.Height/2));
  137. Canvas.SetLeft(controlTarget, (PX-(DW/2)));
  138. Canvas.SetTop(controlTarget, (PY -(DH/2)));
  139. }
  140. }
  141.  
  142. void controlTarget_MouseUp(object sender, MouseButtonEventArgs e)
  143. {
  144. if(e.RightButton == MouseButtonState.Released &&
  145. e.LeftButton == MouseButtonState.Released){
  146. var s = sender as UIElement;
  147. s.ReleaseMouseCapture();
  148. }
  149. }
  150. }
  151. }
  152.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty