;;; Beta quality code - use at own risk ;;; Copyright (C) 2010 Anders Waldenborg ;;; I'll add a GPL header or something like that here later... ;;; Small example on how to use vrend. ;;; Defines the command vrend-clock which creates a new buffer, ;;; Make sure you resize the window/frame and stuff like that. (require 'cl) (require 'vrend) (defun vrend-clock-update-buffer (buf) (let ((win (get-buffer-window buf t))) (when win (let* ((X (window-inside-pixel-edges win)) (w (- (car (cddr X)) (car X))) (h (- (cadr (cddr X)) (cadr X)))) (with-current-buffer buf (erase-buffer) (insert-image (vrend w h '1x1fit ;; Make hour markers... (vrend-path-start 0.0 0.8) (vrend-path-lineto 0.0 0.9) (vrend-path-close) ;; ...12 of them (loop for D from 0 to 11 by 1 do (vrend-with-saved-matrix (vrend-rotate (* D (/ vrend-2pi 12))) (vrend-path-stroke))) ;; and arrows (let* ((ct (current-time)) (T (decode-time ct)) (h (nth 2 T)) (m (nth 1 T)) (s (nth 0 T)) (ms (/ (nth 2 ct) 1000)) (seconds-since-midnight (+ (* (+ (* h 60) m) 60) s)) (seconds-since-hour (+ (* m 60) s)) (ms-since-minute (+ ms (* s 1000)))) (vrend-with-saved-matrix (vrend-path-start 0.0 0.0) (vrend-path-lineto -0.05 0.4) (vrend-path-lineto 0.0 0.6) (vrend-path-lineto 0.05 0.4) (vrend-path-close) (vrend-rotate (* seconds-since-midnight (/ vrend-2pi (* 60 60 12)))) (vrend-path-stroke)) (vrend-with-saved-matrix (vrend-path-start 0.0 0.0) (vrend-path-lineto -0.05 0.3) (vrend-path-lineto 0.0 0.90) (vrend-path-lineto 0.05 0.3) (vrend-path-close) (vrend-rotate (* seconds-since-hour (/ vrend-2pi (* 60 60)))) (vrend-path-stroke)) (vrend-with-saved-matrix (vrend-path-start 0.0 0.0) (vrend-path-lineto 0.0 0.90) (vrend-path-close) (vrend-rotate (* ms-since-minute (/ vrend-2pi 60000.0))) (vrend-path-stroke)))))))))) (defun vrend-kill-buffer-hook () (cancel-timer vrend-clock-timer)) (defun vrend-clock () (interactive) (with-current-buffer (generate-new-buffer "*aw-clock*") (set-window-buffer nil (current-buffer)) (make-local-variable 'vrend-clock-timer) (add-hook 'kill-buffer-hook 'vrend-kill-buffer-hook nil t) (setq vrend-clock-timer (run-at-time nil 0.1 'vrend-clock-update-buffer (current-buffer)))))