home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / Starter / Source / ClockView.m < prev    next >
Encoding:
Text File  |  1994-10-12  |  4.9 KB  |  191 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "ClockView.h"
  5. #import <dpsclient/psops.h>
  6.  
  7. @implementation ClockView
  8.  
  9. - initFrame:(const NXRect *)frameRect
  10. {
  11.     long now;
  12.  
  13.     [super initFrame:frameRect];
  14.     [self setOpaque:YES];
  15.     [self setClipping:NO];
  16. NX_ASSERT(sizeof (int)==sizeof (long),
  17.     "NeXT never should have assumed ints would always be 32 bits");
  18.     (void)time(&now);
  19.     contents = *localtime((time_t *)&now);
  20.     return self;
  21. }
  22.  
  23. - setLongValue:(long)aLong
  24. {
  25.     contents = *localtime((time_t *)&aLong);
  26.     if([window isDisplayEnabled]) [self display];
  27.     return self;
  28. }
  29.  
  30. - setTmValue:(struct tm *)tmp
  31. {
  32.     contents = *tmp;
  33.     if([window isDisplayEnabled]) [self display];
  34.     return self;
  35. }
  36.  
  37. - drawSelf:(const NXRect *)rects :(int)rectCount
  38. {
  39.     const NXRect bkgd={ { 191.0, 9.0 }, { 64.0, 71.0 } },
  40.     am={ { 179.0, 0.0 }, { 12.0, 6.0 } },
  41.     pm={ { 191.0, 0.0 }, { 12.0, 6.0 } },
  42.     colon={ { 175.0, 2.0 }, { 3.0, 6.0 } },
  43.     ydig[10]={ { { 12.0, 8.0 }, { 5.0, 5.0 } },
  44.     { { 0.0, 20.0 }, { 1.0, 5.0 } },
  45.     { { 2.0, 20.0 }, { 4.0, 5.0 } },
  46.     { { 7.0, 20.0 }, { 4.0, 5.0 } },
  47.     { { 12.0, 20.0 }, { 5.0, 5.0 } },
  48.     { { 0.0, 14.0 }, { 4.0, 5.0 } },
  49.     { { 5.0, 14.0 }, { 5.0, 5.0 } },
  50.     { { 11.0, 14.0 }, { 4.0, 5.0 } },
  51.     { { 0.0, 8.0 }, { 5.0, 5.0 } },
  52.     { { 6.0, 8.0 }, { 5.0, 5.0 } } };
  53.     const NXPoint ampm={ 43.0, 55.0 }, colpos={ 20.0, 55.0},
  54.     wdapos={ 21.0, 41.0 }, monpos={ 19.0, 16.0 };
  55.     const float dpos[]={ 166.0, 89.0, 93.0, 104.0, 112.0, 121.0, 130.0,
  56.     140.0, 148.0, 157.0 },
  57.     dwid[]={ 9.0, 4.0, 9.0, 8.0, 9.0, 9.0, 8.0, 8.0, 9.0, 9.0 },
  58.     mpos[]={ 172.0, 65.0, 76.0, 88.0, 100.0, 112.0, 124.0,
  59.     136.0, 148.0, 160.0 },
  60.     mwid[]={ 10.0, 8.0, 10.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
  61.     static NXRect r;
  62.     static NXPoint p;
  63.     register struct tm *tm;
  64.     register int u, t;
  65.  
  66. // you'd think the following could be done in initFrame:, but
  67. // that doesn't work in loadable palettes, grr...
  68.     if (!clockbits) clockbits = [NXImage findImageNamed:"clockbits"];
  69.     [clockbits composite:NX_SOVER fromRect:&bkgd toPoint:&bounds.origin];
  70.  
  71.     tm= &contents;
  72.     if (tm->tm_hour>=0&&tm->tm_min>=0) {
  73.     [clockbits composite:NX_SOVER fromRect:&colon toPoint:&colpos];
  74.     
  75.     // hours
  76.     if (tm->tm_hour>=12) {
  77.         if (tm->tm_hour>12) {
  78.         t=(tm->tm_hour-12)/10; u=(tm->tm_hour-12)%10;
  79.         }
  80.         else {
  81.         t=tm->tm_hour/10; u=tm->tm_hour%10;
  82.         }
  83.         [clockbits composite:NX_SOVER fromRect:&pm toPoint:&m];
  84.     }
  85.     else {
  86.         if (tm->tm_hour==0) {
  87.         t=1; u=2;
  88.         }
  89.         else {
  90.         t=tm->tm_hour/10; u=tm->tm_hour%10;
  91.         }
  92.         [clockbits composite:NX_SOVER fromRect:&am toPoint:&m];
  93.     }
  94.     r.origin.x = dpos[u];
  95.     r.origin.y = 0.0;
  96.     r.size.width = dwid[u];
  97.     r.size.height = 11.0;
  98.     p.x = colpos.x - r.size.width;
  99.     p.y = colpos.y - 2.0;
  100.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  101.     if (t>0) {
  102.         r.origin.x = dpos[t];
  103.         r.size.width = dwid[t];
  104.         p.x -= r.size.width;
  105.         [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  106.     }
  107.  
  108.     // minutes
  109.     t=tm->tm_min/10; u=tm->tm_min%10;
  110.     r.origin.x = dpos[t];
  111.     r.size.width = dwid[t];
  112.     p.x = colpos.x + colon.size.width;
  113.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  114.     p.x += r.size.width;
  115.     r.origin.x = dpos[u];
  116.     r.size.width = dwid[u];
  117.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  118.     }
  119.     else {
  120.     const NXRect timerect={ 4.0, 49.0, 55.0, 18.0 };
  121.  
  122.     PSsetgray(NX_LTGRAY);
  123.     NXRectFill(&timerect);
  124.     }
  125.  
  126.     // day of week
  127.     if (tm->tm_wday>=0) {
  128.     r.origin.x = 0.0;
  129.     r.origin.y = (float)(65-((tm->tm_wday+6)%7)*6);    // barf
  130.     r.size.width = 19.0;
  131.     r.size.height = 5.0;
  132.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&wdapos];
  133.     }
  134.  
  135.     // day of month
  136.     r.origin.y = 14.0;
  137.     r.size.height = 17.0;
  138.     p.y = 22.0;
  139.     t = tm->tm_mday/10; u = tm->tm_mday%10;
  140.     if (t > 0) {
  141.     r.origin.x = mpos[t];
  142.     r.size.width = mwid[t];
  143.     p.x = 30.0-(mwid[t]+mwid[u]+1.0)/2.0;
  144.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  145.     p.x += r.size.width + 1.0;
  146.     }
  147.     else p.x = 30.0-mwid[u]/2.0;
  148.     r.origin.x = mpos[u];
  149.     r.size.width = mwid[u];
  150.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  151.  
  152.     // month
  153.     r.origin.x = 40.0;
  154.     r.origin.y = (float)((11-tm->tm_mon)*6);
  155.     r.size.width = 22.0;
  156.     r.size.height = 5.0;
  157.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&monpos];
  158.  
  159.     // year
  160.     if (tm->tm_year>=0) {
  161.     p.y = 2.0;
  162.     t = tm->tm_year/10; u = tm->tm_year%10;
  163.     if (t>9) {
  164.         t-=10;    // time runs out for UNIX in 2038
  165.         p.x = 21.0;
  166.         r = ydig[2];
  167.         [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  168.         p.x += r.size.width + 1.0;
  169.         r = ydig[0];
  170.     }
  171.     else {
  172.         p.x = 23.0;
  173.         r = ydig[1];
  174.         [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  175.         p.x += r.size.width + 1.0;
  176.         r = ydig[9];
  177.     }
  178.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  179.     p.x += r.size.width + 1.0;
  180.     r = ydig[t];
  181.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  182.     p.x += r.size.width + 1.0;
  183.     r = ydig[u];
  184.     [clockbits composite:NX_SOVER fromRect:&r toPoint:&p];
  185.     }
  186.     return self;
  187. }
  188.  
  189.  
  190. @end
  191.