// Text of project Size Doesn't Matter written on 5/9/95 at 1:47 PM // Beginning of file Size Doesn't Matter.t // Before Script for "ResizeSampleApp" /* ** Newton Developer Technical Support Sample Code ** ** Size Doesn't Matter, Demonstrates dragging to change the size of a view ** ** 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. */ ResizeSampleApp := {title: "Size Doesn't Matter", viewBounds: {top: 0, left: 0, right: 240, bottom: 336}, viewSetupFormScript: func() begin local a := GetAppParams(); self.viewBounds := RelBounds(a.appAreaLeft, a.appAreaTop, a.appAreaWidth, a.appAreaHeight); end, debug: "ResizeSampleApp", _proto: @157 }; sizeableView := {viewFlags: 513, viewFormat: 337, viewBounds: {left: 67, top: 83, right: 169, bottom: 161}, viewClickScript: func(unit) begin local r, newR, newB, newBounds; // used inside loop // deltas keep track of how close the tap point is to the corner. local deltaX := :GlobalBox().right - GetPoint(firstX, unit); local deltaY := :GlobalBox().bottom - GetPoint(firstY, unit); // if we're near the lower right hand corner, resize the view. // note we use ABS. Because of "sloppy clicking" it's possible // for this view's viewClickScript to get called even when // the tap is technically outside the bounds, and it seems like // a good idea to let these taps resize the view too. if ABS(deltaX) < 10 and ABS(deltaY) < 10 then begin InkOff(unit); // make a rectangle for the drag animation r := MakeShape(viewBounds); :Parent():DrawShape(r, XORRectStyle); // draw frame newBounds := Clone(viewBounds); // loop until stroke is finished while not StrokeDone(unit) do begin // track the pen, and if it's moved, update the wire frame newR := GetPoint(finalX, unit) + deltaX; newB := GetPoint(finalY, unit) + deltaY; if newR <> newBounds.right or newB <> newBounds.bottom then begin newBounds.right := newR; newBounds.bottom := newB; :Parent():DrawShape(r, XORRectStyle); // undraw old frame ScaleShape(r, nil, newBounds); :Parent():DrawShape(r, XORRectStyle); // draw frame Sleep(1); // short delay, maybe save batteries? end; end; :Parent():DrawShape(r, XORRectStyle); // undraw old frame newBounds.right := GetPoint(finalX, unit) + deltaX; newBounds.bottom := GetPoint(finalY, unit) + deltaY; // just setting viewBounds won't work, use SyncView or SetValue. SetValue(self, 'viewBounds, newBounds); // call viewChangedScript end else begin // just for fun, drag the view if the tap is anywhere else :Drag(unit, nil); // clean up viewBounds after Drag munges them. // this is only valid for parent top/left justified views! local b := :GlobalBox(); local p := :Parent():GlobalBox(); b.top := b.top - p.top; b.left := b.left - p.left; b.bottom := b.bottom - p.top; b.right := b.right - p.left; SetValue(self, 'viewBounds, b); // call viewChangedScript end; TRUE; // we've handled the tap end, viewSetupFormScript: func() begin // need writeable copy of viewBounds for viewClickScript If IsReadOnly(viewBounds) then self.viewBounds := Clone(viewBounds); end, XORRectStyle: // used in viewClickScript for animating frame during resize. {transferMode: modeXor, penSize: 1, penPattern: vfGray}, debug: "sizeableView", viewClass: 74 }; AddStepForm(ResizeSampleApp, sizeableView); _view000 := {text: "Drag lower right corner to change size.", viewBounds: {top: -40, left: 0, right: 0, bottom: -20}, viewJustify: 8388790, _proto: @218 }; AddStepForm(ResizeSampleApp, _view000); constant |layout_Size Doesn't Matter.t| := ResizeSampleApp; // End of file Size Doesn't Matter.t