| 1 | // SPDX-FileCopyrightText: 2009 Ingo Ruhnke <[email protected]> |
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | |
| 4 | #include "throttle_widget.hpp" |
| 5 | |
| 6 | ThrottleWidget::ThrottleWidget(int width, int height, bool invert_) |
| 7 | : invert(invert_), |
| 8 | pos(0.0) |
| 9 | { |
| 10 | set_size_request(width, height); |
| 11 | //modify_bg(Gtk::STATE_NORMAL , Gdk::Color("white")); |
| 12 | //modify_fg(Gtk::STATE_NORMAL , Gdk::Color("black")); |
| 13 | } |
| 14 | |
| 15 | bool |
| 16 | ThrottleWidget::on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr) |
| 17 | { |
| 18 | double p = 1.0 - (pos + 1.0) / 2.0; |
| 19 | |
| 20 | int w = get_allocation().get_width()-10; |
| 21 | int h = get_allocation().get_height()-10; |
| 22 | |
| 23 | cr->translate(5, 5); |
| 24 | |
| 25 | // Outer Rectangle |
| 26 | cr->set_source_rgb(0.0, 0.0, 0.0); |
| 27 | cr->set_line_width(1.0); |
| 28 | cr->rectangle(0, 0, w, h); |
| 29 | cr->stroke(); |
| 30 | |
| 31 | int dh = h*p; |
| 32 | cr->rectangle(0, h - dh, w, dh); |
| 33 | cr->fill(); |
| 34 | |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | void |
| 39 | ThrottleWidget::set_pos(double p) |
| 40 | { |
| 41 | if (invert) |
| 42 | pos = -p; |
| 43 | else |
| 44 | pos = p; |
| 45 | queue_draw(); |
| 46 | } |
| 47 | |
| 48 | /* EOF */ |