;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.projectional-editor) ;;;;;; ;;; Projection (def (projection e) document->graphics () ()) ;;;;;; ;;; Construction (def (function e) make-projection/document->graphics () (make-projection 'document->graphics)) ;;;;;; ;;; Construction (def (macro e) document->graphics () '(make-projection/document->graphics)) ;;;;;; ;;; Printer (def printer document->graphics (projection recursion input input-reference output-reference) (declare (ignore projection)) (bind ((typed-input-reference `(the ,(form-type input) ,input-reference)) (input-content (content-of input)) (iomap (recurse-printer recursion input-content `(content-of ,typed-input-reference) `(elt (list (elements-of (the graphics/canvas ,output-reference))) 0))) (output-content (output-of iomap)) (input-selection (selection-of input)) (graphics-reference nil)) (map-forward iomap input-selection (lambda (iomap reference) (declare (ignore iomap)) (setf graphics-reference reference))) (bind ((selection-graphics (pattern-case graphics-reference ((the character (elt (the string (text-of (the graphics/text (elt (the list (elements-of (the graphics/canvas ?a))) ?b)))) ?c)) (bind ((text-graphics (elt (elements-of output-content) ?b)) (offset-text (subseq (text-of text-graphics) 0 ?c)) (text (subseq (text-of text-graphics) ?c (1+ ?c))) (location (location-of text-graphics)) (font (font-of text-graphics)) (offset (sdl:get-font-size offset-text :size :w :font font)) (width (sdl:get-font-size text :size :w :font font)) (height (sdl:get-font-size text :size :h :font font))) (make-graphics/rectangle (+ location (make-2d offset 0)) (make-2d width height)))) ((the sequence-position (pos (the string (text-of (the graphics/text (elt (the list (elements-of (the graphics/canvas ?a))) ?b)))) ?c)) (bind ((text-graphics (elt (elements-of output-content) ?b)) (text (subseq (text-of text-graphics) 0 ?c)) (location (location-of text-graphics)) (font (font-of text-graphics)) (offset (sdl:get-font-size text :size :w :font font)) (height (sdl:get-font-height :font font))) (make-graphics/line (+ location (make-2d offset 0)) (+ location (make-2d offset height)) :stroke-color sdl:*black*))))) (output (make-graphics/canvas (optional-list output-content selection-graphics) (make-2d 0 0)))) (make-iomap/recursive input output (list (make-iomap/object input input-reference output output-reference) iomap))))) ;;;;;; ;;; Reader (def reader document->graphics (projection recursion input input-reference output-reference) (declare (ignore projection)) (recurse-reader recursion input input-reference output-reference))