File: Banner.cc

package info (click to toggle)
xtide 2.9.5-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,996 kB
  • ctags: 2,141
  • sloc: cpp: 20,379; sh: 1,044; makefile: 224; yacc: 114; lex: 58
file content (155 lines) | stat: -rw-r--r-- 4,697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// $Id: Banner.cc 2641 2007-09-02 21:31:02Z flaterco $

/*  Banner  Graph printed sideways on tractor feed dot matrix printer

    Copyright (C) 1998  David Flater.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "common.hh"
#include "Graph.hh"
#include "TTYGraph.hh"
#include "Banner.hh"


// Fudge factor to correct aspect ratio on line printer
// Correct 10x6 of Pica type to be 1:1
static const double LPaspectfudge (0.6);


Banner::Banner (unsigned xSize, unsigned ySize): TTYGraph (ySize, xSize) {
  //                                         turn sideways ^^^^^^^^^^^^
}


Banner * const Banner::factory (const Station &station,
				unsigned xSize,
				Timestamp startTime,
				Timestamp endTime) {
  // Everything is sideways.
  Interval increment (std::max (
    (interval_rep_t)1,
    Global::intervalround (Global::aspectMagicNumber /
                           (double)xSize /
                           (station.aspect * LPaspectfudge))));

  // I really painted myself into a corner this time.  To create a
  // Banner I need to know the length.  The length I want depends on
  // labelWidth (the amount by which Graph fudges the start position
  // to avoid clobbering it with depth labels).  To get labelWidth I
  // need an instance of Banner.  Catch-22.

  // In the absence of a better idea, I create one Banner just to get
  // labelWidth and then do it right.  Thankfully, banners are not the
  // sort of objects that get created often.
  Banner throwawayBanner (xSize, Global::minTTYwidth);

  // Stuff duplicated from Graph::drawTides, but with confusion of X and Y.
  const double ymin (vertGraphMargin * (double)xSize);
  const double ymax ((double)xSize - ymin);
  const double valmin (station.minLevel().val());
  const double valmax (station.maxLevel().val());
  assert (valmin < valmax);

  unsigned lineStep, labelWidth, labelRight;
  int minDepth, maxDepth;
  const Dstr unitsDesc (Units::shortName (station.predictUnits()));
  throwawayBanner.figureLabels (ymax, ymin, valmax, valmin, unitsDesc,
				lineStep, labelWidth,
				labelRight, minDepth, maxDepth);

  // At last we have labelWidth and can proceed.
  unsigned ySize (std::max (Global::iround ((endTime - startTime) / increment +
				    throwawayBanner.startPosition(labelWidth)),
			    (int)Global::minTTYwidth));
  return new Banner (xSize, ySize);
}


void Banner::drawHorizontalLine (int xlo,
                                 int xhi,
                                 int y,
			         Colors::Colorchoice c unusedParameter) {
  for (int i=xlo; i<=xhi; ++i)
    setPixel (i, y, '|');
}


void Banner::drawHourTick (int x, Colors::Colorchoice c unusedParameter) {
  setPixel (x, _ySize-1, '-');
}


void Banner::print (Dstr &text_out) {
  // Everything is sideways.
  text_out = (char *)NULL;
  SafeVector<char> buf (_ySize+2);
  buf[_ySize]   = '\n';
  buf[_ySize+1] = '\0';
  for (unsigned x=0; x<_xSize; ++x) {
    for (unsigned y=0; y<_ySize; ++y)
      buf[y] = tty[(_ySize-1-y)*_xSize+x];
    text_out += &(buf[0]);
  }
}


const double Banner::aspectFudgeFactor() const {
  return LPaspectfudge;
}


void Banner::drawStringSideways (int x, int y, const Dstr &s) {
  for (unsigned a=0; a<s.length(); ++a)
    setPixel (x, y-a, s[a]);
}


void Banner::labelHourTick (int x, const Dstr &label) {
  drawStringSideways (x,
		      _ySize - hourTickLen() - 1,
		      label);
}


void Banner::labelEvent (int topLine, const EventBlurb &blurb) {
  if (topLine >= 0) {
    drawStringSideways (blurb.x-1, blurb.line1.length()-1, blurb.line1);
    drawStringSideways (blurb.x,   blurb.line2.length()-1, blurb.line2);
  } else {
    int y (_ySize - hourTickLen() - 4);
    drawStringSideways (blurb.x-1, y, blurb.line1);
    drawStringSideways (blurb.x,   y, blurb.line2);
  }
}


// This has to agree with labelEvent.
void Banner::measureBlurb (EventBlurb &blurb) const {
  blurb.deltaLeft  = -1;
  blurb.deltaRight = 0;
}


void Banner::drawTitleLine (const Dstr &title unusedParameter) {
  // Lose it.
}


const bool Banner::isBanner() const {
  return true;
}

// Cleanup2006 Done