OSDN Git Service

5010f77328d3ec9461285d42ccb758aecf598083
[fooeditengine/FooEditEngine.git] / Core / GripperView.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace FooEditEngine
6 {
7     class GripperView
8     {
9         public const int GripperWidth = 10;
10         public const int HitAreaWidth = 48;
11
12         ITextRender Render;
13         public GripperView(ITextRender render)
14         {
15             this.Render = render;
16             this.Enabled = false;
17         }
18         public bool Enabled
19         {
20             get;
21             set;
22         }
23         public Rectangle Rectangle
24         {
25             get;
26             set;
27         }
28         public Rectangle HitArea
29         {
30             get;
31             set;
32         }
33         public bool IsHit(Point p)
34         {
35             return this.Enabled && this.HitArea.IsHit(p);
36         }
37
38         public void Move(EditView view,TextPoint tp)
39         {
40             this.Rectangle = view.GetRectFromTextPoint(tp, GripperView.GripperWidth, GripperView.GripperWidth);
41             this.HitArea = view.GetRectFromTextPoint(tp, GripperView.HitAreaWidth, GripperView.HitAreaWidth);
42         }
43
44         public void MoveByIndex(EditView view, int index)
45         {
46             this.Rectangle = view.GetRectFromIndex(index, GripperView.GripperWidth, GripperView.GripperWidth);
47             this.HitArea = view.GetRectFromIndex(index, GripperView.HitAreaWidth, GripperView.HitAreaWidth);
48         }
49
50         public Point AdjustPoint(Point p)
51         {
52             Rectangle gripperRect = this.HitArea;
53
54             if (gripperRect.IsHit(p))
55                 p.Y = gripperRect.Y - 1;
56             else
57                 p.Y -= gripperRect.Height;
58
59             if (p.Y < this.Render.TextArea.Y)
60                 p.Y = this.Render.TextArea.Y;
61             return p;
62         }
63
64         public void Draw()
65         {
66             if (this.Enabled)
67             {
68                 Rectangle gripperRect = this.Rectangle;
69                 double radius = gripperRect.Width / 2;
70                 Point point;
71                 point = new Point(gripperRect.X + radius, gripperRect.Y + radius);
72                 this.Render.DrawGripper(point, radius);
73             }
74         }
75
76         public bool Equals(GripperView other)
77         {
78             return this.Rectangle == other.Rectangle;
79         }
80     }
81 }