home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / iv26_w_3.zip / EXAMPLES / DCLOCK / SEGMENT.C < prev    next >
C/C++ Source or Header  |  1992-02-04  |  3KB  |  117 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Segment class for digital clock
  25.  */
  26.  
  27. #include "dclock.h"
  28. #include "segment.h"
  29. #include <stdio.h>
  30.  
  31. Painter* Segment::fadePainter[17];
  32.  
  33. // pattern initialization
  34. const int myPatSeed[17] = {
  35.     0x0000, 0x8000, 0x8020, 0xA020,
  36.     0xA0A0, 0xA4A0, 0xA4A1, 0xA5A1,
  37.     0xA5A5, 0xA5B5, 0xE5B5, 0xF5B5,
  38.     0xF5F5, 0xF5F7, 0xFDF7, 0xFFF7,
  39.     0xFFFF
  40. };
  41.  
  42. Pattern* Segment::MakePattern (int seed) {
  43.     Pattern* pat;
  44.     int dat[patternHeight];
  45.     unsigned int Row[4];
  46.  
  47.     for (int i = 0; i <= 3; i++) {
  48.     Row[i] = seed & 0xF;
  49.     Row[i] |= Row[i]<<4;
  50.     Row[i] |= Row[i]<<8;
  51.     Row[i] |= Row[i]<<16;
  52.     seed >>= 4;
  53.     }
  54.     for (i = 0; i <= patternHeight-1; i++) {
  55.     dat[i] = Row[i%4];
  56.     }
  57.     pat = new Pattern(dat);
  58.     return pat;
  59. }
  60.  
  61. Segment::Segment (Seg s, float Xoff, float Yoff) {
  62.     whichSeg = s;
  63.     Xorg = Xoff;
  64.     Yorg = Yoff;
  65.     p.count = SegData[whichSeg].count;
  66.     fade = 0;        // initially off
  67.     fullFade = 16;
  68.  
  69. }
  70.  
  71. void Segment::Reconfig (Painter* output) {
  72.     register int i;
  73.  
  74.     for (i = 0; i <= fullFade; i++) {
  75.     Painter* p = new Painter(output);
  76.     p->SetPattern(MakePattern(myPatSeed[i]));
  77.     fadePainter[i] = p;
  78.     }
  79. }
  80.  
  81. Segment::~Segment () {}
  82.  
  83. void Segment::Resize (Canvas* c, int height) {
  84.     canvas = c;
  85.     int w = canvas->Width();
  86.     int h = height;
  87.  
  88.     for (int i = 0; i < p.count; i++) {
  89.     p.x[i] = Coord((SegData[whichSeg].x[i]+Xorg) * w);
  90.     p.y[i] = Coord((SegData[whichSeg].y[i]+Yorg) * h);
  91.     }
  92. }
  93.  
  94. void Segment::Draw() {
  95.     fadePainter[fade]->FillPolygon(canvas, p.x, p.y, p.count);
  96. }
  97.  
  98. void Segment::Redraw () {
  99.     if (!IsOff()) {
  100.     Draw();
  101.     }
  102. }
  103.  
  104. boolean Segment::On () {
  105.     if (!IsOn()) {
  106.     FadeUp();
  107.     }
  108.     return IsOn();
  109. }
  110.  
  111. boolean Segment::Off () {
  112.     if (!IsOff()) {
  113.     FadeDown();
  114.     }
  115.     return IsOff();
  116. }
  117.