#lang racket
(require
ffi/unsafe
"base.rkt")
(define libcd
(case (system-type 'os)
[(windows)
(ffi-lib "cd")]
[else
(ffi-lib "libcd")]))
;; {{{ Context content playback
(define canvas-play/ptr!
(get-ffi-obj
"cdCanvasPlay" libcd
(_fun [canvas : _canvas] [context : _context]
[x0 : _int] [x1 : _int] [y0 : _int] [y1 : _int]
[data : _pointer]
-> [rc : _int])))
(define canvas-play/string!
(get-ffi-obj
"cdCanvasPlay" libcd
(_fun [canvas : _canvas] [context : _context]
[x0 : _int] [x1 : _int] [y0 : _int] [y1 : _int]
[data : _string/utf-8]
-> [rc : _int])))
(define (canvas-play! canvas context x0 x1 y0 y1 data)
(let ([canvas-play/data! (if (string? data) canvas-play/string! canvas-play/ptr!)])
(unless (zero? (canvas-play/data! canvas context x0 x1 y0 y1 data))
(error 'canvas-play! "failed to replay graphics"))))
(provide
canvas-play!)
;; }}}