Skip to content

Commit

Permalink
text input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Mar 12, 2019
1 parent dae56e2 commit ea67632
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions callback.lisp
Expand Up @@ -59,6 +59,14 @@
(steam::unregister-callback handle)
(cffi:foreign-free handle)))

(defclass closure-callback (callback)
((closure :initarg :closure :initform (error "CLOSURE required.") :reader closure)))

(defmethod callback ((callresult closure-callback) parameter &optional failed api-call)
(declare (ignore api-call))
(unwind-protect (funcall (closure callback) (if failed NIL parameter))
(free callback)))

(defclass callresult (%callback)
((token :initarg :token :reader token)))

Expand Down
21 changes: 19 additions & 2 deletions steamutils.lisp
Expand Up @@ -50,6 +50,25 @@
(defmethod show-text-input ((utils steamutils) &key (mode :normal) (line-mode :single-line) (description "") (max 32) (default ""))
(steam::utils-show-gamepad-text-input (handle utils) mode line-mode description max default))

(defmethod input-text ((utils steamutils))
(let ((length (steam::utils-get-entered-gamepad-text-length (handle utils))))
(cffi:with-foreign-object (data :char length)
(unless (steam::utils-get-entered-gamepad-text-input (handle utils) data length)
(error "FIXME: failed to retrieve entered text. Was there any text to receive and are you in the callback?"))
(cffi:foreign-string-to-lisp data :count length :encoding :utf-8))))

(defmacro with-input-text ((text utils &rest args) &body body)
(let ((utilsg (gensym "UTILS"))
(struct (gensym "STRUCT")))
`(let ((,utilsg ,utils))
(flet ((,thunk (,struct)
(when (steam::gamepad-text-input-dismissed-submitted ,struct)
(let ((,text (input-text ,utils)))
,@body))))
(make-instance 'closure-callback
:closure #',thunk
:struct-type 'steam::gamepad-text-input-dismissed-t)))))

(defmethod start-virtual-reality-dashboard ((utils steamutils))
(steam::utils-start-vrdashboard (handle utils)))

Expand All @@ -59,8 +78,6 @@
(steam::utils-set-overlay-notification-inset (handle utils) x y)
value))

;; GamepadTextInputDismissed_t handling

(defclass image (c-object)
((width :reader width)
(height :reader height)
Expand Down

0 comments on commit ea67632

Please sign in to comment.