home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-10 | 4.7 KB | 157 lines | [TEXT/PJMM] |
- {• --------------------------------------------------------------- •//}
- {• A public domain demo of "movie" type scrolling, courtesy of •//}
- {• Kenneth A. Long (kenlong@netcom.com). •//}
- {• An itty bitty bytes™ production, for the benefit of anyone •//}
- {• who can use it. •//}
- {• This is basically just "Bullseye" with some things dumped and •//}
- {• two routines added, and a resource file to back the additions. •//}
-
- {• If you want the text drawn over black, like in the movies, •//}
- {• then some other "girations" are necessary. This just shows •//}
- {• the scrolling, with style. •//}
-
- {• Enjoy! •//}
-
- {• --------------------------------------------------------------- •//}
-
- {Revised by Ingemar Ragnemalm:}
- {- Took out event handling - the modal dialog is just enough for the demo}
- {- Converted to Pascal}
- {- Timed the scrolling with TickCount, so it won't get ridiculously slow}
- {or, for athat matter, fast.}
-
- program MovieScroll;
-
- {$IFC UNDEFINED THINK_PASCAL}
- uses
- Types, ToolIntf, Quickdraw, Dialogs, Windows, Menus, OSEvents;
- {$ENDC}
-
- var
- textHand: TEHandle;
- appleMenu, fileMenu: MenuHandle;
- shell_window: WindowPtr;
-
- const
- aboutID = 128;
-
- appleID = 1;
- fileID = 2;
- quitItem = 1;
-
- procedure InitMacintosh;
- begin
- {$IFC UNDEFINED THINK_PASCAL}
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- MaxApplZone;
- {$ENDC}
- FlushEvents(everyEvent, 0);
- InitCursor;
- end;
-
- procedure OutlineDefault (myDialog: WindowPtr; itemNo: Integer);
- var
- x: Integer;
- rectangle: Rect;
- theHandle: Handle;
- begin
- GetDItem(DialogPtr(myDialog), itemNo, x, theHandle, rectangle);
- PenSize(3, 3);
- InsetRect(rectangle, -4, -4);
- FrameRoundRect(rectangle, 16, 16);
- PenSize(1, 1);
- end;
-
- const
- SCREEN = 2; {• Text window useritem.}
- SHOWTIME = 3;
-
- USERITEM = 7; {• Used to outline default button.}
- textID = 128; {• rsrc ID# for text used.}
- styleID = 128; {• rsrc ID# for styl used.}
- kTicksPerStep = 2; {Number of ticks per step}
- var
- saveWPtr: GrafPtr; {• Holds previous grafPtr.}
- aboutPtr: DialogPtr; {• Pointer to dialog.}
- theItem: Integer; {• Item selected by user.}
- mLoc: Point; {• Mouse location.}
- rectangle: Rect;
- x: Integer;
- theHandle: Handle;
- txtRect: Rect; {• Used to hold viewRect.}
- saveTxtHdl: TEHandle; {• Text handle.}
- finished: Boolean; {• Pushed 'The End' button yet?}
- styleHdl: StScrpHandle;
- err: OSErr;
-
- thisTime, lastTime: Longint;
-
- begin
- InitMacintosh;
-
- GetPort(saveWPtr); {• Save the old port.}
- saveTxtHdl := textHand; {• Save the old text hdl.}
-
- {• Get dialog box pointer.}
- aboutPtr := GetNewDialog(aboutID, nil, WindowPtr(-1));
-
- {• This next makes the static text field font monaco 9.}
- SetPort(GrafPtr(aboutPtr)); {• Output to dialog.}
- TextSize(9); {• Set text size.}
- TextFont(monaco); {• Set text font.}
-
- {• Get text window rect.}
- GetDItem(DialogPtr(aboutPtr), SCREEN, x, theHandle, txtRect);
- InsetRect(txtRect, 5, 1); {• Leave margins for text.}
-
- {• Create styled TERecord.}
- textHand := TEStylNew(txtRect, txtRect);
-
- {• Read the TEXT resource.}
- theHandle := GetResource('TEXT', textID);
- HLock(theHandle); {• Lock handle.}
-
- {• Get the style handle.}
- styleHdl := StScrpHandle(Get1Resource('styl', styleID));
- TEStylInsert(theHandle^, SizeResource(theHandle), styleHdl, textHand); {• move text into text record.}
- TESetJust(1, textHand);
- HUnlock(theHandle); {• Unlock handle.}
-
- ShowWindow(aboutPtr); {• Show dialog box now.}
- TEUpdate(txtRect, textHand); {• Draw text in viewRect.}
- InsetRect(txtRect, -5, -1); {• Leave margins for text.}
- FrameRect(txtRect); {• Draw frame around text.}
- OutlineDefault(aboutPtr, USERITEM);
- GetDItem(DialogPtr(aboutPtr), USERITEM, x, theHandle, rectangle); {• outline default button.}
- SetDItem(aboutPtr, USERITEM, x, Handle(@OutlineDefault), rectangle); {• redraw if erased*/}
-
- finished := false; {• Reset flag.}
- repeat {• Repeat until finished.}
- ModalDialog(nil, theItem); {• Show dialog/get result.}
- case theItem of {• Control hit.}
- OK:
- finished := true; {• "The End" button hit / close.}
- SHOWTIME:
- begin
- thisTime := TickCount div kTicksPerStep;
- repeat
- lastTime := TickCount div kTicksPerStep;
- {• scroll up a pixel}
- TEScroll(0, thisTime - TickCount div kTicksPerStep, textHand);
- thisTime := lastTime;
- until Button;
- end;
- otherwise
- end; {• End of case.}
- until finished; {• End of mainloop.}
-
- TEDispose(textHand); {• Reclaim heap space.}
- textHand := saveTxtHdl; {• Restore global textHand.}
- DisposDialog(aboutPtr); {• Get rid of dialog box.}
- SetPort(saveWPtr); {• Restore the old port.}
- end.