wmcube: imported Upstream version 0.99-pre1
[dockapps.git] / wmcube / wmapp / wmhistory.cc
blob5900069d0f1ca7aef8a7c965a69e7aa963ccc84c
1 #include <iostream>
2 #include "wmhistory.h"
3 #include "wmwindow.h"
4 #include "wmapp.h"
6 using std::cerr;
7 using std::endl;
9 // functions for WMHistory -----------------------------------------------
10 // added by Jason
12 void WMHistory::setvalue (int value, int index, bool dodisplay)
14 if (index == -1)
16 wValues.pop_back();
17 wValues.push_front(value);
19 else
20 wValues[index] = value;
21 if (dodisplay)
22 display();
25 void WMHistory::setvalues (const vector<int>& values, bool dodisplay)
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();
37 void WMHistory::clear(bool dodisplay)
38 { setvalues(vector<int>(0), dodisplay); }
40 void WMHistory::real_display ()
41 // XXX: Currently no vertical style, since it doesn't make a lot of sense
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; }
50 for (int x = 0; x < b_width(); x++)
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
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));