home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_PAS / ANIDIAL.ZIP / ANIMATE.DOC next >
Text File  |  1994-01-23  |  8KB  |  169 lines

  1. The Dialog Animator
  2.  
  3. By Tim Schempp
  4. January, 1994
  5. CompuServe Id:  71224, 455
  6.  
  7. The Dialog Animator is a relatively easy way to spice up some of your
  8. Turbo vision Applications.  This documentation will tell you everything
  9. you need to know about using the AnimateDialog unit in your Turbo Vision
  10. Applications.
  11.  
  12. I created the Dialog Animator to make my "About Boxes" more interesting in my
  13. applications.  The Dialog Animator will allow you to put moving views in your
  14. Dialog Boxes.  The Views still operate the same way they did before (except
  15. you have to chase them with the mouse).  The animation can be toggled by
  16. pressing a Hot Key, clicking on a "Special View" or always left on.  If you
  17. like this unit, you can use it in any of your applications.  I will really get
  18. a kick out of seeing it used in someone else's program.  I would also
  19. appreciate any suggestions you may have that will improve the unit.  I've
  20. really had some fun writing it.  These programs and units are distributed
  21. "as is" with no expressed or implied  warranties.  If you decide to use this
  22. program, it is at your own risk.
  23.  
  24. This zipped file should have included the following:
  25.  
  26. 1)  ANIMATE.DOC      This Documentation
  27. 2)  ANIMATED.PAS     The Dialog Animation Unit
  28. 3)  ANITEST.PAS      A sample program which shows all of the animators
  29.                        features.
  30. 4)  SIMPLE.PAS       A simple sample program which shows what's involved
  31.                        with animating a Dialog Box.
  32.  
  33. Before we discuss the animator, it would be good for you to play with the
  34. two sample programs and get a feel for what the Animator does.  ANITEST.PAS
  35. is a pretty long program, but that's how most Turbo Vision Applications are.
  36. Although the Dialog Animator will require you to add a few lines of code to
  37. get things working, I think you will find it easy enough once you get started.
  38.  
  39. In order to Animate a Dialog box, you must use the following.  Declare the
  40. Dialog Box as a PAnimateDialog object and add a pointer to the Dialog Box to
  41. your application object.  You would then override the applications
  42. Idle procedure like this:
  43.  
  44. type    TMyApp=object(TApplication)
  45.         MyDialog:PAnimateDialog;
  46.         procedure Idle; virtual;
  47.                 procedire DoMyDialog;
  48.                end; {object}
  49.  
  50. procedure TMyApp.Init;
  51. begin
  52.   inherited Idle;
  53.   if MyDialog<>nil then MyDialog^.Update;
  54. end;
  55.  
  56. The pointer MyDialog is initiated to nil when your program starts
  57. automatically.  It is important that whenever the Dialog Box is not active,
  58. the pointer MyDialog is equal to nil.  Otherwise the computer will attempt to
  59. Update a non existatant Dialog Box.  This will cause your computer to freeze
  60. (a bad thing).  So whenever your Dialog Box is not active, be sure the Dialog
  61. pointer is equal to nil.
  62.  
  63. Your next step is to create you Dialog Box.  You would do that like this"
  64.  
  65. procedure TMyApp.DoMyDialog;
  66.  
  67.   var R,Bounds:TRect;
  68.       AView:PView;
  69.       AniItem:PAniItem; {An animation entry object.}
  70.  
  71.   begin
  72.    R.Assign(20,2,60,20);
  73.    MyDialog:=New(PAnimateDialog,Init(R,'Look an Animate Dialog Box!'));
  74.  
  75.    with MyDialog^ do
  76.     begin
  77.      GetExtent(Bounds); {<-Create a Boundry for the Animation}
  78.      Inc(Bounds.B.X,-1); Inc(Bounds.B.Y,-1);
  79.      Inc(Bounds.A.X,1);  Inc(Bounds.A.Y,1);
  80.  
  81.      {Make A View}
  82.      R.Assign(15,13,25,15);
  83.      AView:=New(PButton,Init(R,'~O~k',cmOk,bfDefault));
  84.      Insert(AView);
  85.  
  86.      {Add it to the Animation List}
  87.      AniItem:=New(PAniItem,Init(AView,Bounds,AniBounceAround,11,3,1));
  88.      AniList^.Insert(AniItem);
  89.     end; {with}
  90.  
  91.    DeskTop^.ExecView(MyDialog);
  92.    Dispose(MyDialog,Done);
  93.    {*** !!! ***}
  94.    MyDialog:=nil;    {Tell the App the Dialog Box is Gone}
  95.   end;
  96.  
  97. That's how you create an animate Dialog Box.  Each AniItem has several fields:
  98.  
  99.    P,        the view that is going to be animated.
  100.    Bounds,   the boundry the animation is going to take place in, usually
  101.              within the Dialog Boxes frame.
  102.    Original, the original bounds of the view before the animation took place.
  103.    Param,    the type of animation to take place there are three types.
  104.                1) AniNone means that the view will move around the screen till
  105.                   it encounters a boundry and then return to it's starting
  106.                   place.
  107.                2) AniBounceBack means the view will bounce back off the
  108.                   boundry when it encounters it.
  109.                3) AniBounceAround cause the view to bounce around within
  110.                   the boundry.
  111.  DelayTime,  is the number of HUNDREDTHS of a second between animation
  112.              updates.  The program uses the computers internal clock to
  113.              decide when a view needs to be redrawn.
  114. LastUpDated, denotes the last time (in hundredths of a second) the dialog box
  115.              was updated.
  116. Xstep,Ystep  denote how far in there respected directions to advance the view
  117.              in each direction.
  118.  
  119. Notice in the Dialog Box above how the variable MyDialog is very
  120. carefully set to nil when the dialog box is destroyed.  This is
  121. important, to avoid system lock ups from accessing pointers which have been
  122. disposed of.
  123.  
  124. The TAnimateDialog object has several fields as well, three of which you may
  125. access directly.
  126.  
  127.   UpDateOn is a Boolean variable which tells if the Dialog Box should Update
  128.            itself or not. This variable defaults to True, but can be set to
  129.            False to allow a hot key to start the View.
  130.  
  131. SpecialKey holds a keycode for toggling the variable UpDateOn.  It defaults to
  132.            kbNoKey but may be set to say kbF1 or kbAltA to trigger the
  133.            animation.
  134.  
  135. Similarly, you may set the pointer SpecialView to point to a view within you
  136.            dialog box.  when the user double clicks on the view, it will
  137.            trigger it.  SpecialView defaults to nil.  (Static Text objects
  138.            work best for triggering Dialog Box animation.)  This is all
  139.            demonstrated in the WinDialog procedure in program AniTest.
  140.  
  141. It can be fun to add animation to otherwise serious programs.  Consider a
  142. Data entry screen with some static text on the top.  One day the user is
  143. clicking around the screen and accidentally clicks on the static text object.
  144. Boom, all of the input lines start floating around the screen, or the Dialog
  145. Box itself starts floating around the screen, or the windows behind the dialog
  146. box start floating around the screen.  When the user clicks on the text again,
  147. everything returns to normal.  It's a good idea not to animate a Dialog Boxes
  148. trigger or the user may have trouble catching it to turn things back off.
  149.  
  150. You may also find use for the AnimateDialog Box's RestoreViews procedure which
  151. puts all the views back in their original positions.  Be sure and call this
  152. BEFORE you dispose of the dialog box, or again you might experience a system
  153. lock up.  It is useful to call this procedure if you have animated some views
  154. outside of the Dialog Box.  In program AniTest, a ForEach statement is used to
  155. grab all of the objects (in this case windows) in the desktop and insert them
  156. into the AniList.  When the user exits the Dialog Box, the Views are restored
  157. to their original position using a ResotreView  command, and then the Dialog
  158. Box is Disposed of.  It's not nice to make a permanent mess out of the users
  159. DeskTop.
  160.  
  161. To really get a feel for animating Dialog Boxes, try playing with SIMPLE.PAS
  162. and adding some views to it.  How many views you animate in an application is
  163. up to you.  I mainly use this program for my "About Boxes," and sometimes I
  164. hide a few animate Dialog Boxes with hot keys in other places of my
  165. application.  If your buttons float too fast, no one can catch them, and
  166. that's really no fun.  I hope this unit can add a little something new to your
  167. Turbo Vision applications.  Please contact me with any questions or comments
  168. that you have.
  169.