home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / scrsaver.aml < prev    next >
Text File  |  1995-08-10  |  4KB  |  168 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        SCRSAVER.AML                                         */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro is runs a simple screen saver, and        */
  6. /*               demonstrates how to write directly to the physical   */
  7. /*               screen.                                              */
  8. /*                                                                    */
  9. /* Usage:        Select this macro from the Macro List (on the Macro  */
  10. /*               menu), or run it from the macro picklist <shift f12> */
  11. /* ------------------------------------------------------------------ */
  12.  
  13.   include bootpath "define.aml"
  14.  
  15.   var attr
  16.   var count
  17.   var interval
  18.   var minutes
  19.   var obj
  20.  
  21.   // draw the screen saver
  22.   function drawsaver
  23.  
  24.     // change to 50-line mode
  25.     oldrows = getvidrows
  26.     videomode 80 50
  27.  
  28.     // create a dummy window that covers the whole screen,
  29.     // to prevent this demo from overwriting the existing screen
  30.     createwindow
  31.     setcolor 5 (color black on black)
  32.     display
  33.  
  34.     // get the current mouse button state and position
  35.     buttonstate = button? 7fh
  36.     mousex = getmousex
  37.     mousey = getmousey
  38.  
  39.     // get the screen dimensions
  40.     cols = getvidcols
  41.     rows = getvidrows
  42.  
  43.     // hide the mouse
  44.     hidemouse
  45.  
  46.     // make video functions use the actual physical screen,
  47.     // instead of the current window
  48.     gotoscreen
  49.  
  50.     // string to write
  51.     str = "░░░"
  52.  
  53.     // intial x,y position on the screen
  54.     x = (rand mod cols) + 1
  55.     y = (rand mod rows) + 1
  56.  
  57.     // do until a (non-shift) key is pressed
  58.     //while not keyhit? do
  59.     while not event? do
  60.  
  61.       // get next random x,y position
  62.       x = x + ((rand mod 3) - 1)
  63.       y = y + ((rand mod 3) - 1)
  64.  
  65.       // correct x,y if not within screen boundry
  66.       if x > cols then
  67.         x = cols
  68.       elseif x < 1 then
  69.         x = 1
  70.       end
  71.       if y > rows then
  72.         y = rows
  73.       elseif y < 1 then
  74.         y = 1
  75.       end
  76.  
  77.       // write the string
  78.       writestr str attr x y
  79.  
  80.       // change the string and color periodically
  81.       count = count + 1
  82.       if count > interval then
  83.         count = 0
  84.         interval = 700
  85.         // random color
  86.         attr = rand mod 256
  87.         // random string
  88.         str = case rand mod 2
  89.                 when 0 "░░░"
  90.                 when 1 "▒▒▒"
  91.               end
  92.       end
  93.  
  94.     end
  95.  
  96.     // absorb any keys entered
  97.     while keyhit? do
  98.       getkey
  99.     end
  100.  
  101.     // restore the screen
  102.     showmouse
  103.     destroywindow
  104.     videomode 80 oldrows
  105.   end
  106.  
  107.   // screen saver timer management
  108.   function saver (f)
  109.     // remove timers
  110.     if f == -1 then
  111.       destroytimer "saver"
  112.       destroytimer "saver2"
  113.     // check for time expired
  114.     elseif f then
  115.       if _ecount <> geteventcount then
  116.         _ecount = geteventcount
  117.         settimer "saver2" minutes * 60000 obj
  118.       elseif not (timer? "saver2") then
  119.         // call screen saver function
  120.         drawsaver
  121.         _ecount = -1
  122.       end
  123.     // start the check timer
  124.     else
  125.       setrepeat "saver" 1000 obj "saver" 1
  126.       _ecount = -1
  127.     end
  128.   end
  129.  
  130.   // check for a previous install
  131.   obj = lookup "saverobj" "prf"
  132.   if obj then
  133.     installed = TRUE
  134.   else
  135.     obj = getcurrobj
  136.     setxobj "saverobj" obj "prf"
  137.   end
  138.  
  139.   // screen saver dialog box
  140.   dialog "Screen Saver" 46 6 "c"
  141.   field "Delay in minutes:  >"  11 2 6 10
  142.   button "O&k"       3  5 8
  143.   button "&Test"    14  5 8
  144.   whenenter "drawsaver"
  145.   button "&Remove"  25  5 8
  146.   button "Cancel"   36  5 8
  147.  
  148.   case (getdialog ref minutes)
  149.     // install screen saver
  150.     when "Ok"
  151.       if minutes then
  152.         saver
  153.         if not installed then
  154.           stayresident
  155.         end
  156.         msgbox "Screen Saver Installed, delay is " + minutes + " minutes."
  157.       end
  158.       // remove screen saver
  159.     when "Remove"
  160.       if installed then
  161.         saver -1
  162.         destroyobject obj
  163.         unsetx "saverobj" "prf"
  164.         msgbox "Screen Saver Removed."
  165.       end
  166.   end
  167.  
  168.