Open swapneils opened 5 months ago
Hey, @swapneils, thank you for the PR! Could you please provide an example sketch describing the demonstrated behavior before, and expected behavior after?
Here's one example. In the code as written we shouldn't be triggering the on-enter and on-leave methods, since on-hover only has advice for entity instances, and sketch is a direct child of standard-object instead. In this PR the methods activate appropriately.
(defsketch tutorial ((mouse-on nil) (x 100) (y 100))
(circle 300 100 50)
(ellipse 200 200 100 50)
(when mouse-on
(circle x y 20)))
(defmethod on-enter ((i tutorial))
(with-slots (mouse-on) i (setf mouse-on t) (sdl2:hide-cursor)) (print "enter"))
(defmethod on-leave ((i tutorial))
(with-slots (mouse-on) i (setf mouse-on nil) (sdl2:show-cursor)) (print "leave"))
I was toying around with
show-cursor
andhide-cursor
fromcl-sdl2
, and found that running 2 different sketches with different settings for this led to them competing for control of cursor visibility.Presumably SDL2's choice to make these kinds of things global variables means that many other effects have the same issue. Extending
on-leave
andon-enter
to sketch windows could allow tracking of which sketch has mouse-focus, to better filter when to call these methods.