DIRECTORY BiScrollers, BiScrollersExtras, BiScrollersExtras2, FS, Geom2D, Imager, ImagerBox, ImagerInterpress, ImagerTransformation, IO, Menus, MessageWindow, PopUpButtons, Real, RealFns, Rope, SimpleFeedback, ViewerClasses, ViewerOps, ViewerTools; BiScrollersImpl: CEDAR MONITOR IMPORTS FS, Geom2D, Imager, ImagerBox, ImagerInterpress, ImagerTransformation, IO, Menus, MessageWindow, PopUpButtons, Real, RealFns, Rope, SimpleFeedback, ViewerOps, ViewerTools EXPORTS BiScrollers, BiScrollersExtras, BiScrollersExtras2 SHARES Menus = BEGIN OPEN PUB: PopUpButtons, BiScrollers; StyleList: TYPE = LIST OF RECORD [name: ROPE, style: BiScrollerStyle]; bsMenu: PUBLIC Menus.Menu ฌ Menus.CreateMenu[]; styles: StyleList ฌ NIL; defaultStyleName: ROPE ฌ NIL; GetStyle: PUBLIC PROC [name: ROPE ฌ NIL] RETURNS [style: BiScrollerStyle] = { IF name = NIL THEN name ฌ defaultStyleName; FOR sl: StyleList ฌ styles, sl.rest WHILE sl # NIL DO IF sl.first.name.Equal[name] THEN RETURN [sl.first.style] ENDLOOP; style ฌ NIL; }; RegisterStyle: PUBLIC ENTRY PROC [name: ROPE, style: BiScrollerStyle] = { ENABLE UNWIND => {}; styles ฌ CONS[[name, style], styles]; }; SetDefaultStyle: PUBLIC ENTRY PROC [name: ROPE] RETURNS [old: ROPE] = {old ฌ defaultStyleName; defaultStyleName ฌ name}; IsBiScroller: PUBLIC PROC [ra: REF ANY] RETURNS [BOOLEAN] = {RETURN [ISTYPE[ra, BiScroller]]}; NarrowToBiScroller: PUBLIC PROC [ra: REF ANY] RETURNS [BiScroller] = {bs: BiScroller ฌ NARROW[ra]; RETURN [bs]}; QuaViewer: PUBLIC PROC [bs: BiScroller, inner: BOOL ฌ FALSE] RETURNS [Viewer] = {RETURN [bs.style.QuaViewer[bs, inner]]}; QuaBiScroller: PUBLIC PROC [v: Viewer] RETURNS [BiScroller] = {bs: BiScroller ฌ NARROW[v.data]; RETURN [bs]}; ViewerIsABiScroller: PUBLIC PROC [v: Viewer] RETURNS [BOOLEAN] = {RETURN [ISTYPE[v.data, BiScroller]]}; ClientDataOf: PUBLIC PROC [bs: BiScroller] RETURNS [REF ANY] = {RETURN [bs.style.ClientDataOf[bs]]}; ClientDataOfViewer: PUBLIC PROC [v: Viewer] RETURNS [REF ANY] = {bs: BiScroller ฌ NARROW[v.data]; RETURN [bs.style.ClientDataOf[bs]]}; ViewportExtrema: PUBLIC PROC [bs: BiScroller, direction: Vec] RETURNS [min, max: Vec] = BEGIN vl: VecList ฌ bs.style.ViewportOf[bs]; e: Geom2D.ExtremaRec ฌ Geom2D.Extreme[direction, vl.first, Geom2D.Extreme[direction, vl.rest.first, Geom2D.Extreme[direction, vl.rest.rest.first, Geom2D.StartExtreme[direction, vl.rest.rest.rest.first]]]]; RETURN [e.minV, e.maxV]; END; ViewportBox: PUBLIC PROC [bs: BiScroller] RETURNS [bb: Rect] = { Pt: PROC [v: Vec] RETURNS [a: Rect] = INLINE {a ฌ [v.x, v.y, 0, 0]}; vl: VecList ฌ bs.style.ViewportOf[bs]; bb ฌ Geom2D.UpdateRects[ Geom2D.UpdateRects[ Geom2D.UpdateRects[ Pt[vl.first], Pt[vl.rest.first]], Pt[vl.rest.rest.first]], Pt[vl.rest.rest.rest.first]]; }; GenID: PUBLIC PROC [BiScroller] RETURNS [Transform] --TransformGenerator-- = {RETURN [Geom2D.id]}; ConstantVector: PROC [bs: BiScroller] RETURNS [cv: Vec] = { v: Viewer ~ bs.style.QuaViewer[bs, TRUE]; pp: PreservationPair ~ bs.class.common.preserve; cv ฌ [v.cw*pp[X], v.ch*pp[Y]]; RETURN}; ViewLimitsOfImage: PUBLIC PROC [bs: BiScroller, axis: Axis] RETURNS [vmin, vmax: REAL] = BEGIN t: Transform ฌ bs.style.GetTransforms[bs].clientToViewer; tn: Geom2D.Trans ฌ Geom2D.ToTrans[t]; norm, min, max: Vec; SELECT axis FROM X => norm ฌ [tn.dxdx, tn.dxdy]; Y => norm ฌ [tn.dydx, tn.dydy]; ENDCASE => ERROR; [min, max] ฌ bs.class.common.extrema[bs.style.ClientDataOf[bs], norm]; min ฌ t.Transform[min]; max ฌ t.Transform[max]; SELECT axis FROM X => {vmin ฌ min.x; vmax ฌ max.x}; Y => {vmin ฌ min.y; vmax ฌ max.y}; ENDCASE => ERROR; END; Scale: PUBLIC ENTRY PROC [bs: BiScroller, op: ScaleOp, paint: BOOL ฌ TRUE] = {ENABLE ABORTED => {}; IntScale[bs, op, paint]}; IntScale: INTERNAL PROC [bs: BiScroller, op: ScaleOp, paint: BOOL ฌ TRUE] = { cv: Vec ~ ConstantVector[bs]; old: Transform ~ bs.style.GetTransforms[bs].clientToViewer; new: Transform ฌ old.PostTranslate[cv.Neg[]]; WITH op SELECT FROM reset => { v: Geom2D.Trans ฌ Geom2D.ToTrans[bs.class.common.vanilla[bs]]; vd: REAL ฌ v.dxdx*v.dydy - v.dydx*v.dxdy; od: REAL ฌ old.a*old.e - old.d*old.b; new ฌ new.PostScale[ RealFns.SqRt[ABS[vd/ZeroProtect[od]]]*SGN[vd]*SGN[od] ]; }; byArg => new ฌ new.PostScale[arg]; diff => IF bs.class.common.mayStretch THEN new ฌ new.PostScale2[[x, y]] ELSE new ฌ new.PostScale[x]; ENDCASE => ERROR; new ฌ new.PostTranslate[cv]; bs.style.ChangeTransform[bs, new, ignore, paint]; }; SGN: PROC [r: REAL] RETURNS [sgn: [-1 .. 1]] = { sgn ฌ SELECT r FROM <0 => -1, =0 => 0, >0 => 1, ENDCASE => ERROR}; ZeroProtect: PROC [r: REAL] RETURNS [r0: REAL] = {r0 ฌ IF r = 0.0 THEN 1.0 ELSE r}; Rotate: PUBLIC ENTRY PROC [bs: BiScroller, op: RotateOp, paint: BOOL ฌ TRUE] = {ENABLE ABORTED => {}; IntRotate[bs, op, paint]}; IntRotate: INTERNAL PROC [bs: BiScroller, op: RotateOp, paint: BOOL ฌ TRUE] = { cv: Vec ~ ConstantVector[bs]; old: Transform ~ bs.style.GetTransforms[bs].clientToViewer; new: Transform ฌ old.PostTranslate[cv.Neg[]]; WITH op SELECT FROM reset => { v: Geom2D.Trans ฌ Geom2D.ToTrans[bs.class.common.vanilla[bs]]; new ฌ new.PostRotate[ RealFns.ArcTanDeg[y: v.dydx, x: v.dxdx] - RealFns.ArcTanDeg[y: old.d, x: old.a] ]; }; byArg => new ฌ new.PostRotate[arg]; ENDCASE => ERROR; new ฌ new.PostTranslate[cv]; bs.style.ChangeTransform[bs, new, ignore, paint]; }; Shift: PUBLIC ENTRY PROC [bs: BiScroller, dx, dy: REAL, paint: BOOL ฌ TRUE] = {ENABLE ABORTED => {}; IntShift[bs, [dx, dy], paint]}; IntShift: INTERNAL PROC [bs: BiScroller, by: Vec, paint: BOOL ฌ TRUE] = { old: Transform ~ bs.style.GetTransforms[bs].clientToViewer; new: Transform ~ old.PostTranslate[by]; bs.style.ChangeTransform[bs, new, ignore, paint]; }; Align: PUBLIC ENTRY PROC [bs: BiScroller, client, viewer: Location, doX, doY, paint: BOOL ฌ TRUE, ageOp: AgeOp ฌ remember] = {ENABLE ABORTED => {}; IntAlign[bs, client, viewer, ageOp, doX, doY, paint]}; IntAlign: INTERNAL PROC [bs: BiScroller, client, viewer: Location, ageOp: AgeOp, doX, doY, paint: BOOL ฌ TRUE] = { old: Transform ฌ bs.style.GetTransforms[bs].clientToViewer; new: Transform; from, to: Vec ฌ [0.0, 0.0]; Blend: PROC [a: REAL, b0, b1: REAL] RETURNS [c: REAL] = {c ฌ (1-a)*b0 + a*b1}; WITH client SELECT FROM coord => from ฌ old.Transform[[x, y]]; fraction => { min, max: REAL; IF doX THEN { [min, max] ฌ ViewLimitsOfImage[bs, X]; from.x ฌ Blend[fx, min, max]; }; IF doY THEN { [min, max] ฌ ViewLimitsOfImage[bs, Y]; from.y ฌ Blend[fy, min, max]; }; }; ENDCASE => ERROR; WITH viewer SELECT FROM coord => to ฌ [x, y]; fraction => { v: Viewer ฌ bs.style.QuaViewer[bs, TRUE]; to ฌ [fx*v.cw, fy*v.ch]; }; ENDCASE => ERROR; IF NOT doX THEN to.x ฌ from.x; IF NOT doY THEN to.y ฌ from.y; new ฌ old.PostTranslate[from.Neg[]].PostTranslate[to]; bs.style.ChangeTransform[bs, new, ageOp, paint]; }; ViewerBox: PUBLIC PROC [bs: BiScroller] RETURNS [Rect--the viewer area, in viewer coordinates--] ~ { iv: Viewer ~ bs.style.QuaViewer[bs, TRUE]; RETURN [[x: 0, y: 0, w: iv.cw, h: iv.ch]]}; ClientBox: PUBLIC PROC [bs: BiScroller] RETURNS [Rect--the data area, in client coordinates--] ~ { clientData: REF ANY ~ bs.style.ClientDataOf[bs]; limits: Imager.Box; [[limits.xmin,], [limits.xmax,]] ฌ bs.class.common.extrema[clientData, [1, 0]]; [[,limits.ymin], [,limits.ymax]] ฌ bs.class.common.extrema[clientData, [0, 1]]; RETURN ImagerBox.RectangleFromBox[limits]}; Fit: PUBLIC ENTRY PROC [bs: BiScroller, paint, uniformly: BOOL ฌ TRUE] ~ { IntFit[bs, paint, uniformly]; RETURN}; IntFit: INTERNAL PROC [bs: BiScroller, paint, uniformly: BOOL] ~ { iv: Viewer ~ bs.style.QuaViewer[bs, TRUE]; limits: Imager.Box; [limits.xmin, limits.xmax] ฌ ViewLimitsOfImage[bs, X]; [limits.ymin, limits.ymax] ฌ ViewLimitsOfImage[bs, Y]; IntBoxScale[bs, ImagerBox.RectangleFromBox[limits], [0, 0, iv.cw, iv.ch], paint, uniformly]; RETURN}; ShowBox: PUBLIC PROC [bs: BiScroller, client, viewer: Rect, paint, uniformly: BOOL ฌ TRUE] ~ { c2v: Transform ~ bs.style.GetTransforms[bs].clientToViewer; from: Rect ~ c2v.TransformRectangle[client]; BoxScale[bs, from, viewer, paint, uniformly]; RETURN}; BoxScale: PUBLIC ENTRY PROC [bs: BiScroller, from, to: Rect --both in viewer coords--, paint, uniformly: BOOL ฌ TRUE] = {ENABLE ABORTED => {}; IntBoxScale[bs, from, to, paint, uniformly]}; IntBoxScale: INTERNAL PROC [bs: BiScroller, from, to: Rect --both in viewer coords--, paint, uniformly: BOOL ฌ TRUE] = { old: Transform ฌ bs.style.GetTransforms[bs].clientToViewer; new: Transform ฌ old.PostTranslate[[ -(from.x + from.w/2), -(from.y + from.h/2)]]; ndx, ndy, odx, ody, sx, sy: REAL; ndx ฌ to.w; ndy ฌ to.h; odx ฌ from.w; ody ฌ from.h; sx ฌ IF ndx=0 OR odx=0 THEN 1 ELSE ndx/odx; sy ฌ IF ndy=0 OR ody=0 THEN 1 ELSE ndy/ody; IF uniformly OR NOT bs.class.common.mayStretch THEN sx ฌ sy ฌ MIN[sx, sy]; IF bs.class.common.preferIntegerCoefficients THEN {sx ฌ Round[sx]; sy ฌ Round[sy]}; new ฌ new.PostScale2[[sx, sy]]; new ฌ new.PostTranslate[[ (to.x + to.w/2), (to.y + to.h/2)]]; bs.style.ChangeTransform[bs, new, remember, paint]; }; Round: PROC [r: REAL] RETURNS [rr: REAL] = { i: INT ฌ Real.Round[r]; rr ฌ IF (i=0) # (r=0) THEN r ELSE REAL[i]; }; GetArg: PROC [diffOK: BOOL ฌ FALSE] RETURNS [valid: BOOL, arg, arg2: REAL ฌ 0.0] ~ { sel: ROPE ~ ViewerTools.GetSelectionContents[]; s: IO.STREAM; valid ฌ SELECT sel.Length[] FROM > 1 => TRUE, > 0 => sel.Fetch[0] IN ['0 .. '9], ENDCASE => FALSE; IF NOT valid THEN RETURN; s ฌ IO.RIS[sel]; {ENABLE IO.Error, IO.EndOfStream => { valid ฌ FALSE; MessageWindow.Append[ message: IO.PutFR1["Select a number, not %g", IO.refAny[sel]], clearFirst: TRUE]; MessageWindow.Blink[]; CONTINUE}; arg ฌ arg2 ฌ s.GetReal[]; IF diffOK AND (NOT s.EndOf[]) AND s.PeekChar[]=': THEN { IF NOT s.GetChar[]=': THEN ERROR; arg2 ฌ s.GetReal[]; valid ฌ valid}; IF NOT s.EndOf[] THEN IO.Error[ec: SyntaxError, stream: s]}; s.Close[]; RETURN}; GetBS: PROC [v: Viewer] RETURNS [bs: BiScroller] = { FOR v ฌ v, v.parent WHILE (bs ฌ NARROW[ViewerOps.FetchProp[v, $SubBiScroller]]) = NIL DO NULL ENDLOOP; RETURN}; SetBS: PUBLIC PROC [v: Viewer, bs: BiScroller] = { FOR v ฌ v, v.parent WHILE v # NIL DO ViewerOps.AddProp[v, $SubBiScroller, bs] ENDLOOP; RETURN}; CatenateMenus: PUBLIC PROC [pre, post: Menus.Menu] RETURNS [menu: Menus.Menu] = { preLines, postLines: INT; menu ฌ IF pre = NIL THEN Menus.CreateMenu[0] ELSE Menus.CopyMenu[pre]; preLines ฌ Menus.GetNumberOfLines[menu]; postLines ฌ Menus.GetNumberOfLines[post]; Menus.ChangeNumberOfLines[menu, preLines + postLines]; FOR i: INT IN [0 .. postLines) DO Menus.SetLine[menu, preLines+i, Menus.GetLine[post, i]] ENDLOOP; }; BeVec: PROC [ra: REF ANY] RETURNS [Vec] ~ {RETURN [NARROW[ra, REF Vec]ญ]}; BeReal: PROC [ra: REF ANY] RETURNS [REAL] ~ {RETURN [NARROW[ra, REF REAL]ญ]}; BeRect: PROC [ra: REF ANY] RETURNS [Rect] ~ {RETURN [NARROW[ra, REF Rect]ญ]}; FromVec: PROC [x: Vec] RETURNS [REF ANY] ~ {RETURN [NEW [Vec ฌ x]]}; FromReal: PROC [x: REAL] RETURNS [REF ANY] ~ {RETURN [NEW [REAL ฌ x]]}; BeBool: PROC [ra: REF ANY] RETURNS [BOOL] ~ {RETURN [SELECT ra FROM $FALSE => FALSE, $TRUE => TRUE, ENDCASE => ERROR]}; FromBool: PROC [x: BOOL] RETURNS [REF ANY] ~ {RETURN [IF x THEN $TRUE ELSE $FALSE]}; DoBSUserAction: PUBLIC ENTRY PROC [bs: BiScroller, input: LORA, device, user, display: REF ANY ฌ NIL] ~ { ENABLE UNWIND => input ฌ input; paint: BOOL ฌ TRUE; age: AgeOp ฌ remember; SELECT input.first FROM $First => {paint ฌ FALSE; input ฌ input.rest}; $Last => {age ฌ ignore; input ฌ input.rest}; $Mid => {paint ฌ FALSE; age ฌ ignore; input ฌ input.rest}; ENDCASE => NULL; SELECT input.first FROM $Shift => IntShift[bs, BeVec[input.rest.first], paint]; $Scale => {s: Vec ~ BeVec[input.rest.first]; IntScale[bs, IF s.x=s.y THEN [byArg[s.x]] ELSE [diff[s.x, s.y]], paint]}; $ScaleReset => IntScale[bs, [reset[]], paint]; $Rotate => IntRotate[bs, [byArg[BeReal[input.rest.first]]], paint]; $RotateReset => IntRotate[bs, [reset[]], paint]; $FitXY, $FitUniformly => { uniformly: BOOL ~ SELECT input.first FROM $FitUniformly => TRUE, $FitXY => FALSE, ENDCASE => ERROR; IntFit[bs, paint, uniformly]; }; $Vanilla => bs.style.ChangeTransform[bs, bs.class.common.vanilla[bs], age, paint]; $AlignFracs => { client: Vec ~ BeVec[input.rest.first]; viewer: Vec ~ BeVec[input.rest.rest.first]; doX: BOOL ~ BeBool[input.rest.rest.rest.first]; doY: BOOL ~ BeBool[input.rest.rest.rest.rest.first]; IntAlign[bs: bs, client: [fraction[client.x, client.y]], viewer: [fraction[viewer.x, viewer.y]], ageOp: age, doX: doX, doY: doY, paint: paint]}; $BoxScale => { from: Rect ~ BeRect[input.rest.first]; to: Rect ~ BeRect[input.rest.rest.first]; uniformly: BOOL ~ BeBool[input.rest.rest.rest.first]; IntBoxScale[bs, from, to, paint, uniformly]}; $Prev => bs.style.ChangeTransform[bs, bs.style.GetTransforms[bs, previous].clientToViewer, age, paint]; ENDCASE => ERROR; }; scaleClass: PUB.Class = PUB.MakeClass[[ proc: ScalePop, choices: LIST[ [$Magnify, "Double magnification (or multiply by selection)"], [$Reset, "Reset magnification"], [$Shrink, "Halve magnification (or divide by selection)"] ], doc: "Magnify or shrink tool-to-viewer transform", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Scale:"]] ]]; ScalePop: PROC [view, instanceData, classData, key: REF ANY] --PUB.PopUpButtonProc-- = {ENABLE ABORTED => NULL; bs: BiScroller = NARROW[instanceData]; valid: BOOL; arg, arg2: REAL; [valid, arg, arg2] ฌ GetArg[TRUE]; IF NOT valid THEN arg ฌ arg2 ฌ 2.0; IF key=$Shrink THEN {arg ฌ 1.0/arg; arg2 ฌ 1.0/arg2}; bs.class.common.bsUserAction[bs, SELECT key FROM $Magnify, $Shrink => LIST[$Scale, FromVec[[arg, arg2]]], $Reset => LIST[$ScaleReset], ENDCASE => ERROR]; }; CreateScale: PUBLIC PROC [viewerInfo: ViewerClasses.ViewerRec, bs: BiScroller, font: Imager.Font ฌ NIL] RETURNS [button: Viewer] = { IF viewerInfo.name = NIL THEN viewerInfo.name ฌ "Scale"; button ฌ scaleClass.Instantiate[viewerInfo, bs, PUB.ImageForRope[rope: viewerInfo.name, font: font]]; }; ScaleButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ~ NARROW[parent]; bs: BiScroller ~ GetBS[v]; valid: BOOL; arg, arg2: REAL; [valid, arg, arg2] ฌ GetArg[TRUE]; IF NOT valid THEN arg ฌ arg2 ฌ 2.0; IF mouseButton=blue THEN {arg ฌ 1.0/arg; arg2 ฌ 1.0/arg2; mouseButton ฌ red}; bs.class.common.bsUserAction[bs, SELECT mouseButton FROM red => LIST[$Scale, FromVec[[arg, arg2]]], yellow => LIST[$ScaleReset], ENDCASE => ERROR]; }; rotateClass: PUB.Class = PUB.MakeClass[[ proc: RotatePop, choices: LIST[ [$Left, "Rotate left by 90 or selection"], [$Reset, "Reset rotation"], [$Right, "Rotate right by 90 or selection"], [$Left, "Rotate left by 90 or selection"], [$Half, "Rotate 180"], [$Right, "Rotate right by 90 or selection"] ], doc: "Rotate the tool-to-viewer transform", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Rotate:"]] ]]; RotatePop: PROC [view, instanceData, classData, key: REF ANY] --PUB.PopUpButtonProc-- = {ENABLE ABORTED => NULL; bs: BiScroller = NARROW[instanceData]; valid: BOOL; arg: REAL; [valid, arg] ฌ GetArg[]; IF NOT valid THEN arg ฌ 90; bs.class.common.bsUserAction[bs, IF key=$Reset THEN LIST[$RotateReset] ELSE LIST[$Rotate, FromReal[SELECT key FROM $Left => arg, $Right => -arg, $Half => 180, ENDCASE => ERROR]]]; }; CreateRotate: PUBLIC PROC [viewerInfo: ViewerClasses.ViewerRec, bs: BiScroller, font: Imager.Font ฌ NIL] RETURNS [button: Viewer] = { IF viewerInfo.name = NIL THEN viewerInfo.name ฌ "Rotate"; button ฌ rotateClass.Instantiate[viewerInfo, bs, PUB.ImageForRope[rope: viewerInfo.name, font: font]]; }; RotateButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ~ NARROW[parent]; bs: BiScroller ~ GetBS[v]; valid: BOOL; arg: REAL; [valid, arg] ฌ GetArg[]; IF NOT valid THEN arg ฌ 90; bs.class.common.bsUserAction[bs, IF mouseButton=yellow AND NOT shift THEN LIST[$RotateReset] ELSE LIST[$Rotate, FromReal[SELECT mouseButton FROM red => arg, yellow => 180, blue => -arg, ENDCASE => ERROR]]]; }; fitClass: PUB.Class = PUB.MakeClass[[ proc: FitPop, choices: LIST[ [$FitUniformly, "Translate and scale to fill viewer (X and Y scaled by same factor)"], [$FitXY, "x and y may be scaled by different factors"] ], decodeMouseButton: FALSE, doc: "Translate and scale to fill viewer", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Fit:"]] ]]; FitPop: PROC [view, instanceData, classData, key: REF ANY] --PUB.PopUpButtonProc-- = {ENABLE ABORTED => NULL; bs: BiScroller = NARROW[instanceData]; bs.class.common.bsUserAction[bs, LIST[key]]; }; CreateFit: PUBLIC PROC [viewerInfo: ViewerClasses.ViewerRec, bs: BiScroller, font: Imager.Font ฌ NIL] RETURNS [button: Viewer] = { IF viewerInfo.name = NIL THEN viewerInfo.name ฌ "Fit"; button ฌ fitClass.Instantiate[viewerInfo, bs, PUB.ImageForRope[rope: viewerInfo.name, font: font]]; }; FitButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ~ NARROW[parent]; bs: BiScroller ~ GetBS[v]; bs.class.common.bsUserAction[bs, LIST[IF shift THEN $FitXY ELSE $FitUniformly]]; }; resetClass: PUB.Class = PUB.MakeClass[[ proc: ResetPop, choices: LIST[ [$Vanilla, "Reset to some vanilla transform"], [$VanillaAndCenter, "Reset then Center"], [$Center, "Put center of data in center of viewer"] ], doc: "Set the tool-to-viewer transform to something plainish", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Reset:"]] ]]; ResetPop: PROC [view, instanceData, classData, key: REF ANY] --PUB.PopUpButtonProc-- = {ENABLE ABORTED => NULL; bs: BiScroller = NARROW[instanceData]; SELECT key FROM $Vanilla => bs.class.common.bsUserAction[bs, LIST[$Vanilla]]; $VanillaAndCenter => { bs.class.common.bsUserAction[bs, LIST[$First, $Vanilla]]; bs.class.common.bsUserAction[bs, LIST[$Last, $AlignFracs, FromVec[[0.5, 0.5]], FromVec[[0.5, 0.5]], $TRUE, $TRUE]]; }; $Center => bs.class.common.bsUserAction[bs, LIST[$AlignFracs, FromVec[[0.5, 0.5]], FromVec[[0.5, 0.5]], $TRUE, $TRUE]]; ENDCASE => ERROR; }; CreateReset: PUBLIC PROC [viewerInfo: ViewerClasses.ViewerRec, bs: BiScroller, font: Imager.Font ฌ NIL] RETURNS [button: Viewer] = { IF viewerInfo.name = NIL THEN viewerInfo.name ฌ "Reset"; button ฌ resetClass.Instantiate[viewerInfo, bs, PUB.ImageForRope[rope: viewerInfo.name, font: font]]; }; ResetButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ฌ NARROW[parent]; bs: BiScroller ฌ GetBS[v]; SELECT mouseButton FROM red => bs.class.common.bsUserAction[bs, LIST[$Vanilla]]; yellow => { bs.class.common.bsUserAction[bs, LIST[$First, $Vanilla]]; bs.class.common.bsUserAction[bs, LIST[$Last, $AlignFracs, FromVec[[0.5, 0.5]], FromVec[[0.5, 0.5]], $TRUE, $TRUE]]; }; blue => bs.class.common.bsUserAction[bs, LIST[$AlignFracs, FromVec[[0.5, 0.5]], FromVec[[0.5, 0.5]], $TRUE, $TRUE]]; ENDCASE => ERROR; }; edgeClass0: PUB.Class = PUB.MakeClass[[ proc: EdgePop, choices: LIST[ [$Left, "Slide left edge of data to left edge of viewer"], [$Top, "Slide top edge of data to top edge of viewer"], [$Right, "Slide right edge of data to right edge of viewer"], [$TopLeft, "Align upper left corner of data and viewer"], [$TopMiddle, "Align middle of top edge of data and viewer"], [$TopRight, "Align upper right corner of data and viewer"], [$MidLeft, "Align middle of left edge of data and viewer"], [$BotMiddle, "Align middle of bottom edge of data and viewer"], [$MidRight, "Align middle of right edge of data and viewer"], [$BotLeft, "Align lower left corner of data and viewer"], [$Bottom, "Slide bottom edge of data to bottom edge of viewer"], [$BotRight, "Align lower right corner of data and viewer"] ], doc: "Align by edge(s)", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Edge:"]] ]]; edgeClass1: PUB.Class = PUB.MakeClass[[ proc: EdgePop, choices: LIST[ [$Left, "Slide left edge of data to left edge of viewer"], [$Bottom, "Slide bottom edge of data to bottom edge of viewer"], [$Right, "Slide right edge of data to right edge of viewer"], [$MidLeft, "Align middle of left edge of data and viewer"], [$Top, "Slide top edge of data to top edge of viewer"], [$MidRight, "Align middle of right edge of data and viewer"], [$BotLeft, "Align lower left corner of data and viewer"], [$BotMiddle, "Align middle of bottom edge of data and viewer"], [$BotRight, "Align lower right corner of data and viewer"], [$TopLeft, "Align upper left corner of data and viewer"], [$TopMiddle, "Align middle of top edge of data and viewer"], [$TopRight, "Align upper right corner of data and viewer"] ], doc: "Align by edge(s)", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Edge:"]] ]]; edgeClass2: PUB.Class = PUB.MakeClass[[ proc: EdgePop, choices: LIST[ [$Left, "Slide left edge of data to left edge of viewer"], [$MidLeft, "Align middle of left edge of data and viewer"], [$BotLeft, "Align lower left corner of data and viewer"], [$Right, "Slide right edge of data to right edge of viewer"], [$MidRight, "Align middle of right edge of data and viewer"], [$BotRight, "Align lower right corner of data and viewer"], [$Bottom, "Slide bottom edge of data to bottom edge of viewer"], [$BotMiddle, "Align middle of bottom edge of data and viewer"], [$TopLeft, "Align upper left corner of data and viewer"], [$Top, "Slide top edge of data to top edge of viewer"], [$TopMiddle, "Align middle of top edge of data and viewer"], [$TopRight, "Align upper right corner of data and viewer"] ], doc: "Align by edge(s)", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Edge:"]] ]]; edgeClass: PUB.Class ฌ edgeClass0; EdgePop: PROC [view, instanceData, classData, key: REF ANY] --PUB.PopUpButtonProc-- = {ENABLE ABORTED => NULL; bs: BiScroller = NARROW[instanceData]; loc: Location.fraction ฌ [fraction[0, 0]]; doX, doY: BOOL ฌ TRUE; SELECT key FROM $Left => {loc.fx ฌ 0; doY ฌ FALSE}; $Right => {loc.fx ฌ 1; doY ฌ FALSE}; $Bottom => {loc.fy ฌ 0; doX ฌ FALSE}; $Top => {loc.fy ฌ 1; doX ฌ FALSE}; $BotLeft => loc ฌ [fraction[0, 0]]; $MidLeft => loc ฌ [fraction[0, 0.5]]; $TopLeft => loc ฌ [fraction[0, 1]]; $BotMiddle => loc ฌ [fraction[0.5, 0]]; $BotRight => loc ฌ [fraction[1, 0]]; $MidRight => loc ฌ [fraction[1, 0.5]]; $TopRight => loc ฌ [fraction[1, 1]]; $TopMiddle => loc ฌ [fraction[0.5, 1]]; ENDCASE => ERROR; bs.class.common.bsUserAction[bs, LIST[$AlignFracs, FromVec[[loc.fx, loc.fy]], FromVec[[loc.fx, loc.fy]], FromBool[doX], FromBool[doY]]]; }; CreateEdge: PUBLIC PROC [viewerInfo: ViewerClasses.ViewerRec, bs: BiScroller, font: Imager.Font ฌ NIL] RETURNS [button: Viewer] = { IF viewerInfo.name = NIL THEN viewerInfo.name ฌ "Edge"; button ฌ edgeClass.Instantiate[viewerInfo, bs, PUB.ImageForRope[rope: viewerInfo.name, font: font]]; }; LeftButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ฌ NARROW[parent]; bs: BiScroller ฌ GetBS[v]; bs.class.common.bsUserAction[bs, LIST[$AlignFracs, FromVec[[0.0, 0.0]], FromVec[[0.0, 0.0]], $TRUE, $FALSE]]; }; RightButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ฌ NARROW[parent]; bs: BiScroller ฌ GetBS[v]; bs.class.common.bsUserAction[bs, LIST[$AlignFracs, FromVec[[1.0, 0.0]], FromVec[[1.0, 0.0]], $TRUE, $FALSE]]; }; TopButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ฌ NARROW[parent]; bs: BiScroller ฌ GetBS[v]; bs.class.common.bsUserAction[bs, LIST[$AlignFracs, FromVec[[0.0, 1.0]], FromVec[[0.0, 1.0]], $FALSE, $TRUE]]; }; BottomButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ฌ NARROW[parent]; bs: BiScroller ฌ GetBS[v]; bs.class.common.bsUserAction[bs, LIST[$AlignFracs, FromVec[[0.0, 0.0]], FromVec[[0.0, 0.0]], $FALSE, $TRUE]]; }; prevClass: PUB.Class = PUB.MakeClass[[ proc: PrevPop, choices: LIST[ [$Prev] ], doc: "Restore previous tool-to-viewer transform", help: PUB.HelpFromDoc["BiScrollersDoc.Tioga", LIST["Prev:"]] ]]; PrevPop: PROC [view, instanceData, classData, key: REF ANY] --PUB.PopUpButtonProc-- = {ENABLE ABORTED => NULL; bs: BiScroller = NARROW[instanceData]; bs.class.common.bsUserAction[bs, LIST[$Prev]]; }; CreatePrev: PUBLIC PROC [viewerInfo: ViewerClasses.ViewerRec, bs: BiScroller, font: Imager.Font ฌ NIL] RETURNS [button: Viewer] = { IF viewerInfo.name = NIL THEN viewerInfo.name ฌ "Prev"; button ฌ prevClass.Instantiate[viewerInfo, bs, PUB.ImageForRope[rope: viewerInfo.name, font: font]]; }; PrevTransformButt: PROC [parent: REF ANY, clientData: REF ANY ฌ NIL, mouseButton: Menus.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] --Menus.MenuProc-- = {ENABLE ABORTED => NULL; v: Viewer ฌ NARROW[parent]; bs: BiScroller ฌ GetBS[v]; bs.class.common.bsUserAction[bs, LIST[$Prev]]; }; CreateDraw: PUBLIC PROC [viewerInfo: ViewerClasses.ViewerRec, bs: BiScroller, font: Imager.Font ฌ NIL] RETURNS [button: Viewer] = { IF viewerInfo.name = NIL THEN viewerInfo.name ฌ "Draw"; button ฌ drawClass.Instantiate[viewerInfo, bs, PUB.ImageForRope[rope: viewerInfo.name, font: font]]; RETURN}; drawClass: PUB.Class ฌ PUB.MakeClass[[ proc: DrawCtl, choices: LIST[ [$ToIP, "Create an interpress master of viewer contents"] ], doc: "Drawing control operations"]]; DrawCtl: PROC [view, instanceData, classData, key: REF ANY] --PUB.PopUpButtonProc-- = { bs: BiScroller ~ NARROW[instanceData]; SELECT key FROM $ToIP => { fileName: ROPE ~ ViewerTools.GetSelectionContents[]; writtenName: ROPE; width, height: REAL; [writtenName, width, height] ฌ ToIP[bs, fileName, ".ip" !FS.Error => { SimpleFeedback.Append[$BiAxials, oneLiner, $Error, Rope.Concat["File create error: ", error.explanation]]; GOTO Dun}]; SimpleFeedback.PutFL[$BiAxials, oneLiner, $Error, "%g is %g by %g", LIST[[rope[FS.ExpandName[writtenName].fullFName]], [real[width]], [real[height]] ]]; key ฌ key}; ENDCASE => ERROR; RETURN EXITS Dun => key ฌ key}; DrawButt: PROC [parent: Viewer, clientData: REF ANY ฌ NIL, mouseButton: ViewerClasses.MouseButton ฌ red, shift, control: BOOL ฌ FALSE] ~ { bs: BiScroller ~ QuaBiScroller[parent]; DrawCtl[parent, bs, NIL, $ToIP]; RETURN}; ToIP: PUBLIC PROC [bs: BiScroller, fileName, defaultExtension: ROPE ฌ NIL] RETURNS [writtenName: ROPE, width, height: REAL] ~ { asBS: BiScroller ~ bs; outer: Viewer ~ QuaViewer[asBS, FALSE]; inner: Viewer ~ QuaViewer[asBS, TRUE]; xfm: Transform ~ asBS.style.GetTransforms[asBS].clientToViewer; IF fileName.Length=0 THEN fileName ฌ outer.name.Concat[defaultExtension] ELSE IF fileName.Find["."]<0 THEN fileName ฌ fileName.Concat[defaultExtension]; {file: ImagerInterpress.Ref ~ ImagerInterpress.Create[fileName]; PaintPage: PROC [context: Imager.Context] ~ { context.ConcatT[xfm]; [] ฌ inner.class.paint[inner, context, NIL, TRUE]; RETURN}; width ฌ inner.cw/ppi; height ฌ inner.ch/ppi; file.DoPage[PaintPage, Imager.metersPerInch/ppi]; file.Close[]; RETURN [fileName, width, height]}}; ppi: REAL ฌ 72.0; SetViewerPosition: PUBLIC PROC [v: Viewer, x, y, w, h: INTEGER] = { ViewerOps.MoveViewer[v, x, y, w, h, FALSE]; }; Start: PROC = { Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Scale", ScaleButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Rotate", RotateButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Fit", FitButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Reset", ResetButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Left", LeftButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Right", RightButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Top", TopButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Bottom", BottomButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Prev", PrevTransformButt], 0]; Menus.AppendMenuEntry[bsMenu, Menus.CreateEntry["Draw", DrawButt], 0]; }; Start[]; END.  BiScrollersImpl.Mesa Copyright ำ 1992 by Xerox Corporation. All rights reserved. Pier, August 27, 1986 4:12:22 pm PDT Last tweaked by Mike Spreitzer on March 20, 1992 7:46 am PST What's a good encoding? This variable allows experimentation without recompiling. สg•NewlineDelimiter –(cedarcode) style™™Jšœ ฯeœ1™Kšœžœ˜%—K˜š  œžœžœ žœžœžœ˜?Kšœžœ žœ˜F—K˜š œžœžœ"žœ˜WKšž˜K˜&˜K˜#K˜(K˜-K˜;—Kšžœ˜Kšžœ˜—K˜š  œžœžœžœ˜@š œžœ žœ ž˜,K˜—K˜&˜@Kšœ ˜ Kšœ˜K˜K˜—K˜—K˜š  œžœžœžœ ฯcœ˜LKšœžœ˜—K˜š œžœžœ˜;Kšœ#žœ˜)Kšœ0˜0K˜Kšžœ˜—K˜š  œžœžœžœžœ˜XKšž˜K˜9K˜%K˜šžœž˜Kšžœ˜Kšžœ˜Kšžœžœ˜—K˜FK˜K˜šžœž˜Kšžœ!˜"Kšžœ!˜"Kšžœžœ˜—Kšžœ˜—K˜š  œžœžœžœ&žœžœ˜LKšœžœžœ!˜0—K˜š  œžœžœ&žœžœ˜MK˜Kšœ;˜;K˜-šžœžœž˜šœ ˜ K˜>Kšœžœ!˜)Kšœžœ˜%˜Kšœ žœžœžœ˜5Kšœ˜—Kšœ˜—K˜"Kšœžœžœžœ˜dKšžœžœ˜—K˜Kšœ1˜1K˜—K˜šžœžœžœžœ˜0šœžœž˜K˜ K˜K˜Kšžœžœ˜——K˜š   œžœžœžœžœ˜0Kšœžœ žœžœ˜"—K˜š  œžœžœžœ'žœžœ˜NKšœžœžœ"˜1—K˜š   œžœžœ'žœžœ˜OK˜Kšœ;˜;K˜-šžœžœž˜šœ ˜ K˜>˜Kšœ)˜)Kšœ%˜%Kšœ˜—Kšœ˜—K˜#Kšžœžœ˜—K˜Kšœ1˜1K˜—K˜š œžœžœžœžœ žœžœ˜MKšœžœžœ'˜6—K˜š  œžœžœ"žœžœ˜IKšœ;˜;Kšœ'˜'Kšœ1˜1K˜—K˜š  œžœžœžœ=žœžœ˜|Kšœžœžœ>˜M—K˜š  œžœžœKžœžœ˜rK˜;K˜K˜š œžœฯgœžœ žœžœžœ˜7Kšœขœขœ˜—šžœžœž˜K˜&˜ Kšœ žœ˜šžœžœ˜ Kšœ#žœ˜&K˜K˜—šžœžœ˜ Kšœ#žœ˜&K˜K˜—K˜—Kšžœžœ˜—šžœžœž˜K˜šœ ˜ Kšœ#žœ˜)K˜K˜—Kšžœžœ˜—Kšžœžœžœ˜Kšžœžœžœ˜K˜6Kšœ0˜0K˜—K˜š   œžœžœžœก*œ˜dKšœ$žœ˜*Kšžœ%˜+—K˜š   œžœžœžœก(œ˜bKšœ žœžœ˜0K˜K˜OK˜OKšžœ%˜+—K˜š  œžœžœžœ$žœžœ˜JKšœ˜Kšžœ˜—K˜š œžœžœ$žœ˜BKšœ$žœ˜*K˜Kšœ3žœ˜6Kšœ3žœ˜6Kšœ\˜\Kšžœ˜—K˜š  œžœžœ:žœžœ˜^Kšœ;˜;Kšœ,˜,Kšœ-˜-Kšžœ˜—K˜š œžœžœžœ!กœžœžœ˜wKšœžœžœ5˜D—K˜š   œžœžœ!กœžœžœ˜xK˜;˜$K˜K˜—Kšœžœ˜!K˜ K˜ K˜ K˜ Kš œžœžœžœžœ ˜+Kš œžœžœžœžœ ˜+Kš žœ žœžœžœ žœ ˜Jšžœ*˜,Kšžœ"˜&—K˜˜Kšœ˜Kšœ˜—Kšœ3˜3K˜—K˜š  œžœžœžœžœ˜,Kšœžœ˜Kš œžœžœžœžœ˜*K˜—K˜š œžœ žœžœžœ žœ žœ ˜TKšœžœ&˜/Kšœžœžœ˜ šœžœž˜ Kšœžœ˜ Kšœžœ ˜"Kšžœžœ˜—Kšžœžœžœžœ˜Kšœžœžœ˜šœžœžœžœ˜%Kšœžœ˜šœ˜Kšœ žœ#žœ˜>Kšœ žœ˜—K˜Kšžœ˜ —K˜š žœžœžœ žœžœ˜8Kšžœžœžœžœ˜!K˜K˜—K•StartOfExpansion&[ec: IO.ErrorCode, stream: STREAM]šžœžœ žœžœ$˜˜>Kšœ ˜ Kšœ9˜9K˜—K˜2Kšœžœ%žœ ˜=Kšœ˜—K˜š œžœ&žœžœกœžœžœžœ˜oKšœžœ˜&Kšœžœ˜ Kšœ žœ˜Kšœžœ˜"Kšžœžœžœ˜#Kšžœ žœ"˜5šœ!žœž˜0Kšœžœ˜8Kšœ žœ˜Kšžœžœ˜—K˜—K˜š   œžœžœKžœžœ˜„Kšžœžœžœ˜8Kšœ0žœ2˜eK˜—K˜š  œžœ žœžœžœžœžœ8žœžœกœžœžœžœ˜ฎKšœ žœ ˜Kšœ˜Kšœžœ˜ Kšœ žœ˜Kšœžœ˜"Kšžœžœžœ˜#Kšžœžœ5˜Mšœ!žœ ž˜8Kšœžœ˜*Kšœ žœ˜Kšžœžœ˜—K˜—K˜šœ žœ žœ ˜(K˜šœ žœ˜Kšœ*˜*Kšœ˜Kšœ,˜,Kšœ*˜*Kšœ˜Kšœ+˜+K˜—K˜+Kšœžœ%žœ ˜>Kšœ˜—K˜š  œžœ&žœžœกœžœžœžœ˜pKšœžœ˜&Kšœžœ˜ Kšœžœ˜ K˜Kšžœžœžœ ˜šœ!žœ ˜.Kšžœžœ˜šžœžœžœž˜+K˜ K˜K˜ Kšžœžœ˜——K˜—K˜š   œžœžœKžœžœ˜…Kšžœžœžœ˜9Kšœ1žœ2˜fK˜—K˜š  œžœ žœžœžœžœžœ8žœžœกœžœžœžœ˜ฏKšœ žœ ˜Kšœ˜Kšœžœ˜ Kšœžœ˜ K˜Kšžœžœžœ ˜šœ!žœžœžœ˜DKšžœžœ˜šžœžœžœ ž˜3Kšœ ˜ Kšœ˜Kšœ ˜ Kšžœžœ˜——K˜—K˜šœ žœ žœ ˜%K˜ šœ žœ˜KšœV˜VKšœ6˜6Kšœ˜—Kšœžœ˜K˜*Kšœžœ%žœ ˜;Kšœ˜—K˜š œžœ&žœžœกœžœžœžœ˜mKšœžœ˜&Kšœ!žœ˜,K˜—K˜š   œžœžœKžœžœ˜‚Kšžœžœžœ˜6Kšœ.žœ2˜cK˜—K˜š œžœ žœžœžœžœžœ8žœžœกœžœžœžœ˜ฌKšœ žœ ˜Kšœ˜Kšœ!žœ+˜PK˜—K˜šœ žœ žœ ˜'K˜šœ žœ˜Kšœ.˜.Kšœ)˜)Kšœ3˜3Kšœ˜—K˜>Kšœžœ%žœ ˜=Kšœ˜—K˜š œžœ&žœžœกœžœžœžœ˜oKšœžœ˜&šžœž˜Kšœ-žœ ˜=šœ˜Kšœ!žœ˜9Kšœ!žœN˜sK˜—Kšœ,žœG˜wKšžœžœ˜—K˜—K˜š   œžœžœKžœžœ˜„Kšžœžœžœ˜8Kšœ0žœ2˜eK˜—K˜š  œžœ žœžœžœžœžœ8žœžœกœžœžœžœ˜ฎKšœ žœ ˜K˜šžœ ž˜Kšœ(žœ ˜8šœ ˜ Kšœ!žœ˜9Kšœ!žœN˜sK˜—Kšœ)žœG˜tKšžœžœ˜—K˜—K˜šœ žœ žœ ˜'K˜šœ žœ˜Kšœ:˜:Kšœ7˜7Kšœ=˜=K˜9K˜