home *** CD-ROM | disk | FTP | other *** search
- /*
- Program: POPSTOP.PRG
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Copyright (c) 1988-90, Greg Lief
- Clipper 5.0 version
- Compile instructions: clipper popstop /n/w/a
-
- Procs & Fncts: DRAWSTOPBX()
-
- Calls: SHADOWBOX() (function in SHADOWB.PRG)
- CHECKMOVE() (function in MOVING.PRG)
- */
-
- //───── begin preprocessor directives
-
- #include "grump.ch"
- #include "inkey.ch"
-
- //───── end preprocessor directives
-
- //───── begin global declarations
-
- #define ALREADY_ON (start_time > 0)
- static start_time := 0, stoptop := 4, stopleft := 26
-
- //───── end global declarations
-
- function popstop(gfproc, line, var)
- local elaptime, disptime, hotkey := 0, key := 0, tempcolor, ;
- oldscrn := savescreen(stoptop, stopleft, stoptop + 5, stopleft + 29)
- GFSaveEnv(, 0) // shut off cursor
- //───── determine whether this was called via hot-key; if so, disable it
- if (gfproc != NIL)
- setkey(hotkey := lastkey(), NIL)
- endif
-
- drawstopbx()
- //───── if the variable start_time is type numeric, it means the clock is running..
- do while key != 27
- if ! ALREADY_ON
- @ stoptop+2, stopleft+2 ssay 'Alt-B ='
- @ row()+1, stopleft+2 ssay 'Bk Grnd'
- @ row(), stopleft+22 ssay 'start'
- @ row()+1, stopleft+6 ssay 'Press Esc to exit'
- if (key := ginkey(0)) = K_ALT_F10 // change color!
- tempcolor := colorpal(tempcolor, 16, if(stopleft > 36, 0, 64))
- //───── if they didn't bust out, change the stopwatch color
- if lastkey() != K_ESC
- ColorSet(C_STOPWATCH_BOX, tempcolor)
- drawstopbx()
- endif
- loop
- endif
- if key < 32 .and. key != K_ESC .and. key != K_ENTER
- checkmove(key, 5, 29, @stoptop, @stopleft, @oldscrn) // $moving.prg
- loop
- endif
- endif
- if key = K_ALT_B
- start_time := seconds()
- key := K_ESC //───── to force exit from the main loop
- elseif key != K_ESC .or. ALREADY_ON
- //───── use different prompts if the clock is already running...
- @ stoptop+2, stopleft+2 ssay if(ALREADY_ON, ' in ', space(7))
- @ row()+1, stopleft+2 ssay if(ALREADY_ON, 'bk grnd', space(7))
- @ row(), stopleft+22 ssay 'stop '
- @ row()+1, stopleft+6 ssay if(ALREADY_ON, 'Press Esc to exit', ;
- replicate(chr(220), 17))
- ColorSet(C_STOPWATCH_WINDOW)
- start_time := if(! ALREADY_ON, seconds(), start_time)
- do while inkey() = 0
- elaptime := seconds() - start_time
- //───── sound alarm at minute and hour intervals
- if elaptime == 60.00
- tone(MUSIC_ALERT,1)
- tone(MUSIC_ALERT,1)
- tone(MUSIC_ALERT,1)
- endif
- if elaptime == 3600.00
- tone(MUSIC_ALERT,2)
- tone(MUSIC_ALERT,2)
- start_time := 0
- endif
- disptime := str(int(elaptime / 60), 2) + ':' + ;
- if(elaptime % 60 < 10, '0' + str(elaptime % 60, 4, 2), ;
- str(elaptime % 60, 5, 2))
- @ stoptop+2, stopleft+10 ssay disptime
- enddo
- ColorSet(C_STOPWATCH_BOX)
- @ stoptop+2, stopleft+10 ssay disptime
- key := lastkey()
- if ! (key == K_ESC .and. ALREADY_ON)
- start_time := 0
- endif
- endif
- enddo
-
- //───── restore hot-key
- if hotkey != 0
- setkey( hotkey, {|p, l, v| popstop(p, l, v)} )
- endif
-
- //───── restore previous environment
- restscreen(stoptop, stopleft, stoptop + 5, stopleft + 29, oldscrn)
- GFRestEnv()
- return NIL
-
- * end function PopStop()
- *--------------------------------------------------------------------*
-
-
- /*
- DrawStopBx() -- draw the stopwatch box
- */
- static function drawstopbx
- local ccolor, ptr
- ColorSet(C_STOPWATCH_BOX)
- ccolor := setcolor()
- shadowbox(stoptop, stopleft, stoptop+4, stopleft+27, 5)
- //───── determine converse of main color and use it as the title
- ptr := at('/', ccolor)
- setcolor(substr(ccolor, ptr + 1, at(',', ccolor) - ptr - 1) + '/' + ;
- substr(ccolor, 1, ptr - 1) )
- @ stoptop, stopleft+ 9 ssay 'STOP WATCH'
- setcolor(ccolor)
- @ row()+2, stopleft+ 9 ssay '0:00.00'
- @ row(), stopleft+19 ssay 'any key'
- @ row()+1, stopleft+19 ssay 'to'
- SINGLEBOX(stoptop+1, stopleft+9, stoptop+3, stopleft+18)
- return NIL
-
- * end static function DrawStopBx()
- *--------------------------------------------------------------------*
-
- * eof popstop.prg
-