OSDN Git Service

GDIの関数でDPIを取得するのはコストが高いので、別の方法にすることにした
[fooeditengine/FooEditEngine.git] / Core / GripperView.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace FooEditEngine
6 {
7     struct GripperRectangle
8     {
9         public Gripper TopLeft;
10         public Gripper TopRight;
11         public Gripper BottomLeft;
12         public Gripper BottomRight;
13         public GripperRectangle(Gripper bottom_left,Gripper bottom_right)
14         {
15             this.TopLeft = null;
16             this.TopRight = null;
17             this.BottomLeft = bottom_left;
18             this.BottomRight = bottom_right;
19         }
20     }
21     class Gripper
22     {
23         public const int GripperWidth = 10;
24         public const int HitAreaWidth = 48;
25
26         ITextRender Render;
27         public Gripper()
28         {
29             this.Enabled = false;
30         }
31         public bool Enabled
32         {
33             get;
34             set;
35         }
36         public Rectangle Rectangle
37         {
38             get;
39             set;
40         }
41         public Rectangle HitArea
42         {
43             get;
44             set;
45         }
46         public bool IsHit(Point p)
47         {
48             return this.Enabled && this.HitArea.IsHit(p);
49         }
50
51         public void Move(EditView view,TextPoint tp)
52         {
53             this.Rectangle = view.GetRectFromTextPoint(tp, Gripper.GripperWidth, Gripper.GripperWidth);
54             this.HitArea = view.GetRectFromTextPoint(tp, Gripper.HitAreaWidth, Gripper.HitAreaWidth);
55         }
56
57         public void MoveByIndex(EditView view, int index)
58         {
59             this.Rectangle = view.GetRectFromIndex(index, Gripper.GripperWidth, Gripper.GripperWidth);
60             this.HitArea = view.GetRectFromIndex(index, Gripper.HitAreaWidth, Gripper.HitAreaWidth);
61         }
62
63         public Point AdjustPoint(Point p)
64         {
65             Rectangle gripperRect = this.HitArea;
66
67             if (gripperRect.IsHit(p))
68                 p.Y = gripperRect.Y - 1;
69             else
70                 p.Y -= gripperRect.Height;
71
72             //if (p.Y < this.Render.TextArea.Y)
73             //    p.Y = this.Render.TextArea.Y;
74             return p;
75         }
76
77         public void Draw(ITextRender render)
78         {
79             if (this.Enabled)
80             {
81                 Rectangle gripperRect = this.Rectangle;
82                 double radius = gripperRect.Width / 2;
83                 Point point;
84                 point = new Point(gripperRect.X + radius, gripperRect.Y + radius);
85                 render.DrawGripper(point, radius);
86             }
87         }
88
89         public bool Equals(Gripper other)
90         {
91             return this.Rectangle == other.Rectangle;
92         }
93     }
94 }