Fixed text file permissions
[snark14.git] / tools / Display / line_window_t.cpp
1 /** @file line_window_t.cpp
2     @package snark14Display
3     @author Bruno M. Carvalho and Deniz Sarioz
4     licensed under (open-source) QPL v1.0
5     which accompanies this distribution in the file QPL
6 */
7
8 #include <iostream>
9
10 #include <qpainter.h>
11 #include <qcolor.h>
12
13 #include "sd_line_t.hpp"
14 #include "line_window_t.hpp"
15
16 void line_window_t::add(int x, int y) {
17   point_window_t mypoint = {x, y};
18   data.push_back(mypoint);
19 } // --line_window_t::add/2
20
21 void line_window_t::add(point_window_t& ptw) {
22   data.push_back(ptw);
23 } // --line_window_t::add/1
24
25 bool line_window_t::empty() { return data.empty(); } // --line_window_t::empty()
26
27 void line_window_t::clear() { data.clear(); } // --line_window_t::clear()
28
29 /** pre: all coordinates are within paint's win          */
30 /* (i.e., all points in data ought to be within window.) */
31 void line_window_t::plot(QPainter& P, QColor& C, Qt::PenStyle & Ps) {
32   // modify P somehow: just a point if single line, bunch of segments otherwise.
33   data_window_t::const_iterator it = data.begin();
34   int x1, x2, y1, y2;
35   x1 = it->x;
36   y1 = it->y;
37   it++;
38   
39   QPen pen = P.pen();
40   pen.setStyle( Ps );
41   pen.setWidth( 2 );
42   pen.setColor( C );
43 //  P.setPen( Cz);
44   P.setPen( pen );
45   
46   if(it == data.end()) {
47     // 'line' has just a single point: plot blotch @ (x1, y1)
48     sd_line_t::drawBigPoint(P, x1 , y1);
49   } else {
50     // draw segments between consecutive pixel pairs in list
51     for(; it!=data.end(); it++) {
52       x2 = it->x;
53       y2 = it->y;
54       P.drawLine(x1, y1, x2, y2);
55       x1 = x2;
56       y1 = y2;
57     }
58   }
59 } // --line_window_t::plot()
60
61
62 void line_window_t::show() {
63   for(data_window_t::const_iterator it = data.begin(); it != data.end(); it++) {
64     std::cerr << "(" << (it->x) << "," << (it->y) << ") "; 
65   }
66   std::cerr << " ### ";
67 } // --line_window_t::show()