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

  1. /*static char *SCCSID = "@(#)paint.c    6.6 92/02/18";*/
  2. /*=========================================================================\
  3.  *                                                                         *
  4.  *       FILE:paint.c                                                      *
  5.  *                                                                         *
  6.  *       DESCRIPTION:   routines used in painting the clock face           *
  7.  *                                                                         *
  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.  *
  25.  *  This source file contains the following functions:
  26.  *
  27.  *   ClkPaint
  28.  *   ClkDrawHand
  29.  *   ClkDrawFace
  30.  *   ClkDrawRing
  31.  *   ClkDrawDate
  32.  *   ClkDrawTicks
  33.  *   DrawDigitalTime
  34.  *   GetArrangedDate
  35.  *   DrawTrapez
  36.  *   DrawFullRing
  37.  *
  38.  *
  39. \*==============================================================*/
  40.  
  41. /*--------------------------------------------------------------*\
  42.  *  Include files, macros, defined constants, and externs
  43. \*--------------------------------------------------------------*/
  44.  
  45. #define INCL_WIN
  46. #define INCL_GPI
  47. #define INCL_DOSSEMAPHORES
  48. #define INCL_DOSDATETIME
  49.  
  50. #include <os2.h>
  51. #include <string.h>
  52. #include <stdlib.h>
  53. #include "clock.h"
  54. #include "res.h"
  55. #include "clkdata.h"
  56.  
  57. /*--------------------------------------------------------------*\
  58.  *  Global variables  and definitions for this file
  59. \*--------------------------------------------------------------*/
  60.  
  61.  
  62. #define MATLF_SIZE ( sizeof ( MATRIXLF ) / sizeof ( LONG ) )
  63.  
  64. #define CLK_MAJORTICKS  0x0001
  65. #define CLK_MINORTICKS  0x0002
  66.  
  67. #define XDATE 52L
  68. #define YDATE 14L
  69. #define ZDATE 1L
  70.  
  71. POINTL aptlFillet1[]= {{53L ,63L },{ 70L ,50L },{68L,47L}} ;
  72. POINTL aptlFillet2[]= {{68L,47L},{ 70L, 50L },{56L ,67L }} ;
  73. POINTL aptlFillet3[]= {{53L ,64L },{ 56L ,62L },{60L,58L}} ;
  74. POINTL aptlFillet4[]= {{60L,58L},{ 60L, 63L },{56L ,67L }} ;
  75. POINTL ptlLight= { -1L , 1L } ;
  76. POINTL ptlShade= {  2L, -2L } ;
  77. POINTL ptlFace = { 0L, 0L};
  78.  
  79. static FIXED fxSin [60] =
  80. {
  81.     0x00000000, 0x00001ac2, 0x00003539, 0x00004f1b, 0x0000681f, 0x00007fff,
  82.     0x00009679, 0x0000ab4c, 0x0000be3e, 0x0000cf1b, 0x0000ddb3, 0x0000e9de,
  83.     0x0000f378, 0x0000fa67, 0x0000fe98, 0x0000ffff, 0x0000fe98, 0x0000fa67,
  84.     0x0000f378, 0x0000e9de, 0x0000ddb3, 0x0000cf1b, 0x0000be3e, 0x0000ab4c,
  85.     0x00009679, 0x00008000, 0x00006820, 0x00004f1b, 0x00003539, 0x00001ac2,
  86.     0x00000000, 0xffffe53e, 0xffffcac7, 0xffffb0e5, 0xffff97e1, 0xffff8001,
  87.     0xffff6988, 0xffff54b5, 0xffff41c2, 0xffff30e5, 0xffff224d, 0xffff1622,
  88.     0xffff0c88, 0xffff0599, 0xffff0168, 0xffff0001, 0xffff0167, 0xffff0599,
  89.     0xffff0c88, 0xffff1622, 0xffff224d, 0xffff30e5, 0xffff41c2, 0xffff54b4,
  90.     0xffff6987, 0xffff8000, 0xffff97e0, 0xffffb0e4, 0xffffcac6, 0xffffe53e
  91. } ;
  92.  
  93.  
  94. /*--------------------------------------------------------------*\
  95.  *  Entry point declarations
  96. \*--------------------------------------------------------------*/
  97.  
  98. VOID ClkPaint        (HWND hWind);
  99. VOID ClkDrawHand     (HPS hpsSpace, SHORT sHand, SHORT sMany);
  100. VOID ClkDrawFace     (HPS hpsSpace);
  101. VOID ClkDrawRing     (HPS hpsSpace);
  102. VOID ClkDrawDate     (HPS hpsSpace, USHORT usDate);
  103. VOID ClkDrawTicks    (HPS hpsSpace, USHORT usMany);
  104. VOID DrawDigitalTime (HWND hWind);
  105. VOID GetArrangedDate (CHAR pszDate[]);
  106. VOID DrawTrapez      (HPS ,POINTL *, LONG );
  107. VOID DrawFullRing    (HPS hpsSpace, PPOINTL ppPoint, FIXED fixed1,
  108.                        FIXED fixed2, LONG lSize);
  109.  
  110.  
  111. /****************************************************************\
  112.  *
  113.  *--------------------------------------------------------------
  114.  *
  115.  *  Name: DrawClock()
  116.  *
  117.  *  Purpose:Draw the clock face ,hand and minute hand,
  118.  *
  119.  *
  120.  *
  121.  *  Usage:
  122.  *
  123.  *  Method:
  124.  *          -
  125.  *
  126.  *          -
  127.  *          -
  128.  *
  129.  *          -
  130.  *          -
  131.  *
  132.  *  Returns: VOID
  133.  *
  134.  *
  135. \****************************************************************/
  136. VOID DrawClock (HPS hpsDraw)
  137. {
  138.     RECTL rcl;
  139.  
  140.     WinQueryWindowRect (hwndClient, &rcl);
  141.     WinFillRect (hpsBuffer, &rcl, cp.clrBackground);
  142.  
  143.     /* draw the face, the hour hand, and the minute hand */
  144.  
  145.     ClkDrawRing (hpsDraw);
  146.     ClkDrawFace (hpsDraw);
  147.     ClkDrawDate (hpsDraw, DM_REDRAW);
  148.     ClkDrawHand (hpsDraw, HT_HOUR_SHADE, dt.hours);
  149.     ClkDrawHand (hpsDraw, HT_MINUTE_SHADE, dt.minutes);
  150.     ClkDrawHand (hpsDraw, HT_HOUR, dt.hours);
  151.     ClkDrawHand (hpsDraw, HT_MINUTE, dt.minutes);
  152.  
  153.     /* draw the tick marks */
  154.     if ((cp.usMajorTickPref == CLKTM_ALWAYS) ||
  155.             ((cp.usMajorTickPref == CLKTM_NOTICONIC) && ! fIconic))
  156.         ClkDrawTicks (hpsDraw, CLK_MAJORTICKS);
  157.  
  158.     if ((cp.usMinorTickPref == CLKTM_ALWAYS) ||
  159.             ((cp.usMinorTickPref == CLKTM_NOTICONIC) && !fIconic))
  160.         ClkDrawTicks (hpsDraw, CLK_MINORTICKS);
  161. }
  162.  
  163. /****************************************************************\
  164.  *
  165.  *--------------------------------------------------------------
  166.  *
  167.  *  Name:UpdateScreen()
  168.  *
  169.  *  Purpose: Update the screen area.
  170.  *
  171.  *
  172.  *
  173.  *  Usage:
  174.  *
  175.  *  Method:
  176.  *          -
  177.  *
  178.  *          -
  179.  *          -
  180.  *
  181.  *          -
  182.  *          -
  183.  *
  184.  *  Returns:
  185.  *
  186.  *
  187. \****************************************************************/
  188. VOID UpdateScreen (HPS hps, RECTL *prclUpdate)
  189. {
  190.     POINTL aptl[3];
  191.  
  192.     if (prclUpdate != NULL)
  193.     {
  194.         aptl[0].x = prclUpdate->xLeft;
  195.         aptl[0].y = prclUpdate->yBottom;
  196.         aptl[1].x = prclUpdate->xRight;
  197.         aptl[1].y = prclUpdate->yTop;
  198.         aptl[2].x = prclUpdate->xLeft;
  199.         aptl[2].y = prclUpdate->yBottom;
  200.     }
  201.     else
  202.     {
  203.         WinQueryWindowRect (hwndClient, (PRECTL)aptl);
  204.         aptl[2].x =
  205.         aptl[2].y = 0;
  206.     }
  207.  
  208.     GpiBitBlt (hps, hpsBuffer, 3L, aptl, ROP_SRCCOPY, 0L);
  209. }
  210. /****************************************************************\
  211.  *
  212.  *--------------------------------------------------------------
  213.  *
  214.  *  Name:ClkPaint
  215.  *
  216.  *  Purpose: Paint the clock client window.
  217.  *
  218.  *
  219.  *
  220.  *  Usage:
  221.  *
  222.  *  Method:
  223.  *          -
  224.  *
  225.  *          -
  226.  *          -
  227.  *
  228.  *          -
  229.  *          -
  230.  *
  231.  *  Returns:  VOID
  232.  *
  233.  *
  234. \****************************************************************/
  235. VOID ClkPaint (HWND hwnd)
  236. {
  237.     RECTL rclUpdate;
  238.     HPS hpsWnd;
  239.  
  240.     if (cp.usDispMode & DM_ANALOG)
  241.     {
  242.  
  243.         WinBeginPaint (hwnd, hps, &rclUpdate);
  244.  
  245.         GpiCreateLogColorTable (hps, 0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  246.  
  247.         WinFillRect (hps, &rclUpdate, cp.clrBackground);
  248.  
  249.         if (fBufferDirty)
  250.         {
  251.             DrawClock (hpsBuffer);
  252.             fBufferDirty = FALSE;
  253.         }
  254.  
  255.         UpdateScreen (hps, &rclUpdate);
  256.  
  257.         /*
  258.          * Draw the second hand last, so xor will work.
  259.          */
  260.         if (fShowSecondHand && (cp.usDispMode & DM_SECONDHAND))
  261.             ClkDrawHand(hps, HT_SECOND, dt.seconds);
  262.  
  263.         WinEndPaint (hps);
  264.  
  265.     }
  266.     else
  267.     { /*For now, if it is not Analog, it must be digital*/
  268.  
  269.         hpsWnd = WinBeginPaint (hwnd, NULLHANDLE, &rclUpdate);
  270.  
  271.         GpiCreateLogColorTable(hpsWnd, 0L, LCOLF_RGB, 0L, 0L, (PLONG) NULL);
  272.  
  273.         WinFillRect (hpsWnd, &rclUpdate, cp.clrBackground);
  274.  
  275.         memset (achOldTime, 0, sizeof(achOldTime));
  276.         memset (achOldAmPm, '0', sizeof(achOldAmPm));
  277.         memset (achOldDate, '0', sizeof(achOldDate));
  278.  
  279.         DrawDigitalTime (hwnd);
  280.  
  281.         WinEndPaint (hpsWnd);
  282.     }
  283. }
  284.  
  285.  
  286. /**************************************************************************\
  287. *                                                                          *
  288. *       ROUTINE:    ClkDrawHand                                            *
  289. *                                                                          *
  290. *       COMMENT:    Draws specified hand at specified hour in given PS     *
  291. *                                                                          *
  292. \**************************************************************************/
  293.  
  294. VOID ClkDrawHand ( HPS hps , SHORT sHandType , SHORT sAngle )
  295. {
  296.     static POINTL aptlHour [ ] = { { 6 , 0 } , { 0 , 62 } , { -6 , 0 } ,
  297.                                    { 0 , -14 } , { 6 , 0 } } ;
  298.     static POINTL aptlHourLine1 [] = {{0L,-10L},{0L,56}};
  299.  
  300.     static POINTL aptlMinute [ ] = { { 5 , 0 } , { 0 , 77 } , { -5 , 0 } ,
  301.                                      { 0 , -14 } , { 5 , 0 } } ;
  302.     static POINTL aptlMinuteLine1 [] = {{0L,-15L},{0L,72}};
  303.  
  304.     static POINTL aptlSecond [ ] = { { 0 , -15 } , { 0 , 74 } } ;
  305.     static POINTL ptlOrigin = {0L,0L};
  306.  
  307.     static LONG cptlHour = sizeof ( aptlHour ) / sizeof ( POINTL ) ;
  308.     static LONG cptlMinute = sizeof ( aptlMinute ) / sizeof ( POINTL ) ;
  309.     static LONG cptlSecond = sizeof ( aptlSecond ) / sizeof ( POINTL ) ;
  310.     BOOL f ;
  311.  
  312.     static MATRIXLF matlfModel =
  313.     {
  314.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  315.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  316.         100L ,                      100L ,                      1L } ;
  317.  
  318.     static MATRIXLF matlfShade =
  319.     {
  320.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  321.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  322.         3L ,                     -3L ,                      1L } ;
  323.  
  324.     /* prepare a rotation transform and set it into the ps */
  325.     /*      cos x    - sin x    0     *\
  326.     |       sin x      cos x    0      |
  327.     \*      100        100      1     */
  328.  
  329.     matlfModel.fxM11 =
  330.     matlfModel.fxM22 = fxSin[(sAngle + 15) % 60];
  331.     matlfModel.fxM12 = fxSin[(sAngle + 30) % 60];
  332.     matlfModel.fxM21 = fxSin[sAngle];
  333.  
  334.     f = GpiSetModelTransformMatrix(hps, (LONG)MATLF_SIZE, &matlfModel,
  335.             TRANSFORM_REPLACE);
  336.  
  337.     /* draw the specified hand */
  338.  
  339.     switch ( sHandType )
  340.     {
  341.  
  342.         case HT_HOUR:
  343.             GpiSetColor ( hps , vclrHands[SURFACE] ) ;
  344.             GpiBeginPath ( hps , 1L ) ;
  345.             GpiSetCurrentPosition ( hps , aptlHour ) ;
  346.             GpiPolyLine ( hps , cptlHour , aptlHour ) ;
  347.             GpiEndPath ( hps ) ;
  348.             GpiFillPath ( hps , 1L , FPATH_ALTERNATE ) ;
  349.             GpiSetColor ( hps , vclrHands[SHADE]   ) ;
  350.             GpiSetCurrentPosition ( hps , aptlHour ) ;
  351.             GpiPolyLine ( hps , cptlHour , aptlHour ) ;
  352.             GpiSetColor ( hps , vclrHands[SHADE]   ) ;
  353.             GpiSetCurrentPosition ( hps , aptlHourLine1 ) ;
  354.             GpiPolyLine ( hps , 1L , &(aptlHourLine1[1]) ) ;
  355.             break;
  356.         case HT_HOUR_SHADE:
  357.             GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  358.                                               & matlfShade , TRANSFORM_ADD     ) ;
  359.             GpiSetColor ( hps , vclrFace [SHADE]   ) ;
  360.             GpiBeginPath ( hps , 1L ) ;
  361.             GpiSetCurrentPosition ( hps , aptlHour ) ;
  362.             GpiPolyLine ( hps , cptlHour , aptlHour ) ;
  363.             GpiEndPath ( hps ) ;
  364.             GpiFillPath ( hps , 1L , FPATH_ALTERNATE ) ;
  365.             break;
  366.  
  367.         case HT_MINUTE:
  368.             GpiSetColor ( hps , vclrHands[SURFACE] ) ;
  369.             GpiBeginPath ( hps , 1L ) ;
  370.             GpiSetCurrentPosition ( hps , aptlMinute ) ;
  371.             GpiPolyLine ( hps , cptlMinute , aptlMinute ) ;
  372.             GpiEndPath ( hps ) ;
  373.             GpiFillPath ( hps , 1L , FPATH_ALTERNATE ) ;
  374.  
  375.             GpiSetColor ( hps , vclrHands[SHADE]   ) ;
  376.             GpiSetCurrentPosition ( hps , aptlMinute ) ;
  377.             GpiPolyLine ( hps , cptlMinute , aptlMinute ) ;
  378.             GpiSetColor ( hps , vclrHands[SHADE]   ) ;
  379.             GpiSetCurrentPosition ( hps , aptlMinuteLine1 ) ;
  380.             GpiPolyLine ( hps , 1L , &(aptlMinuteLine1[1]) ) ;
  381.             GpiSetCurrentPosition ( hps , & ptlOrigin) ;
  382.             GpiFullArc ( hps , DRO_OUTLINEFILL , MAKEFIXED ( 2 , 0 ) ) ;
  383.             break;
  384.         case HT_MINUTE_SHADE:
  385.             GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  386.                                               & matlfShade , TRANSFORM_ADD     ) ;
  387.             GpiSetColor ( hps , vclrFace [SHADE]   ) ;
  388.             GpiBeginPath ( hps , 1L ) ;
  389.             GpiSetCurrentPosition ( hps , aptlMinute ) ;
  390.             GpiPolyLine ( hps , cptlMinute , aptlMinute ) ;
  391.             GpiEndPath ( hps ) ;
  392.             GpiFillPath ( hps , 1L , FPATH_ALTERNATE ) ;
  393.             break;
  394.  
  395.         case HT_SECOND:
  396.             /* draw in XOR mixmode, so we can undraw later */
  397.             GpiSetMix ( hps , FM_INVERT ) ;
  398.             GpiSetCurrentPosition ( hps , aptlSecond ) ;
  399.             GpiPolyLine ( hps , cptlSecond , aptlSecond ) ;
  400.             GpiSetMix ( hps , FM_OVERPAINT ) ;
  401.             break;
  402.     }
  403. }
  404.  
  405. /****************************************************************\
  406.  *
  407.  *--------------------------------------------------------------
  408.  *
  409.  *  Name:ClkDrawFace()
  410.  *
  411.  *  Purpose:
  412.  *
  413.  *
  414.  *
  415.  *  Usage:
  416.  *
  417.  *  Method:
  418.  *          -
  419.  *
  420.  *          -
  421.  *          -
  422.  *
  423.  *          -
  424.  *          -
  425.  *
  426.  *  Returns: VOID
  427.  *
  428.  *
  429. \****************************************************************/
  430. VOID ClkDrawFace ( HPS hps )
  431. {
  432.     BOOL f ;
  433.     static POINTL ptlLight= { -2L , 2L } ;
  434.     static POINTL ptlShade= {  2L, -2L } ;
  435.     static POINTL ptlFace = { 0L, 0L};
  436.     /*        1         0      0     *\
  437.     *         0         1      0      *
  438.     \*      100       100      1     */
  439.  
  440.     static MATRIXLF matlfModel = {
  441.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  442.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  443.         100L ,                      100L ,                      1L } ;
  444.  
  445.     /* center at (100, 100) and draw the clock face */
  446.     f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  447.                                      & matlfModel , TRANSFORM_REPLACE ) ;
  448.  
  449.  
  450.     GpiSetColor ( hps , vclrFace[SURFACE]);
  451.     GpiSetCurrentPosition ( hps , & ptlFace ) ;
  452.     GpiFullArc ( hps , DRO_OUTLINEFILL , MAKEFIXED ( 80, 0 ) ) ;
  453. }
  454.  
  455.  
  456. VOID ClkDrawRing ( HPS hps )
  457. {
  458.     BOOL f ;
  459.     static POINTL ptlLight= { -2L , 2L } ;
  460.     static POINTL ptlShade= {  1L, -1L } ;
  461.     static POINTL ptlFace = { 0L, 0L};
  462.     static POINTL ptlShadeIn= { -3L , 3L } ;
  463.     static POINTL ptlLightIn= {  1L, -1L } ;
  464.     /*        1         0      0     *\
  465.     *         0         1      0      *
  466.     \*      100       100      1     */
  467.  
  468.     static MATRIXLF matlfModel = {
  469.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  470.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  471.         100L ,                      100L ,                      1L } ;
  472.  
  473.     /* center at (100, 100) and draw the clock face */
  474.     f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  475.                                      & matlfModel , TRANSFORM_REPLACE ) ;
  476.  
  477.     DrawFullRing(hps,
  478.                     &ptlShade,
  479.                     MAKEFIXED(95,0),
  480.                     MAKEFIXED(99 ,0),
  481.                     vclrRing[SHADE]);
  482.  
  483.     DrawFullRing(hps,
  484.                     &ptlLight,
  485.                     MAKEFIXED(95,0),
  486.                     MAKEFIXED(98 ,0),
  487.                     vclrRing[LIGHT]   );
  488.  
  489.     DrawFullRing(hps,
  490.                     &ptlLightIn,
  491.                     MAKEFIXED(88,0),
  492.                     MAKEFIXED(94,0),
  493.                     vclrRing[LIGHT]   );
  494.  
  495.  
  496.     DrawFullRing(hps,
  497.                     &ptlShadeIn,
  498.                     MAKEFIXED(86,0),
  499.                     MAKEFIXED(93,0),
  500.                     vclrRing[SHADE]);
  501.  
  502.     DrawFullRing(hps,
  503.                     &ptlFace ,
  504.                     MAKEFIXED(94,0),
  505.                     MAKEFIXED(98 ,0),
  506.                     vclrRing[SURFACE]);
  507.  
  508.     GpiSetColor ( hps , vclrFace[SURFACE]);
  509.     GpiSetCurrentPosition ( hps , & ptlFace ) ;
  510.     GpiFullArc ( hps , DRO_OUTLINEFILL , MAKEFIXED ( 91, 0 ) ) ;
  511. }
  512.  
  513.  
  514. /**************************************************************************\
  515. *                                                                          *
  516. *       ROUTINE:    ClkDrawDate ( )                                        *
  517. *                                                                          *
  518. *       COMMENT:    Draws Date when analog time is displayed               *
  519. *                                                                          *
  520. \**************************************************************************/
  521. VOID ClkDrawDate (HPS hps, USHORT usDrawMode)
  522. {
  523.     char achFinalDate[9];
  524.     SIZEF sizef;
  525.  
  526.     static POINTL ptl = { 2 * ZDATE, 3 * ZDATE };
  527.     static POINTL aptlDateShade[ ] = { { 0L , 0L },
  528.                                        { 0L , YDATE },
  529.                                        { XDATE , YDATE },
  530.                                        { XDATE - ZDATE , YDATE - ZDATE },
  531.                                        { ZDATE , YDATE - ZDATE },
  532.                                        { ZDATE, ZDATE }
  533.                                      };
  534.     static POINTL aptlDateLight[ ] = { { 0L , 0L },
  535.                                        { XDATE , 0L },
  536.                                        { XDATE , YDATE },
  537.                                        { XDATE - ZDATE , YDATE - ZDATE },
  538.                                        { XDATE - ZDATE, ZDATE },
  539.                                        { ZDATE, ZDATE }
  540.                                      };
  541.     static POINTL aptlDateBG[] = { {0L ,0L},
  542.                                    {XDATE,YDATE} };
  543.  
  544.     if ((cp.usDispMode & DM_DATE) && (!fIconic)) {
  545.  
  546.         GetArrangedDate (achFinalDate);
  547.  
  548.         GpiSetModelTransformMatrix (hps, (LONG)MATLF_SIZE, &vmatlfDateTrans,
  549.                 TRANSFORM_REPLACE);
  550.         GpiSetModelTransformMatrix (hps, (LONG)MATLF_SIZE, &vmatlfDateScale,
  551.                 TRANSFORM_ADD);
  552.  
  553.         if (strncmp(achFinalDate, achOldDate, sizeof(achFinalDate) - 1)) {
  554.  
  555.             GpiSetColor (hps, vclrDate[BACKGROUND]);
  556.             GpiSetCurrentPosition (hps, &aptlDateBG[0]);
  557.             GpiBox (hps, DRO_FILL, &aptlDateBG[1], 0L, 0L);
  558.             usDrawMode = DM_REDRAW;
  559.         }
  560.  
  561.         if ((usDrawMode == DM_REDRAW) || (vusDatePos = DP_INSIDE)) {
  562.  
  563. #ifdef DISABLE
  564.             WinSetRect(NULL, &rclDateString, 2, 2, XDATE - 2,
  565.                        YDATE - 2);
  566.             ClkDrawDigitalString(hps, "88888888", &rclDateString,
  567.                     0x00101010, 0x00808080);
  568.  
  569. #else
  570.  
  571.             GpiSetColor (hps, CLR_BLACK);
  572. #ifdef DISABLE
  573.             GpiSetColor (hps, vclrDate[SURFACE]);
  574. #endif
  575.             GetArrangedDate (achFinalDate);
  576.             GpiSetCharMode (hps,CM_MODE3);
  577.             GpiSetCurrentPosition (hps, &ptl);
  578.             sizef.cx = MAKEFIXED (10, 0);
  579.             sizef.cy = MAKEFIXED (YDATE, 0);
  580.             GpiSetCharBox(hps, &sizef);
  581.             GpiCharString (hps, (ULONG)sizeof(achFinalDate), (PSZ)achFinalDate);
  582. #endif
  583.  
  584.             GpiSetColor (hps, vclrDate[SHADE]);
  585.             GpiSetCurrentPosition (hps, aptlDateShade);
  586.             GpiBeginPath (hps, 1L);
  587.             GpiPolyLine (hps, 5L, &(aptlDateShade[1]));
  588.             GpiCloseFigure (hps);
  589.             GpiEndPath (hps);
  590.             GpiFillPath (hps, 1L, FPATH_ALTERNATE);
  591.  
  592.             GpiSetColor (hps, vclrDate[LIGHT]);
  593.             GpiSetCurrentPosition (hps, aptlDateLight);
  594.             GpiBeginPath (hps, 1L);
  595.             GpiPolyLine (hps, 5L, &(aptlDateLight[1]));
  596.             GpiCloseFigure (hps);
  597.             GpiEndPath (hps);
  598.             GpiFillPath (hps, 1L, FPATH_ALTERNATE);
  599.         }
  600.     } else {
  601.         /*
  602.          * If we're minimized then we need to update the
  603.          * icontext with the date.
  604.          */
  605.         if (((cp.usDispMode & (DM_TIME | DM_DATE)) == (DM_TIME | DM_DATE)) &&
  606.                 (fIconic)) {
  607.             GetArrangedDate (achFinalDate);
  608.             WinSetWindowText (hwndFrame, achFinalDate);
  609.         }
  610.     }
  611. }
  612.  
  613.  
  614. /****************************************************************\
  615.  *
  616.  *--------------------------------------------------------------
  617.  *
  618.  *  Name:ClkDrawTicks()
  619.  *
  620.  *  Purpose:Draws Clock Ticks()
  621.  *
  622.  *
  623.  *
  624.  *  Usage:
  625.  *
  626.  *  Method:
  627.  *          -
  628.  *
  629.  *          -
  630.  *          -
  631.  *
  632.  *          -
  633.  *          -
  634.  *
  635.  *  Returns: VOID
  636.  *
  637.  *
  638. \****************************************************************/
  639. VOID ClkDrawTicks ( HPS hps , USHORT usTicks )
  640. {
  641.     BOOL f ;
  642.     USHORT usAngle,usTrapez ;
  643.  
  644.  
  645.     /* prepare a transform to use when rotating the ticks */
  646.     /*      cos x    - sin x    0     *\
  647.     |       sin x      cos x    0      |
  648.     \*      100        100      1     */
  649.  
  650.     static MATRIXLF matlfModel = {
  651.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  652.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  653.         100L ,                      100L ,                      1L } ;
  654.  
  655.     /* define what the tick marks look like */
  656.     static POINTL aptlMajorTick [ ] = { { -3 , 94 } , { 3 , 100 } } ;
  657.     static BYTE   aclr [12][4] = {
  658.             /*12*/        {SHADE,LIGHT,LIGHT,SHADE},
  659.             /*1*/         {LIGHT,LIGHT,LIGHT,SHADE},
  660.             /*2*/         {LIGHT,LIGHT,SHADE,SHADE},
  661.             /*3*/         {LIGHT,LIGHT,SHADE,SHADE},
  662.             /*4*/         {LIGHT,LIGHT,SHADE,LIGHT},
  663.             /*5*/         {LIGHT,SHADE,SHADE,LIGHT},
  664.             /*6*/         {LIGHT,SHADE,SHADE,LIGHT},
  665.             /*7*/         {LIGHT,SHADE,SHADE,LIGHT},
  666.             /*8*/         {LIGHT,SHADE,LIGHT,LIGHT},
  667.             /*9*/         {SHADE,SHADE,LIGHT,LIGHT},
  668.             /*9*/         {SHADE,SHADE,LIGHT,LIGHT},
  669.             /*11*/        {SHADE,LIGHT,LIGHT,SHADE}
  670.                                  };
  671.     static  POINTL aptlMT  [4][4] = {
  672.                                   { {-3,81},{-1,83},{1,83},{3,81  }} ,
  673.                                   { {-3,81},{-1,83},{-1,87},{-3,89 }} ,
  674.                                   { {-3,89},{-1,87},{1,87},{3,89 }} ,
  675.                                   { {3,89},{1,87},{1,83},{3,81  }}
  676.                                  };
  677.     static POINTL aptlMajorTickShadow [ ] = { { -1 , 83 } , { 1 , 87  } } ;
  678.     static POINTL aptlMinorTick [ ] = { { 0 , 83 } , { 0 , 85 } } ;
  679.  
  680.  
  681.     /* have we been asked to draw the major ticks? */
  682.     if ( usTicks & CLK_MAJORTICKS )
  683.         for ( usAngle = 0 ; usAngle < 60 ; usAngle += 5 ) {
  684.  
  685.             /* set the rotation transform */
  686.             matlfModel . fxM11 =
  687.             matlfModel . fxM22 = fxSin [ ( usAngle + 15 ) % 60 ] ;
  688.             matlfModel . fxM12 = fxSin [ ( usAngle + 30 ) % 60 ] ;
  689.             matlfModel . fxM21 = fxSin [ usAngle ] ;
  690.             f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  691.                                              & matlfModel ,
  692.                                              TRANSFORM_REPLACE ) ;
  693.  
  694.             /* draw a major tick mark */
  695.             for (usTrapez = 0; usTrapez < 4; usTrapez++) {
  696.                 DrawTrapez(hps,aptlMT[usTrapez],vclrMajorTicks[aclr[usAngle/5][usTrapez]]);
  697.             }
  698.             GpiSetColor ( hps , vclrMajorTicks[SURFACE]) ;
  699.             GpiSetCurrentPosition ( hps , & aptlMajorTickShadow [ 0 ] ) ;
  700.             GpiBox ( hps , DRO_FILL , & aptlMajorTickShadow [ 1 ] , 0L , 0L ) ;
  701.     }
  702.  
  703.     /* have we been asked to draw the minor ticks? */
  704.     /* draw in the default color */
  705.     GpiSetColor ( hps ,vclrMinorTicks[SHADE]  ) ;
  706.     if ( usTicks & CLK_MINORTICKS )
  707.         for ( usAngle = 0 ; usAngle < 60 ; usAngle ++ ) {
  708.             if ((usAngle % 5) != 0) {
  709.  
  710.                 matlfModel . fxM11 =
  711.                 matlfModel . fxM22 = fxSin [ ( usAngle + 15 ) % 60 ] ;
  712.                 matlfModel . fxM12 = fxSin [ ( usAngle + 30 ) % 60 ] ;
  713.                 matlfModel . fxM21 = fxSin [ usAngle ] ;
  714.  
  715.                 /* set the transform */
  716.                 f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  717.                                                  & matlfModel ,
  718.                                                  TRANSFORM_REPLACE ) ;
  719.  
  720.                 /* draw a minor tick mark */
  721.                 GpiSetCurrentPosition ( hps , & aptlMinorTick [ 0 ] ) ;
  722.                 GpiBox ( hps , DRO_OUTLINEFILL , & aptlMinorTick [ 1 ] , 0L , 0L ) ;
  723.             }
  724.     }
  725. }
  726. /****************************************************************\
  727.  *
  728.  *--------------------------------------------------------------
  729.  *
  730.  *  Name:DrawTrapez()
  731.  *
  732.  *  Purpose:
  733.  *
  734.  *
  735.  *
  736.  *  Usage:
  737.  *
  738.  *  Method:
  739.  *          -
  740.  *
  741.  *          -
  742.  *          -
  743.  *
  744.  *          -
  745.  *          -
  746.  *
  747.  *  Returns:
  748.  *
  749.  *
  750. \****************************************************************/
  751. VOID DrawTrapez(HPS hps,POINTL *aptl,LONG color)
  752. {
  753.     GpiSetColor ( hps,color) ;
  754.     GpiBeginPath(hps, 1L);                  /* start the path bracket */
  755.     GpiSetCurrentPosition ( hps ,  aptl  ) ;
  756.     GpiPolyLine(hps, 3L,&(aptl[1]) );      /* draw the three sides   */
  757.     GpiCloseFigure(hps);                    /* close the triangle     */
  758.     GpiEndPath(hps);                        /* end the path bracket   */
  759.     GpiFillPath(hps, 1L, FPATH_ALTERNATE);  /* draw and fill the path */
  760. }
  761. /****************************************************************\
  762.  *
  763.  *--------------------------------------------------------------
  764.  *
  765.  *  Name:
  766.  *
  767.  *  Purpose:
  768.  *
  769.  *
  770.  *
  771.  *  Usage:
  772.  *
  773.  *  Method:
  774.  *          -
  775.  *
  776.  *          -
  777.  *          -
  778.  *
  779.  *          -
  780.  *          -
  781.  *
  782.  *  Returns:
  783.  *          1 - if sucessful execution completed
  784.  *          0 - if error
  785. \****************************************************************/
  786. #ifdef orchik
  787. VOID ClkDrawTicks ( HPS hps , USHORT usTicks )
  788. {
  789.     BOOL f ;
  790.     USHORT usAngle ;
  791.  
  792.     /* prepare a transform to use when rotating the ticks */
  793.     /*      cos x    - sin x    0     *\
  794.     |       sin x      cos x    0      |
  795.     \*      100        100      1     */
  796.  
  797.     static MATRIXLF matlfModel = {
  798.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  799.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  800.         100L ,                      100L ,                      1L } ;
  801.     static MATRIXLF matlfLight = {
  802.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  803.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  804.         -1L ,                       1L ,                      1L } ;
  805.     static MATRIXLF matlfShade = {
  806.         MAKEFIXED ( 1 , 0 ) ,       MAKEFIXED ( 0 , 0 ) ,       0L ,
  807.         MAKEFIXED ( 0 , 0 ) ,       MAKEFIXED ( 1 , 0 ) ,       0L ,
  808.          1L ,                      -1L ,                      1L } ;
  809.  
  810.     /* define what the tick marks look like */
  811.     static POINTL aptlMajorTick [ ] = { { -2 , 91 } , { 2 , 97  } } ;
  812.     static POINTL aptlMajorTickShade [ ] = { { -2 , 91 } , { 2 , 97  } } ;
  813.     static POINTL aptlMajorTickLight [ ] = { { -2 , 91 } , { 2 , 970 } } ;
  814.     static POINTL aptlMinorTick [ ] = { { 0 , 91 } , { 0 , 92 } } ;
  815.  
  816.     /* draw in the default color */
  817.     GpiSetColor ( hps , CLR_DEFAULT ) ;
  818.  
  819.     /* have we been asked to draw the major ticks? */
  820.     if ( usTicks & CLK_MAJORTICKS )
  821.         for ( usAngle = 0 ; usAngle < 60 ; usAngle += 5 ) {
  822.  
  823.             /* set the rotation transform */
  824.             matlfModel . fxM11 =
  825.             matlfModel . fxM22 = fxSin [ ( usAngle + 15 ) % 60 ] ;
  826.             matlfModel . fxM12 = fxSin [ ( usAngle + 30 ) % 60 ] ;
  827.             matlfModel . fxM21 = fxSin [ usAngle ] ;
  828.             /* draw a major tick mark shade*/
  829.             f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  830.                                              & matlfModel ,
  831.                                              TRANSFORM_REPLACE ) ;
  832.             f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  833.                                              & matlfShade ,
  834.                                              TRANSFORM_ADD     ) ;
  835.             GpiSetColor (hps, 0x00C0C0C0);
  836.             GpiSetCurrentPosition ( hps , & aptlMajorTickShade [ 0 ] ) ;
  837.             GpiBox ( hps , DRO_FILL , & aptlMajorTick [ 1 ] , 2L , 2L ) ;
  838.  
  839.             /*Draw light*/
  840.  
  841.             f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  842.                                              & matlfModel ,
  843.                                              TRANSFORM_REPLACE ) ;
  844.             f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  845.                                              & matlfLight ,
  846.                                              TRANSFORM_ADD     ) ;
  847.             GpiSetColor(hps, RGB_WHITE);
  848.             GpiSetCurrentPosition ( hps , & aptlMajorTickLight [ 0 ] ) ;
  849.             GpiBox ( hps , DRO_FILL , & aptlMajorTick [ 1 ] , 2L , 2L ) ;
  850.  
  851.             /*Draw tick mark surface */
  852.  
  853.             f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  854.                                              & matlfModel ,
  855.                                              TRANSFORM_REPLACE ) ;
  856.             GpiSetColor(hps, 0x00808080);
  857.             GpiSetCurrentPosition ( hps , & aptlMajorTick [ 0 ] ) ;
  858.             GpiBox ( hps , DRO_FILL , & aptlMajorTick [ 1 ] , 2L , 2L ) ;
  859.     }
  860.  
  861.     /* have we been asked to draw the minor ticks? */
  862.     if ( usTicks & CLK_MINORTICKS )
  863.         for ( usAngle = 0 ; usAngle < 60 ; usAngle ++ ) {
  864.             if ((usAngle % 5) != 0) {
  865.                 matlfModel . fxM11 =
  866.                 matlfModel . fxM22 = fxSin [ ( usAngle + 15 ) % 60 ] ;
  867.                 matlfModel . fxM12 = fxSin [ ( usAngle + 30 ) % 60 ] ;
  868.                 matlfModel . fxM21 = fxSin [ usAngle ] ;
  869.  
  870.                 /* set the transform */
  871.                 f = GpiSetModelTransformMatrix ( hps , ( LONG ) MATLF_SIZE ,
  872.                                                  & matlfModel ,
  873.                                                  TRANSFORM_REPLACE ) ;
  874.  
  875.                 /* draw a minor tick mark */
  876.                 GpiSetCurrentPosition ( hps , & aptlMinorTick [ 0 ] ) ;
  877.                 GpiLine ( hps , & aptlMinorTick [ 1 ] ) ;
  878.             }
  879.     }
  880. }
  881.  
  882. #endif
  883. /****************************************************************\
  884.  *
  885.  *--------------------------------------------------------------
  886.  *
  887.  *  Name:DrawFullRing()
  888.  *
  889.  *  Purpose: This routine draws the ring for the clock face.
  890.  *
  891.  *
  892.  *
  893.  *  Usage:
  894.  *
  895.  *  Method:
  896.  *          -
  897.  *
  898.  *          -
  899.  *          -
  900.  *
  901.  *          -
  902.  *          -
  903.  *
  904.  *  Returns:
  905.  *
  906.  *
  907. \****************************************************************/
  908. VOID DrawFullRing(HPS hps,PPOINTL pptlCenter,FIXED fxRadIn, FIXED fxRadOut,
  909.                      LONG lColor)
  910. {
  911.     GpiSetColor(hps,lColor);
  912.     GpiSetCurrentPosition ( hps , pptlCenter );
  913.     GpiBeginPath(hps,1L);
  914.     GpiFullArc ( hps , DRO_OUTLINE ,  fxRadIn  ) ;
  915.     GpiFullArc ( hps , DRO_OUTLINE ,  fxRadOut  ) ;
  916.     GpiCloseFigure(hps);
  917.     GpiEndPath(hps);
  918.     GpiFillPath ( hps , 1L , FPATH_ALTERNATE ) ;
  919. }
  920.  
  921.  
  922. /*--------------------------------------------------------------*\
  923.  *  End of file :paint.c
  924. \*--------------------------------------------------------------*/
  925.