// Text of project Bitmap written on 4/23/97 at 10:35 AM // Beginning of file Bitmap Layout // Before Script for "myapp" // Newton Developer Technical Support Sample Code // Bitmap, bitmap transform sample // by Bob Ebert & J. Christopher Bell, Newton Developer Technical Support // Copyright ©1995-1997 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. myapp := {viewBounds: {left: 0, top: 0, right: 0, bottom: 0}, viewFormat: 83951953, NewBitmap: func() begin local bitmap := MakeBitmap(original:localbox().right, original:localbox().bottom, nil); local shapes := [ MakeText(GetRandomWord(3,5) && "&" && GetRandomWord(8,10), 10, 20, 100, 33), MakeOval(Random(30,40), Random(40,50), Random(50, 70), Random(60, 70)), ]; DrawIntoBitmap(shapes, '{pen: 2, font: {family: espy, face:0, size:10}}, bitmap); SetValue(original, 'bitmap, bitmap); SetValue(once, 'bitmap, DeepClone(bitmap)); SetValue(again, 'bitmap, DeepClone(bitmap)); end, ViewSetupDoneScript: func() :NewBitmap();, DoTransform: func(operation) begin local tempBitmap; local transform; if SetContains('[flipHorizontal, flipVertical, rotateRight, rotateLeft], operation) then begin SetValue(once, 'bitmap, MungeBitmap(DeepClone(original.bitmap), operation, nil)); SetValue(again, 'bitamp, MungeBitmap(again.bitmap, operation, nil)); end; else if operation = 'viewIntoBitmap then begin tempBitmap := MakeBitmap(original:localbox().right, original:localbox().bottom, nil); titleView:ViewIntoBitmap(nil, nil, tempBitmap); SetValue(once, 'bitmap, tempBitmap); tempBitmap := DeepClone(again.bitmap); titleView:ViewIntoBitmap(nil, nil, tempBitmap); SetValue(again, 'bitmap, tempBitmap); end else if operation = 'offset then begin transform := {transform: [Random(5,10), Random(5, 10)]}; tempBitmap := MakeBitmap(original:localbox().right, original:localbox().bottom, nil); DrawIntoBitmap(original.bitmap, transform, tempBitmap); SetValue(once, 'bitmap, tempBitmap); tempBitmap := MakeBitmap(original:localbox().right, original:localbox().bottom, nil); DrawIntoBitmap(again.bitmap, transform, tempBitmap); SetValue(again, 'bitmap, tempBitmap); end else if operation = 'scale then begin local box := original:localbox(); transform := {transform: [box, InsetRect(box, - box.right DIV 4, - box.bottom DIV 4)]}; tempBitmap := MakeBitmap(original:localbox().right, original:localbox().bottom, nil); DrawIntoBitmap(original.bitmap, transform, tempBitmap); SetValue(once, 'bitmap, DeepClone(tempBitmap)); tempBitmap := MakeBitmap(original:localbox().right, original:localbox().bottom, nil); DrawIntoBitmap(again.bitmap, transform, tempBitmap); SetValue(again, 'bitmap, tempBitmap); end; end, viewJustify: 240, viewFlags: 33, declareSelf: 'base, ReorientToScreen: ROM_defRotateFunc, ViewSetupFormScript: func() begin RemoveSlot(self, 'viewJustify); // in case we've already run the "screen too small code" (see below); RemoveSlot(self, 'viewBounds); // in case we've already run the "screen too small code" (see below); // If the screen is too small (in this orientation), hide the view and close it in a delayed action if getappparams().appareaheight < 320 or getappparams().appareawidth < 240 then begin viewjustify := vjLeftH + vjTopV; viewbounds := RelBounds(0,0,1,1); :Notify(kNotifyAlert, kAppName, "Sorry, the screen is too small to run this application."); AddDelayedCall(func(v) v:close(), [self], 1); end; end, debug: "myapp", viewClass: 74 }; titleView := {title: "Bitmap Transforms", debug: "titleView", _proto: @229}; AddStepForm(myapp, titleView); StepDeclare(myapp, titleView, 'titleView); Original := {text: "Original", viewBounds: {left: 0, top: 26, right: 60, bottom: 42}, viewJustify: 18, debug: "Original", _proto: @218 }; AddStepForm(myapp, Original); original := {viewBounds: {left: 0, top: 25, right: 100, bottom: 125}, viewFlags: 33, ViewDrawScript: func() begin if bitmap then :DrawShape(bitmap, nil); end, viewFormat: 336, bitMap: nil, viewJustify: 16, debug: "original", viewClass: 74 }; AddStepForm(myapp, original); StepDeclare(myapp, original, 'original); left stuff := {viewBounds: {left: 0, top: 150, right: 50, bottom: 300}, viewFlags: 1, viewFormat: 0, viewJustify: 201326592, debug: "left stuff", viewClass: 74 }; AddStepForm(myapp, left stuff); once := {viewBounds: {left: 0, top: 10, right: 100, bottom: 110}, viewFlags: 33, viewFormat: 336, ViewDrawScript: func() begin if bitmap then :DrawShape(bitmap, nil); end, bitMap: nil, viewJustify: 16, debug: "once", viewClass: 74 }; AddStepForm(left stuff, once); StepDeclare(myapp, once, 'once); _view000 := {text: "Transform\nOnce", viewBounds: {left: 0, top: 120, right: 100, bottom: 150}, viewJustify: 18, _proto: @218 }; AddStepForm(left stuff, _view000); right stuff := {viewBounds: {left: 50, top: 150, right: 100, bottom: 300}, viewFlags: 1, viewFormat: 0, viewJustify: 201326592, debug: "right stuff", viewClass: 74 }; AddStepForm(myapp, right stuff); again := {viewBounds: {left: 0, top: 10, right: 100, bottom: 110}, viewFlags: 33, viewFormat: 336, ViewDrawScript: func() begin if bitmap then :DrawShape(bitmap, nil); end, bitMap: nil, viewJustify: 16, debug: "again", viewClass: 74 }; AddStepForm(right stuff, again); StepDeclare(myapp, again, 'again); _view001 := {text: "Transform\nAgain", viewBounds: {left: 0, top: 120, right: 70, bottom: 150}, viewJustify: 18, _proto: @218 }; AddStepForm(right stuff, _view001); _view002 := { menuLeftButtons: [{_proto: protoTextButton, text: "New Bitmap", buttonClickScript: func() :NewBitmap(), }], menuRightButtons: [ { _proto: protoPopupButton, text: "Transform", popup: [ "Flip Horizontal", "Flip Vertical", "Rotate Right", "Rotate Left", "Copy ViewIntoBitmap", "Random Offset", "Scale 125%", ], transforms: [ 'flipHorizontal, 'flipVertical, 'rotateRight, 'rotateLeft, 'viewIntoBitmap, 'offset, 'scale ], pickActionScript: func(itemSelected) begin if kDebugOn then print("Item selected: " & transforms[itemSelected]); :DoTransform(transforms[itemSelected]); :Hilite(nil); end } ], _proto: @401 }; AddStepForm(myapp, _view002); constant |layout_Bitmap Layout| := myapp; // End of file Bitmap Layout