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;