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)
108 public static implicit operator Point(System.Drawing.Point p)
110 return new Point(p.X, p.Y);
112 public static implicit operator System.Drawing.Point(Point p)
114 return new System.Drawing.Point((int)p.X, (int)p.Y);
116 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
118 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
122 public static implicit operator Point(System.Windows.Point p)
124 return new Point(p.X, p.Y);
126 public static implicit operator System.Windows.Point(Point p)
128 return new System.Windows.Point(p.X, p.Y);
130 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
132 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
135 #if METRO || WINDOWS_UWP
136 public static implicit operator Point(Windows.Foundation.Point p)
138 return new Point(p.X, p.Y);
140 public static implicit operator Windows.Foundation.Point(Point p)
142 return new Windows.Foundation.Point(p.X, p.Y);
144 public static implicit operator SharpDX.Mathematics.Interop.RawVector2(Point p)
146 return new SharpDX.Mathematics.Interop.RawVector2((float)p.X, (float)p.Y);
153 public double Height;
154 public Size(double width, double height)
157 this.Height = height;
163 /// <param name="a">比較される方</param>
164 /// <param name="b">比較対象</param>
165 /// <returns>条件を満たすなら真</returns>
166 public static bool operator ==(Size a, Size b)
174 /// <param name="a">比較される方</param>
175 /// <param name="b">比較対象</param>
176 /// <returns>条件を満たすなら真</returns>
177 public static bool operator !=(Size a, Size b)
185 /// <param name="o">比較対象</param>
186 /// <returns>一致するなら真</returns>
187 public override bool Equals(object o)
190 return this.Width == b.Width && this.Height == b.Height;
196 /// <returns>ハッシュを返す</returns>
197 public override int GetHashCode()
199 int result = this.Height.GetHashCode();
200 result ^= this.Width.GetHashCode();
204 public static implicit operator Size(System.Drawing.Size p)
206 return new Size(p.Width, p.Height);
208 public static implicit operator System.Drawing.Size(Size p)
210 return new System.Drawing.Size((int)p.Width, (int)p.Height);
214 public static implicit operator Size(System.Windows.Size p)
216 return new Size(p.Width, p.Height);
218 public static implicit operator System.Windows.Size(Size p)
220 return new System.Windows.Size(p.Width, p.Height);
223 #if METRO || WINDOWS_UWP
224 public static implicit operator Size(Windows.Foundation.Size p)
226 return new Size(p.Width, p.Height);
228 public static implicit operator Windows.Foundation.Size(Size p)
230 return new Windows.Foundation.Size(p.Width, p.Height);
236 public Point Location;
240 get { return this.Location; }
242 public Point TopRight
244 get { return new Point(this.Right, this.Location.Y); }
246 public Point BottomLeft
248 get { return new Point(this.Location.X, this.Bottom); }
250 public Point BottomRight
252 get { return new Point(this.Right, this.Bottom); }
256 get { return this.X + this.Width; }
260 get { return this.Y + this.Height; }
264 get { return this.Size.Height; }
265 set { this.Size.Height = value; }
269 get { return this.Size.Width; }
270 set { this.Size.Width = value; }
274 get { return this.Location.X; }
278 get { return this.Location.Y; }
280 public Rectangle(double x, double y, double width, double height)
282 this.Location = new Point(x, y);
283 this.Size = new Size(width, height);
285 public Rectangle(Point leftTop, Point bottomRight)
287 this.Location = leftTop;
288 this.Size = new Size(bottomRight.X - leftTop.X, bottomRight.Y - leftTop.Y);
294 public static Rectangle Empty = new Rectangle(0, 0, 0, 0);
297 /// 任意の点が領域内にあるなら真を返す
299 /// <param name="p"></param>
300 /// <returns></returns>
301 public bool IsHit(Point p)
303 if (p.X >= this.TopLeft.X &&
304 p.Y >= this.TopLeft.Y &&
305 p.X <= this.BottomRight.X &&
306 p.Y <= this.BottomRight.Y)
314 /// <param name="a">比較される方</param>
315 /// <param name="b">比較対象</param>
316 /// <returns>条件を満たすなら真</returns>
317 public static bool operator ==(Rectangle a, Rectangle b)
325 /// <param name="a">比較される方</param>
326 /// <param name="b">比較対象</param>
327 /// <returns>条件を満たすなら真</returns>
328 public static bool operator !=(Rectangle a, Rectangle b)
336 /// <param name="o">比較対象</param>
337 /// <returns>一致するなら真</returns>
338 public override bool Equals(object o)
340 Rectangle b = (Rectangle)o;
341 return this.Location.Equals(b.Location) && this.Size.Equals(b.Size);
347 /// <returns>ハッシュを返す</returns>
348 public override int GetHashCode()
350 int result = this.Location.GetHashCode();
351 result ^= this.Size.GetHashCode();
355 public static implicit operator Rectangle(System.Drawing.Rectangle p)
357 return new Rectangle(p.X,p.Y,p.Width,p.Height);
359 public static implicit operator System.Drawing.Rectangle(Rectangle p)
361 return new System.Drawing.Rectangle((int)p.X, (int)p.Y, (int)p.Width, (int)p.Height);
363 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
365 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
369 public static implicit operator Rectangle(System.Windows.Rect p)
371 return new Rectangle(p.X,p.Y,p.Width,p.Height);
373 public static implicit operator System.Windows.Rect(Rectangle p)
375 return new System.Windows.Rect(p.X, p.Y, p.Width, p.Height);
377 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
379 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
382 #if METRO || WINDOWS_UWP
383 public static implicit operator Rectangle(Windows.Foundation.Rect p)
385 return new Rectangle(p.X, p.Y, p.Width, p.Height);
387 public static implicit operator Windows.Foundation.Rect(Rectangle p)
389 return new Windows.Foundation.Rect(p.X, p.Y, p.Width, p.Height);
392 public static implicit operator SharpDX.Mathematics.Interop.RawRectangleF(Rectangle p)
394 return new SharpDX.Mathematics.Interop.RawRectangleF((float)p.X, (float)p.Y, (float)p.BottomRight.X, (float)p.BottomRight.Y);
401 public struct Color: IEqualityComparer<Color>
423 /// <param name="a">A成分</param>
424 /// <param name="r">R成分</param>
425 /// <param name="g">G成分</param>
426 /// <param name="b">B成分</param>
427 public Color(byte a = 255, byte r = 0, byte g = 0, byte b = 0)
438 /// <param name="x">比較される方</param>
439 /// <param name="y">比較する方</param>
440 /// <returns>等しいなら真。そうでなければ偽</returns>
441 public bool Equals(Color x, Color y)
443 return x.A == y.A && x.R == y.R && x.G == y.G && x.B == y.B;
449 /// <param name="obj">Colorオブジェクト</param>
450 /// <returns>ハッシュ</returns>
451 public int GetHashCode(Color obj)
453 return this.A ^ this.R ^ this.B ^ this.G;
459 /// <param name="o">比較対象</param>
460 /// <returns>一致するなら真</returns>
461 public override bool Equals(object o)
464 return this.Equals(this,b);
470 /// <returns>ハッシュを返す</returns>
471 public override int GetHashCode()
473 return this.GetHashCode(this);
501 class ChangedRenderRsourceEventArgs : EventArgs
503 public ResourceType type;
504 public ChangedRenderRsourceEventArgs(ResourceType type)
509 delegate void ChangedRenderResourceEventHandler(object sender, ChangedRenderRsourceEventArgs e);
510 interface ITextRender
515 bool RightToLeft { get; set; }
520 Rectangle TextArea { get; set; }
525 double LineNemberWidth { get; }
530 int TabWidthChar { get; set; }
535 bool ShowFullSpace { get; set; }
540 bool ShowHalfSpace { get; set; }
545 bool ShowTab { get; set; }
550 bool ShowLineBreak { get; set; }
558 /// 保持しているリソースに変化があったことを通知する
560 event ChangedRenderResourceEventHandler ChangedRenderResource;
563 /// RightToLeftの値が変わったことを通知する
565 event EventHandler ChangedRightToLeft;
570 /// <param name="str">文字列</param>
571 /// <param name="x">x座標</param>
572 /// <param name="y">y座標</param>
573 /// <param name="align">書式方向</param>
574 /// <param name="layoutRect">レイアウト領域</param>
575 /// <param name="colorType">色</param>
576 void DrawString(string str, double x, double y, StringAlignment align, Size layoutRect,StringColorType colorType = StringColorType.Forground);
581 /// <param name="lti">LineToIndexオブジェクト</param>
582 /// <param name="row">行</param>
583 /// <param name="x">行の左上を表すX座標</param>
584 /// <param name="y">行の左上を表すY座標</param>
585 /// <param name="SelectRanges">選択領域を保持しているコレクション。選択領域の開始位置は行の先頭を0とする相対位置としてください(位置が-1の場合表示されません)</param>
586 void DrawOneLine(LineToIndexTable lti, int row, double x, double y, IEnumerable<Selection> SelectRanges);
591 /// <param name="doc">ドキュメント</param>
592 /// <param name="layoutLineCollection">レイアウトライン</param>
593 /// <param name="startIndex">開始インデックス</param>
594 /// <param name="endIndex">終了インデックス</param>
595 /// <param name="wrapwidth">折り返しの幅</param>
596 /// <returns>行のリスト</returns>
597 List<LineToIndexTableData> BreakLine(Document doc,LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth);
602 /// <param name="str">文字列</param>
603 /// <returns>ITextLayoutオブジェクト</returns>
604 /// <param name="syntaxCollection">ハイライト関連の情報を保持しているコレクション</param>
605 /// <param name="MarkerRanges">マーカーを保持しているコレクション。マーカーの開始位置は行の先頭を0とする相対位置としてください(位置が-1の場合表示しないこと)</param>
606 ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable<Marker> MarkerRanges);
611 /// <param name="p">中心点</param>
612 /// <param name="radius">半径</param>
613 void DrawGripper(Point p, double radius);
618 /// <param name="rect">クリッピングする範囲</param>
619 void BeginClipRect(Rectangle rect);
626 interface IEditorRender : ITextRender
631 double FoldingWidth { get; }
634 /// キャッシュされたビットマップを描写する
636 /// <param name="rect">描く領域</param>
637 void DrawCachedBitmap(Rectangle rect);
642 /// <param name="from">開始座標</param>
643 /// <param name="to">修了座標</param>
644 void DrawLine(Point from, Point to);
652 /// キャッシュが存在するなら真を返し、そうでないなら偽を返す
659 /// <param name="rect"></param>
660 /// <param name="type"></param>
661 void FillRectangle(Rectangle rect,FillRectType type);
666 /// <param name="expand">展開済みなら真</param>
667 /// <param name="x">x座標</param>
668 /// <param name="y">y座標</param>
669 void DrawFoldingMark(bool expand, double x, double y);
674 /// <param name="rect">塗りつぶすべき領域</param>
675 void FillBackground(Rectangle rect);
684 interface IPrintableTextRender : ITextRender
689 float HeaderHeight { get; }
694 float FooterHeight { get; }