2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 namespace FooEditEngine
20 public double GetOffsetY(double line_height)
22 return this.Row * line_height - this.Y;
24 public SrcPoint(double x, int row, double y)
27 throw new ArgumentOutOfRangeException("マイナスを値を指定することはできません");
37 public struct TextRange
51 public static TextRange Null = new TextRange(0, 0);
56 /// <param name="index">開始インデックス</param>
57 /// <param name="length">長さ</param>
58 public TextRange(int index, int length)
68 public struct TextPoint : IComparable<TextPoint>
80 /// TextPointがドキュメント上のどこも指していないことを表す
82 public static readonly TextPoint Null = new TextPoint(-1,-1);
87 /// <param name="row">行番号</param>
88 /// <param name="col">桁</param>
89 public TextPoint(int row, int col)
98 /// <param name="a">比較される方</param>
99 /// <param name="b">比較対象</param>
100 /// <returns>条件を満たすなら真</returns>
101 public static bool operator <(TextPoint a, TextPoint b)
103 return a.CompareTo(b) == -1;
109 /// <param name="a">比較される方</param>
110 /// <param name="b">比較対象</param>
111 /// <returns>条件を満たすなら真</returns>
112 public static bool operator <=(TextPoint a, TextPoint b)
114 return a.CompareTo(b) != 1;
120 /// <param name="a">比較される方</param>
121 /// <param name="b">比較対象</param>
122 /// <returns>条件を満たすなら真</returns>
123 public static bool operator >(TextPoint a, TextPoint b)
125 return a.CompareTo(b) == 1;
131 /// <param name="a">比較される方</param>
132 /// <param name="b">比較対象</param>
133 /// <returns>条件を満たすなら真</returns>
134 public static bool operator >=(TextPoint a, TextPoint b)
136 return a.CompareTo(b) != -1;
142 /// <param name="a">比較される方</param>
143 /// <param name="b">比較対象</param>
144 /// <returns>条件を満たすなら真</returns>
145 public static bool operator ==(TextPoint a, TextPoint b)
153 /// <param name="a">比較される方</param>
154 /// <param name="b">比較対象</param>
155 /// <returns>条件を満たすなら真</returns>
156 public static bool operator !=(TextPoint a, TextPoint b)
164 /// <param name="o">比較対象</param>
165 /// <returns>一致するなら真</returns>
166 public override bool Equals(object o)
168 TextPoint b = (TextPoint)o;
169 return this.col == b.col && this.row == b.row;
175 /// <returns>ハッシュを返す</returns>
176 public override int GetHashCode()
178 int result = this.row.GetHashCode();
179 result ^= this.col.GetHashCode();
183 #region IComparable<TextPoint> メンバー
188 /// <param name="other">比較対象となるTextPointオブジェクト</param>
189 /// <returns>相対値を返す</returns>
190 public int CompareTo(TextPoint other)
192 if (this.row == other.row && this.col == other.col)
194 if (this.row < other.row)
196 else if (this.row == other.row && this.col < other.col)
208 public struct TextRectangle
212 TextPoint _BottomRight;
215 /// 矩形エリアがドキュメントのどこも指していないことを表す
217 public static readonly TextRectangle Null = new TextRectangle(new TextPoint(-1,-1),new TextPoint(-1,-1));
222 public TextPoint TopLeft
226 return this._TopLeft;
233 public TextPoint TopRight
237 return new TextPoint(this._TopLeft.row, this._BottomRight.col);
244 public TextPoint BottomLeft
248 return new TextPoint(this._BottomRight.row, this._TopLeft.col);
255 public TextPoint BottomRight
259 return this._BottomRight;
266 /// <param name="row">行</param>
267 /// <param name="col">桁</param>
268 /// <param name="height">高さ</param>
269 /// <param name="width">幅</param>
270 public TextRectangle(int row, int col, int height,int width)
272 this._TopLeft = new TextPoint(row, col);
273 this._BottomRight = new TextPoint(row + height - 1, col + width - 1);
279 /// <param name="topLeft">矩形の左上</param>
280 /// <param name="bottomRight">矩形の右下</param>
281 public TextRectangle(TextPoint topLeft, TextPoint bottomRight)
283 this._TopLeft = topLeft;
284 this._BottomRight = bottomRight;
290 /// <param name="a">比較される方</param>
291 /// <param name="b">比較対象</param>
292 /// <returns>条件を満たすなら真</returns>
293 public static bool operator ==(TextRectangle a, TextRectangle b)
301 /// <param name="a">比較される方</param>
302 /// <param name="b">比較対象</param>
303 /// <returns>条件を満たすなら真</returns>
304 public static bool operator !=(TextRectangle a, TextRectangle b)
312 /// <param name="o">比較対象</param>
313 /// <returns>一致するなら真</returns>
314 public override bool Equals(object o)
316 TextRectangle b = (TextRectangle)o;
317 return this._TopLeft == b._TopLeft && this._BottomRight == b._BottomRight;
323 /// <returns>ハッシュを返す</returns>
324 public override int GetHashCode()
326 int result = this._TopLeft.GetHashCode();
327 result ^= this._BottomRight.GetHashCode();