DeviceWorkstation.st
changeset 8867 fde04bd5f24b
parent 8864 4ef7f3f274ef
child 8870 d0a74d18b207
--- a/DeviceWorkstation.st	Fri Nov 15 10:47:38 2019 +0100
+++ b/DeviceWorkstation.st	Fri Nov 15 10:48:18 2019 +0100
@@ -886,6 +886,31 @@
     "Modified: / 18.3.1999 / 18:20:39 / stefan"
 !
 
+currentDisplayResolution
+    "ONLY WINDOWS redfines this method
+     here just return my known extent 
+
+     this is the current resolution of the display,
+     without any effect of scaling
+
+     for e.g.
+        real current display resolution -> 1080p
+        scaling 150%
+        virtual display resolution -> 720p
+
+        real current display resolution -> 1080p
+        scaling 100%
+        virtual display resolution -> 1080p"         
+
+    "
+        self currentDisplayResolution
+    "    
+
+    ^ Display extent
+
+    "Created: / 15-11-2019 / 10:42:20 / Stefan Reise"
+!
+
 currentWindow
     "Return the currently active window,
      that is, the topView of the currently executing windowGroup"
@@ -961,7 +986,7 @@
 
 scaleFactorForRootDisplayCoordinates
     "this is the factor we need to adopt for the root display coordinates,
