wmcube: imported Upstream version 0.99-pre1
[dockapps.git] / wmcube / wmapp / wmmeterbar.cc
blob2ec6dfd5fbcf4aa69988abffe28a4df03d524dd1
1 #include <iostream>
2 #include <algorithm> // for max()
3 #include "wmmeterbar.h"
4 #include "wmwindow.h"
5 #include "wmapp.h"
7 using std::cerr;
8 using std::endl;
10 // functions for WMMeterBar ----------------------------------------------
11 // added by Jason
13 void
14 WMMeterBar::real_display()
16 if ((orientation() == Orientation::Horizontal && width() < 2 * border())
17 || (orientation() == Orientation::Vertical && height() < 2 * border()))
18 { cerr << "WMError: Meter Bar " << this << " too small" << endl; return; }
20 //first draw desired background
21 switch (style())
23 case Spectrum:
24 if (orientation() == Orientation::Horizontal)
25 WMApp::Xw.draw_horizontal_gradient(window()->pixmap(),
26 b_left(), b_top(), b_right(), b_bottom(), 0x5C00, 0x5C0000);
27 else
28 WMApp::Xw.draw_vertical_gradient(window()->pixmap(),
29 b_left(), b_top(), b_right(), b_bottom(), 0x5C0000, 0x5C00);
30 break;
31 case Spec_No_BG:
32 WMApp::Xw.fill_rectangle(window()->pixmap(), b_position(),
33 WMColor(Background));
34 break;
35 case Blue:
36 WMApp::Xw.fill_rectangle(window()->pixmap(), b_position(),
37 WMColor(Background));
38 if (orientation() == Orientation::Horizontal)
39 for (int x = 0; x < b_width(); x += 2)
40 WMApp::Xw.draw_line(window()->pixmap(), x + b_left(), b_top(),
41 x + b_left(), b_bottom(), 0x004941);
42 else
43 for (int y = 0; y < b_height(); y += 2)
44 WMApp::Xw.draw_line(window()->pixmap(), b_left(),
45 b_bottom() - y, b_right(), b_bottom() - y, 0x004941);
46 break;
49 //then draw the progress bar
50 if (total() && value())
51 switch (style())
53 case Spectrum:
54 case Spec_No_BG:
55 if (orientation() == Orientation::Horizontal)
56 WMApp::Xw.draw_horizontal_gradient(window()->pixmap(),
57 b_left(), b_top(), b_right(), b_bottom(),
58 0xFF00, 0xFF0000, fraction());
59 else
60 WMApp::Xw.draw_vertical_gradient(window()->pixmap(),
61 b_left(), b_bottom(), b_right(), b_top(),
62 0xFF00, 0xFF0000, fraction());
63 break;
64 case Blue:
65 if (orientation() == Orientation::Horizontal)
66 for (int x = 0;
67 x < static_cast<int>(std::min(1.0, fraction()) * b_width());
68 x += 2)
69 WMApp::Xw.draw_line(window()->pixmap(), x + b_left(), b_top(),
70 x + b_left(), b_bottom(), WMColor(Bright));
71 else
72 for (int y = 0;
73 y < static_cast<int>(std::min(1.0, fraction()) * b_height());
74 y += 2)
75 WMApp::Xw.draw_line(window()->pixmap(), b_left(), b_bottom() - y,
76 b_right(), b_bottom() - y, WMColor(Bright));
77 break;