// Text of project ScrollOver written on 5/9/95 at 12:39 PM // Beginning of file main.t // Before Script for "ScrollingSample" /* ** Newton Developer Technical Support Sample Code ** ** Scroll Over, Demonstrates scrolling of views using two methods. ** ** by Bob Ebert, Newton Developer Technical Support ** ** Copyright © 1993-1995 by Apple Computer, Inc. All rights reserved. ** ** You may incorporate this sample code into your applications without ** restriction. This sample code has been provided "AS IS" and the ** responsibility for its operation is 100% yours. You are not ** permitted to modify and redistribute the source as "DTS Sample Code." ** If you are going to re-distribute the source, we require that you ** make it clear in the source that the code was descended from ** Apple-provided sample code, but that you've made changes. */ ScrollingSample := {title: "Scroll Over", viewBounds: {left: 0, top: 0, right: 240, bottom: 336}, debug: "ScrollingSample", _proto: @157 }; clipper1 := {viewFlags: 545, viewFormat: 337, viewBounds: {left: 11, top: 27, right: 231, bottom: 157}, viewOriginX: 0, viewOriginY: 0, ScrollMe: // This is the function that actually scrolls by using SetOrigin // within the clipper1 window. Any child views of the clipper1 // window will scroll. (That's why the scroller controll isn't // a child of the clipper1 window!) func(deltaX, deltaY) begin local x := viewOriginX + deltaX; local y := viewOriginY + deltaY; if x > xMax then x := xMax; if y > yMax then y := yMax; if x < 0 then x := 0; if y < 0 then y := 0; :SetOrigin(x, y); // also Dirties the view. RefreshViews(); end, xMax: nil, yMax: nil, viewSetupDoneScript: func() begin xMax := viewWithPict1:LocalBox().right - clipper1:LocalBox().right; yMax := viewWithPict1:LocalBox().bottom - clipper1:LocalBox().bottom; end, viewClickScript: func(unit) begin local startX := GetPoint(firstX, unit); local startY := GetPoint(firstY, unit); local deltaX; local deltaY; InkOff(unit); PlaySound(ROM_click); repeat deltaX := startX - GetPoint(finalX, unit); startX := GetPoint(finalX, unit); deltaY := startY - GetPoint(finalY, unit); startY := GetPoint(finalY, unit); :ScrollMe(deltaX, deltaY); until StrokeDone(unit); TRUE; end, debug: "clipper1", viewClass: 74 }; AddStepForm(ScrollingSample, clipper1); StepDeclare(ScrollingSample, clipper1, 'clipper1); viewWithPict1 := {viewFlags: 1, icon: GetPictAsBits("Black World Map", nil), viewFormat: 256, viewBounds: {top: 0, left: 0, right: 360, bottom: 180}, debug: "viewWithPict1", viewClass: 76 }; AddStepForm(clipper1, viewWithPict1); StepDeclare(ScrollingSample, viewWithPict1, 'viewWithPict1); scrollCompass := {viewFlags: 513, viewFormat: 0, viewBounds: {left: 12, top: 124, right: 44, bottom: 156}, viewClickScript: // This function is called when the pen is down in the // scroller controll, and it calls clipper1:ScrollMe to // move the window around. Ideally this view should have // its mask set, and if fact the mask is in the resource // file, but NTK isn't dealing with the mask properly yet. func(unit) begin local deltaX, deltaY; InkOff(unit); PlaySound(ROM_click); repeat // compute where in the view the pen is currently and scroll in the right // direction. The values 12 and 20 are pretty arbitrary. deltaX := if GetPoint(finalX, unit) < viewBounds.left + 12 then -16 else if GetPoint(finalX, unit) > viewBounds.left + 20 then 16 else 0; deltaY := if GetPoint(finalY, unit) < viewBounds.top + 12 then -16 else if GetPoint(finalY, unit) > viewBounds.top + 20 then 16 else 0; clipper1:ScrollMe(deltaX, deltaY); until StrokeDone(unit); TRUE; end, icon: GetPictAsBits("Scroll2D", 1), debug: "scrollCompass", viewClass: 76 }; AddStepForm(ScrollingSample, scrollCompass); // After Script for "scrollCompass" thisView := scrollCompass; thisView.viewTransferMode := modeMask; clipper2 := {viewFlags: 33, viewFormat: 337, viewBounds: {top: 170, left: 10, right: 230, bottom: 300}, declareSelf: 'base // this needs to be here so the cannonicalCompass knows // which view to dirty as part of the redraw. , debug: "clipper2", viewClass: 74 }; AddStepForm(ScrollingSample, clipper2); StepDeclare(ScrollingSample, clipper2, 'clipper2); viewWithPict2 := {viewFlags: 1, icon: GetPictAsBits("White World Map", nil), viewFormat: 256, viewBounds: {left: 0, top: 0, right: 360, bottom: 180}, viewSetupDoneScript: func() begin // set up the canonicalCompass to scroll this view. canonicalCompass.scrolledView := self; // the canonicalCompass expects dataBounds to be a slot // with a bounds frame containing the size of the data that // needs to be scrolled. Just use the viewBounds. self.dataBounds := viewBounds; // NOTE: NTK should be setting the viewBounds for this // view to match the size of the picture in the resource // file. Currently it doesn't, so the viewBounds was // just typed in. It would have been possible to use the // PictBounds global function (at compile time) to get // the size of the picture resource, but I'm lazy. // NOTE 2: viewOriginX and viewOriginY are supposed to be // created and set by the view system, but it's set up to // save memory and treat NIL as 0. However, the canonicalCompass // doesn't handle that case, so we have to create the // viewOriginX and viewOriginY slots ourself and initialize // them to 0. self.viewOriginX := 0; self.viewOriginY := 0; end, debug: "viewWithPict2", viewClass: 76 }; AddStepForm(clipper2, viewWithPict2); StepDeclare(ScrollingSample, viewWithPict2, 'viewWithPict2); canonicalCompass := { scrolledView: // will be set to the view to be scrolled // in the viewWithPict2's viewSetupDoneScript. nil;, debug: "canonicalCompass", _proto: @226 }; AddStepForm(clipper2, canonicalCompass); StepDeclare(ScrollingSample, canonicalCompass, 'canonicalCompass); // After Script for "canonicalCompass" thisView := canonicalCompass; thisView._proto := ROM_canonicalcompass; // this script is called at COMPILE TIME after the view has been compiled // It's currently the only way to set the _proto slot with the 1.0b4 // NTK. The canonicalCompass proto isn't in the NTK library just yet. constant |layout_main.t| := ScrollingSample; // End of file main.t