Mon, 30 Dec 2019 20:21:39 +0200
"fullscreen" mode modulo GR being capable of it, better transformations
src/Visualise.jl | file | annotate | diff | comparison | revisions |
--- a/src/Visualise.jl Sat Dec 28 17:18:52 2019 +0200 +++ b/src/Visualise.jl Mon Dec 30 20:21:39 2019 +0200 @@ -78,33 +78,66 @@ return 0x010101*y + 0xff000000 end -function do_visualise(imgs; refresh=true) +function fill_viewport(vp, c) + GR.savestate() + GR.selntran(0) + GR.setscale(0) + GR.setfillintstyle(GR.INTSTYLE_SOLID) + GR.setfillcolorind(c) + GR.fillrect(vp...) + GR.selntran(1) + GR.restorestate() +end + +function do_visualise(imgs; refresh=true, fullscreen=false) n = length(imgs) # Get device dimensions in metres and pixels scrw, scrh, pw, ph = GR.inqdspsize() - aspect = n > 0 ? Float64(size(imgs[1], 1))/Float64(size(imgs[1], 2)) : 1 - # Scaling to maximums ize window + imgaspect = n > 0 ? float(size(imgs[1], 1))/float(size(imgs[1], 2)) : 1 + # Scaling to maximum size window sc=0.7 # Set up window and transformations GR.clearws() GR.setscale(0); GR.selntran(1) # - First OS window size - if scrw/n>scrh - GR.setwsviewport(0, sc*scrh*n, 0, sc*scrh*aspect) + if fullscreen + w, h = float(scrw), float(scrh) + elseif scrw/n>scrh + w, h = float(sc*scrh*n), float(sc*scrh*imgaspect) else - GR.setwsviewport(0, sc*scrw, 0, sc*scrw/n*aspect) + w, h = float(sc*scrw), float(sc*scrw/n*imgaspect) + end + GR.setwsviewport(0, w, 0, h) + # NDC to device + if w>h + canvas=[0, 1, 0, h/w] + else + canvas=[0, w/h, 0, 1] end - # - Part of normalised window shown - GR.setwswindow(0, 1, 0, 1/n*aspect); - GR.setviewport(0, 1, 0, 1/n*aspect); - # World coordinates - GR.setwindow(0, n, 0, aspect) + GR.setwswindow(canvas...) + fill_viewport(canvas, 1) + # World coordinates to NDC + if imgaspect/n<h/w + y0 = (canvas[3]+canvas[4])/2 + ww = (canvas[2]-canvas[1])/2 + y1 = y0-ww*(imgaspect/n) + y2 = y0+ww*(imgaspect/n) + GR.setviewport(canvas[1], canvas[2], y1, y2) + else + x0 = (canvas[1]+canvas[2])/2 + hh = (canvas[4]-canvas[3])/2 + x1 = x0-hh*(n/imgaspect) + x2 = x0+hh*(n/imgaspect) + GR.setviewport(x1, x2, canvas[3], canvas[4]) + end + GR.setwindow(0, n, 0, 1) + # Clear background # Plot images for i=1:n im = imgs[i]' sz = size(im) - GR.drawimage(i-1, i, 0, aspect, sz[1], sz[2], grayGR.(im)) + GR.drawimage(i-1, i, 0, 1, sz[1], sz[2], grayGR.(im)) end if refresh GR.updatews()