Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sdl2: fix mouse x,y on retina screens
Previously, retina resolution was added to lem for rendering its fonts.
This accidentally skipped over doing the same scaling calculation for
the mouse coordinates so we fix that here.
  • Loading branch information
seanfarley committed Jul 7, 2023
commit 908b9b08426ccf8561e9731ac572d936d11f0930
53 changes: 25 additions & 28 deletions frontends/sdl2/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@
((eql button sdl2-ffi:+sdl-button-middle+) :button-2)
((eql button 4) :button-4))))
(when button
(let ((pixel-x x)
(pixel-y y)
(char-x (floor x (char-width)))
(char-y (floor y (char-height))))
(lem:send-event (lambda ()
(lem:receive-mouse-button-down char-x char-y pixel-x pixel-y button clicks)))))))
(let ((char-x (scaled-char-width *display* x))
(char-y (scaled-char-height *display* y)))
(lem:send-event
(lambda ()
(lem:receive-mouse-button-down char-x char-y x y button
clicks)))))))

(defun on-mouse-button-up (button x y)
(show-cursor)
Expand All @@ -662,37 +662,34 @@
((eql button sdl2-ffi:+sdl-button-right+) :button-3)
((eql button sdl2-ffi:+sdl-button-middle+) :button-2)
((eql button 4) :button-4)))
(pixel-x x)
(pixel-y y)
(char-x (floor x (char-width)))
(char-y (floor y (char-height))))
(lem:send-event (lambda ()
(lem:receive-mouse-button-up char-x char-y pixel-x pixel-y button)))))
(char-x (scaled-char-width *display* x))
(char-y (scaled-char-height *display* y)))
(lem:send-event
(lambda ()
(lem:receive-mouse-button-up char-x char-y x y button)))))

(defun on-mouse-motion (x y state)
(show-cursor)
(let ((button (if (= sdl2-ffi:+sdl-button-lmask+ (logand state sdl2-ffi:+sdl-button-lmask+))
:button-1
nil)))
(let ((pixel-x x)
(pixel-y y)
(char-x (floor x (char-width)))
(char-y (floor y (char-height))))
(lem:send-event (lambda ()
(lem:receive-mouse-motion char-x char-y pixel-x pixel-y button))))))
(let ((char-x (scaled-char-width *display* x))
(char-y (scaled-char-height *display* y)))
(lem:send-event
(lambda ()
(lem:receive-mouse-motion char-x char-y x y button))))))

(defun on-mouse-wheel (wheel-x wheel-y which direction)
(declare (ignore which direction))
(show-cursor)
(multiple-value-bind (x y) (sdl2:mouse-state)
(let ((pixel-x x)
(pixel-y y)
(char-x (floor x (char-width)))
(char-y (floor y (char-height))))
(lem:send-event (lambda ()
(lem:receive-mouse-wheel char-x char-y pixel-x pixel-y wheel-x wheel-y)
(when (= 0 (lem:event-queue-length))
(lem:redraw-display)))))))
(let ((char-x (scaled-char-width *display* x))
(char-y (scaled-char-height *display* y)))
(lem:send-event
(lambda ()
(lem:receive-mouse-wheel char-x char-y x y wheel-x wheel-y)
(when (= 0 (lem:event-queue-length))
(lem:redraw-display)))))))

(defun on-textediting (text)
(handle-textediting (get-platform) text)
Expand Down Expand Up @@ -1021,8 +1018,8 @@
(multiple-value-bind (x y bitmask)
(sdl2:mouse-state)
(declare (ignore bitmask))
(values (floor x (display-char-width *display*))
(floor y (display-char-height *display*))))))
(values (scaled-char-width *display* x)
(scaled-char-height *display* y)))))

(defmethod lem-if:get-char-width ((implementation sdl2))
(char-width))
Expand Down