OSDN Git Service

マウスで選択中に領域外へはみ出た場合、スクロールするようにした」
authorkonekoneko <test2214@hotmail.co.jp>
Thu, 28 Jul 2016 17:11:07 +0000 (02:11 +0900)
committerkonekoneko <test2214@hotmail.co.jp>
Thu, 28 Jul 2016 17:11:07 +0000 (02:11 +0900)
Core/Controller.cs
Core/EditView.cs
Metro/FooEditEngine/FooTextBox.cs

index 8855f51..4df64bf 100644 (file)
@@ -759,7 +759,13 @@ namespace FooEditEngine
                 {
                     tp = this.View.GetTextPointFromPostion(p);
                     if (tp != TextPoint.Null)
+                    {
                         this.MoveCaretAndSelect(tp);
+                    }
+                    else
+                    {
+                        return false;
+                    }
                 }
                 this.Document.SelectGrippers.BottomLeft.Enabled = this.SelectionLength != 0;
                 return true;
index 6defca0..24600b7 100644 (file)
@@ -21,6 +21,12 @@ namespace FooEditEngine
         Both,
     }
 
+    enum TextPointSearchRange
+    {
+        TextAreaOnly,
+        Full
+    }
+
     /// <summary>
     /// キャレットとドキュメントの表示を担当します。レイアウト関連もこちらで行います
     /// </summary>
@@ -179,6 +185,22 @@ namespace FooEditEngine
                 return false;
         }
 
+        public bool IsUpperTextArea(double x, double y)
+        {
+            if (x >= this.render.TextArea.X && x <= this.render.TextArea.Right && y < this.render.TextArea.Y)
+                return true;
+            else
+                return false;
+        }
+
+        public bool IsUnderTextArea(double x,double y)
+        {
+            if (x >= this.render.TextArea.X && x <= this.render.TextArea.Right && y > this.render.TextArea.Bottom)
+                return true;
+            else
+                return false;
+        }
+
         /// <summary>
         /// ヒットテストを行う
         /// </summary>
@@ -478,12 +500,17 @@ namespace FooEditEngine
         /// 指定した座標の一番近くにあるTextPointを取得する
         /// </summary>
         /// <param name="p">テキストエリアを左上とする相対位置</param>
+        /// <param name="searchRange">探索範囲</param>
         /// <returns>レイアウトラインを指し示すTextPoint</returns>
-        public TextPoint GetTextPointFromPostion(Point p)
+        public TextPoint GetTextPointFromPostion(Point p,TextPointSearchRange searchRange = TextPointSearchRange.TextAreaOnly)
         {
-            if (p.Y < this.render.TextArea.TopLeft.Y || 
-                p.Y > this.render.TextArea.BottomRight.Y)
-                return TextPoint.Null;
+            if(searchRange == TextPointSearchRange.TextAreaOnly)
+            {
+                if (p.Y < this.render.TextArea.TopLeft.Y ||
+                    p.Y > this.render.TextArea.BottomRight.Y)
+                    return TextPoint.Null;
+            }
+
             TextPoint tp = new TextPoint();
 
             if (this.LayoutLines.Count == 0)
@@ -492,28 +519,56 @@ namespace FooEditEngine
             p.Y -= this.render.TextArea.Y;
 
             int lineHeadIndex, lineLength;
-            double y = 0;
-            tp.row = this.LayoutLines.Count - 1;
-            for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
+
+            if(p.Y >= this.render.TextArea.TopLeft.Y)
             {
-                double height = this.LayoutLines.GetLayout(i).Height;
+                double y = 0;
+                tp.row = this.LayoutLines.Count - 1;
+                for (int i = this.Src.Row; i < this.LayoutLines.Count; i++)
+                {
+                    double height = this.LayoutLines.GetLayout(i).Height;
 
-                lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
-                lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
+                    lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
+                    lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
 
-                if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
-                    continue;
+                    if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
+                        continue;
 
-                if (y + height > p.Y)
+                    if (y + height > p.Y)
+                    {
+                        tp.row = i;
+                        break;
+                    }
+                    y += height;
+                }
+            }else
+            {
+                double y = this.render.TextArea.TopLeft.Y;
+                tp.row = 0;
+                for (int i = this.Src.Row; i >= 0; i--)
                 {
-                    tp.row = i;
-                    break;
+                    double height = this.LayoutLines.GetLayout(i).Height;
+
+                    lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
+                    lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
+
+                    if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
+                        continue;
+
+                    if (y - height < p.Y)
+                    {
+                        tp.row = i;
+                        break;
+                    }
+                    y -= height;
                 }
-                y += height;
             }
 
-            if (p.X < this.render.TextArea.X)
-                return tp;
+            if (searchRange == TextPointSearchRange.TextAreaOnly)
+            {
+                if (p.X < this.render.TextArea.X)
+                    return tp;
+            }
 
             tp.col = GetIndexFromColPostion(tp.row, p.X);
 
index 1ff236f..8057168 100644 (file)
@@ -775,7 +775,7 @@ namespace FooEditEngine.Metro
             //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
         }
 
-            void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
+        void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
         {
             if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
             {
@@ -926,14 +926,18 @@ namespace FooEditEngine.Metro
         void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
         {
             Point p = e.Position;
+            TextPointSearchRange searchRange;
             if (this.View.HitTextArea(p.X, p.Y))
-            {
-                TextPoint tp = this.View.GetTextPointFromPostion(p);
-                this._Controller.MoveCaretAndSelect(tp);
-                if (this.peer != null)
-                    this.peer.OnNotifyCaretChanged();
-                this.Refresh();
-            }
+                searchRange = TextPointSearchRange.TextAreaOnly;
+            else if (this._Controller.SelectionLength > 0)
+                searchRange = TextPointSearchRange.Full;
+            else
+                return;
+            TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
+            this._Controller.MoveCaretAndSelect(tp);
+            if (this.peer != null)
+                this.peer.OnNotifyCaretChanged();
+            this.Refresh();
         }
 
         bool IsModiferKeyPressed(VirtualKey key)