return new TextPoint(row, col);
}
+ Rectangle GetGripperRect(GripperPostion type, int width, int height)
+ {
+ double radius = width / 2;
+ if (type == GripperPostion.BottomRight)
+ return this.View.GetRectFromIndex(this.SelectionStart + this.SelectionLength,width,height);
+ else if (type == GripperPostion.BottomLeft)
+ return this.View.GetRectFromIndex(this.SelectionStart,width,height);
+ else
+ throw new ArgumentOutOfRangeException();
+ }
+
/// <summary>
/// 選択文字列のインデントを一つ増やす
/// </summary>
Point _CaretLocation = new Point();
TextPoint _CaretPostion = new TextPoint();
long tickCount;
- bool _CaretBlink,_HideRuler = true;
+ bool _CaretBlink, _HideRuler = true;
internal const int LineNumberLength = 6;
const int UpdateAreaPaddingWidth = 2;
const int UpdateAreaWidth = 4;
const int UpdateAreaTotalWidth = UpdateAreaWidth + UpdateAreaPaddingWidth;
+ GripperView[] selectionGrippers = new GripperView[2];
/// <summary>
/// コンストラクター
/// </summary>
- public EditView(Document doc, IEditorRender r,int MarginLeftAndRight = 5)
- : this(doc,r,new Padding(MarginLeftAndRight, 0, MarginLeftAndRight, 0))
+ public EditView(Document doc, IEditorRender r, int MarginLeftAndRight = 5)
+ : this(doc, r, new Padding(MarginLeftAndRight, 0, MarginLeftAndRight, 0))
{
}
/// <param name="r">レンダー</param>
/// <param name="margin">マージン(1番目:左、2番目:上、3番目:右、4番目:下)</param>
public EditView(Document doc, IEditorRender r, Padding margin)
- : base(doc,r,margin)
+ : base(doc, r, margin)
{
this.CaretBlinkTime = 500;
this.CaretWidthOnInsertMode = 1;
this.HideLineMarker = true;
this.IsFocused = false;
this.Selections = new SelectCollection();
+ this.selectionGrippers[0] = new GripperView(this, GripperPostion.BottomLeft);
+ this.selectionGrippers[1] = new GripperView(this, GripperPostion.BottomRight);
}
/// <summary>
}
/// <summary>
+ /// 選択範囲にあるグリッパーのリスト
+ /// </summary>
+ public IList<GripperView> SelectGrippers
+ {
+ get
+ {
+ return this.selectionGrippers;
+ }
+ }
+
+ /// <summary>
/// ラインマーカーを描くなら偽。そうでなければ真
/// </summary>
public bool HideLineMarker
}
this.DrawCaret();
+
+ foreach (GripperView gripper in this.selectionGrippers)
+ gripper.Draw();
}
void DrawUpdateArea(int row,double ypos)
return p;
}
+ public GripperView HitGripperFromPoint(Point p)
+ {
+ for(int i = 0; i < this.selectionGrippers.Length; i++)
+ {
+ if (this.selectionGrippers[i].IsHit(p))
+ {
+ System.Diagnostics.Debug.WriteLine("gripper hitted number:{0}", i);
+ return selectionGrippers[i];
+ }
+ }
+ return null;
+ }
+
+ public Rectangle GetRectFromIndex(int index,int width,int height)
+ {
+ TextPoint tp = this.LayoutLines.GetTextPointFromIndex(index);
+ return this.GetRectFromTextPoint(tp, width, height);
+ }
+
+ public Rectangle GetRectFromTextPoint(TextPoint tp, int width, int height)
+ {
+ double radius = width / 2;
+ Point point = this.GetPostionFromTextPoint(tp);
+ double lineHeight = this.LayoutLines.GetLayout(tp.row).Height;
+
+ return new Rectangle(point.X - radius, point.Y + lineHeight, width, height);
+ }
+
/// <summary>
/// キャレットを指定した位置に移動させる
/// </summary>
public const int GripperWidth = 10;
public const int HitAreaWidth = 48;
- Controller Controller;
- EditView View;
ITextRender Render;
GripperPostion type;
- public GripperView(Controller controller, EditView view, GripperPostion type)
+ public GripperView(EditView view, GripperPostion type)
{
- this.Controller = controller;
- this.View = view;
this.Render = view.render;
this.Enabled = false;
this.type = type;
}
public Rectangle Rectangle
{
- get
- {
- return this.GetGripperRect(this.type, GripperWidth, GripperWidth);
- }
+ get;
+ set;
+ }
+ public Rectangle HitArea
+ {
+ get;
+ set;
}
public bool IsHit(Point p)
{
- Rectangle gripperRect = this.GetGripperRect(type, HitAreaWidth, HitAreaWidth);
- return this.Enabled && gripperRect.IsHit(p);
+ return this.Enabled && this.HitArea.IsHit(p);
+ }
+
+ public void Move(EditView view,TextPoint tp)
+ {
+ this.Rectangle = view.GetRectFromTextPoint(tp, GripperView.GripperWidth, GripperView.GripperWidth);
+ this.HitArea = view.GetRectFromTextPoint(tp, GripperView.HitAreaWidth, GripperView.HitAreaWidth);
+ }
+
+ public void MoveByIndex(EditView view, int index)
+ {
+ this.Rectangle = view.GetRectFromIndex(index, GripperView.GripperWidth, GripperView.GripperWidth);
+ this.HitArea = view.GetRectFromIndex(index, GripperView.HitAreaWidth, GripperView.HitAreaWidth);
}
public Point AdjustPoint(Point p)
{
- Rectangle gripperRect = this.GetGripperRect(type, HitAreaWidth, HitAreaWidth);
+ Rectangle gripperRect = this.HitArea;
if (gripperRect.IsHit(p))
p.Y = gripperRect.Y - 1;
void DrawGripper(GripperPostion type)
{
- Rectangle gripperRect = GetGripperRect(type, GripperWidth, GripperWidth);
+ Rectangle gripperRect = this.Rectangle;
double radius = gripperRect.Width / 2;
Point point;
point = new Point(gripperRect.X + radius, gripperRect.Y + radius);
this.Render.DrawGripper(point, radius);
}
- Rectangle GetGripperRect(GripperPostion type, int width, int height)
- {
- TextPoint tp;
- Point point;
- double radius = width / 2;
- if (type == GripperPostion.BottomRight)
- tp = this.View.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart + this.Controller.SelectionLength);
- else if (type == GripperPostion.BottomLeft)
- tp = this.View.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
- else
- throw new ArgumentOutOfRangeException();
-
- point = this.View.GetPostionFromTextPoint(tp);
- double lineHeight = this.View.LayoutLines.GetLayout(tp.row).Height;
-
- return new Rectangle(point.X - radius, point.Y + lineHeight, width, height);
- }
-
public bool Equals(GripperView other)
{
return this.Rectangle == other.Rectangle;
this._Controller = new Controller(this.Document, this.View);
this._Controller.SelectionChanged += Controller_SelectionChanged;
- this.FirstGripper = new GripperView(this._Controller, this.View, GripperPostion.BottomLeft);
- this.SecondGripper = new GripperView(this._Controller, this.View, GripperPostion.BottomRight);
-
this.gestureRecongnizer.GestureSettings = GestureSettings.Drag |
GestureSettings.RightTap |
GestureSettings.Tap |
SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
this.nowCaretMove = false;
+ this.View.SelectGrippers[0].MoveByIndex(this.View, this.Controller.SelectionStart);
+ this.View.SelectGrippers[1].MoveByIndex(this.View, this.Controller.SelectionStart + this.Controller.SelectionLength);
if (this.textStore.IsLocked() == false)
this.textStore.NotifySelectionChanged();
}
- GripperView FirstGripper, SecondGripper;
bool HittedCaret;
GripperView hittedGripper;
private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
{
this.HittedCaret = false;
- this.hittedGripper = null;
Point p = e.Position;
TextPoint tp = this.View.GetTextPointFromPostion(p);
{
HittedCaret = true;
}
-
- if (this.FirstGripper.IsHit(p))
- {
- hittedGripper = this.FirstGripper;
- HittedCaret = true;
- System.Diagnostics.Debug.WriteLine("first gripper hitted");
- }
-
- else if (this.SecondGripper.IsHit(p))
+
+ this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
+ if (this.hittedGripper != null)
{
- hittedGripper = this.SecondGripper;
- HittedCaret = true;
- System.Diagnostics.Debug.WriteLine("second gripper hitted");
+ this.HittedCaret = true;
}
}
TextPoint tp = this.View.GetTextPointFromPostion(p);
if (this._Controller.IsReverseSelect())
{
- if (Object.ReferenceEquals(hittedGripper,this.SecondGripper))
+ if (Object.ReferenceEquals(hittedGripper,this.View.SelectGrippers[1]))
this._Controller.MoveSelectBefore(tp);
else
this._Controller.MoveCaretAndSelect(tp);
}
else
{
- if (Object.ReferenceEquals(hittedGripper,this.FirstGripper))
+ if (Object.ReferenceEquals(hittedGripper, this.View.SelectGrippers[0]))
this._Controller.MoveSelectBefore(tp);
else
this._Controller.MoveCaretAndSelect(tp);
}
+ this.hittedGripper.Move(this.View, tp);
}
else
{
}
if (this.peer != null)
this.peer.OnNotifyCaretChanged();
- if (this._Controller.SelectionLength != 0)
- this.FirstGripper.Enabled = true;
- else
- this.FirstGripper.Enabled = false;
+ this.View.SelectGrippers[0].Enabled = this._Controller.SelectionLength != 0;
this.Refresh();
this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);
else
this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);
- this.FirstGripper.Enabled = false;
- this.SecondGripper.Enabled = false;
+ this.View.SelectGrippers[0].Enabled = false;
+ this.View.SelectGrippers[1].Enabled = false;
this.Refresh();
return;
}
this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
else
this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
- this.FirstGripper.Enabled = false;
- this.SecondGripper.Enabled = false;
+ this.View.SelectGrippers[0].Enabled = false;
+ this.View.SelectGrippers[1].Enabled = false;
this.Refresh();
}
}
void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
{
bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
- this.FirstGripper.Enabled = false;
- this.SecondGripper.Enabled = touched;
+ this.View.SelectGrippers[0].Enabled = false;
+ this.View.SelectGrippers[1].Enabled = touched;
this.JumpCaret(e.Position);
System.Diagnostics.Debug.WriteLine(e.TapCount);
if (e.TapCount == 2)
{
- this.FirstGripper.Enabled = touched;
+ this.View.SelectGrippers[0].Enabled = touched;
//タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
this.Controller.SelectWord(this.Controller.SelectionStart, touched);
}
this.View.Draw(updateRect);
else
this.Render.FillBackground(updateRect);
- this.FirstGripper.Draw();
- this.SecondGripper.Draw();
this.Render.EndDraw();
}
else
toX = -this.horizontalScrollBar.Value;
this._Controller.Scroll(toX, this.View.Src.Row, false, false);
- this.FirstGripper.Enabled = false;
- this.SecondGripper.Enabled = false;
+ this.View.SelectGrippers[0].Enabled = false;
+ this.View.SelectGrippers[1].Enabled = false;
this.Refresh();
}
if (newRow >= this.View.LayoutLines.Count)
return;
this._Controller.Scroll(this.View.Src.X, newRow, false, false);
- this.FirstGripper.Enabled = false;
- this.SecondGripper.Enabled = false;
+ this.View.SelectGrippers[0].Enabled = false;
+ this.View.SelectGrippers[1].Enabled = false;
this.Refresh();
}