// Text of project Drawing written on 11/20/95 at 5:53 PM
// Beginning of file Draw.t

// Before Script for "_view000"
/*
**      Newton Developer Technical Support Sample Code
**
**      Drawing, Shows how to use shapes
**
**      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.
*/


nil;	// result of beforeScript


_view000 :=
    {title: "Drawing Examples",
     viewBounds: {left: -1, top: 0, right: 236, bottom: 325},
     viewDrawScript:
       func()
       begin
           :DrawMe();	// just draw all the shapes
       end,
     myLine: nil,
     myRect: nil,
     myRoundRect: nil,
     myOval: nil,
     myWedge: nil,
     myPolygon: nil,
     myShape: nil,
     myRegion: nil,
     myPict: nil,
     myText: nil,
     myScaledPict: nil,
     myStyle: nil,
     DrawMe:
       func()
       begin
       /*	There are two ways to pass shapes to DrawShape, either
       	individual shape objects, or all of them inside an Array.
       	We show both techniques in this sample.
       	
       	:DrawShape(myLine, myStyle);
       	:DrawShape(myRect, myStyle);
       	:DrawShape(myRoundRect, myStyle);
       	:DrawShape(myOval, myStyle);
       	:DrawShape(myWedge, myStyle);
       	:DrawShape(myPolygon, myStyle);
       	:DrawShape(myRegion, myStyle);
       	:DrawShape(myText, myStyle);
       	:DrawShape(myPict, myStyle);
       	:DrawShape(myScaledPict, myStyle);
       */
       	// Draw BASIC shapes
       	:DrawShape([myLine, myRect, myRoundRect, myOval, myWedge, myPolygon, myRegion, myText], myStyle);
       
       	// Draw OFFSET PICTURE shape
       	:DrawShape(myPict, myStyle);
       	
       	// Draw SCALED PICTURE
       	:DrawShape(myScaledPict, myStyle);
       					    
       end,
     viewSetupDoneScript:
       func()
       begin
       	// Create all the example BASIC shape objects.
       	myLine := MakeLine(0,10, 20, 30);
       	myRect := MakeRect(0,40,20,60);
       	myRoundRect := MakeRoundRect(0, 70, 20, 90, 10);
       	myOval := MakeOval(0, 100, 20, 120);
       	myWedge := MakeWedge(0, 130, 20, 150, 0, 90);
       	myPolygon := MakePolygon([0, 160, 20, 180, 20, 160]);
       
       	local rectangle := MakeRect(0, 220, 30, 240);
       	local oval := MakeOval(0, 230, 30, 250);
       	myRegion := MakeRegion([rectangle, oval,]);
       	myText := MakeText("Bob", 0, 260, 55, 280);
       	
       	
       	// Create the example PICTURE shape object and then OFFSET it
       	myPict := MakePict([myLine, myRect, myRoundRect, myOval, myWedge, 
       								myPolygon, myRegion, myText], myStyle);
       	OffsetShape(myPict, 40, 5);
       	
       	
       	// Create the example SCALED PICTURE shape object
       	myScaledPict := DeepClone(myPict);
       	local startRect := ShapeBounds(myScaledPict);
       	local endRect := {left: 80, top: 10, right: 150, bottom: 150,};
       	ScaleShape(myScaledPict, startRect, endRect);
       end,
     viewSetupFormScript:
       func()
       begin
       	local a := GetAppParams();
          self.viewBounds := RelBounds(a.appAreaLeft, a.appAreaTop, a.appAreaWidth, a.appAreaHeight);
       end,
     viewQuitScript:
       func()
       begin
       	// NIL out all the shapes to reclaim some space.
       	myLine := nil;
       	myRect := nil;
       	myRoundRect := nil;
       	myOval := nil;
       	myWedge := nil;
       	myPolygon := nil;
       	myRegion := nil;
       	myText := nil;
       	myPict := nil;
       	myScaledPict := nil;
       	myStyle := nil;
       end,
     _proto: @157
    };

_view001 :=
    {viewFlags: 545,
     viewFormat: 336,
     viewBounds: {left: 122, top: 18, right: 234, bottom: 138},
     viewClickScript:
       func(unit)
       begin
       	// Normally, all drawing will just happen in the viewDrawScript. If something
       	// needs to be changed, the :dirty() message could be called to update the screen.
       	// In some cases, you need to draw at a time other than the viewDrawScript
       	// Don't just use DrawShape directly...use :DoDrawing to properly set up the 
       	// CLIPPING region. Remember that if the shapes will stay on the screen, you will
       	// need to save enough info so that your viewDrawScript can draw it again!
           // 
           // The LockScreen call prevents the user from seeing the shapes AS they draw.
           
           :LockScreen(true);
           :DoDrawing('DrawMe, nil);
           :LockScreen(nil);
           
       	while not StrokeDone(unit) do
       		Sleep(20);	// don't stay in really tight loops in NewtonScript; it drains the battery!
       
       	:Dirty();	// clear and/or redraw this view as appropriate
       end,
     viewClass: 74
    };
AddStepForm(_view000, _view001);




constant |layout_Draw.t| := _view000;
// End of file Draw.t