-     if windows did scale the application (when the app is not high DPI aware"
+     if windows did scale the application (when the app is not high DPI aware)"
 
     "
         self scaleFactorForRootDisplayCoordinates              
@@ -970,7 +995,7 @@
     ^ 1@1
 
     "Created: / 14-11-2019 / 13:43:12 / Stefan Reise"
-    "Modified (comment): / 15-11-2019 / 09:42:36 / Stefan Reise"
+    "Modified (comment): / 15-11-2019 / 10:23:45 / Stefan Reise"
 ! !
 
 !DeviceWorkstation class methodsFor:'standalone setup'!
@@ -990,6 +1015,40 @@
     "Modified: 23.4.1996 / 22:01:28 / cg"
 ! !
 
+!DeviceWorkstation class methodsFor:'transformations'!
+
+transformVirtualDisplayPointToRootDisplayPoint:aPoint
+    "this is required when you want to access the root display coordinates correctly,
+     because may windows did scale the application (when the app is not high DPI aware),
+     and if windows did scale the application, the application gets a virtual display
+     with a diffrent resolution"
+
+    ^ (aPoint * self scaleFactorForRootDisplayCoordinates) rounded
+
+    "Created: / 15-11-2019 / 10:31:31 / Stefan Reise"
+!
+
+transformVirtualDisplayRectangleToRootDisplayRectangle:aRectangle
+    "this is required when you want to access the root display coordinates correctly,
+     because may windows did scale the application (when the app is not high DPI aware),
+     and if windows did scale the application, the application gets a virtual display
+     with a diffrent resolution"
+
+    "ATTENTION:
+     do not call #transformVirtualDisplayPointToRootDisplayPoint: 2 times here,
+     because this would also call #scaleFactorForRootDisplayCoordinates 2 times,
+     but the call #scaleFactorForRootDisplayCoordinates is a little expensive"
+
+    |scaleFactorForRootDisplayCoordinates|
+
+    scaleFactorForRootDisplayCoordinates := self scaleFactorForRootDisplayCoordinates.
+
+    ^ (aRectangle origin * scaleFactorForRootDisplayCoordinates) rounded
+        corner:(aRectangle corner * scaleFactorForRootDisplayCoordinates) rounded
+
+    "Created: / 15-11-2019 / 10:22:38 / Stefan Reise"
+! !
+
 !DeviceWorkstation methodsFor:'Compatibility-ST80'!
 
 colorDepth
@@ -6926,31 +6985,14 @@
     "Modified: 24.7.1997 / 16:04:54 / cg"
 !
 
-rectangleFromUser:initialRectangle 
-    keepExtent:keepExtent
-
-    ^ self 
-        rectangleFromUser:initialRectangle 
-        keepExtent:keepExtent
-        scaleFactor:self class scaleFactorForRootDisplayCoordinates
-
-    "Created: / 24-07-1997 / 15:26:47 / cg"
-    "Modified: / 10-09-1998 / 17:38:41 / cg"
-    "Modified: / 23-02-2017 / 13:30:21 / stefan"
-    "Modified: / 14-11-2019 / 13:43:28 / Stefan Reise"
-!
-
-rectangleFromUser:initialRectangle 
-    keepExtent:keepExtent
-    scaleFactor:scaleFactor 
-
+rectangleFromUser:initialRectangle keepExtent:keepExtent
     "{ Pragma: +optSpace }"
 
     "let user specify a rectangle on the screen, return the rectangle.
      Start with initialRectangle.
      A helper for rectangleFromUser; can also be used for resizing operations."
 
-    |curs1 origin corner root rect doRegrab prevGrab delay|
+    |curs1 origin corner root rect doRegrab prevGrab delay displayRectangleBlock|
 
     "/ regrabbing leads to horrible flicker and
     "/ events being sent to applications under the mouse.
@@ -6970,6 +7012,13 @@
     "
     origin := initialRectangle origin.
 
+    displayRectangleBlock := 
+        [:gc :rect |
+            gc                  
+                displayRectangle:(Screen 
+                    transformVirtualDisplayRectangleToRootDisplayRectangle:rect).
+        ].
+
     root clippedByChildren:false.
     root foreground:blackColor background:whiteColor.
 
@@ -6981,7 +7030,10 @@
         keepExtent ifFalse:[
             corner := origin.
             rect := origin corner:corner.
-            root displayRectangle:rect.
+
+            displayRectangleBlock
+                value:root
+                value:rect.
         ].
 
         prevGrab := activePointerGrab.
@@ -6993,11 +7045,14 @@
         [self leftButtonPressed] whileFalse:[delay wait].
 
         keepExtent ifTrue:[
-            p := (self pointerPosition * scaleFactor) rounded.
+            p := self pointerPosition.
             origin := p.
             corner := origin + initialRectangle extent.
             rect := origin corner:corner.
-            root displayRectangle:rect.
+
+            displayRectangleBlock
+                value:root
+                value:rect.
         ].
 
         [self leftButtonPressed] whileTrue:[
@@ -7006,7 +7061,7 @@
             right := initialRectangle corner x.
             bottom := initialRectangle corner y.
 
-            p := (self pointerPosition * scaleFactor) rounded.
+            p := self pointerPosition.
             keepExtent ifTrue:[
                 newOrigin := p.
                 newCorner := newOrigin + initialRectangle extent.
@@ -7039,7 +7094,10 @@
             ].
 
             ((newOrigin ~= origin) or:[newCorner ~= corner]) ifTrue:[
-                root displayRectangle:rect.
+                displayRectangleBlock
+                    value:root
+                    value:rect.
+
                 doRegrab ifTrue:[
                     self grabPointerInView:root withCursor:curs1.
                 ].
@@ -7047,14 +7105,21 @@
                 origin :=  newOrigin.
                 corner :=  newCorner.
                 rect := origin corner:corner.
-                root displayRectangle:rect.
+
+                displayRectangleBlock
+                    value:root
+                    value:rect.
+
                 self disposeButtonEventsFor:nil.
                 self flush.
             ] ifFalse:[
                 delay wait.
             ]
         ].
-        root displayRectangle:rect.
+
+        displayRectangleBlock
+            value:root
+            value:rect.
     ].
 
 
@@ -7078,7 +7143,10 @@
      Display rectangleFromUser:(100@100 corner:300@300) keepExtent:true
     "
 
-    "Created: / 14-11-2019 / 13:40:45 / Stefan Reise"
+    "Created: / 24-07-1997 / 15:26:47 / cg"
+    "Modified: / 10-09-1998 / 17:38:41 / cg"
+    "Modified: / 23-02-2017 / 13:30:21 / stefan"
+    "Modified: / 15-11-2019 / 10:26:36 / Stefan Reise"
 !
 
 topviewFromUser