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 / DDATA.C < prev    next >
C/C++ Source or Header  |  1992-01-30  |  7KB  |  205 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.  * layout data and initializations for dclock
  25.  */
  26.  
  27. #include "dclock.h"
  28. #include "segment.h"
  29.  
  30. int Width = 175;
  31. int Height = 30;
  32. int XPos = 815;
  33. int YPos = 65;
  34.  
  35. TMode TimeMode = CIVIL;        // initial (default) values for options
  36. CMode CreateMode = SWEPT;
  37. boolean JohnsFlag = false;
  38. boolean Invert = false;
  39. boolean ShowDate = true;
  40. boolean ShowBorder = false;
  41. boolean ShowTime = true;
  42.  
  43. int SlantPC = 30;
  44. int ThickPC = 15;
  45. int FadeRate = 4;
  46. int FadeStep = 1;
  47.  
  48. boolean SegCode[11][7] = {    // segments to form various digits
  49.     {1,1,1,1,1,1,0},        // digit 0
  50.     {0,1,1,0,0,0,0},
  51.     {1,1,0,1,1,0,1},
  52.     {1,1,1,1,0,0,1},
  53.     {0,1,1,0,0,1,1},
  54.     {1,0,1,1,0,1,1},
  55.     {1,0,1,1,1,1,1},
  56.     {1,1,1,0,0,0,0},
  57.     {1,1,1,1,1,1,1},
  58.     {1,1,1,0,0,1,1},        // digit 9
  59.     {0,0,0,0,0,0,0}        // blank digit
  60. };
  61.  
  62. float HTx, HUx, MTx, MUx;    // normalized digit x offsets
  63. float COLx;            // normalized colon x offset
  64. float ALLy;            // normalized digit y offsets
  65. float DigitWidth;        // normalized digit width with slant
  66. float DigitHeight;        // normalized digit height
  67.  
  68. SegLayout SegData[7];        // normalized segments, slanted, unshifted
  69. SegLayout ColonData[2];        // normalized colon, slanted, shifted
  70.  
  71. CharLayout AData = {        // character A
  72.     11,                //count
  73.     {0.0,0.1,0.15,0.25,0.2,0.18,0.07,0.08,0.17,0.125,0.05},    // x
  74.     {0.0,0.3,0.3,0.0,0.0,0.05,0.05,0.1,0.1,0.22,0.0}        // y
  75. };
  76. CharLayout PData = {        // character P
  77.     12,
  78.     {0.0,0.0,0.2,0.25,0.25,0.2,0.05,0.05,0.2,0.2,0.05,0.05},
  79.     {0.0,0.3,0.3,0.25,0.15,0.1,0.1,0.15,0.15,0.25,0.25,0.0}
  80. };
  81. CharLayout MData = {        // character M
  82.     12,
  83.     {0.0,0.0,0.05,0.2,0.35,0.4,0.4,0.35,0.35,0.2,0.05,0.05},
  84.     {0.0,0.3,0.3,0.1,0.3,0.3,0.0,0.0,0.2,0.0,0.2,0.0}
  85. };
  86.  
  87. // these are variables so that a meta-view can potentially change them
  88.  
  89. float BorderWidth = 0.0;    // digit relative border width
  90. float LMargin = 0.3;        // ... left margin
  91. float RMargin = 0.3;        // ... right margin
  92. float TMargin = 0.1;        // ... top margin
  93. float BMargin = 0.1;        // ... bottom margin
  94. float DigitGap = 0.2;        // ... interdigit spacing
  95. float SepGap = 1.0;        // ... separator spacing
  96. float VThick = 0.2;        // ... thickness of vertical segments
  97. float HThick = 0.15;        // ... thickness of horizontal segments
  98. float Slant = 0.3;        // ... rightwards slant of digit top
  99.  
  100. float width, height;        // total dimensions, digit relative
  101.  
  102. void MakeSeg( Seg s, SegLayout& base, float Xoff, float Yoff ) {
  103.     for ( int i=0; i<base.count; i++ ) {
  104.     SegData[s].y[i] = base.y[i]+Yoff;
  105.     SegData[s].x[i] = base.x[i]+Xoff+SegData[s].y[i]*Slant/width;
  106.     }
  107.     SegData[s].count = base.count;
  108. }
  109.  
  110. void InitData() {
  111.     FadeStep = FadeRate==0 ? 16 : 1;
  112.     SegCode[9][SegD] = (JohnsFlag)? true : false;
  113.     Slant = min( max( 0,SlantPC ), 100 )/100.0;
  114.     HThick = min( max( 5,ThickPC ), 25 )/100.0;
  115.     VThick = min( max( 5,ThickPC ), 25 )/100.0 * 3.0/2.0;
  116.  
  117.     Width = Coord( min( max( 100,Width ), 1024));
  118.     Height = Coord( min( max( 25,Height ), 865));
  119.     YPos = YPos - Height + 1;// ypos is the TOP of clock; we need the bottom
  120.  
  121.     width = 2*BorderWidth+LMargin+4.0+2*DigitGap+SepGap+RMargin+Slant;
  122.     height = 2*BorderWidth+BMargin+1.0+TMargin;
  123.  
  124.     HTx = (BorderWidth + LMargin)/width;    // hours tens digit x offset
  125.     HUx = HTx + (1.0 + DigitGap)/width;        // hours units ...
  126.     MTx = HUx + (1.0 + SepGap)/width;        // minutes tens ...
  127.     MUx = MTx + (1.0 + DigitGap)/width;        // minutes units ...
  128.     COLx = HUx + (1.0 + SepGap/2.0)/width;    // colon ...
  129.     ALLy = (BorderWidth + BMargin)/height;
  130.     DigitWidth = (1.0 + Slant)/width;
  131.     DigitHeight = 1.0/height;
  132.  
  133.     SegLayout Colon;                // generic normalized colon dot
  134.  
  135.     Colon.count = 6;
  136.     Colon.x[0] = 0.0;
  137.     Colon.x[1] = ( - VThick/2.0)/width;
  138.     Colon.x[2] = ( - VThick/2.0)/width;
  139.     Colon.x[3] = 0.0;
  140.     Colon.x[4] = VThick/2.0/width;
  141.     Colon.x[5] = VThick/2.0/width;
  142.     Colon.y[0] = 0.0;
  143.     Colon.y[1] = 0.5*HThick/height;
  144.     Colon.y[2] = 1.0*HThick/height;
  145.     Colon.y[3] = 1.5*HThick/height;
  146.     Colon.y[4] = 1.0*HThick/height;
  147.     Colon.y[5] = 0.5*HThick/height;
  148.  
  149.     ColonData[0].count = Colon.count;
  150.     ColonData[1].count = Colon.count;
  151.     for ( int i=0; i< Colon.count; i++ ) {
  152.     ColonData[0].y[i] = Colon.y[i]+(0.5-2.25*HThick)/height+ALLy;
  153.     ColonData[0].x[i] = Colon.x[i]+COLx+ColonData[0].y[i]*Slant/width;
  154.     ColonData[1].y[i] = Colon.y[i]+(0.5+0.25*HThick)/height+ALLy;
  155.     ColonData[1].x[i] = Colon.x[i]+COLx+ColonData[1].y[i]*Slant/width;
  156.     }
  157.  
  158.     for ( i=0; i<12; i++ ) {            // shift, scale, slant A, P, M
  159.     AData.y[i] = (AData.y[i]+0.7)/height + ALLy;
  160.     AData.x[i] = (AData.x[i])/width+HTx+AData.y[i]*Slant/width-0.15/width;
  161.     PData.y[i] = (PData.y[i]+0.7)/height + ALLy;
  162.     PData.x[i] = (PData.x[i])/width+HTx+PData.y[i]*Slant/width-0.15/width;
  163.     MData.y[i] = (MData.y[i]+0.7)/height + ALLy;
  164.     MData.x[i] = (MData.x[i]+0.3)/width+HTx+MData.y[i]*Slant/width-0.15/width;
  165.     }
  166.  
  167.     SegLayout HSeg, VSeg;    // generic normalized horiz and vert segments
  168.  
  169.     HSeg.count = 6;
  170.     HSeg.x[0] = VThick/2.0/width;
  171.     HSeg.x[1] = VThick/width;
  172.     HSeg.x[2] = (1.0 - VThick)/width;
  173.     HSeg.x[3] = (1.0 - VThick/2.0)/width;
  174.     HSeg.x[4] = (1.0 - VThick)/width;
  175.     HSeg.x[5] = VThick/width;
  176.     HSeg.y[0] = HThick/2.0/height;
  177.     HSeg.y[1] = HThick/height;
  178.     HSeg.y[2] = HThick/height;
  179.     HSeg.y[3] = HThick/2.0/height;
  180.     HSeg.y[4] = 0.0;
  181.     HSeg.y[5] = 0.0;
  182.  
  183.     VSeg.count = 6;
  184.     VSeg.x[0] = VThick/2.0/width;
  185.     VSeg.x[1] = 0.0;
  186.     VSeg.x[2] = 0.0;
  187.     VSeg.x[3] = VThick/2.0/width;
  188.     VSeg.x[4] = VThick/width;
  189.     VSeg.x[5] = VThick/width;
  190.     VSeg.y[0] = HThick/2.0/height;
  191.     VSeg.y[1] = HThick/height;
  192.     VSeg.y[2] = (0.5 - HThick/2.0)/height;
  193.     VSeg.y[3] = 0.5/height;
  194.     VSeg.y[4] = (0.5 - HThick/2.0)/height;
  195.     VSeg.y[5] = HThick/height;
  196.  
  197.     MakeSeg( SegA, HSeg, 0.0, (1.0-HThick)/height );
  198.     MakeSeg( SegB, VSeg, (1.0-VThick)/width, (0.5-HThick/2.0)/height );
  199.     MakeSeg( SegC, VSeg, (1.0-VThick)/width, 0.0 );
  200.     MakeSeg( SegD, HSeg, 0.0, 0.0 );
  201.     MakeSeg( SegE, VSeg, 0.0, 0.0 );
  202.     MakeSeg( SegF, VSeg, 0.0, (0.5-HThick/2.0)/height );
  203.     MakeSeg( SegG, HSeg, 0.0, (0.5-HThick/2.0)/height );
  204. }
  205.