-- ImageNut.mesa April 1, 1982 1:28 pm -- Implemented by Gifford and Cattell, March 1982 -- Last edited by: -- Willie-Sue on: June 28, 1982 4:14 pm -- Cattell on: October 26, 1982 12:10 pm DIRECTORY CIFS USING [GetFC, Open, read], Containers USING [ChildXBound, ChildYBound], DBView: TYPE USING [GetName], File USING [Capability], Graphics: TYPE USING [ImageRef, DrawImage, Box, GetBounds, SetCP, Scale], GraphicsOps: TYPE USING [NewAisImageFromCapability, ImageBox], GraphicsBasic, Nut: TYPE USING [Register, DisplayProc], Rope: TYPE USING [ROPE], ViewerClasses: TYPE USING [ViewerClass, ViewerClassRec, Viewer, ViewerRec, PaintProc], ViewerOps: TYPE USING [RegisterViewerClass, CreateViewer]; ImageNut: PROGRAM IMPORTS CIFS, Containers, DBView, Graphics, GraphicsOps, Nut, ViewerOps = { DisplayImage: Nut.DisplayProc = { -- display an image child: ViewerClasses.Viewer; fileName: Rope.ROPE _ DBView.GetName[e]; cap: File.Capability_ CIFS.GetFC[CIFS.Open[fileName, CIFS.read]]; image: Graphics.ImageRef _ GraphicsOps.NewAisImageFromCapability[cap]; -- create a child viewer info: ViewerClasses.ViewerRec_ [parent: newV, wx: 0, wy: 0, ww: newV.cw, wh: newV.ch, data: image, border: FALSE]; child _ ViewerOps.CreateViewer[flavor: $Image, info: info]; Containers.ChildYBound[newV, child]; Containers.ChildXBound[newV, child]; }; PaintImage: ViewerClasses.PaintProc = { -- paint an image viewer box: Graphics.Box; xmin, ymin, xmax, ymax, scale: REAL; image: GraphicsBasic.ImageRef _ LOOPHOLE[self.data]; -- scale image to fit in the available space [xmin, ymin, xmax, ymax] _ GraphicsOps.ImageBox[image]; box _ Graphics.GetBounds[context]; scale _ MIN[(box.xmax - box.xmin)/(xmax - xmin), (box.ymax - box.ymin)/(ymax - ymin)]; -- Put orign of picture in lower left corner Graphics.SetCP[self: context, x: box.xmin - xmin, y: box.ymin - ymin]; Graphics.Scale[self: context, sx: scale, sy: scale]; -- now paint image Graphics.DrawImage[context, image]; }; Init: PROC = { -- set up the world -- create a new type of viewer for images vc: ViewerClasses.ViewerClass _ NEW[ViewerClasses.ViewerClassRec]; vc.paint _ PaintImage; ViewerOps.RegisterViewerClass[flavor: $Image, class: vc]; -- register us as a nut! Nut.Register[domain: "Picture", display: DisplayImage]; Nut.Register[domain: "Map", display: DisplayImage]; }; -- start trap does it all. Init[]; }.