// Text of project protoVertSlider test written on 9/9/96 at 3:01 PM // Beginning of file protoVertSlider // Before Script for "_userproto000" // Copyright © 1996 by Apple Computer, Inc. All rights reserved. _userproto000 := {viewFlags: 545, viewFormat: 1, viewValue: 50, maxValue: 100, minValue: 1, viewClickScript: func(unit) begin local y, max, min, offset, height, box, width; BusyBoxControl(0); // turn off the busy-indicator InkOff(unit); // and don't display ink // cache some values for more speed box := self:GlobalBox(); offset := box.top; width := box.right - box.left; height := box.bottom - offset; min := minValue; max := maxValue; // keep looping in here until the user releases the pen while not StrokeDone(unit) do begin y := GetPoint(finalY, unit) - offset; // get the Y coordinate of the pen in local coordinates if y < 0 then val := max; else if y > height then val := min; else val := max - Floor((y/height) * (max-min)); // only redraw if things have changed if val <> viewValue then begin viewValue := val; :DoDrawing('viewDrawScript, nil); end; self:?TrackSlider(); Sleep(1); // this helps out battery life considerably end; self:?ChangedSlider(); true; // returning true indicates that we handled the click. end, viewDrawScript: constant edge := 2; // amount the knob overlaps the line // making these styles constants will ensure they're not recreated on the fly each time. DefConst('kWhiteStyle, {fillPattern: vfWhite, pensize: 0, penpattern: vfNone}); DefConst('kGreyStyle, {fillPattern: SetClass("\uaa005500aa005500", 'pattern), pensize: 1, penpattern: vfWhite}); DefConst('kFillStyle, {fillPattern: vfBlack, pensize: 0, penpattern: vfNone}); DefConst('kKnobStyle, {fillPattern: vfWhite, pensize: [2,1], penpattern: vfBlack}); func() begin local width, pos, val, middle, max, min, bnds; bnds := self:LocalBox(); // cache these values for speed val := viewValue; max := maxValue; min := minValue; if min >= max then return; // alternatively, throwing might be a good reaction if val < min then val := min; if val > max then val := max; width := BAND(bnds.right-1, 0x0fffe); // make sure it's an even number middle := width div 2; pos:= bnds.bottom - floor((((val-min) / (max-min)) * (bnds.bottom - width -2))); self:DrawShape([ // erase the side bars kWhiteStyle, MakeRect(0, 0, edge, bnds.bottom), MakeRect(width+1-edge, 0, bnds.right, bnds.bottom), // draw the grey part (indicating possibility of value) kGreyStyle, MakeRect(edge, 0, width+1-edge, pos - middle), // draw the black part (indicating value) kFillStyle, MakeRect(edge, pos - middle, width+1-edge, bnds.bottom), // draw the knob kKnobStyle, MakePolygon([middle, pos, width, pos - middle, middle, pos - width, 0, pos - middle, middle, pos]) ], nil); end, viewClass: 74 }; constant |layout_protoVertSlider| := _userproto000; // End of file protoVertSlider // Beginning of file protoVertSlider testform app := {viewBounds: {left: -1, top: 42, right: 145, bottom: 150}, debug: "app", _proto: @180 }; // Before Script for "vs" // Copyright © 1996 by Apple Computer, Inc. All rights reserved. vs := {viewBounds: {left: 98, top: 28, right: 108, bottom: 97}, changedSlider: func() begin // This optional method is called when the user has let go of the knob PlaySound(rom_plinkbeep); end, maxValue: 11, minValue: 1, viewValue: 5, trackSlider: func() begin // This optional method is called while the slider is being moved. // You may want to play a small "click" to imitate the ROM's horizontal slider. // Update the status display with the current value. display:UpdateDisplay(viewValue); end, debug: "vs", _proto: _userproto000 }; AddStepForm(app, vs); StepDeclare(app, vs, 'vs); display := {text: "", viewBounds: {left: 35, top: 55, right: 90, bottom: 69}, viewSetupFormScript: func() begin :updateDisplay(vs.viewValue); end, updateDisplay: func(val) begin SetValue(self, 'text, "Value: " & val); RefreshViews(); end, debug: "display", _proto: @218 }; AddStepForm(app, display); StepDeclare(app, display, 'display); _view000 := {title: "protoVertSlider", _proto: @229}; AddStepForm(app, _view000); // After Script for "app" thisView := app; // Copyright 1996 by Apple Computer, Inc. All rights reserved. constant |layout_protoVertSlider testform| := app; // End of file protoVertSlider testform