Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - on idle do install a procedure to execute in the wait key loop http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 on idle do          Install a procedure to execute in the wait key loop
------------------------------------------------------------------------------
 Syntax
   on idle do [xProc]

 Arguments
   xProc is a function to repeatedly execute in the idle loop.

 Description
   The on idle do command installs the specified xProc into the
   wait key loop. Whenever Force waits for keyboard entry, this procedure
   will then get called periodically. The idle procedure will only be
   called when the system waits for keystrokes. Other idle situations,
   like while packing or indexing a database do not call the idle
   procedure.

   The on idle do command is handy to execute background tasks, like
   displaying a clock, without using the timerentry()/activateprocs() family
   of routines.

   To uninstall an idle loop procedure, write the command without an xProc
   name.

 Example
   #define EXAMPLE_SYSTEM
   #include example.hdr

   #define MENU_ITEMS   4
   #define MENU_TOP    10
   #define MENU_LEFT   31
   #define MENU_WIDTH   5
   
   vardef static
      char(8) cLastTime := "        "
   enddef
   
   // Displays the time in the top left corner of the screen
   //
   proc DispTime static
   // To avoid unnecessary flicker, we only show the time when it has changed
   if time() != cLastTime
     saverc()               // a simple way to save the cursor coordinates...
     @ 0, 0 ?? time()
     restrc()               // ...and to restore them again
     cLastTime := time()
   endif
   endproc
   
   func logical ClickWithin static
   // Return if mouse click happened within menu area
   vardef
      uint nRow, nCol
   enddef
   nRow := mouserow()
   nCol := mousecol()
   return( nRow >= MENU_TOP .and. nRow <= MENU_TOP + ( MENU_ITEMS - 1 ) .and. ;
      nCol >= MENU_LEFT .and. nCol <= MENU_LEFT + MENU_WIDTH - 1 )
   endfunc
   
   proc MouseMenu static
   vardef
      uint n
   enddef
   @ 0, 70 ?? time()            // show current time
   if mouseclick( MB_LEFT ) .and. ClickWithin() // if relevant mouse action
      for n := 1 to MENU_ITEMS  // deselect all items
         selectid( n, .f. )
      next
      selectid( mouserow() - MENU_TOP + 1, .t. ) // highlight selected item
   endif
   endproc
   
   proc Test_onidledo
   vardef
      uint nChoice
   enddef
   clear
   cursor( .f. )
   mouseon()
   on idle do MouseMenu                      // install callback function
   @ MENU_TOP + 0, MENU_LEFT prompt "one"    // set up menu
   @ MENU_TOP + 1, MENU_LEFT prompt "two"
   @ MENU_TOP + 2, MENU_LEFT prompt "three"
   @ MENU_TOP + 3, MENU_LEFT prompt "four"
   menu to nChoice                           // execute menu
   on idle do                                // clean up
   mouseoff()
   endproc

   proc main
   Test_onidledo()
   endproc

See Also: on key do

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson