Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend on-leave and on-enter to sketch windows #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

swapneils
Copy link

I was toying around with show-cursor and hide-cursor from cl-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 and on-enter to sketch windows could allow tracking of which sketch has mouse-focus, to better filter when to call these methods.

@vydd
Copy link
Owner

vydd commented Jan 28, 2024

Hey, @swapneils, thank you for the PR! Could you please provide an example sketch describing the demonstrated behavior before, and expected behavior after?

@swapneils
Copy link
Author

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"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants