home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / timeserv / digital.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  5KB  |  154 lines

  1. /*static char *SCCSID = "@(#)digital.c    6.4 92/02/18";*/
  2. /*=========================================================================\
  3.  *                                                                         *
  4.  *       FILE:digital.c                                                    *
  5.  *                                                                         *
  6.  *       DESCRIPTION: This file contains the routines necessary for        *
  7.  *                    updating the digital clock face                      *
  8.  *                                                                         *
  9.  *                                                                         *
  10.  *      Copyright 1989, 1990, 1992 IBM Corp.                               *
  11.  *                                                                         *
  12.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        *
  13.  *      sample code created by IBM Corporation. This sample code is not    *
  14.  *      part of any standard or IBM product and is provided to you solely  *
  15.  *      for  the purpose of assisting you in the development of your       *
  16.  *      applications.  The code is provided "AS IS", without               *
  17.  *      warranty of any kind.  IBM shall not be liable for any damages     *
  18.  *      arising out of your use of the sample code, even if they have been *
  19.  *      advised of the possibility of   such damages.                      *
  20.  *                                                                         *
  21.  *-------------------------------------------------------------------------*
  22.  *--------------------------------------------------------------
  23.  *
  24.  *  This source file contains the following functions:
  25.  *
  26.  *  ClkDrawDigitalString()
  27.  *
  28.  *
  29.  *
  30. \*==============================================================*/
  31.  
  32. /*--------------------------------------------------------------*\
  33.  *  Include files, macros, defined constants, and externs
  34. \*--------------------------------------------------------------*/
  35.  
  36. #define INCL_WIN
  37. #define INCL_GPI
  38. #define INCL_DOSSEMAPHORES
  39. #define INCL_DOSDATETIME
  40. #include <os2.h>
  41. #include <string.h>
  42. #include "clock.h"
  43. #include "res.h"
  44. #include "clkdata.h"
  45.  
  46.  
  47.  
  48.  
  49. /*--------------------------------------------------------------*\
  50.  *  Global variables  and definitions for this file
  51. \*--------------------------------------------------------------*/
  52. POINTL aptlSeg1[] =
  53. {
  54.     {  2, 40 },
  55.     { 18, 40 },
  56.     { 20, 42 },
  57.     {  0, 42 },
  58. };
  59. /*--------------------------------------------------------------*\
  60.  *  Entry point declarations
  61. \*--------------------------------------------------------------*/
  62.  
  63. /****************************************************************\
  64.  *  Routine Name:
  65.  *--------------------------------------------------------------
  66.  *
  67.  *  Name: ClkDrawDigitalString()
  68.  *
  69.  *  Purpose:
  70.  *
  71.  *
  72.  *
  73.  *  Usage:
  74.  *
  75.  *  Method:
  76.  *          -
  77.  *
  78.  *          -
  79.  *          -
  80.  *
  81.  *          -
  82.  *          -
  83.  *
  84.  *  Returns:VOID
  85.  *
  86.  *
  87. \****************************************************************/
  88. VOID ClkDrawDigitalString(HPS hps, char *psz, RECTL *prcl,
  89.                           LONG clrFore, LONG clrBack)
  90. {
  91.  
  92.     RECTL rclDevice;
  93.     RECTL rclChar;
  94.     USHORT cch, cxChar, cyChar, cxSegment, cySegment, i;
  95.     LONG lPSid;
  96.     USHORT xRemainder;
  97.  
  98.     /*
  99.      * Do things in device coordinates to avoid problems with rounding.
  100.      */
  101.     rclDevice = *prcl;
  102.     GpiConvert(hps, CVTC_WORLD, CVTC_DEVICE, 2L, (PPOINTL)&rclDevice);
  103.  
  104.     /*
  105.      * Save and reset the PS to the default state.
  106.      */
  107.     lPSid = GpiSavePS(hps);
  108.     GpiResetPS(hps, GRES_ATTRS);
  109.  
  110.     /*
  111.      * Go into RGB mode
  112.      */
  113.     GpiCreateLogColorTable(hps, 0L, LCOLF_RGB, 0L, 0L, NULL);
  114.  
  115.     cch = (USHORT)strlen(psz);
  116.  
  117.     /*
  118.      * How wide and how tall will each character be?
  119.      */
  120.     cxChar = (USHORT)(rclDevice.xRight - rclDevice.xLeft) / cch;
  121.     cyChar = (USHORT)(rclDevice.yTop   - rclDevice.yBottom);
  122.  
  123.     cxSegment = cxChar / (USHORT)5;
  124.  
  125.     /*
  126.      * Find out how much, if any we'll need to center the
  127.      * digits by.
  128.      */
  129.     xRemainder = (USHORT)(rclDevice.xRight - rclDevice.xLeft) % cch;
  130.  
  131.     WinSetRect(NULLHANDLE, &rclChar,
  132.                (rclDevice.xLeft + (xRemainder / 2) ),
  133.                (rclDevice.yBottom),
  134.                ( (rclDevice.xLeft + (xRemainder / 2)) + cxChar - cxSegment),
  135.                (rclDevice.yBottom + cyChar) );
  136.  
  137.     for (i = 0; i < cch; i++)
  138.     {
  139.         WinDrawBorder(hps, &rclChar, cxSegment, cySegment, clrFore, clrBack,
  140.                 DB_INTERIOR);
  141.         WinOffsetRect(NULLHANDLE, &rclChar, cxChar, 0);
  142.     }
  143.  
  144.     /*
  145.      * Put it back like we found it.
  146.      */
  147.     GpiRestorePS (hps, lPSid);
  148. }
  149.  
  150.  
  151. /*--------------------------------------------------------------*\
  152.  *  End of file : digital.c
  153. \*--------------------------------------------------------------*/
  154.