OSDN Git Service

予測候補の位置が相変わらずおかしいので再修正
authorkonekoneko <test2214@hotmail.co.jp>
Sat, 10 Sep 2016 13:18:02 +0000 (18:48 +0530)
committerkonekoneko <test2214@hotmail.co.jp>
Sat, 10 Sep 2016 13:18:02 +0000 (18:48 +0530)
Core/Util.cs
Metro/FooEditEngine/Direct2D/D2DRender.cs
Metro/FooEditEngine/FooTextBox.cs

index 044ba38..f2e16f9 100644 (file)
@@ -19,6 +19,19 @@ namespace FooEditEngine
     class Util
     {
 #if METRO
+        public static void GetDpi(out float dpix, out float dpiy)
+        {
+            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 Windows.Foundation.Point GetClientPoint(Windows.Foundation.Point screen, Windows.UI.Xaml.UIElement element)
         {
             //Windows10以降では補正する必要がある
@@ -29,11 +42,11 @@ namespace FooEditEngine
             var gt = element.TransformToVisual(element);
             return gt.TransformPoint(screen);
         }
-        public static Windows.Foundation.Point GetScreentPoint(Windows.Foundation.Point client, Windows.UI.Xaml.UIElement element)
+        public static Point GetScreentPoint(Point client, Windows.UI.Xaml.UIElement element)
         {
             //ウィンドウ内での絶対座標を取得する
             var gt = element.TransformToVisual(null);
-            Windows.Foundation.Point screenPoint = gt.TransformPoint(client);
+            Point screenPoint = gt.TransformPoint(client);
 
             //Windows10以降では補正する必要がある
             Windows.Foundation.Rect win_rect = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds;
index adcd0d7..ccbe04b 100644 (file)
@@ -115,8 +115,7 @@ namespace FooEditEngine
 
         public override void GetDpi(out float dpix, out float dpiy)
         {
-            dpix = DisplayInformation.GetForCurrentView().LogicalDpi;
-            dpiy = DisplayInformation.GetForCurrentView().LogicalDpi;
+            Util.GetDpi(out dpix, out dpiy);
         }
 
         public bool Resize(Windows.UI.Xaml.Shapes.Rectangle rect, double width, double height)
index 3f361d4..e15249b 100644 (file)
@@ -705,12 +705,11 @@ namespace FooEditEngine.Metro
             Point startPos, endPos;
             TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
 
-            float dpi;
-            this.Render.GetDpi(out dpi, out dpi);
-            double scale = dpi / 96.0;
-            
-            var screenStartPos = Util.GetScreentPoint(startPos.Scale(scale), this);
-            var screenEndPos = Util.GetScreentPoint(endPos.Scale(scale), this);
+            double scale = Util.GetScale();
+
+            //DIPを渡すと予測候補の位置がおかしくなるので、デバイス依存の座標に変換する
+            var screenStartPos = Util.GetScreentPoint(startPos, this).Scale(scale);
+            var screenEndPos = Util.GetScreentPoint(endPos, this).Scale(scale);
             o_topLeft = new POINT((int)(screenStartPos.X), (int)(screenStartPos.Y));
             o_bottomRight = new POINT((int)(screenEndPos.X), (int)(screenEndPos.Y));
         }