Explorar o código

wxnviz: fix for HiDPI monitors with scaling set, fix decoding (#307)

Anna Petrasova %!s(int64=5) %!d(string=hai) anos
pai
achega
d7397d5162
Modificáronse 2 ficheiros con 32 adicións e 25 borrados
  1. 17 10
      gui/wxpython/nviz/mapwindow.py
  2. 15 15
      gui/wxpython/nviz/wxnviz.py

+ 17 - 10
gui/wxpython/nviz/mapwindow.py

@@ -404,7 +404,8 @@ class GLWindow(MapWindowBase, glcanvas.GLCanvas):
             else:
                 self.SetCurrent()
             self._display.ResizeWindow(size.width,
-                                       size.height)
+                                       size.height,
+                                       self.GetContentScaleFactor())
 
             # reposition checkbox in statusbar
             self.parent.StatusbarReposition()
@@ -674,7 +675,7 @@ class GLWindow(MapWindowBase, glcanvas.GLCanvas):
             size = self.GetClientSize()
             self._display.LookHere(
                 self.mouse['begin'][0],
-                size[1] - self.mouse['begin'][1])
+                size[1] - self.mouse['begin'][1], self.GetContentScaleFactor())
             focus = self._display.GetFocus()
             for i, coord in enumerate(('x', 'y', 'z')):
                 self.iview['focus'][coord] = focus[i]
@@ -743,7 +744,8 @@ class GLWindow(MapWindowBase, glcanvas.GLCanvas):
         size = self.GetClientSize()
         # UL -> LL
         x, y = xyCoords
-        sid, x, y, z = self._display.GetPointOnSurface(x, size[1] - y)
+        sid, x, y, z = self._display.GetPointOnSurface(x, size[1] - y,
+                                                       self.GetContentScaleFactor())
 
         if not sid:
             return None
@@ -768,9 +770,10 @@ class GLWindow(MapWindowBase, glcanvas.GLCanvas):
             if hasattr(self.lmgr, "nviz"):
                 self.lmgr.nviz.UpdateSettings()
                 x, y = pos[0], self.GetClientSize()[1] - pos[1]
-                result = self._display.GetPointOnSurface(x, y)
+                result = self._display.GetPointOnSurface(x, y,
+                                                         self.GetContentScaleFactor())
                 if result[0]:
-                    self._display.LookHere(x, y)
+                    self._display.LookHere(x, y, self.GetContentScaleFactor())
                     focus = self._display.GetFocus()
                     for i, coord in enumerate(('x', 'y', 'z')):
                         self.iview['focus'][coord] = focus[i]
@@ -859,9 +862,11 @@ class GLWindow(MapWindowBase, glcanvas.GLCanvas):
         """Simulation of panning using focus"""
         size = self.GetClientSize()
         id1, x1, y1, z1 = self._display.GetPointOnSurface(
-            self.mouse['tmp'][0], size[1] - self.mouse['tmp'][1])
+            self.mouse['tmp'][0], size[1] - self.mouse['tmp'][1],
+            self.GetContentScaleFactor())
         id2, x2, y2, z2 = self._display.GetPointOnSurface(
-            event.GetX(), size[1] - event.GetY())
+            event.GetX(), size[1] - event.GetY(),
+            self.GetContentScaleFactor())
         if id1 and id1 == id2:
             dx, dy, dz = x2 - x1, y2 - y1, z2 - z1
             focus = self.iview['focus']
