diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-12-22 14:05:58 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-12-22 14:05:58 -0500 |
commit | ad2a71bd5d6d984fc72a5474c55c7fb052cd694c (patch) | |
tree | 5d6a1de87aac9eff2f09631339fb9dda0d3607cc | |
parent | cf606558b6aa6864ed94134e98d45fc06d110911 (diff) |
window: Allow unspecified and centered window positions.
* sdl2/bindings.scm (SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_UNDEFINED):
New variables.
* sdl2/video.scm (make-window): Accept #f and 'center' as valid
coordinates for undefined and centered positioning, respectively. Use
an undefined position by default.
-rw-r--r-- | sdl2/bindings.scm | 3 | ||||
-rw-r--r-- | sdl2/video.scm | 20 |
2 files changed, 19 insertions, 4 deletions
diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm index 79fbf92..eb7689e 100644 --- a/sdl2/bindings.scm +++ b/sdl2/bindings.scm @@ -141,6 +141,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES." (define SDL_WINDOW_ALLOW_HIGHDPI #x00002000) (define SDL_WINDOW_MOUSE_CAPTURE #x00004000) +(define-public SDL_WINDOWPOS_CENTERED 805240832) +(define-public SDL_WINDOWPOS_UNDEFINED 536805376) + (define-foreign sdl-create-window '* "SDL_CreateWindow" (list '* int int int int uint32)) diff --git a/sdl2/video.scm b/sdl2/video.scm index ab2ec0f..efd87ac 100644 --- a/sdl2/video.scm +++ b/sdl2/video.scm @@ -73,7 +73,7 @@ (window-position window)))) (define* (make-window #:key (title "Guile SDL2 Window") - (position '(0 0)) (size '(640 480)) + (position '(#f #f)) (size '(640 480)) (maximize? #f) (minimize? #f) (show? #t) (resizable? #f) (opengl? #f) (border? #t) @@ -81,7 +81,17 @@ (grab-input? #f) (high-dpi? #f)) "Create a new window named TITLE with dimensions SIZE located at POSITION on the display. POSITION and SIZE are two-element lists in -the form '(x y)', where each coordinate is measured in pixels." +the form '(x y)', where each coordinate is measured in pixels. In the +case of POSITION, a coordinate may use the special symbol 'center' to +indicate that the window should be centered on that axis, or #f to +indicate that it does not matter where the window is located on that +axis." + (define coord->int + (match-lambda + (#f ffi:SDL_WINDOWPOS_UNDEFINED) + ('center ffi:SDL_WINDOWPOS_CENTERED) + (n n))) + (define x (match-lambda ((x _) x))) (define y (match-lambda ((_ y) y))) @@ -116,8 +126,10 @@ the form '(x y)', where each coordinate is measured in pixels." ffi:SDL_WINDOW_ALLOW_HIGHDPI 0))) (ptr (ffi:sdl-create-window (string->pointer title) - (x position) (y position) - (x size) (y size) + (coord->int (x position)) + (coord->int (y position)) + (x size) + (y size) flags))) (if (null-pointer? ptr) (sdl-error "make-window" "failed to create window") |