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/>.
12 using System.Collections.Generic;
14 namespace FooEditEngine
20 public Point(double x, double y)
28 /// <param name="a">比較される方</param>
29 /// <param name="b">比較対象</param>
30 /// <returns>条件を満たすなら真</returns>
31 public static bool operator ==(Point a, Point b)
39 /// <param name="a">比較される方</param>
40 /// <param name="b">比較対象</param>
41 /// <returns>条件を満たすなら真</returns>
42 public static bool operator !=(Point a, Point b)
50 /// <param name="o">比較対象</param>
51 /// <returns>一致するなら真</returns>
52 public override bool Equals(object o)
55 return this.X == b.X && this.Y == b.Y;
61 /// <returns>ハッシュを返す</returns>
62 public override int GetHashCode()
64 int result = this.X.GetHashCode();
65 result ^= this.Y.GetHashCode();
69 public Point Scale(double scale)
76 public Point Offset(double x_offset, double y_offset)
83 public static implicit operator Point(System.Drawing.Point p)
85 return new Point(p.X, p.Y);
87 public static implicit operator System.Drawing.Point(Point p)
89 return new System.Drawing.Point((int)p.X, (int)p.Y);
91 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
93 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
97 public static implicit operator Point(System.Windows.Point p)
99 return new Point(p.X, p.Y);
101 public static implicit operator System.Windows.Point(Point p)
103 return new System.Windows.Point(p.X, p.Y);
105 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
107 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
110 #if METRO || WINDOWS_UWP
111 public static implicit operator Point(Windows.Foundation.Point p)
113 return new Point(p.X, p.Y);
115 public static implicit operator Windows.Foundation.Point(Point p)
117 return new Windows.Foundation.Point(p.X, p.Y);
119 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
121 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
128 public double Height;
129 public Size(double width, double height)
132 this.Height = height;
138 /// <param name="a">比較される方</param>
139 /// <param name="b">比較対象</param>
140 /// <returns>条件を満たすなら真</returns>
141 public static bool operator ==(Size a, Size b)
149 /// <param name="a">比較される方</param>
150 /// <param name="b">比較対象</param>
151 /// <returns>条件を満たすなら真</returns>
152 public static bool operator !=(Size a, Size b)
160 /// <param name="o">比較対象</param>
161 /// <returns>一致するなら真</returns>
162 public override bool Equals(object o)
165 return this.Width == b.Width && this.Height == b.Height;
171 /// <returns>ハッシュを返す</returns>
172 public override int GetHashCode()
174 int result = this.Height.GetHashCode();
175 result ^= this.Width.GetHashCode();
179 public static implicit operator Size(System.Drawing.Size p)
181 return new Size(p.Width, p.Height);
183 public static implicit operator System.Drawing.Size(Size p)
185 return new System.Drawing.Size((int)p.Width, (int)p.Height);
189 public static implicit operator Size(System.Windows.Size p)
191 return new Size(p.Width, p.Height);
193 public static implicit operator System.Windows.Size(Size p)
195 return new System.Windows.Size(p.Width, p.Height);
198 #if METRO || WINDOWS_UWP
199 public static implicit operator Size(Windows.Foundation.Size p)
201 return new Size(p.Width, p.Height);
203 public static implicit operator Windows.Foundation.Size(Size p)
205 return new Windows.Foundation.Size(p.Width, p.Height);
211 public Point Location;
215 get { return this.Location; }
217 public Point TopRight
219 get { return new Point(this.Right, this.Location.Y); }
221 public Point BottomLeft
223 get { return new Point(this.Location.X, this.Bottom); }
225 public Point BottomRight
227 get { return new Point(this.Right, this.Bottom); }
231 get { return this.X + this.Width; }
235 get { return this.Y + this.Height; }
239 get { return this.Size.Height; }
240 set { this.Size.Height = value; }
244 get { return this.Size.Width; }
245 set { this.Size.Width = value; }
249 get { return this.Location.X; }
253 get { return this.Location.Y; }
255 public Rectangle(double x, double y, double width, double height)
257 this.Location = new Point(x, y);
258 this.Size = new Size(width, height);
260 public Rectangle(Point leftTop, Point bottomRight)
262 this.Location = leftTop;
263 this.Size = new Size(bottomRight.X - leftTop.X, bottomRight.Y - leftTop.Y);
269 public static Rectangle Empty = new Rectangle(0, 0, 0, 0);
272 /// 任意の点が領域内にあるなら真を返す
274 /// <param name="p"></param>
275 /// <returns></returns>
276 public bool IsHit(Point p)
278 if (p.X >= this.TopLeft.X &&
279 p.Y >= this.TopLeft.Y &&
280 p.X <= this.BottomRight.X &&
281 p.Y <= this.BottomRight.Y)
289 /// <param name="a">比較される方</param>
290 /// <param name="b">比較対象</param>
291 /// <returns>条件を満たすなら真</returns>
292 public static bool operator ==(Rectangle a, Rectangle b)
300 /// <param name="a">比較される方</param>
301 /// <param name="b">比較対象</param>
302 /// <returns>条件を満たすなら真</returns>
303 public static bool operator !=(Rectangle a, Rectangle b)
311 /// <param name="o">比較対象</param>
312 /// <returns>一致するなら真</returns>
313 public override bool Equals(object o)
315 Rectangle b = (Rectangle)o;
316 return this.Location.Equals(b.Location) && this.Size.Equals(b.Size);
322 /// <returns>ハッシュを返す</returns>
323 public override int GetHashCode()
325 int result = this.Location.GetHashCode();
326 result ^= this.Size.GetHashCode();
330 public static implicit operator Rectangle(System.Drawing.Rectangle p)
332 return new Rectangle(p.X,p.Y,p.Width,p.Height);
334 public static implicit operator System.Drawing.Rectangle(Rectangle p)
336 return new System.Drawing.Rectangle((int)p.X, (int)p.Y, (int)p.Width, (int)p.Height);
338 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
340 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
344 public static implicit operator Rectangle(System.Windows.Rect p)
346 return new Rectangle(p.X,p.Y,p.Width,p.Height);
348 public static implicit operator System.Windows.Rect(Rectangle p)
350 return new System.Windows.Rect(p.X, p.Y, p.Width, p.Height);
352 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
354 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
357 #if METRO || WINDOWS_UWP
358 public static implicit operator Rectangle(Windows.Foundation.Rect p)
360 return new Rectangle(p.X, p.Y, p.Width, p.Height);
362 public static implicit operator Windows.Foundation.Rect(Rectangle p)
364 return new Windows.Foundation.Rect(p.X, p.Y, p.Width, p.Height);
367 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
369 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
376 public struct Color: IEqualityComparer<Color>
398 /// <param name="a">A成分</param>
399 /// <param name="r">R成分</param>
400 /// <param name="g">G成分</param>
401 /// <param name="b">B成分</param>
402 public Color(byte a = 255, byte r = 0, byte g = 0, byte b = 0)
413 /// <param name="x">比較される方</param>
414 /// <param name="y">比較する方</param>
415 /// <returns>等しいなら真。そうでなければ偽</returns>
416 public bool Equals(Color x, Color y)
418 return x.A == y.A && x.R == y.R && x.G == y.G && x.B == y.B;
424 /// <param name="obj">Colorオブジェクト</param>
425 /// <returns>ハッシュ</returns>
426 public int GetHashCode(Color obj)
428 return this.A ^ this.R ^ this.B ^ this.G;
434 /// <param name="o">比較対象</param>
435 /// <returns>一致するなら真</returns>
436 public override bool Equals(object o)
439 return this.Equals(this,b);
445 /// <returns>ハッシュを返す</returns>
446 public override int GetHashCode()
448 return this.GetHashCode(this);
476 class ChangedRenderRsourceEventArgs : EventArgs
478 public ResourceType type;
479 public ChangedRenderRsourceEventArgs(ResourceType type)
484 delegate void ChangedRenderResourceEventHandler(object sender, ChangedRenderRsourceEventArgs e);
485 interface ITextRender
490 bool RightToLeft { get; set; }
495 Rectangle TextArea { get; set; }
500 double LineNemberWidth { get; }
505 int TabWidthChar { get; set; }
510 bool ShowFullSpace { get; set; }
515 bool ShowHalfSpace { get; set; }
520 bool ShowTab { get; set; }
525 bool ShowLineBreak { get; set; }
533 /// 保持しているリソースに変化があったことを通知する
535 event ChangedRenderResourceEventHandler ChangedRenderResource;
538 /// RightToLeftの値が変わったことを通知する
540 event EventHandler ChangedRightToLeft;
545 /// <param name="str">文字列</param>
546 /// <param name="x">x座標</param>
547 /// <param name="y">y座標</param>
548 /// <param name="align">書式方向</param>
549 /// <param name="layoutRect">レイアウト領域</param>
550 /// <param name="colorType">色</param>
551 void DrawString(string str, double x, double y, StringAlignment align, Size layoutRect,StringColorType colorType = StringColorType.Forground);
556 /// <param name="lti">LineToIndexオブジェクト</param>
557 /// <param name="row">行</param>
558 /// <param name="x">行の左上を表すX座標</param>
559 /// <param name="y">行の左上を表すY座標</param>
560 /// <param name="SelectRanges">選択領域を保持しているコレクション。選択領域の開始位置は行の先頭を0とする相対位置としてください(位置が-1の場合表示されません)</param>
561 void DrawOneLine(LineToIndexTable lti, int row, double x, double y, IEnumerable<Selection> SelectRanges);
566 /// <param name="doc">ドキュメント</param>
567 /// <param name="layoutLineCollection">レイアウトライン</param>
568 /// <param name="startIndex">開始インデックス</param>
569 /// <param name="endIndex">終了インデックス</param>
570 /// <param name="wrapwidth">折り返しの幅</param>
571 /// <returns>行のリスト</returns>
572 List<LineToIndexTableData> BreakLine(Document doc,LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth);
577 /// <param name="str">文字列</param>
578 /// <returns>ITextLayoutオブジェクト</returns>
579 /// <param name="syntaxCollection">ハイライト関連の情報を保持しているコレクション</param>
580 /// <param name="MarkerRanges">マーカーを保持しているコレクション。マーカーの開始位置は行の先頭を0とする相対位置としてください(位置が-1の場合表示しないこと)</param>
581 ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable<Marker> MarkerRanges);
586 /// <param name="p">中心点</param>
587 /// <param name="radius">半径</param>
588 void DrawGripper(Point p, double radius);
593 /// <param name="rect">クリッピングする範囲</param>
594 void BeginClipRect(Rectangle rect);
601 interface IEditorRender : ITextRender
606 double FoldingWidth { get; }
609 /// キャッシュされたビットマップを描写する
611 /// <param name="rect">描く領域</param>
612 void DrawCachedBitmap(Rectangle rect);
617 /// <param name="from">開始座標</param>
618 /// <param name="to">修了座標</param>
619 void DrawLine(Point from, Point to);
627 /// キャッシュが存在するなら真を返し、そうでないなら偽を返す
634 /// <param name="rect"></param>
635 /// <param name="type"></param>
636 void FillRectangle(Rectangle rect,FillRectType type);
641 /// <param name="expand">展開済みなら真</param>
642 /// <param name="x">x座標</param>
643 /// <param name="y">y座標</param>
644 void DrawFoldingMark(bool expand, double x, double y);
649 /// <param name="rect">塗りつぶすべき領域</param>
650 void FillBackground(Rectangle rect);
659 interface IPrintableTextRender : ITextRender
664 float HeaderHeight { get; }
669 float FooterHeight { get; }