1 #include <iostream>
2 #include "wmhistory.h"
3 #include "wmwindow.h"
4 #include "wmapp.h"
5 
6 using std::cerr;
7 using std::endl;
8 
9 // functions for WMHistory -----------------------------------------------
10 // added by Jason
11 
setvalue(int value,int index,bool dodisplay)12 void WMHistory::setvalue (int value, int index, bool dodisplay)
13 {
14   if (index == -1)
15   {
16     wValues.pop_back();
17     wValues.push_front(value);
18   }
19   else
20     wValues[index] = value;
21   if (dodisplay)
22     display();
23 }
24 
setvalues(const vector<int> & values,bool dodisplay)25 void WMHistory::setvalues (const vector<int>& values, bool dodisplay)
26 {
27   vector<int>::const_iterator src = values.begin();
28   deque<int>::iterator dest = wValues.begin();
29   while (src != values.end() && dest != wValues.end())
30     *dest++ = *src++;
31   while (dest != wValues.end())
32     *dest++ = 0;
33   if (dodisplay)
34     display();
35 }
36 
clear(bool dodisplay)37 void WMHistory::clear(bool dodisplay)
38 { setvalues(vector<int>(0), dodisplay); }
39 
real_display()40 void WMHistory::real_display ()
41 // XXX: Currently no vertical style, since it doesn't make a lot of sense
42 {
43   WMApp::Xw.fill_rectangle(window()->pixmap(), b_position(),
44 		  	   WMColor(Background));
45   if (!wTotal)
46     return;
47   if (width() < 2 * border() || height() < 2 * border())
48     { cerr << "WMError: History " << this << " too small" << endl; return; }
49 
50   for (int x = 0; x < b_width(); x++)
51   {
52     int h = static_cast<int> (fraction(x) * b_height());
53     if (h < 1)
54       continue;
55     else if (h == 1)
56       WMApp::Xw.draw_point(window()->pixmap(), b_right() - 1 - x, b_bottom() - 1
57 		           , WMColor(Bright));
58     else
59     {
60       WMApp::Xw.draw_line(window()->pixmap(), b_right() - 1 - x, b_bottom() - h,
61 		          b_right() - 1 - x, b_bottom() - h + 1, WMColor(Bright));
62       if (h > 2)
63         WMApp::Xw.draw_line(window()->pixmap(), b_right() - 1 - x, b_bottom() - h + 2, b_right() - 1 - x, b_bottom() - 1, WMColor(Medium));
64     }
65   }
66 }
67 
68