Overview
Comment: | Fixed getting extents |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.61 |
Files: | files | file ages | folders |
SHA1: |
e32e49b9abdfa57c0f9ac8b726f2f0c9 |
User & Date: | matt on 2016-07-14 23:31:14 |
Other Links: | branch diff | manifest | tags |
Context
2016-07-15
| ||
00:18 | dashboard compiles now check-in: e13bddd3c6 user: matt tags: v1.61 | |
2016-07-14
| ||
23:31 | Fixed getting extents check-in: e32e49b9ab user: matt tags: v1.61 | |
03:50 | Getting extents check-in: 04f3e0f7d5 user: matt tags: v1.61 | |
Changes
Modified vg-test.scm from [90d7b39a30] to [af708285e8].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | (use canvas-draw iup) (import canvas-draw-iup) (load "vg.scm") (define d1 (vg:drawing-new)) (define l1 (vg:lib-new)) (define c1 (vg:comp-new)) (let ((r1 (vg:make-rect 20 20 40 40)) (r2 (vg:make-rect 40 40 80 80))) (vg:add-objs-to-comp c1 r1 r2)) ;; add the c1 component to lib l1 with name firstcomp (vg:add-comp-to-lib l1 "firstcomp" c1) ;; add the l1 lib to drawing with name firstlib (vg:add-lib d1 "firstlib" l1) ;; instantiate firstlib/firstcomp as inst1 in drawing d1 at 0,0 (vg:instantiate d1 "firstlib" "firstcomp" "inst1" 0 0) (vg:instantiate d1 "firstlib" "firstcomp" "inst2" 200 200) | > > > > > | | > > > > > > > > > > > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | (use canvas-draw iup) (import canvas-draw-iup) (load "vg.scm") (use trace) (trace vg:draw-rect) (define d1 (vg:drawing-new)) (define l1 (vg:lib-new)) (define c1 (vg:comp-new)) (define c2 (vg:comp-new)) (let ((r1 (vg:make-rect 20 20 40 40)) (r2 (vg:make-rect 40 40 80 80))) (vg:add-objs-to-comp c1 r1 r2)) ;; add the c1 component to lib l1 with name firstcomp (vg:add-comp-to-lib l1 "firstcomp" c1) (vg:add-comp-to-lib l1 "secondcomp" c2) ;; add the l1 lib to drawing with name firstlib (vg:add-lib d1 "firstlib" l1) ;; instantiate firstlib/firstcomp as inst1 in drawing d1 at 0,0 (vg:instantiate d1 "firstlib" "firstcomp" "inst1" 0 0) (vg:instantiate d1 "firstlib" "firstcomp" "inst2" 200 200) ;; (vg:drawing-scalex-set! d1 1.1) ;; (vg:drawing-scaley-set! d1 0.5) ;; (define xtnts (vg:scale-offset-xy ;; (vg:component-get-extents c1) ;; 1.1 1.1 -2 -2)) ;; get extents of c1 and put a rectange around it ;; (define xtnts (apply vg:grow-rect 10 10 (vg:components-get-extents c1))) (vg:add-objs-to-comp c1 (apply vg:make-rect xtnts)) ;; get extents of all objects and put rectangle around it ;; (define big-xtnts (vg:instances-get-extents d1)) (vg:add-objs-to-comp c2 (apply vg:make-rect big-xtnts)) (vg:instantiate d1 "firstlib" "secondcomp" "inst3" 0 0) (vg:drawing-scalex-set! d1 1.8) (vg:drawing-scaley-set! d1 1.1) (define cnv #f) (define the-cnv (canvas #:size "500x400" #:expand "YES" #:scrollbar "YES" #:posx "0.5" #:posy "0.5" #:action (make-canvas-action (lambda (c xadj yadj) (set! cnv c))))) (show (dialog (vbox the-cnv))) (vg:drawing-cnv-set! d1 cnv) (vg:draw d1 #t) ;; (canvas-rectangle! cnv 10 100 10 80) (main-loop) |
Modified vg.scm from [40e90c99ca] to [12a91a7e84].
1 2 3 4 5 6 7 8 9 10 11 12 | ;; ;; Copyright 2016 Matthew Welland. ;; ;; This program is made available under the GNU GPL version 2.0 or ;; greater. See the accompanying file COPYING for details. ;; ;; This program is distributed WITHOUT ANY WARRANTY; without even the ;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. ;; strftime('%m/%d/%Y %H:%M:%S','now','localtime') | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ;; ;; Copyright 2016 Matthew Welland. ;; ;; This program is made available under the GNU GPL version 2.0 or ;; greater. See the accompanying file COPYING for details. ;; ;; This program is distributed WITHOUT ANY WARRANTY; without even the ;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. ;; strftime('%m/%d/%Y %H:%M:%S','now','localtime') (use defstruct srfi-1) (declare (unit vg)) (use canvas-draw iup) (import canvas-draw-iup) ;; structs ;; (defstruct vg:lib comps) |
︙ | ︙ | |||
211 212 213 214 215 216 217 218 219 220 221 222 | text: (vg:obj-text obj) line-color: (vg:obj-line-color obj) font: (vg:obj-font obj))) (pts (vg:obj-pts obj))) (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts)) (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) )) res)) ;;====================================================================== ;; Unravel and draw the objects ;;====================================================================== | > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | < | > | | > | > | | > > > | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | text: (vg:obj-text obj) line-color: (vg:obj-line-color obj) font: (vg:obj-font obj))) (pts (vg:obj-pts obj))) (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts)) (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) )) res)) ;;====================================================================== ;; instances ;;====================================================================== (define (vg:instances-get-extents drawing . instance-names) (let ((xtnt-lst (vg:draw drawing #f)) (llx #f) (lly #f) (ulx #f) (uly #f)) (for-each (lambda (extents) (let* ((ollx (list-ref extents 0)) (olly (list-ref extents 1)) (oulx (list-ref extents 2)) (ouly (list-ref extents 3))) (if (or (not llx)(< ollx llx))(set! llx ollx)) (if (or (not lly)(< olly lly))(set! lly olly)) (if (or (not ulx)(> oulx ulx))(set! ulx oulx)) (if (or (not uly)(> ouly uly))(set! uly ouly)))) xtnt-lst) (list llx lly ulx uly))) ;;====================================================================== ;; Unravel and draw the objects ;;====================================================================== ;; with get-extents = #t return the extents ;; with draw = #f don't actually draw the object ;; (define (vg:draw-obj drawing obj #!key (draw #t)) (print "obj type: " (vg:obj-type obj)) (case (vg:obj-type obj) ((r)(vg:draw-rect drawing obj draw: draw)))) ;; given a rect obj draw it on the canvas applying first the drawing ;; scale and offset ;; (define (vg:draw-rect drawing obj #!key (draw #t)) (let* ((cnv (vg:drawing-cnv drawing)) (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj))) (llx (car pts)) (lly (cadr pts)) (ulx (caddr pts)) (uly (cadddr pts))) (if draw (canvas-rectangle! cnv llx ulx lly uly)) pts)) ;; return extents (define (vg:draw drawing draw-mode . instnames) (let ((insts (vg:drawing-insts drawing)) (res '())) (for-each (lambda (instname) (let* ((inst (hash-table-ref insts instname)) (libname (vg:inst-libname inst)) (compname (vg:inst-compname inst)) (comp (vg:get-component drawing libname compname))) (print "comp: " comp) (for-each (lambda (obj) (print "obj: " (vg:obj-pts obj)) (let ((obj-xfrmd (vg:map-obj drawing inst obj))) (print "obj-xfrmd: " (vg:obj-pts obj-xfrmd)) (set! res (cons (vg:draw-obj drawing obj-xfrmd draw: draw-mode) res)))) ;; (vg:comp-objs comp)))) (if (null? instnames) (hash-table-keys insts) instnames)) res)) ;; (hash-table-values insts)))) |