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
32 /// <param name="x">X座標</param>
33 /// <param name="y">Y座標</param>
34 public Point(double x, double y)
42 /// <param name="a">比較される方</param>
43 /// <param name="b">比較対象</param>
44 /// <returns>条件を満たすなら真</returns>
45 public static bool operator ==(Point a, Point b)
53 /// <param name="a">比較される方</param>
54 /// <param name="b">比較対象</param>
55 /// <returns>条件を満たすなら真</returns>
56 public static bool operator !=(Point a, Point b)
64 /// <param name="o">比較対象</param>
65 /// <returns>一致するなら真</returns>
66 public override bool Equals(object o)
69 return this.X == b.X && this.Y == b.Y;
75 /// <returns>ハッシュを返す</returns>
76 public override int GetHashCode()
78 int result = this.X.GetHashCode();
79 result ^= this.Y.GetHashCode();
86 /// <param name="scale">倍率</param>
87 /// <returns></returns>
88 public Point Scale(double scale)
98 /// <param name="x_offset">移動量X</param>
99 /// <param name="y_offset">移動量Y</param>
100 /// <returns></returns>
101 public Point Offset(double x_offset, double y_offset)
111 /// <param name="p"></param>
112 public static implicit operator Point(System.Drawing.Point p)
114 return new Point(p.X, p.Y);
119 /// <param name="p"></param>
120 public static implicit operator System.Drawing.Point(Point p)
122 return new System.Drawing.Point((int)p.X, (int)p.Y);
127 /// <param name="p"></param>
128 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
130 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
137 /// <param name="p"></param>
138 public static implicit operator Point(System.Windows.Point p)
140 return new Point(p.X, p.Y);
145 /// <param name="p"></param>
146 public static implicit operator System.Windows.Point(Point p)
148 return new System.Windows.Point(p.X, p.Y);
153 /// <param name="p"></param>
154 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
156 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
159 #if METRO || WINDOWS_UWP
163 /// <param name="p"></param>
164 public static implicit operator Point(Windows.Foundation.Point p)
166 return new Point(p.X, p.Y);
171 /// <param name="p"></param>
172 public static implicit operator Windows.Foundation.Point(Point p)
174 return new Windows.Foundation.Point(p.X, p.Y);
179 /// <param name="p"></param>
180 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
182 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
189 public double Height;
190 public Size(double width, double height)
193 this.Height = height;
199 /// <param name="a">比較される方</param>
200 /// <param name="b">比較対象</param>
201 /// <returns>条件を満たすなら真</returns>
202 public static bool operator ==(Size a, Size b)
210 /// <param name="a">比較される方</param>
211 /// <param name="b">比較対象</param>
212 /// <returns>条件を満たすなら真</returns>
213 public static bool operator !=(Size a, Size b)
221 /// <param name="o">比較対象</param>
222 /// <returns>一致するなら真</returns>
223 public override bool Equals(object o)
226 return this.Width == b.Width && this.Height == b.Height;
232 /// <returns>ハッシュを返す</returns>
233 public override int GetHashCode()
235 int result = this.Height.GetHashCode();
236 result ^= this.Width.GetHashCode();
240 public static implicit operator Size(System.Drawing.Size p)
242 return new Size(p.Width, p.Height);
244 public static implicit operator System.Drawing.Size(Size p)
246 return new System.Drawing.Size((int)p.Width, (int)p.Height);
250 public static implicit operator Size(System.Windows.Size p)
252 return new Size(p.Width, p.Height);
254 public static implicit operator System.Windows.Size(Size p)
256 return new System.Windows.Size(p.Width, p.Height);
259 #if METRO || WINDOWS_UWP
260 public static implicit operator Size(Windows.Foundation.Size p)
262 return new Size(p.Width, p.Height);
264 public static implicit operator Windows.Foundation.Size(Size p)
266 return new Windows.Foundation.Size(p.Width, p.Height);
272 public Point Location;
276 get { return this.Location; }
278 public Point TopRight
280 get { return new Point(this.Right, this.Location.Y); }
282 public Point BottomLeft
284 get { return new Point(this.Location.X, this.Bottom); }
286 public Point BottomRight
288 get { return new Point(this.Right, this.Bottom); }
292 get { return this.X + this.Width; }
296 get { return this.Y + this.Height; }
300 get { return this.Size.Height; }
301 set { this.Size.Height = value; }
305 get { return this.Size.Width; }
306 set { this.Size.Width = value; }
310 get { return this.Location.X; }
314 get { return this.Location.Y; }
316 public Rectangle(double x, double y, double width, double height)
318 this.Location = new Point(x, y);
319 this.Size = new Size(width, height);
321 public Rectangle(Point leftTop, Point bottomRight)
323 this.Location = leftTop;
324 this.Size = new Size(bottomRight.X - leftTop.X, bottomRight.Y - leftTop.Y);
330 public static Rectangle Empty = new Rectangle(0, 0, 0, 0);
333 /// 任意の点が領域内にあるなら真を返す
335 /// <param name="p"></param>
336 /// <returns></returns>
337 public bool IsHit(Point p)
339 if (p.X >= this.TopLeft.X &&
340 p.Y >= this.TopLeft.Y &&
341 p.X <= this.BottomRight.X &&
342 p.Y <= this.BottomRight.Y)
350 /// <param name="a">比較される方</param>
351 /// <param name="b">比較対象</param>
352 /// <returns>条件を満たすなら真</returns>
353 public static bool operator ==(Rectangle a, Rectangle b)
361 /// <param name="a">比較される方</param>
362 /// <param name="b">比較対象</param>
363 /// <returns>条件を満たすなら真</returns>
364 public static bool operator !=(Rectangle a, Rectangle b)
372 /// <param name="o">比較対象</param>
373 /// <returns>一致するなら真</returns>
374 public override bool Equals(object o)
376 Rectangle b = (Rectangle)o;
377 return this.Location.Equals(b.Location) && this.Size.Equals(b.Size);
383 /// <returns>ハッシュを返す</returns>
384 public override int GetHashCode()
386 int result = this.Location.GetHashCode();
387 result ^= this.Size.GetHashCode();
391 public static implicit operator Rectangle(System.Drawing.Rectangle p)
393 return new Rectangle(p.X,p.Y,p.Width,p.Height);
395 public static implicit operator System.Drawing.Rectangle(Rectangle p)
397 return new System.Drawing.Rectangle((int)p.X, (int)p.Y, (int)p.Width, (int)p.Height);
399 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
401 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
405 public static implicit operator Rectangle(System.Windows.Rect p)
407 return new Rectangle(p.X,p.Y,p.Width,p.Height);
409 public static implicit operator System.Windows.Rect(Rectangle p)
411 return new System.Windows.Rect(p.X, p.Y, p.Width, p.Height);
413 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
415 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
418 #if METRO || WINDOWS_UWP
419 public static implicit operator Rectangle(Windows.Foundation.Rect p)
421 return new Rectangle(p.X, p.Y, p.Width, p.Height);
423 public static implicit operator Windows.Foundation.Rect(Rectangle p)
425 return new Windows.Foundation.Rect(p.X, p.Y, p.Width, p.Height);
428 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
430 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
437 public struct Color: IEqualityComparer<Color>
459 /// <param name="a">A成分</param>
460 /// <param name="r">R成分</param>
461 /// <param name="g">G成分</param>
462 /// <param name="b">B成分</param>
463 public Color(byte a = 255, byte r = 0, byte g = 0, byte b = 0)
474 /// <param name="x">比較される方</param>
475 /// <param name="y">比較する方</param>
476 /// <returns>等しいなら真。そうでなければ偽</returns>
477 public bool Equals(Color x, Color y)
479 return x.A == y.A && x.R == y.R && x.G == y.G && x.B == y.B;
485 /// <param name="obj">Colorオブジェクト</param>
486 /// <returns>ハッシュ</returns>
487 public int GetHashCode(Color obj)
489 return this.A ^ this.R ^ this.B ^ this.G;
495 /// <param name="o">比較対象</param>
496 /// <returns>一致するなら真</returns>
497 public override bool Equals(object o)
500 return this.Equals(this,b);
506 /// <returns>ハッシュを返す</returns>
507 public override int GetHashCode()
509 return this.GetHashCode(this);
537 class ChangedRenderRsourceEventArgs : EventArgs
539 public ResourceType type;
540 public ChangedRenderRsourceEventArgs(ResourceType type)
545 delegate void ChangedRenderResourceEventHandler(object sender, ChangedRenderRsourceEventArgs e);
546 interface ITextRender
551 bool RightToLeft { get; set; }
556 Rectangle TextArea { get; set; }
561 double LineNemberWidth { get; }
566 int TabWidthChar { get; set; }
571 bool ShowFullSpace { get; set; }
576 bool ShowHalfSpace { get; set; }
581 bool ShowTab { get; set; }
586 bool ShowLineBreak { get; set; }
594 /// 保持しているリソースに変化があったことを通知する
596 event ChangedRenderResourceEventHandler ChangedRenderResource;
599 /// RightToLeftの値が変わったことを通知する
601 event EventHandler ChangedRightToLeft;
606 /// <param name="str">文字列</param>
607 /// <param name="x">x座標</param>
608 /// <param name="y">y座標</param>
609 /// <param name="align">書式方向</param>
610 /// <param name="layoutRect">レイアウト領域</param>
611 /// <param name="colorType">色</param>
612 void DrawString(string str, double x, double y, StringAlignment align, Size layoutRect,StringColorType colorType = StringColorType.Forground);
617 /// <param name="doc">ドキュメントオブジェクト</param>
618 /// <param name="lti">LineToIndexオブジェクト</param>
619 /// <param name="row">行</param>
620 /// <param name="x">行の左上を表すX座標</param>
621 /// <param name="y">行の左上を表すY座標</param>
622 void DrawOneLine(Document doc,LineToIndexTable lti, int row, double x, double y);
627 /// <param name="str">文字列</param>
628 /// <returns>ITextLayoutオブジェクト</returns>
629 /// <param name="syntaxCollection">ハイライト関連の情報を保持しているコレクション</param>
630 /// <param name="MarkerRanges">マーカーを保持しているコレクション。マーカーの開始位置は行の先頭を0とする相対位置としてください(位置が-1の場合表示しないこと)</param>
631 /// <param name="Selections">選択領域を保持しているコレクション。マーカーの開始位置は行の先頭を0とする相対位置としてください(位置が-1の場合表示しないこと)</param>
632 /// <param name="WrapWidth">折り返しの幅</param>
633 ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable<Marker> MarkerRanges, IEnumerable<Selection> Selections,double WrapWidth);
638 /// <param name="p">中心点</param>
639 /// <param name="radius">半径</param>
640 void DrawGripper(Point p, double radius);
645 /// <param name="rect">クリッピングする範囲</param>
646 void BeginClipRect(Rectangle rect);
653 interface IEditorRender : ITextRender
658 double FoldingWidth { get; }
661 /// キャッシュされたビットマップを描写する
663 /// <param name="rect">描く領域</param>
664 void DrawCachedBitmap(Rectangle rect);
669 /// <param name="from">開始座標</param>
670 /// <param name="to">修了座標</param>
671 void DrawLine(Point from, Point to);
679 /// キャッシュが存在するなら真を返し、そうでないなら偽を返す
686 /// <param name="rect"></param>
687 /// <param name="type"></param>
688 void FillRectangle(Rectangle rect,FillRectType type);
693 /// <param name="expand">展開済みなら真</param>
694 /// <param name="x">x座標</param>
695 /// <param name="y">y座標</param>
696 void DrawFoldingMark(bool expand, double x, double y);
701 /// <param name="rect">塗りつぶすべき領域</param>
702 void FillBackground(Rectangle rect);
711 interface IPrintableTextRender : ITextRender
716 float HeaderHeight { get; }
721 float FooterHeight { get; }