// Text of project InkTranslate written on 11/21/95 at 3:14 PM // Beginning of file InkTranslate Layout // Before Script for "InkTranslate" // Copyright ©1995 Apple Computer, Inc. All rights reserved. InkTranslate := {title: "InkTranslate", viewBounds: {left: 0, top: 0, right: 240, bottom: 320}, viewFormat: 83951953, points: nil, viewFlags: 517, Translate: func() begin local stroke, child, num, strokeBundle; local children := source:childviewFrames(); points := []; if kDebugOn then print("There are" && length(children) && "children."); if children and length(children) > 0 then begin foreach child in children do if child.ink exists then begin strokeBundle := ExpandInk(child, 0); // one stroke bundle can have more than one stroke. // For instance, a "t" character would have two strokes for one // character, but both strokes are in the same stroke bundle num := CountStrokes(strokeBundle); if kDebugOn then print("Processing bundle of" && num && "strokes."); for i := 0 to num-1 do begin stroke := GetStroke(strokeBundle, i); // we get the points for each stroke (each pen-down) and then we // must reverse the order of the x,y pairs, because it returns the // values in y, x order, but we need them in x,y for using with MakePolygon()... // The '0' paramater to GetStrokePoitnsArray means "screen resolution, filter duplicates" AddArraySlot(points, :ReverseEntries(GetStrokePointsArray(stroke, 0))); end; end else if kDebugOn then print("No ink slot in this child! Skipping it..."); end else :Notify(kNotifyAlert, "InkTranslate", "Draw something in the upper input area."); destination:Dirty(); // Make its viewDrawScript be called end, ReverseEntries: func native (array a) begin // switch x, y coords in the array local int temp; for i := 0 to length(a) - 1 by 2 do begin temp := a[i]; a[i] := a[i+1]; a[i+1] := temp; end; a; end, viewSetupFormScript: func() begin // adjust to the screen size local b := GetAppParams(); constant kMaxWidth := 240; constant kMaxHeight := 336; viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop, Min(b.appAreaWidth, kMaxWidth), Min(b.appAreaHeight, kMaxHeight) ); end, debug: "InkTranslate", _proto: @157 }; source := {viewFlags: 2593, viewFormat: 8529, viewBounds: {left: 11, top: 27, right: 225, bottom: 145}, viewLineSpacing: 20, debug: "source", viewClass: 77 }; AddStepForm(InkTranslate, source); StepDeclare(InkTranslate, source, 'source); destination := {viewBounds: {left: 10, top: 178, right: 226, bottom: 298}, viewFlags: 1, viewFormat: 561, viewDrawScript: func() begin // points is created in the base view when you tap the "Translate" button if points then begin local shapeArray := foreach pointSet in points collect MakePolygon(pointSet); :DrawShape(shapeArray, nil); end; end // Note: There is a design bug here! // Polygons made with only one coordinate pair (just a single point) don't // show up. So "strokes" of only one point won't be shown in the destination. // This could be fixed by detecting the case when generating the points array // and duplicating the coordinates . We didn't do it because it tarnishes the // purity of the stroke->points translation code. :) /*  Oh, OK. Twist my arm. Here's one way to do it. local shapeArray := foreach pointSet in points collect if length(pointSet) = 2 then MakePolygon([pointSet[0], pointSet[1], pointSet[0], pointSet[1]]); else MakePolygon(pointSet); */, debug: "destination", viewClass: 74 }; AddStepForm(InkTranslate, destination); StepDeclare(InkTranslate, destination, 'destination); translateButton := { buttonClickScript: func() begin :Translate(); end, text: "Translate", viewBounds: {left: 68, top: 156, right: 176, bottom: 169}, debug: "translateButton", _proto: @226 }; AddStepForm(InkTranslate, translateButton); constant |layout_InkTranslate Layout| := InkTranslate; // End of file InkTranslate Layout