using System.Collections.Generic;
using System.Globalization;
using System.Text;
+using System.Reflection;
+using System.Collections;
namespace FooEditEngine
{
class Util
{
-#if METRO
- public static Windows.Foundation.Point GetClientPoint(Windows.Foundation.Point screen, Windows.UI.Xaml.UIElement element)
+#if METRO || WINDOWS_UWP
+ public static void GetDpi(out float dpix, out float dpiy)
{
- var gt = element.TransformToVisual(element);
+ dpix = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
+ dpiy = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
+ }
+
+ public static double GetScale()
+ {
+ float dpi;
+ Util.GetDpi(out dpi, out dpi);
+ return dpi / 96.0;
+ }
+
+ public static Point GetClientPoint(Point screen, Windows.UI.Xaml.UIElement element)
+ {
+ //Windows10以降では補正する必要がある
+ Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
+ screen = screen.Offset(-win_rect.X, -win_rect.Y);
+
+ var gt = Windows.UI.Xaml.Window.Current.Content.TransformToVisual(element);
return gt.TransformPoint(screen);
}
- public static Windows.Foundation.Point GetScreentPoint(Windows.Foundation.Point client, Windows.UI.Xaml.UIElement element)
+
+ public static Point GetPointInWindow(Point client, Windows.UI.Xaml.UIElement element)
{
- var gt = element.TransformToVisual(Windows.UI.Xaml.Window.Current.Content);
+ //ウィンドウ内での絶対座標を取得する
+ var gt = element.TransformToVisual(null);
return gt.TransformPoint(client);
}
+
+ public static Point GetScreentPoint(Point client, Windows.UI.Xaml.UIElement element)
+ {
+ //ウィンドウ内での絶対座標を取得する
+ Point screenPoint = GetPointInWindow(client, element);
+
+ //Windows10以降では補正する必要がある
+ Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
+ screenPoint = screenPoint.Offset(win_rect.X, win_rect.Y);
+
+ return screenPoint;
+ }
public static Windows.Foundation.Rect GetClientRect(Windows.Foundation.Rect screen, Windows.UI.Xaml.UIElement element)
{
- var gt = element.TransformToVisual(element);
+ //Windows10以降では補正する必要がある
+ Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
+ screen.X -= win_rect.X;
+ screen.Y -= win_rect.Y;
+
+ var gt = Windows.UI.Xaml.Window.Current.Content.TransformToVisual(element);
return gt.TransformBounds(screen);
}
public static Windows.Foundation.Rect GetScreentRect(Windows.Foundation.Rect client, Windows.UI.Xaml.UIElement element)
{
- var gt = element.TransformToVisual(Windows.UI.Xaml.Window.Current.Content);
- return gt.TransformBounds(client);
+ //ウィンドウ内での絶対座標を取得する
+ var gt = element.TransformToVisual(null);
+ Windows.Foundation.Rect screenRect = gt.TransformBounds(client);
+
+ //Windows10以降では補正する必要がある
+ Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
+ screenRect.X += win_rect.X;
+ screenRect.Y += win_rect.Y;
+
+ return screenRect;
}
public static IEnumerable<char> GetEnumrator(string s)
{
char[] chars = s.ToCharArray();
return chars;
}
+#elif WPF
+ public static void GetDpi(out float dpix, out float dpiy)
+ {
+ var dpiXProperty = typeof(System.Windows.SystemParameters).GetProperty("DpiX", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
+ var dpiYProperty = typeof(System.Windows.SystemParameters).GetProperty("Dpi", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
+
+ dpix = (int)dpiXProperty.GetValue(null, null);
+ dpiy = (int)dpiYProperty.GetValue(null, null);
+ }
+
+ public static double GetScale()
+ {
+ float dpi;
+ Util.GetDpi(out dpi, out dpi);
+ return dpi / 96.0;
+ }
+
+ public static IEnumerable<char> GetEnumrator(string s)
+ {
+ return s;
+ }
#else
public static IEnumerable<char> GetEnumrator(string s)
{
{
return (int)(x + 0.5);
}
+
}
}