// Text of project Bitmap written on 11/20/95 at 6:10 PM
// 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 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 :=
    {title: "Bitmap Transforms",
     viewBounds: {left: 0, top: 0, right: 240, bottom: 320},
     viewFormat: 83951953,
     viewSetupFormScript:
       func()
       	begin
       		constant kMaxWidth := 240;
       		constant kMaxHeight := 336;
       		local b := GetAppParams();
       		
       		viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop,
       				Min(b.appAreaWidth, kMaxWidth),
       				Min(b.appAreaHeight, kMaxHeight) );
       		
       		myapp := self;
       	end,
     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);
       				operations:ViewIntoBitmap(nil, nil, tempBitmap);
       				SetValue(once, 'bitmap, tempBitmap);
       				
       				tempBitmap := DeepClone(again.bitmap);
       				operations: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: 80,
     debug: "myapp",
     _proto: @157
    };

Original :=
    {text: "Original",
     viewBounds: {left: 90, top: 26, right: 146, bottom: 42},
     viewJustify: 2,
     debug: "Original",
     _proto: @218
    };
AddStepForm(myapp, Original);



original :=
    {viewBounds: {left: 67, top: 51, right: 169, bottom: 137},
     viewFlags: 33,
     viewDrawScript:
       func()
       begin
       	if bitmap then
       		:DrawShape(bitmap, nil); 
       end,
     viewFormat: 336,
     bitMap: nil,
     debug: "original",
     viewClass: 74
    };
AddStepForm(myapp, original);
StepDeclare(myapp, original, 'original);



New :=
    {
     buttonClickScript:
       func()
       	begin
       		:NewBitmap();
       	end,
     text: "New Bitmaps",
     viewBounds: {left: 20, top: 150, right: 96, bottom: 163},
     debug: "New",
     _proto: @226
    };
AddStepForm(myapp, New);



Operations :=
    {text: "Transform",
     viewBounds: {left: 140, top: 150, right: 205, bottom: 163},
     pickActionScript:
       func(itemSelected)
       	begin
       		if kDebugOn then print("Item selected: " & transforms[itemSelected]);
       		:DoTransform(transforms[itemSelected]);
       		:Hilite(nil);
       	end ,
     popup:
       [
       	"Flip Horizontal",
       	"Flip Vertical",
       	"Rotate Right",
       	"Rotate Left",
       	"Copy ViewIntoBitmap",
       	"Offset",
       	"Scale 125%",
       ],
     viewFlags: 515,
     viewJustify: 8388614,
     transforms:
       [
       	'flipHorizontal,
       	'flipVertical,
       	'rotateRight,
       	'rotateLeft,
       	'viewIntoBitmap,
       	'offset,
       	'scale
       ],
     debug: "Operations",
     _proto: @386
    };
AddStepForm(myapp, Operations);
StepDeclare(myapp, Operations, 'Operations);



once :=
    {viewBounds: {left: 11, top: 179, right: 113, bottom: 265},
     viewFlags: 33,
     viewFormat: 336,
     viewDrawScript:
       func()
       begin
       	if bitmap then
       		:DrawShape(bitmap, nil); 
       end,
     bitMap: nil,
     debug: "once",
     viewClass: 74
    };
AddStepForm(myapp, once);
StepDeclare(myapp, once, 'once);



Transform Once :=
    {text: "Transform\nOnce",
     viewBounds: {left: 10, top: 274, right: 114, bottom: 290},
     viewJustify: 2,
     debug: "Transform Once",
     _proto: @218
    };
AddStepForm(myapp, Transform Once);



again :=
    {viewBounds: {left: 131, top: 179, right: 233, bottom: 265},
     viewFlags: 33,
     viewFormat: 336,
     viewDrawScript:
       func()
       begin
       	if bitmap then
       		:DrawShape(bitmap, nil); 
       end,
     bitMap: nil,
     debug: "again",
     viewClass: 74
    };
AddStepForm(myapp, again);
StepDeclare(myapp, again, 'again);



Transform Again :=
    {text: "Transform\nAgain",
     viewBounds: {left: 130, top: 274, right: 234, bottom: 290},
     viewJustify: 2,
     debug: "Transform Again",
     _proto: @218
    };
AddStepForm(myapp, Transform Again);




constant |layout_Bitmap Layout| := myapp;
// End of file Bitmap Layout



