get-scaled-client-size and high-DPI on Windows

25 views
Skip to first unread message

Ryan Kramer

unread,
Jul 24, 2021, 11:55:58 AM7/24/21
to Racket Users
The following program looks "correct" when my Windows display scaling is set to 100%, and looks "wrong" when set to anything higher than 100%. By "correct" I mean that the 4 squares meet in the center of the canvas, stretched to the maximum size possible that the canvas width and height will allow.

What is interesting is that I can make the program look correct by immediately scaling the values returned from `get-scaled-client-size`. For example, if my display is set to 150%, I can make the program look correct by immediately multiplying the returned width and height by 2/3, because 100% is 2/3 of 150%. But right now I have to hard-code the 2/3 factor. Is there a way to get that 2/3 factor programmatically in Racket? Or (even better), is there something else I should be calling instead of `get-scaled-client-size` that would return the dimensions I want?

This is Racket CS 8.0.0.11 on Windows. Let me know if you want screenshots. Thanks in advance.


#lang racket/gui

(require pict)

(define frame
  (new frame%
       [label "Scale Test"]))

(define (paint canvas dc)
  (define-values (w h) (send canvas get-scaled-client-size))
  (define-values (size x-offset y-offset)
    (if (> w h)
        (values h (/ (- w h) 2) 0)
        (values w 0 (/ (- h w) 2))))
  (println (list w h size x-offset y-offset))
  (for ([x (list x-offset (+ x-offset (/ size 2)))]
        #:when #t
        [y (list y-offset (+ y-offset (/ size 2)))])
    (send dc draw-rectangle x y (/ size 2) (/ size 2))))

(define canvas
  (new canvas%
       [parent frame]
       [paint-callback paint]))

(send frame show #t)

Ryan Kramer

unread,
Jul 24, 2021, 11:59:34 AM7/24/21
to Racket Users
Wow, how did I write that much and not notice `get-client-size`, which is exactly what I want? The documentation is fine, apparently I just can't read today!
Reply all
Reply to author
Forward
0 new messages