home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / POPSTOP.PRG < prev    next >
Encoding:
Text File  |  1991-05-02  |  4.4 KB  |  137 lines

  1. /*
  2.    Program: POPSTOP.PRG
  3.    System: GRUMPFISH LIBRARY
  4.    Author: Greg Lief
  5.    Copyright (c) 1988-90, Greg Lief
  6.    Clipper 5.0 version
  7.    Compile instructions: clipper popstop /n/w/a
  8.  
  9.    Procs & Fncts: DRAWSTOPBX()
  10.  
  11.            Calls: SHADOWBOX()   (function in SHADOWB.PRG)
  12.                   CHECKMOVE()   (function in MOVING.PRG)
  13. */
  14.  
  15. //───── begin preprocessor directives
  16.  
  17. #include "grump.ch"
  18. #include "inkey.ch"
  19.  
  20. //───── end preprocessor directives
  21.  
  22. //───── begin global declarations
  23.  
  24. #define ALREADY_ON   (start_time > 0)
  25. static start_time := 0, stoptop := 4, stopleft := 26
  26.  
  27. //───── end global declarations
  28.  
  29. function popstop(gfproc, line, var)
  30. local elaptime, disptime, hotkey := 0, key := 0, tempcolor, ;
  31.       oldscrn := savescreen(stoptop, stopleft, stoptop + 5, stopleft + 29)
  32. GFSaveEnv(, 0)         // shut off cursor
  33. //───── determine whether this was called via hot-key; if so, disable it
  34. if (gfproc != NIL)
  35.    setkey(hotkey := lastkey(), NIL)
  36. endif
  37.  
  38. drawstopbx()
  39. //───── if the variable start_time is type numeric, it means the clock is running..
  40. do while key != 27
  41.    if ! ALREADY_ON
  42.       @ stoptop+2,  stopleft+2  ssay 'Alt-B ='
  43.       @ row()+1,    stopleft+2  ssay 'Bk Grnd'
  44.       @ row(),      stopleft+22 ssay 'start'
  45.       @ row()+1,    stopleft+6  ssay 'Press Esc to exit'
  46.       if (key := ginkey(0)) = K_ALT_F10   // change color!
  47.          tempcolor := colorpal(tempcolor, 16, if(stopleft > 36, 0, 64))
  48.          //───── if they didn't bust out, change the stopwatch color
  49.          if lastkey() != K_ESC
  50.             ColorSet(C_STOPWATCH_BOX, tempcolor)
  51.             drawstopbx()
  52.          endif
  53.          loop
  54.       endif
  55.       if key < 32 .and. key != K_ESC .and. key != K_ENTER
  56.          checkmove(key, 5, 29, @stoptop, @stopleft, @oldscrn)  // $moving.prg
  57.          loop
  58.       endif
  59.    endif
  60.    if key = K_ALT_B
  61.       start_time := seconds()
  62.       key := K_ESC     //───── to force exit from the main loop
  63.    elseif key != K_ESC .or. ALREADY_ON
  64.       //───── use different prompts if the clock is already running...
  65.       @ stoptop+2,  stopleft+2  ssay if(ALREADY_ON, '  in   ', space(7))
  66.       @ row()+1, stopleft+2  ssay if(ALREADY_ON, 'bk grnd', space(7))
  67.       @ row(),   stopleft+22 ssay 'stop '
  68.       @ row()+1, stopleft+6  ssay if(ALREADY_ON, 'Press Esc to exit', ;
  69.                                  replicate(chr(220), 17))
  70.       ColorSet(C_STOPWATCH_WINDOW)
  71.       start_time := if(! ALREADY_ON, seconds(), start_time)
  72.       do while inkey() = 0
  73.          elaptime := seconds() - start_time
  74.          //───── sound alarm at minute and hour intervals
  75.          if elaptime == 60.00
  76.             tone(MUSIC_ALERT,1)
  77.             tone(MUSIC_ALERT,1)
  78.             tone(MUSIC_ALERT,1)
  79.          endif
  80.          if elaptime == 3600.00
  81.             tone(MUSIC_ALERT,2)
  82.             tone(MUSIC_ALERT,2)
  83.             start_time := 0
  84.          endif
  85.          disptime := str(int(elaptime / 60), 2) + ':' + ;
  86.                      if(elaptime % 60 < 10, '0' + str(elaptime % 60, 4, 2), ;
  87.                      str(elaptime % 60, 5, 2))
  88.          @ stoptop+2, stopleft+10 ssay disptime
  89.       enddo
  90.       ColorSet(C_STOPWATCH_BOX)
  91.       @ stoptop+2, stopleft+10 ssay disptime
  92.       key := lastkey()
  93.       if ! (key == K_ESC .and. ALREADY_ON)
  94.          start_time := 0
  95.       endif
  96.    endif
  97. enddo
  98.  
  99. //───── restore hot-key
  100. if hotkey != 0
  101.    setkey( hotkey, {|p, l, v| popstop(p, l, v)} )
  102. endif
  103.  
  104. //───── restore previous environment
  105. restscreen(stoptop, stopleft, stoptop + 5, stopleft + 29, oldscrn)
  106. GFRestEnv()
  107. return NIL
  108.  
  109. * end function PopStop()
  110. *--------------------------------------------------------------------*
  111.  
  112.  
  113. /*
  114.    DrawStopBx() -- draw the stopwatch box
  115. */
  116. static function drawstopbx
  117. local ccolor, ptr
  118. ColorSet(C_STOPWATCH_BOX)
  119. ccolor := setcolor()
  120. shadowbox(stoptop, stopleft, stoptop+4, stopleft+27, 5)
  121. //───── determine converse of main color and use it as the title
  122. ptr := at('/', ccolor)
  123. setcolor(substr(ccolor, ptr + 1, at(',', ccolor) - ptr - 1) + '/' + ;
  124.          substr(ccolor, 1, ptr - 1) )
  125. @ stoptop, stopleft+ 9 ssay 'STOP WATCH'
  126. setcolor(ccolor)
  127. @ row()+2, stopleft+ 9 ssay '0:00.00'
  128. @ row(),   stopleft+19 ssay 'any key'
  129. @ row()+1, stopleft+19 ssay 'to'
  130. SINGLEBOX(stoptop+1, stopleft+9, stoptop+3, stopleft+18)
  131. return NIL
  132.  
  133. * end static function DrawStopBx()
  134. *--------------------------------------------------------------------*
  135.  
  136. * eof popstop.prg
  137.