diff options
-rw-r--r-- | chickadee.scm | 69 | ||||
-rw-r--r-- | doc/api.texi | 73 |
2 files changed, 124 insertions, 18 deletions
diff --git a/chickadee.scm b/chickadee.scm index 3022a52..a3434b8 100644 --- a/chickadee.scm +++ b/chickadee.scm @@ -248,6 +248,8 @@ border is disabled, otherwise it is enabled.") (define (warp-mouse x y) (sdl2:warp-mouse x y (unwrap-window (current-window)))) +(define noop (const #t)) + (define* (run-game #:key (window-title "Chickadee!") (window-width 640) @@ -256,22 +258,32 @@ border is disabled, otherwise it is enabled.") window-resizable? (clear-color %default-clear-color) (update-hz 60) - (load (const #t)) - (update (const #t)) - (draw (const #t)) + (load noop) + (update noop) + (draw noop) (quit abort-game) - (key-press (const #t)) - (key-release (const #t)) - (text-input (const #t)) - (mouse-press (const #t)) - (mouse-release (const #t)) - (mouse-move (const #t)) - (mouse-wheel (const #t)) - (controller-add (const #t)) - (controller-remove (const #t)) - (controller-press (const #t)) - (controller-release (const #t)) - (controller-move (const #t)) + (key-press noop) + (key-release noop) + (text-input noop) + (mouse-press noop) + (mouse-release noop) + (mouse-move noop) + (mouse-wheel noop) + (controller-add noop) + (controller-remove noop) + (controller-press noop) + (controller-release noop) + (controller-move noop) + (window-keyboard-enter noop) + (window-keyboard-leave noop) + (window-mouse-enter noop) + (window-mouse-leave noop) + (window-show noop) + (window-hide noop) + (window-minimize noop) + (window-maximize noop) + (window-move noop) + (window-resize noop) error) (sdl-init) (start-text-input) @@ -362,12 +374,35 @@ border is disabled, otherwise it is enabled.") (controller-axis-event-which event)) (controller-axis-event-axis event) (/ (controller-axis-event-value event) 32768.0))) - ((window-resized-event? event) + ((window-focus-gained-event? event) + (window-keyboard-enter)) + ((window-focus-lost-event? event) + (window-keyboard-leave)) + ((window-enter-event? event) + (window-mouse-enter)) + ((window-leave-event? event) + (window-mouse-leave)) + ((window-shown-event? event) + (window-show)) + ((window-hidden-event? event) + (window-hide)) + ((window-minimized-event? event) + (window-minimize)) + ((window-maximized-event? event) + (window-maximize)) + ((window-moved-event? event) + (match (window-event-vector event) + ((x y) + (window-move x y)))) + ((window-size-changed-event? event) (match (window-event-vector event) ((width height) + (set! window-width width) + (set! window-height height) (atomic-box-set! default-viewport (make-viewport 0 0 width height)) (atomic-box-set! default-projection - (orthographic-projection 0 width height 0 0 1))))))) + (orthographic-projection 0 width height 0 0 1)) + (window-resize width height)))))) ;; Process all pending events. (let loop ((event (poll-event))) (when event diff --git a/doc/api.texi b/doc/api.texi index b9e2229..468c5a3 100644 --- a/doc/api.texi +++ b/doc/api.texi @@ -46,7 +46,13 @@ calling @code{run-game} is already taken care of for you. [#:key-press] [#:key-release] [#:text-input] @ [#:mouse-press] [#:mouse-release] [#:mouse-move] @ [#:controller-add] [#:controller-remove] [#:controller-press] @ - [#:controller-release] [#:controller-move] [#:error] + [#:controller-release] [#:controller-move] @ + [#:window-keyboard-enter] [#:window-keyboard-leave] @ + [#:window-mouse-enter] [#:window-mouse-leave] @ + [#:window-show] [#:window-hide] @ + [#:window-minimize] [#:window-maximize] @ + [#:window-move] [#:window-resize] @ + [#:error] Run the Chickadee game loop. @@ -292,6 +298,71 @@ values are: @end enumerate @item +@var{window-keyboard-enter}: Called with zero arguments when the +window gains keyboard focus. + +@item +@var{window-keyboard-leave}: Called with zero arguments when the +window loses keyboard focus. + +@item +@var{window-mouse-enter}: Called with zero arguments when the window +gains mouse focus. + +@item +@var{window-mouse-leave}: Called with zero arguments when the window +loses mouse focus. + +@item +@var{window-show}: Called with zero arguments when the window is +shown after having been hidden. + +@item +@var{window-hide}: Called with zero arguments when the window is +hidden. + +@item +@var{window-minimize}: Called with zero arguments when the window is +minimized. + +@item +@var{window-maximize}: Called with zero arguments when the window is +maximized. + +@item +@var{window-move}: Called with two arguments when the window is moved +within the desktop environment. + +@enumerate + +@item +@var{x}: The x coordinate of the top-left corner of the window, in +pixels. + +@item +@var{y}: The y coordinate of the top-left corner of the window, in +pixels. + +@end enumerate + +Desktop environments use the top-left corner as the origin rather than +the bottom-left like Chickadee does, hence the discrepancy here. + +@item +@var{window-resize}: Called with zero arguments when the window is +resized. + +@enumerate + +@item +@var{width}: The new width in pixels. + +@item +@var{height}: The new height in pixels. + +@end enumerate + +@item @var{error}: Called with two arguments when an error occurs: @enumerate |