OSDN Git Service

グリッパーを移動する部分をコントローラーに移動した
authorgdkhd812 <test@nnn.co.jp>
Sat, 24 Oct 2015 14:29:32 +0000 (19:59 +0530)
committergdkhd812 <test@nnn.co.jp>
Sat, 24 Oct 2015 14:29:32 +0000 (19:59 +0530)
Core/Controller.cs
Metro/FooEditEngine/FooTextBox.cs

index a0b85d3..bee7a83 100644 (file)
@@ -774,6 +774,55 @@ namespace FooEditEngine
             this.View.AdjustCaretAndSrc();
         }
 
+        /// <summary>
+        /// グリッパーとキャレットを同時に移動する
+        /// </summary>
+        /// <param name="p">ポインターの座標</param>
+        /// <param name="hittedGripper">動かす対象となるグリッパー</param>
+        /// <returns>移動できた場合は真を返す。そうでなければ偽を返す</returns>
+        /// <remarks>グリッパー内にポインターが存在しない場合、グリッパーはポインターの座標近くの行に移動する</remarks>
+        public bool MoveCaretAndGripper(Point p, GripperView hittedGripper)
+        {
+            bool HittedCaret = false;
+            TextPoint tp = this.View.GetTextPointFromPostion(p);
+            if (tp == this.View.CaretPostion)
+            {
+                HittedCaret = true;
+            }
+
+            if (HittedCaret || hittedGripper != null)
+            {
+                if (hittedGripper != null)
+                {
+                    tp = this.View.GetTextPointFromPostion(hittedGripper.AdjustPoint(p));
+                    if (this.IsReverseSelect())
+                    {
+                        if (Object.ReferenceEquals(hittedGripper, this.View.SelectGrippers.BottomRight))
+                            this.MoveSelectBefore(tp);
+                        else
+                            this.MoveCaretAndSelect(tp);
+                    }
+                    else
+                    {
+                        if (Object.ReferenceEquals(hittedGripper, this.View.SelectGrippers.BottomLeft))
+                            this.MoveSelectBefore(tp);
+                        else
+                            this.MoveCaretAndSelect(tp);
+                    }
+                    hittedGripper.Move(this.View, tp);
+                }
+                else
+                {
+                    tp = this.View.GetTextPointFromPostion(p);
+                    if (tp != TextPoint.Null)
+                        this.MoveCaretAndSelect(tp);
+                }
+                this.View.SelectGrippers.BottomLeft.Enabled = this.SelectionLength != 0;
+                return true;
+            }
+            return false;
+        }
+
         public void MoveSelectBefore(TextPoint tp)
         {
             int NewAnchorIndex;
index b7aeff6..f01a8a4 100644 (file)
@@ -780,8 +780,6 @@ namespace FooEditEngine.Metro
                 this.textStore.NotifySelectionChanged();
         }
 
-        bool HittedCaret;
-        GripperView hittedGripper;
         private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
         {
             //sender.InertiaTranslationDeceleration = 0.001f;
@@ -789,22 +787,11 @@ namespace FooEditEngine.Metro
             //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
         }
 
+        GripperView hittedGripper;
         void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
         {
-            this.HittedCaret = false;
-
-            Point p = e.Position;
-            TextPoint tp = this.View.GetTextPointFromPostion(p);
-            if (tp == this.View.CaretPostion)
-            {
-                HittedCaret = true;
-            }
-
+            //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
             this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
-            if (this.hittedGripper != null)
-            {
-                this.HittedCaret = true;
-            }
         }
 
         const int WheelNoti = 120;
@@ -813,45 +800,11 @@ namespace FooEditEngine.Metro
 
         void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
         {
-            if (HittedCaret)
+            if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
             {
-                Point p;
-                if (this.hittedGripper == null)
-                     p = e.Position;
-                else
-                    p = this.hittedGripper.AdjustPoint(e.Position);
-
-                if (hittedGripper != null)
-                {
-                    TextPoint tp = this.View.GetTextPointFromPostion(p);
-                    if (this._Controller.IsReverseSelect())
-                    {
-                        if (Object.ReferenceEquals(hittedGripper,this.View.SelectGrippers.BottomRight))
-                            this._Controller.MoveSelectBefore(tp);
-                        else
-                            this._Controller.MoveCaretAndSelect(tp);
-                    }
-                    else
-                    {
-                        if (Object.ReferenceEquals(hittedGripper, this.View.SelectGrippers.BottomLeft))
-                            this._Controller.MoveSelectBefore(tp);
-                        else
-                            this._Controller.MoveCaretAndSelect(tp);
-                    }
-                    this.hittedGripper.Move(this.View, tp);
-                }
-                else
-                {
-                    TextPoint tp = this.View.GetTextPointFromPostion(p);
-                    if(tp != TextPoint.Null)
-                        this._Controller.MoveCaretAndSelect(tp);
-                }
                 if (this.peer != null)
                     this.peer.OnNotifyCaretChanged();
-                this.View.SelectGrippers.BottomLeft.Enabled = this._Controller.SelectionLength != 0;
-
-                this.Refresh();
-                
+                this.Refresh();                
                 return;
             }