|
176 | 176 | (display-latin-font display) |
177 | 177 | (display-cjk-normal-font display))))) |
178 | 178 |
|
| 179 | +(defmethod scaled-char-width ((display display) x) |
| 180 | + (let ((scale-x (round (first (display-scale display))))) |
| 181 | + (floor (* scale-x x) (char-width)))) |
| 182 | + |
| 183 | +(defmethod scaled-char-height ((display display) y) |
| 184 | + (let ((scale-y (round (second (display-scale display))))) |
| 185 | + (floor (* scale-y y) (char-height)))) |
| 186 | + |
179 | 187 | (defmethod update-display ((display display)) |
180 | 188 | (sdl2:render-present (display-renderer display))) |
181 | 189 |
|
|
398 | 406 | texture |
399 | 407 | x |
400 | 408 | y |
401 | | - (* (display-char-width *display*) |
402 | | - (length string)) |
| 409 | + (* (char-width) (length string)) |
403 | 410 | height) |
404 | 411 | (sdl2:destroy-texture texture) |
405 | 412 | (length string)))) |
|
640 | 647 | ((eql button sdl2-ffi:+sdl-button-middle+) :button-2) |
641 | 648 | ((eql button 4) :button-4)))) |
642 | 649 | (when button |
643 | | - (let ((pixel-x x) |
644 | | - (pixel-y y) |
645 | | - (char-x (floor x (char-width))) |
646 | | - (char-y (floor y (char-height)))) |
647 | | - (lem:send-event (lambda () |
648 | | - (lem:receive-mouse-button-down char-x char-y pixel-x pixel-y button clicks))))))) |
| 650 | + (let ((char-x (scaled-char-width *display* x)) |
| 651 | + (char-y (scaled-char-height *display* y))) |
| 652 | + (lem:send-event |
| 653 | + (lambda () |
| 654 | + (lem:receive-mouse-button-down char-x char-y x y button |
| 655 | + clicks))))))) |
649 | 656 |
|
650 | 657 | (defun on-mouse-button-up (button x y) |
651 | 658 | (show-cursor) |
|
654 | 661 | ((eql button sdl2-ffi:+sdl-button-right+) :button-3) |
655 | 662 | ((eql button sdl2-ffi:+sdl-button-middle+) :button-2) |
656 | 663 | ((eql button 4) :button-4))) |
657 | | - (pixel-x x) |
658 | | - (pixel-y y) |
659 | | - (char-x (floor x (char-width))) |
660 | | - (char-y (floor y (char-height)))) |
661 | | - (lem:send-event (lambda () |
662 | | - (lem:receive-mouse-button-up char-x char-y pixel-x pixel-y button))))) |
| 664 | + (char-x (scaled-char-width *display* x)) |
| 665 | + (char-y (scaled-char-height *display* y))) |
| 666 | + (lem:send-event |
| 667 | + (lambda () |
| 668 | + (lem:receive-mouse-button-up char-x char-y x y button))))) |
663 | 669 |
|
664 | 670 | (defun on-mouse-motion (x y state) |
665 | 671 | (show-cursor) |
666 | 672 | (let ((button (if (= sdl2-ffi:+sdl-button-lmask+ (logand state sdl2-ffi:+sdl-button-lmask+)) |
667 | 673 | :button-1 |
668 | 674 | nil))) |
669 | | - (let ((pixel-x x) |
670 | | - (pixel-y y) |
671 | | - (char-x (floor x (char-width))) |
672 | | - (char-y (floor y (char-height)))) |
673 | | - (lem:send-event (lambda () |
674 | | - (lem:receive-mouse-motion char-x char-y pixel-x pixel-y button)))))) |
| 675 | + (let ((char-x (scaled-char-width *display* x)) |
| 676 | + (char-y (scaled-char-height *display* y))) |
| 677 | + (lem:send-event |
| 678 | + (lambda () |
| 679 | + (lem:receive-mouse-motion char-x char-y x y button)))))) |
675 | 680 |
|
676 | 681 | (defun on-mouse-wheel (wheel-x wheel-y which direction) |
677 | 682 | (declare (ignore which direction)) |
678 | 683 | (show-cursor) |
679 | 684 | (multiple-value-bind (x y) (sdl2:mouse-state) |
680 | | - (let ((pixel-x x) |
681 | | - (pixel-y y) |
682 | | - (char-x (floor x (char-width))) |
683 | | - (char-y (floor y (char-height)))) |
684 | | - (lem:send-event (lambda () |
685 | | - (lem:receive-mouse-wheel char-x char-y pixel-x pixel-y wheel-x wheel-y) |
686 | | - (when (= 0 (lem:event-queue-length)) |
687 | | - (lem:redraw-display))))))) |
| 685 | + (let ((char-x (scaled-char-width *display* x)) |
| 686 | + (char-y (scaled-char-height *display* y))) |
| 687 | + (lem:send-event |
| 688 | + (lambda () |
| 689 | + (lem:receive-mouse-wheel char-x char-y x y wheel-x wheel-y) |
| 690 | + (when (= 0 (lem:event-queue-length)) |
| 691 | + (lem:redraw-display))))))) |
688 | 692 |
|
689 | 693 | (defun on-textediting (text) |
690 | 694 | (handle-textediting (get-platform) text) |
|
749 | 753 | (sdl2:free-surface image))) |
750 | 754 |
|
751 | 755 | (defun adapt-high-dpi-display-scale () |
752 | | - (with-debug ("adpat-high-dpi-display-scale") |
| 756 | + (with-debug ("adapt-high-dpi-display-scale") |
753 | 757 | (with-renderer () |
754 | 758 | (multiple-value-bind (renderer-width renderer-height) |
755 | 759 | (sdl2:get-renderer-output-size (current-renderer)) |
|
760 | 764 | (setf (display-scale *display*) (list scale-x scale-y))))))) |
761 | 765 |
|
762 | 766 | (defun adapt-high-dpi-font-size () |
763 | | - (with-debug ("adpat-high-dpi-font-size") |
| 767 | + (with-debug ("adapt-high-dpi-font-size") |
764 | 768 | (with-renderer () |
765 | 769 | (let ((font-config (display-font-config *display*)) |
766 | 770 | (ratio (round (first (display-scale *display*))))) |
|
1013 | 1017 | (multiple-value-bind (x y bitmask) |
1014 | 1018 | (sdl2:mouse-state) |
1015 | 1019 | (declare (ignore bitmask)) |
1016 | | - (values (floor x (display-char-width *display*)) |
1017 | | - (floor y (display-char-height *display*)))))) |
| 1020 | + (values (scaled-char-width *display* x) |
| 1021 | + (scaled-char-height *display* y))))) |
1018 | 1022 |
|
1019 | 1023 | (defmethod lem-if:get-char-width ((implementation sdl2)) |
1020 | 1024 | (char-width)) |
|
0 commit comments