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 using System.Collections.Generic;
14 using System.Globalization;
16 using System.Reflection;
17 using System.Collections;
19 namespace FooEditEngine
23 #if METRO || WINDOWS_UWP
24 public static void GetDpi(out float dpix, out float dpiy)
26 dpix = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
27 dpiy = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
30 public static double GetScale()
33 Util.GetDpi(out dpi, out dpi);
37 public static Point GetClientPoint(Point screen, Windows.UI.Xaml.UIElement element)
39 //Windows10以降では補正する必要がある
40 Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
41 screen = screen.Offset(-win_rect.X, -win_rect.Y);
43 var gt = Windows.UI.Xaml.Window.Current.Content.TransformToVisual(element);
44 return gt.TransformPoint(screen);
47 public static Point GetPointInWindow(Point client, Windows.UI.Xaml.UIElement element)
50 var gt = element.TransformToVisual(null);
51 return gt.TransformPoint(client);
54 public static Point GetScreentPoint(Point client, Windows.UI.Xaml.UIElement element)
57 Point screenPoint = GetPointInWindow(client, element);
59 //Windows10以降では補正する必要がある
60 Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
61 screenPoint = screenPoint.Offset(win_rect.X, win_rect.Y);
65 public static Windows.Foundation.Rect GetClientRect(Windows.Foundation.Rect screen, Windows.UI.Xaml.UIElement element)
67 //Windows10以降では補正する必要がある
68 Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
69 screen.X -= win_rect.X;
70 screen.Y -= win_rect.Y;
72 var gt = Windows.UI.Xaml.Window.Current.Content.TransformToVisual(element);
73 return gt.TransformBounds(screen);
75 public static Windows.Foundation.Rect GetScreentRect(Windows.Foundation.Rect client, Windows.UI.Xaml.UIElement element)
78 var gt = element.TransformToVisual(null);
79 Windows.Foundation.Rect screenRect = gt.TransformBounds(client);
81 //Windows10以降では補正する必要がある
82 Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
83 screenRect.X += win_rect.X;
84 screenRect.Y += win_rect.Y;
88 public static IEnumerable<char> GetEnumrator(string s)
90 char[] chars = s.ToCharArray();
94 public static IEnumerable<char> GetEnumrator(string s)
100 public static T ConvertAbsIndexToRelIndex<T>(T n, int StartIndex, int Length) where T : IRange
102 n = Util.NormalizeIMaker<T>(n);
104 int markerEnd = n.start + n.length - 1;
106 int EndIndex = StartIndex + Length;
108 if (n.start >= StartIndex && markerEnd <= EndIndex)
109 n.start -= StartIndex;
110 else if (n.start >= StartIndex && n.start <= EndIndex)
112 n.start -= StartIndex;
113 n.length = EndIndex - StartIndex + 1;
115 else if (markerEnd >= StartIndex && markerEnd <= EndIndex)
118 n.length = markerEnd - StartIndex + 1;
120 else if (n.start >= StartIndex && markerEnd <= EndIndex)
121 n.start -= StartIndex;
122 else if (n.start <= StartIndex && markerEnd > EndIndex)
125 n.length = EndIndex - StartIndex + 1;
135 public static bool IsWordSeparator(char c)
137 if (c == Document.NewLine || char.IsSeparator(c) || char.IsPunctuation(c) || CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.MathSymbol)
142 public static void Swap<T>(ref T a, ref T b)
149 public static string Generate(char c, int count)
151 StringBuilder tabstr = new StringBuilder();
152 for (int j = count; j > 0; j--)
154 return tabstr.ToString();
157 public static Rectangle OffsetAndDeflate(Rectangle r, Size s)
159 return new Rectangle(r.X + s.Width,r.Y + s.Height, r.Width - s.Width, r.Height - s.Height);
162 public static T NormalizeIMaker<T>(T m) where T : IRange
166 m.start = m.start + m.length;
167 m.length = Math.Abs(m.length);
171 public static int RoundUp(double x)
173 return (int)(x + 0.5);