@@ -883,9 +888,11 @@ class GLWindow(MapWindowBase, glcanvas.GLCanvas):
         """
         size = self.GetClientSize()
         id1, x1, y1, z1 = self._display.GetPointOnSurface(
-            self.mouse['tmp'][0], size[1] - self.mouse['tmp'][1])
+            self.mouse['tmp'][0], size[1] - self.mouse['tmp'][1],
+            self.GetContentScaleFactor())
         id2, x2, y2, z2 = self._display.GetPointOnSurface(
-            event.GetX(), size[1] - event.GetY())
+            event.GetX(), size[1] - event.GetY(),
+            self.GetContentScaleFactor())
 
         if id1 and id1 == id2:
             dx, dy = x2 - x1, y2 - y1
@@ -1015,7 +1022,7 @@ class GLWindow(MapWindowBase, glcanvas.GLCanvas):
     def QuerySurface(self, x, y):
         """Query surface on given position"""
         size = self.GetClientSize()
-        result = self._display.QueryMap(x, size[1] - y)
+        result = self._display.QueryMap(x, size[1] - y, self.GetContentScaleFactor())
         if result:
             self.qpoints.append((result['x'], result['y'], result['z']))
             self.log.WriteLog("%-30s: %.3f" % (_("Easting"), result['x']))

+ 15 - 15
gui/wxpython/nviz/wxnviz.py

@@ -150,7 +150,7 @@ class Nviz(object):
         GVL_libinit()
         GVL_init_region()
 
-    def ResizeWindow(self, width, height):
+    def ResizeWindow(self, width, height, scale=1):
         """GL canvas resized
 
         :param width: window width
@@ -159,11 +159,11 @@ class Nviz(object):
         :return: 1 on success
         :return: 0 on failure (window resized by default to 20x20 px)
         """
-        self.width = width
-        self.height = height
+        self.width = int(width * scale)
+        self.height = int(height * scale)
         Debug.msg(3, "Nviz::ResizeWindow(): width=%d height=%d",
-                  width, height)
-        return Nviz_resize_window(width, height)
+                  self.width, self.height)
+        return Nviz_resize_window(self.width, self.height)
 
     def GetLongDim(self):
         """Get longest dimension, used for initial size of north arrow"""
@@ -219,13 +219,13 @@ class Nviz(object):
 
         return (x.value, y.value, h.value)
 
-    def LookHere(self, x, y):
+    def LookHere(self, x, y, scale=1):
         """Look here feature
         :param x,y: screen coordinates
         """
 
-        Nviz_look_here(x, y)
-        Debug.msg(3, "Nviz::LookHere(): x=%f, y=%f", x, y)
+        Nviz_look_here(int(x * scale), int(y * scale))
+        Debug.msg(3, "Nviz::LookHere(): x=%f, y=%f", x * scale, y * scale)
 
     def LookAtCenter(self):
         """Center view at center of displayed surface"""
@@ -1922,7 +1922,7 @@ class Nviz(object):
         """
         Nviz_delete_scalebar(self.data, id)
 
-    def GetPointOnSurface(self, sx, sy):
+    def GetPointOnSurface(self, sx, sy, scale=1):
         """Get point on surface
 
         :param sx,sy: canvas coordinates (LL)
@@ -1931,20 +1931,20 @@ class Nviz(object):
         x = c_float()
         y = c_float()
         z = c_float()
-        Debug.msg(5, "Nviz::GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
+        Debug.msg(5, "Nviz::GetPointOnSurface(): sx=%d sy=%d" % (sx * scale, sy * scale))
         num = GS_get_selected_point_on_surface(
-            sx, sy, byref(sid), byref(x), byref(y), byref(z))
+            int(sx * scale), int(sy * scale), byref(sid), byref(x), byref(y), byref(z))
         if num == 0:
             return (None, None, None, None)
 
         return (sid.value, x.value, y.value, z.value)
 
-    def QueryMap(self, sx, sy):
+    def QueryMap(self, sx, sy, scale=1):
         """Query surface map
 
         :param sx,sy: canvas coordinates (LL)
         """
-        sid, x, y, z = self.GetPointOnSurface(sx, sy)
+        sid, x, y, z = self.GetPointOnSurface(sx, sy, scale)
         if not sid:
             return None
 
@@ -1957,8 +1957,8 @@ class Nviz(object):
                 'x': x,
                 'y': y,
                 'z': z,
-                'elevation': catstr.value.replace('(', '').replace(')', ''),
-                'color': valstr.value}
+                'elevation': DecodeString(catstr.value).replace('(', '').replace(')', ''),
+                'color': DecodeString(valstr.value)}
 
     def GetDistanceAlongSurface(self, sid, p1, p2, useExag=True):
         """Get distance measured along surface"""