home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / cl_clk10.zip / CLOCK.PRG < prev    next >
Text File  |  1993-03-24  |  15KB  |  369 lines

  1. /******************************************
  2. *  Function:    Clock
  3. *  Purpose:     Provides an on-screen clock
  4. *               (Screen Saver)
  5. *  Parameters:  hourmode12  :=  .T. for 12 Hour Am/Pm mode (default)
  6. *                               .F. for 24 Military time
  7. *               dispstring  :=  Character string to display under clock
  8. *                               (default is "Press Any Key to Continue...")
  9. *  Returns:     NIL
  10. *  Author:      Donald T. Olsen (c) copyright 1993
  11. *               96 OSS/OSOAC
  12. *               Dyess AFB, TX 79607
  13. *               Phone: (915)-696-2588 .or. AV: 461-2588
  14. *               Internet:
  15. *                    96wglglmpc@strathost.stratcom.af.mil
  16. *                    dolsen@dylan.af.mil
  17. *                    dolsen@donatello.af.mil
  18. *  Date:        24 March 1993
  19. *  Clipper:     Ver 5.01a
  20. *  Compile:     RTLINK clock /l /m /n
  21. *  Cost:        Free (of course), I only ask that you not sell it for
  22. *               your own profit.  If you change/enhance/rewrite it, do
  23. *               not redistribute your version.  Give me credit for the
  24. *               effort put into it.  (Integrity)
  25. *  Notes:       Additional notes can be found at the end of this program
  26. *               (That is my workspace.)
  27. *
  28. */
  29.  
  30. #include "SET.CH"
  31. #include "SETCURS.CH"
  32.  
  33. //                 Characters           Array Pos:       Used In Numbers:
  34. STATIC    char  :=  { " ─┐  ", ;     //     1            1
  35.                       "  │  ", ;     //     2            1
  36.                       "══╧══", ;     //     3            1
  37.                       "╓───┐", ;     //     4            2,3,5,6,7,8,9,0
  38.                       "    │", ;     //     5            2,3,4,5,7,9
  39.                       "╔═══╛", ;     //     6            2
  40.                       "║    ", ;     //     7            2,5,6
  41.                       "╚═══╛", ;     //     8            2,3,5,6,8,9,0
  42.                       "  ══╡", ;     //     9            3
  43.                       "║   │", ;     //    10            4,6,8,9,0
  44.                       "╚═══╡", ;     //    11            4,9
  45.                       "╚═══╕", ;     //    12            5
  46.                       "╠═══╡", ;     //    13            8
  47.                       "╠═══╕", ;     //    14            6
  48.                       "    ╛", ;     //    15            4,7
  49.                       "╓   ┐", ;     //    16            4
  50.                       "     "  }     //    17            Blank (12-Hour mode)
  51.  
  52. // cross-reference of chars array to construct the #s           Array Pos
  53. STATIC    ref  :=  { { 17, 17, 17, 17, 17 }, ;     //  Blank        1
  54.                      {  4, 10, 10, 10,  8 }, ;     //  Zero         2
  55.                      {  1,  2,  2,  2,  3 }, ;     //  One          3
  56.                      {  4,  5,  6,  7,  8 }, ;     //  Two          4
  57.                      {  4,  5,  9,  5,  8 }, ;     //  Three        5
  58.                      { 16, 10, 11,  5, 15 }, ;     //  Four         6
  59.                      {  4,  7, 12,  5,  8 }, ;     //  Five         7
  60.                      {  4,  7, 14, 10,  8 }, ;     //  Six          8
  61.                      {  4,  5,  5,  5, 15 }, ;     //  Seven        9
  62.                      {  4, 10, 13, 10,  8 }, ;     //  Eight       10
  63.                      {  4, 10, 11,  5,  8 }  }     //  Nine        11
  64. // and the others
  65. STATIC  clktop := 9, clkleft := 1, clkdir := 1
  66.  
  67. // clktop   := Starting row postion of clock when first called
  68. // clkleft  := Starting column position (1 while clock moves up)
  69. //                                     (32 while clock moves down)
  70. // clkdir   := Starting direction of clock movement 1=Up, -1=Down
  71.  
  72. FUNCTION Clock( hourmode12, dispstring )
  73. LOCAL inscreen, inrow, incol, incursor, incolor, inscore, nhour, moved, ;
  74.       am, ht, ho, mt, mo, st, so, line, outtahere, ddate
  75. inscreen   := SAVESCREEN( 0, 0, MAXROW(), MAXCOL() )
  76. inrow      := ROW()
  77. incol      := COL()
  78. incursor   := SETCURSOR( SC_NONE )
  79. incolor    := SETCOLOR("BG+/N")
  80. inscore    := SET(_SET_SCOREBOARD, .F.)
  81. moved      := .F.
  82. outtahere  := .F.
  83. hourmode12 := IF(hourmode12 = NIL, .T., hourmode12)
  84. dispstring := IF(dispstring = NIL, "Press Any Key to Continue...", dispstring)
  85. IF VALTYPE(hourmode12) + VALTYPE(dispstring) != "LC"
  86.   _Err_Msg("Programmer Error - Invalid Parameter type passed to Clock")
  87.   RETURN( NIL )
  88. ENDIF
  89.  
  90. // TIME() is in format "HH:MM:SS"  or  "12:56:23"
  91.  
  92. // Clear the screen and Display the unchangables (dots and dispstring)
  93. DispUnchangables( dispstring )
  94.  
  95. // Loop till a key is pressed, I'm outtahere.
  96. WHILE !outtahere
  97.   ddate := DATE()
  98.   DispDate( ddate )
  99.  
  100.   // Loop till the date changes
  101.   WHILE ddate = DATE() .and. !outtahere
  102.     am  := ( VAL(SUBSTR(TIME(), 1, 2) ) < 12 )
  103.     IF hourmode12
  104.       DispAmPm( am )
  105.     ENDIF
  106.  
  107.     // Loop till the Am/Pm changes
  108.     WHILE am = ( VAL(SUBSTR(TIME(), 1, 2) ) < 12 ) .and. !outtahere
  109.       nhour := VAL(SUBSTR(TIME(), 1, 2))
  110.       // nhour will be a string after the IF statement
  111.       IF hourmode12
  112.         // In 12 hour mode must subtract 12 from any time 1 pm and after
  113.         // Also Midnight to one o'clock is a 12 not a 0
  114.         nhour := PADL( ALLTRIM( STR( IF(nhour>12, nhour-12, IF(nhour = 0, 12, nhour)), 2 )), 2, "0")
  115.         ht  := IF( SUBSTR(nhour, 1, 1) = "0", 1, ;
  116.               VAL( SUBSTR(nhour, 1, 1) ) + 2 )
  117.       ELSE
  118.         nhour := PADL( ALLTRIM( STR( nhour, 2 ) ), 2, "0")
  119.         ht  := VAL( SUBSTR(nhour, 1, 1) ) + 2
  120.       ENDIF
  121.       ho    := VAL( SUBSTR(nhour, 2, 1) ) + 2
  122.       // 0 in the Update_um function is translated into the screen column
  123.       // at which the hours, minutes and seconds will be displayed
  124.       Update_um( 0, ht, ho )
  125.  
  126.       // Loop till the hour changes
  127.       WHILE ( nhour = SUBSTR(TIME(), 1, 2) .or. ;
  128.              IF(VAL(nhour)<12,VAL(nhour)+12,VAL(nhour)-12) = ;
  129.              VAL(SUBSTR(TIME(), 1, 2)) ) ;
  130.              .and. !outtahere
  131.  
  132.         mt    := VAL( SUBSTR(TIME(), 4, 1) ) + 2
  133.         mo      := VAL( SUBSTR(TIME(), 5, 1) ) + 2
  134.         Update_um( 1, mt, mo )
  135.  
  136.         // Loop till the minute changes
  137.         WHILE ALLTRIM(STR(mt-2,1))+ALLTRIM(STR(mo-2,1)) = ;
  138.               SUBSTR(TIME(), 4, 2) .and. !outtahere
  139.           st    := VAL( SUBSTR(TIME(), 7, 1) ) + 2
  140.           so    := VAL( SUBSTR(TIME(), 8, 1) ) + 2
  141.           // IF seconds/ones reaches 0 move clock
  142.           IF so - 2 = 0 .and. !moved
  143.             MoveClock()
  144.             // Moved indicates whether the clock has been moved during
  145.             // this 10 second cycle.  Without this flag the clock might
  146.             // move multiple times while the seconds are being updated
  147.             // with 0 in the ones position.  This way it will only move once.
  148.             moved := .T.
  149.             // If clock is at the top or bottom of the screen, flip sides
  150.             IF clktop = -1 .or. clktop = MAXROW() - 6
  151.               Flip_um()
  152.               // Redisplay the date and AmPm (if in that mode)
  153.               Dispdate(ddate)
  154.               IF hourmode12
  155.                 DispAmPm(am)
  156.               ENDIF
  157.             ENDIF
  158.           ENDIF
  159.           // If seconds/ones is 5 set moved off
  160.           IF so - 2 = 5
  161.             moved := .F.
  162.           ENDIF
  163.           Update_um( 2, st, so )
  164.           outtahere := ( INKEY() <> 0 )
  165.         ENDDO
  166.       ENDDO
  167.     ENDDO
  168.   ENDDO
  169. ENDDO
  170. // Reset the environment, you may need other resets
  171. RESTSCREEN( 0, 0, MAXROW(), MAXCOL(), inscreen )
  172. SETPOS( inrow, incol )
  173. SETCURSOR( incursor )
  174. SETCOLOR( incolor )
  175. SET(_SET_SCOREBOARD, inscore)
  176. RETURN( NIL )
  177.  
  178.  
  179. /******************************************
  180. *  Function:    Update_um
  181. *  Purpose:     Update any one of the Hour,
  182. *               Minute or Seconds Display
  183. *  Parameters:  Which ( a 0 for hours )
  184. *                     ( a 1 for minutes )
  185. *                     ( a 2 for seconds )
  186. *               Tens/Ones - array ref of
  187. *                  which number to display
  188. *  Called:      Anytime there is a change to
  189. *               the Hours, Minutes or Seconds
  190. */
  191. STATIC FUNCTION Update_um( which, tens, ones )
  192. LOCAL line, leftpos
  193. // Starting postions of numbers are 14 columns apart so...
  194. leftpos := clkleft+(which*14)
  195. FOR line = 1 to 5
  196.   @ clktop+line, leftpos SAY char[ ref[ tens, line ] ] + " " + ;
  197.                             char[ ref[ ones, line ] ] COLOR "BG+/N"
  198. NEXT
  199. RETURN( NIL )
  200.  
  201. /******************************************
  202. *  Function:    MoveClock
  203. *  Purpose:     Moves clock up or down screen
  204. *               and sets new clktop reference
  205. */
  206. STATIC FUNCTION MoveClock()
  207. SCROLL(0, 0, MAXROW(), MAXCOL(), clkdir)
  208. clktop := clktop - clkdir
  209. RETURN( NIL )
  210.  
  211. /******************************************
  212. *  Function:    DispUnchangables
  213. *  Purpose:     Displays dots and message these never need to be
  214. *               displayed again, except of course when the clock
  215. *               is called again.
  216. */
  217. STATIC FUNCTION DispUnchangables( dispstring )
  218. SCROLL()
  219. @ clktop + 2, clkleft + 12 SAY "∙             ∙" COLOR "W+*/N"
  220. @ clktop + 4, clkleft + 12 SAY "∙             ∙" COLOR "W+*/N"
  221. @ clktop + 6, 0 SAY PADC(dispstring, 80) COLOR "W+/R"
  222. RETURN( NIL )
  223.  
  224. /******************************************
  225. *  Function:    DispAmPm
  226. *  Purpose:     Displays AM/PM at the
  227. *               correct position
  228. *  Parameters:  Logical .T. for AM
  229. *                       .F. for PM
  230. *  Called:      On initial start-up and when clock is fliped side-to-side
  231. *               and when Am/Pm changes
  232. */
  233. FUNCTION DispAmPm( am )
  234. LOCAL incolor := SETCOLOR("GR+/N")
  235. IF am
  236.   @ clktop + 2, clkleft + 40 SAY "╟─┤ ║ │"
  237. ELSE
  238.   SETCOLOR("B+/N")
  239.   @ clktop + 2, clkleft + 40 SAY "╟─┘ ║ │"
  240. ENDIF
  241. @ clktop + 1, clkleft + 40 SAY "╓─┐ ╓┬┐"
  242. SETCOLOR(incolor)
  243. RETURN( NIL )
  244.  
  245. /******************************************
  246. *  FUNCTION:    DispDate( indate )
  247. *  Purpose:     Converts a date string to a character ( Friday  13 Sep 1991 )
  248. *  Parameters:  Date to be converted
  249. *  Called:      On initial start-up and when clock is fliped side-to-side
  250. *               and when date changes
  251. */
  252. FUNCTION DispDate( indate )
  253. LOCAL datestring, centerstr, displeft, displine
  254. datestring := CDOW( indate ) + "  " + LTRIM( STR( DAY( indate ), 0 ) ) + " " +;
  255.              CMONTH( indate ) + " " + LTRIM( STR( YEAR( indate ), 0 ) )
  256. centerstr  := IF(clkdir = 1, 61, 16)
  257. displine   := IF(clkdir = 1, 4, 3)
  258. displeft   := INT( centerstr - LEN(datestring)/2 )
  259. @ clktop+displine, displeft-14 SAY SPACE(28)
  260. @ clktop+displine, displeft SAY datestring COLOR "G+/N"
  261. @ clktop+displine+1, displeft-15 SAY SPACE(30)
  262. @ clktop+displine+1, displeft-1 SAY REPLICATE( CHR(196), LEN(datestring)+2 ) ;
  263.                                 COLOR "G+/N"
  264. RETURN( NIL )
  265.  
  266. /******************************************
  267. *  FUNCTION:    Flip_um
  268. *  Purpose:     Flips clock and date on screen
  269. *  Parameters:  None
  270. *  Returns:     Nothing
  271. *  Notes:       After this function is called a call to functions DispDate() and
  272. *               DispAmPm() must be made in order to completely redraw the screen.
  273. *  Called:      When clock reaches either the top of the screen or the bottom
  274. */
  275. FUNCTION Flip_um()
  276. LOCAL clockscr := SAVESCREEN(clktop, clkleft, clktop+5, clkleft+39)
  277. clkleft := IF(clkleft = 1, 32, 1)
  278. clkdir  := IF(clkdir = -1, 1, -1)
  279. SCROLL(clktop, 0, clktop+5, MAXCOL())
  280. RESTSCREEN(clktop, clkleft, clktop+5, clkleft+39, clockscr)
  281. RETURN( NIL )
  282.  
  283. /******************************************
  284. *  FUNCTION:    _Err_Msg
  285. *  Purpose:     A generic function to provide on screen notice of an error
  286. *  Parameters:  Message to display, and optional Color logical to indicate
  287. *               if message should be displayed in color (default ISCOLOR() )
  288. *  Returns:     NIL
  289. *
  290. */
  291. FUNCTION _Err_Msg(l1, color)
  292. LOCAL width,lcol,rcol,icolor,origscrn
  293. color    := IF(color=NIL, ISCOLOR(), color)
  294. IF VALTYPE(l1) + VALTYPE(color) != "CL"
  295.   _Err_Msg("Programmer Error - Invalid parameter passed to _Err_Msg()")
  296.   RETURN( NIL )
  297. ENDIF
  298. l1       := ALLTRIM( l1 )
  299. width    := IF( LEN(l1) < 33, 33, LEN(l1) )
  300. lcol     := ROUND( (80-width)/2, 0 ) - 3
  301. rcol     := lcol + width + 5
  302. icolor   := SETCOLOR()
  303. origscrn := SAVESCREEN( MAXROW()-4, lcol, MAXROW(), rcol+1 )
  304. IF color
  305.   SETCOLOR( "W/R" )
  306. ENDIF
  307. // Shadow( MAXROW()-4, lcol, MAXROW()-1, rcol)
  308. @ MAXROW()-4, lcol, MAXROW()-1, rcol BOX "╒═╕│╛═╘│ "
  309. IF color
  310.   SETCOLOR( "W+/R" )
  311. ENDIF
  312. @ MAXROW()-4, 35 SAY "<<ERROR>>"
  313. @ MAXROW()-3, ROUND( (80-LEN(l1))/2,0 ) SAY l1
  314. @ MAXROW()-2, 24 SAY "** Press any key to continue **"
  315. TONE(70,4)
  316. TONE(50,4)
  317. INKEY(0)
  318. RESTSCREEN( MAXROW()-4, lcol, MAXROW(), rcol+1, origscrn )
  319. SETCOLOR( icolor )
  320. RETURN( NIL )
  321.  
  322.  
  323. /*****************************   Notes   *****************************
  324.  
  325. HOUR ref from clkleft    :=  0
  326. MINUTES ref from clkleft := 14
  327. SECONDS ref from clkleft := 28
  328.  
  329. AM/PM ref from clkleft   := 40
  330.  
  331. clkleft will either be 1   (clock moving up)
  332.                     or 32  (clock moving down)
  333.  
  334. clkdir will either be 1    (clock moving up)
  335.                    or -1   (clock moving down)
  336.  
  337. Keyline
  338.              1 1           2 2           4                   6
  339.  1           3 5           7 9           1                   1
  340.   ─┐   ╓───┐   ╓───┐ ╓───┐   ╓───┐ ╓───┐ ╓─┐ ╓┬┐
  341.    │       │ ∙ ║     ║     ∙     │     │ ╟─┤ ║ │
  342.    │   ╔═══╛   ╚═══╕ ╠═══╕   ╔═══╛   ══╡
  343.    │   ║     ∙     │ ║   │ ∙ ║         │       Wednesday  31 September 1993
  344.  ══╧══ ╚═══╛   ╚═══╛ ╚═══╛   ╚═══╛ ╚═══╛      ──────────────────────────────
  345. ████████████████████████████████████████████████████████████████████████████████
  346.  
  347.                 1               3           4 4             6           7
  348.                 6               2           4 6             0           2
  349.                                  ─┐   ╓───┐   ╓───┐ ╓───┐   ╓───┐ ╓───┐ ╓─┐ ╓┬┐
  350.                                   │       │ ∙ ║     ║     ∙     │     │ ╟─┤ ║ │
  351.   Wednesday  31 September 1993    │   ╔═══╛   ╚═══╕ ╠═══╕   ╔═══╛   ══╡
  352.  ──────────────────────────────   │   ║     ∙     │ ║   │ ∙ ║         │
  353.                                 ══╧══ ╚═══╛   ╚═══╛ ╚═══╛   ╚═══╛ ╚═══╛
  354. ████████████████████████████████████████████████████████████████████████████████
  355.  
  356.  
  357. Here is what all of the numbers look like.
  358.  
  359. ╒══════════════════════════════════════════════════════════════════════╕
  360. │  ─┐    ╓───┐  ╓───┐  ╓   ┐  ╓───┐  ╓───┐  ╓───┐  ╓───┐  ╓───┐  ╓───┐ │
  361. │   │        │      │  ║   │  ║      ║          │  ║   │  ║   │  ║   │ │
  362. │   │    ╔═══╛    ══╡  ╚═══╡  ╚═══╕  ╠═══╕      │  ╠═══╡  ╚═══╡  ║   │ │
  363. │   │    ║          │      │      │  ║   │      │  ║   │      │  ║   │ │
  364. │ ══╧══  ╚═══╛  ╚═══╛      ╛  ╚═══╛  ╚═══╛      ╛  ╚═══╛  ╚═══╛  ╚═══╛ │
  365. ╘══════════════════════════════════════════════════════════════════════╛
  366.  
  367. */
  368.  
  369.