| 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 "axis_widget.hpp" |
| 20 |
|
| 21 |
AxisWidget::AxisWidget(int width, int height) |
| 22 |
: Gtk::Alignment(Gtk::ALIGN_CENTER, Gtk::ALIGN_START, 0.0f, 0.0f), |
| 23 |
x(0), y(0) |
| 24 |
{ |
| 25 |
//modify_bg(Gtk::STATE_NORMAL , Gdk::Color("white")); |
| 26 |
//modify_fg(Gtk::STATE_NORMAL , Gdk::Color("black")); |
| 27 |
add(drawingarea); |
| 28 |
drawingarea.signal_draw().connect(sigc::mem_fun(this, &AxisWidget::on_draw)); |
| 29 |
drawingarea.set_size_request(width, height); |
| 30 |
} |
| 31 |
|
| 32 |
bool |
| 33 |
AxisWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) |
| 34 |
{ |
| 35 |
int w = drawingarea.get_allocation().get_width() - 10; |
| 36 |
int h = drawingarea.get_allocation().get_height() - 10; |
| 37 |
int px = w/2 + (w/2 * x); |
| 38 |
int py = h/2 + (h/2 * y); |
| 39 |
|
| 40 |
cr->translate(5, 5); |
| 41 |
|
| 42 |
// Outer Rectangle |
| 43 |
cr->set_source_rgb(0.0, 0.0, 0.0); |
| 44 |
cr->set_line_width(1.0); |
| 45 |
cr->rectangle(0, 0, w, h); |
| 46 |
cr->stroke(); |
| 47 |
|
| 48 |
// BG Circle |
| 49 |
cr->arc(w/2, h/2, w/2, 0.0, 2.0 * M_PI); |
| 50 |
cr->set_source_rgba(0.0, 0.0, 0.0, 0.1); |
| 51 |
cr->fill(); |
| 52 |
|
| 53 |
// Cross |
| 54 |
cr->set_line_width(0.5); |
| 55 |
cr->set_source_rgba(0.0, 0.0, 0.0, 0.5); |
| 56 |
cr->move_to(w/2, 0); |
| 57 |
cr->line_to(w/2, h); |
| 58 |
|
| 59 |
cr->set_source_rgba(0.0, 0.0, 0.0, 0.5); |
| 60 |
cr->move_to(0, h/2); |
| 61 |
cr->line_to(w, h/2); |
| 62 |
cr->stroke(); |
| 63 |
|
| 64 |
// Cursor |
| 65 |
cr->set_source_rgb(0.0, 0.0, 0.0); |
| 66 |
cr->set_line_width(2.0); |
| 67 |
cr->move_to(px, py-5); |
| 68 |
cr->line_to(px, py+5); |
| 69 |
cr->move_to(px-5, py); |
| 70 |
cr->line_to(px+5, py); |
| 71 |
cr->stroke(); |
| 72 |
|
| 73 |
return true; |
| 74 |
} |
| 75 |
|
| 76 |
void |
| 77 |
AxisWidget::set_x_axis(double x_) |
| 78 |
{ |
| 79 |
x = x_; |
| 80 |
queue_draw(); |
| 81 |
} |
| 82 |
|
| 83 |
void |
| 84 |
AxisWidget::set_y_axis(double y_) |
| 85 |
{ |
| 86 |
y = y_; |
| 87 |
queue_draw(); |
| 88 |
} |
| 89 |
|
| 90 |
/* EOF */ |
| 91 |
|