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

Revise input-handling interface. #156

Merged
merged 2 commits into from
Jan 28, 2024

Conversation

Kevinpgalligan
Copy link
Contributor

There's now a tree of 'on-mouse-' functions, the user can hook into them at any point. 'on-mouse-button' propagates to 'on-mouse-left' which propagates to 'on-mouse-left-up' and 'on-mouse-left-down'. Same for 'on-mouse-middle' and 'on-mouse-right'.

Keeps 'on-click', since that's a simple and common case.

Also changes the 'state' parameter of 'on-key' so that it can have values ':up' or ':down', to be consistent with the mouse interface.

Testing

Basically added print statements to all the methods and made sure they were called. (Except the middle-mouse ones, since I'm testing with a trackpad, ha).

(defsketch mouse () (circle 10 10 10) (stop-loop))
(defmethod on-mouse-button :before ((i mouse) button state x y)
  (format t "on-mouse-button: ~a ~a ~a ~a~%" button state x y))
(defmethod on-mouse-left :before ((i mouse) state x y)
  (format t "on-mouse-left: ~a ~a ~a~%" state x y))
(defmethod on-mouse-right :before ((i mouse) state x y)
  (format t "on-mouse-right: ~a ~a ~a~%" state x y))
(defmethod on-mouse-left-down :before ((i mouse) x y)
  (format t "on-mouse-left-down: ~a ~a~%" x y))
(defmethod on-mouse-left-up :before ((i mouse) x y)
  (format t "on-mouse-left-up: ~a ~a~%" x y))
(defmethod on-mouse-left-down :before ((i mouse) x y)
  (format t "on-mouse-left-down: ~a ~a~%" x y))
(defmethod on-mouse-right-down :before ((i mouse) x y)
  (format t "on-mouse-right-down: ~a ~a~%" x y))
(defmethod on-mouse-right-up :before ((i mouse) x y)
  (format t "on-mouse-right-up: ~a ~a~%" x y))
(defmethod on-click :before ((i mouse) x y)
  (format t "on-click: ~a ~a~%" x y))
(defmethod on-key :before ((i mouse) key state)
  (format t "on-key: ~a ~a~%" key state))

The output:

;; Pressed left mouse
on-mouse-button: LEFT DOWN 179 110
on-mouse-left: DOWN 179 110
on-mouse-left-down: 179 110
;; Released left mouse
on-mouse-button: LEFT UP 178 110
on-mouse-left: UP 178 110
on-mouse-left-up: 178 110
on-click: 178 110
;; Pressed right mouse
on-mouse-button: RIGHT DOWN 139 40
on-mouse-right: DOWN 139 40
on-mouse-right-down: 139 40
;; Released right mouse
on-mouse-button: RIGHT UP 139 39
on-mouse-right: UP 139 39
on-mouse-right-up: 139 39
;; And on-key
on-key: S DOWN
on-key: S UP
on-key: SPACE DOWN
on-key: SPACE UP

There's now a tree of 'on-mouse-' functions, the user can
hook into them at any point. 'on-mouse-button' propagates
to 'on-mouse-left' which propagates to 'on-mouse-left-up'
and 'on-mouse-left-down'.

Keeps 'on-click', since that's a simple and common case.

Also changes the 'state' parameter 'on-key' so that it can have
values ':up' or ':down', to be consistent with the mouse interface.
@vydd vydd merged commit 4b3d526 into vydd:master Jan 28, 2024
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