25. NS BASIC Tech Note: NS BASIC goes Poof! July 24, 1996
--------------------------------------------------------------------------
I have been playing around with using viewffects for providing animaton
when
opening/closing windows. I have used ones such as DrawerEffect and
BarnDoorOpenEffect. These are nice to provide some variation in the
opening
and closing of windows. I had been wanting, though without much luck, to
be
able to make windows close with the poof & clouds you get when scrubbing
out
something.
Through the help of Micael Engber (and his article in PIE Developers),
James
Thiele, Oliver Veolckers, John Schettino, and Steve Weyers I have been able
to make it work in NS BASIC. Without the help from these people, I would
still be struggling along. Immediately below is the expanded code for
clarity, followed by the exact BASIC code. If you do "poof out" a window,
it
is best not to use an opening veiwEffect because it makes the ending screen
refresh non-standard.
The Detailed code:
// Provide the windowSpec of the window to be "poofed" to the function
FUNCTION poofItsGone(winToHide)
begin
// Isolate the original window spec so it isn't modified
local poofBox := Clone(winToHide.viewBounds);
// copy the clouds
local bma:=[Clone(@53), Clone(@54), Clone(@55)];
// You must make the cloud bigger to cover the whole window (or the corners
will
// still show). Make the number (3 below) bigger or smaller as required (a
smaller
// number will make the cloud larger, a larger number will make it smaller)
local qWidth := (poofBox.right - poofBox.left) DIV 3;
local qHeight := (poofBox.bottom - poofBox.top) DIV 3;
// Adjust the sides of the new viewbounds.
poofBox.top := poofBox.top - qHeight;
poofBox.left := poofBox.left - qWidth;
poofBox.bottom := poofBox.bottom + qHeight;
poofBox.right := poofBox.right + qWidth;
// Build a speacial window used just to refresh the screen area outside the
original
// window, don't worry because it won't show up on the screen
local danQuayle := BuildContext({viewclass:74, viewFlags: 64,
viewBounds: poofBox});
// Make the poof sounds.
PlaySound(@314);
// Iterate thru a loop.
foreach bm in bma do
begin
bm.bounds := poofBox;
// Show the cloud.
GetRoot():CopyBits(bm, poofBox.left, poofBox.top, 8);
// I'm using a Newton 110, you may need to adjust the sleep time for your
Newton
// but it must be at least "1" or you won't see anything.
Sleep(1);
// Hide the cloud.
GetRoot():CopyBits(bm, poofBox.left, poofBox.top, 3);
end;
// Hide the window so it doesn't reappear.
winToHide:Hide();
// Open then close "danQuayle" to refresh the screen around the original
window
danQuayle:Open();
danQuayle:Close();
end
Now for the NS BASIC code:
In this case I am poofing out a window called aboutWin, with a window spec
called aboutWinSpec. Any valid windowSpec can be substituted - this is a
general purpose code.
This line (0028 in my case) should be put in the main body of the program.
0028 FUNCTION poofItsGone(winToHide) BEGIN local poofBox :=
Clone(winToHide.viewBounds); local bma:= [Clone(@53), Clone(@54),
Clone(@55)]; local qWidth := (poofBox.right - poofBox.left) DIV 3; local
qHeight := (poofBox.bottom - poofBox.top) DIV 3; poofBox.top :=
poofBox.top -
qHeight; poofBox.left := poofBox.left - qWidth; poofBox.bottom :=
poofBox.bottom + qHeight; poofBox.right := poofBox.right + qWidth; local
danQuayle := BuildContext({viewclass:74, viewFlags: 64, viewBounds:
poofBox}); PlaySound(@314); foreach bm in bma do begin bm.bounds :=
poofBox;
GetRoot():CopyBits(bm, poofBox.left, poofBox.top, 8); Sleep(1);
GetRoot():CopyBits(bm, poofBox.left, poofBox.top, 3); end;
winToHide:Hide();
danQuayle:Open(); danQuayle:Close(); end
This is the line that the GOTO/GOSUB in the windowSpec points to (0062 in
my
case):
0062 LET unUsed := U:poofItsGone(aboutWinSpec)
This is my windowSpec (just for reference):
0325 LET aboutWinSpec := {GOTO: 0062, text: aboutText, viewbounds: {top:
103,
bottom: 217, left: 46, right: 194}, viewFont: {family: 'espy, face: 0,
size:
10}, viewJustify: 2, viewFormat:
6*vfPen+4*vfRound+vfFrameMatte+vfFillWhite}
Many thanks to Matthew Riehl for this Tech Note! You can reach him at
SharpsShtr@aol.com.