Debian Codegraph @

src/throttle_widget.cpp

raw
1 /*
2 ** jstest-gtk - A graphical joystick tester
3 ** Copyright (C) 2009 Ingo Ruhnke <[email protected]>
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "throttle_widget.hpp"
20
21 ThrottleWidget::ThrottleWidget(int width, int height, bool invert_)
22 : invert(invert_),
23 pos(0.0)
24 {
25 set_size_request(width, height);
26 //modify_bg(Gtk::STATE_NORMAL , Gdk::Color("white"));
27 //modify_fg(Gtk::STATE_NORMAL , Gdk::Color("black"));
28 }
29
30 bool
31 ThrottleWidget::on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr)
32 {
33 double p = 1.0 - (pos + 1.0) / 2.0;
34
35 int w = get_allocation().get_width()-10;
36 int h = get_allocation().get_height()-10;
37
38 cr->translate(5, 5);
39
40 // Outer Rectangle
41 cr->set_source_rgb(0.0, 0.0, 0.0);
42 cr->set_line_width(1.0);
43 cr->rectangle(0, 0, w, h);
44 cr->stroke();
45
46 int dh = h*p;
47 cr->rectangle(0, h - dh, w, dh);
48 cr->fill();
49
50 return true;
51 }
52
53 void
54 ThrottleWidget::set_pos(double p)
55 {
56 if (invert)
57 pos = -p;
58 else
59 pos = p;
60 queue_draw();
61 }
62
63 /* EOF */