| 1 |
/* |
| 2 |
** jstest-gtk - A simple joystick test and calibration utility |
| 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 "rudder_widget.hpp" |
| 20 |
|
| 21 |
RudderWidget::RudderWidget(int width, int height) |
| 22 |
: pos(0.0) |
| 23 |
{ |
| 24 |
set_size_request(width, height); |
| 25 |
} |
| 26 |
|
| 27 |
bool |
| 28 |
RudderWidget::on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr) |
| 29 |
{ |
| 30 |
double p = (pos + 1.0)/2.0; |
| 31 |
|
| 32 |
int w = get_allocation().get_width()-10; |
| 33 |
int h = get_allocation().get_height()-10; |
| 34 |
|
| 35 |
cr->translate(5, 5); |
| 36 |
|
| 37 |
// Outer Rectangle |
| 38 |
cr->set_source_rgb(0.0, 0.0, 0.0); |
| 39 |
cr->set_line_width(1.0); |
| 40 |
cr->rectangle(0, 0, w, h); |
| 41 |
cr->stroke(); |
| 42 |
|
| 43 |
cr->set_source_rgba(0.0, 0.0, 0.0, 0.5); |
| 44 |
cr->move_to(w/2, 0); |
| 45 |
cr->line_to(w/2, h); |
| 46 |
cr->stroke(); |
| 47 |
|
| 48 |
cr->set_line_width(2.0); |
| 49 |
cr->set_source_rgb(0.0, 0.0, 0.0); |
| 50 |
cr->move_to(w * p, 0); |
| 51 |
cr->line_to(w * p, h); |
| 52 |
cr->stroke(); |
| 53 |
|
| 54 |
return true; |
| 55 |
} |
| 56 |
|
| 57 |
void |
| 58 |
RudderWidget::set_pos(double p) |
| 59 |
{ |
| 60 |
pos = p; |
| 61 |
queue_draw(); |
| 62 |
} |
| 63 |
|
| 64 |
/* EOF */ |