OSDN Git Service

WPF版:スワイプするとスクロールするようにした&タッチするとキャレットが移動するようにした
authorgdkhd812 <test@nnn.co.jp>
Sat, 12 Dec 2015 10:22:43 +0000 (15:52 +0530)
committergdkhd812 <test@nnn.co.jp>
Sat, 12 Dec 2015 10:22:43 +0000 (15:52 +0530)
WPF/FooEditEngine/FooTextBox.cs

index c4437e7..005da1b 100644 (file)
@@ -141,6 +141,8 @@ namespace FooEditEngine.WPF
             this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
 
             this.CaretMoved += (s, e) => { };
+
+            this.IsManipulationEnabled = true;
         }
 
         /// <summary>
@@ -814,7 +816,7 @@ namespace FooEditEngine.WPF
             if (e.LeftButton == MouseButtonState.Pressed)
             {
 
-                this.Document.SelectWord(index);
+                this.Document.SelectWord((int)index);
                 this.textStore.NotifySelectionChanged();
                 if(this.peer != null)
                     this.peer.OnNotifyCaretChanged();
@@ -919,6 +921,62 @@ namespace FooEditEngine.WPF
             }
         }
 
+        /// <inheritdoc/>
+        protected override void OnTouchDown(TouchEventArgs e)
+        {
+            var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
+            TextPoint tp = this.View.GetTextPointFromPostion(p);
+            if (tp == TextPoint.Null)
+                return;
+            int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
+
+            FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
+            if (foldingData != null)
+            {
+                if (foldingData.Expand)
+                    this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
+                else
+                    this.View.LayoutLines.FoldingCollection.Expand(foldingData);
+                this._Controller.JumpCaret(foldingData.Start, false);
+            }
+            else
+            {
+                this._Controller.JumpCaret(tp.row, tp.col, false);
+            }
+            if (this.peer != null)
+                this.peer.OnNotifyCaretChanged();
+            this.View.IsFocused = true;
+            this.Focus();
+            this.Refresh();
+        }
+
+        /// <inheritdoc/>
+        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
+        {
+            Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
+
+            //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
+            if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
+            {
+                System.Diagnostics.Debug.WriteLine("tran y:{0}", translation.Y);
+                //下に動かした場合はマイナスの値が飛んでくる、上に動かした場合はプラスの値が飛んでくる
+                this.View.Scroll(this.Document.Src.X, this.Document.Src.Y - translation.Y);
+                this.View.IsFocused = false;
+                this.Refresh();
+                return;
+            }
+
+            int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
+            if (deltax != 0)
+            {
+                if (translation.X < 0)
+                    this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
+                else
+                    this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
+                this.Refresh();
+            }
+        }
+
         private Point GetDipFromPoint(Point p)
         {
             float dpi;