| 1 | // SPDX-FileCopyrightText: 2009 Ingo Ruhnke <[email protected]> |
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | |
| 4 | #include "axis_widget.hpp" |
| 5 | |
| 6 | AxisWidget::AxisWidget(int width, int height) |
| 7 | : Gtk::Alignment(Gtk::ALIGN_CENTER, Gtk::ALIGN_START, 0.0f, 0.0f), |
| 8 | x(0), y(0) |
| 9 | { |
| 10 | //modify_bg(Gtk::STATE_NORMAL , Gdk::Color("white")); |
| 11 | //modify_fg(Gtk::STATE_NORMAL , Gdk::Color("black")); |
| 12 | add(drawingarea); |
| 13 | drawingarea.signal_draw().connect(sigc::mem_fun(this, &AxisWidget::on_draw)); |
| 14 | drawingarea.set_size_request(width, height); |
| 15 | } |
| 16 | |
| 17 | bool |
| 18 | AxisWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) |
| 19 | { |
| 20 | int w = drawingarea.get_allocation().get_width() - 10; |
| 21 | int h = drawingarea.get_allocation().get_height() - 10; |
| 22 | int px = w/2 + (w/2 * x); |
| 23 | int py = h/2 + (h/2 * y); |
| 24 | |
| 25 | cr->translate(5, 5); |
| 26 | |
| 27 | // Outer Rectangle |
| 28 | cr->set_source_rgb(0.0, 0.0, 0.0); |
| 29 | cr->set_line_width(1.0); |
| 30 | cr->rectangle(0, 0, w, h); |
| 31 | cr->stroke(); |
| 32 | |
| 33 | // BG Circle |
| 34 | cr->arc(w/2, h/2, w/2, 0.0, 2.0 * M_PI); |
| 35 | cr->set_source_rgba(0.0, 0.0, 0.0, 0.1); |
| 36 | cr->fill(); |
| 37 | |
| 38 | // Cross |
| 39 | cr->set_line_width(0.5); |
| 40 | cr->set_source_rgba(0.0, 0.0, 0.0, 0.5); |
| 41 | cr->move_to(w/2, 0); |
| 42 | cr->line_to(w/2, h); |
| 43 | |
| 44 | cr->set_source_rgba(0.0, 0.0, 0.0, 0.5); |
| 45 | cr->move_to(0, h/2); |
| 46 | cr->line_to(w, h/2); |
| 47 | cr->stroke(); |
| 48 | |
| 49 | // Cursor |
| 50 | cr->set_source_rgb(0.0, 0.0, 0.0); |
| 51 | cr->set_line_width(2.0); |
| 52 | cr->move_to(px, py-5); |
| 53 | cr->line_to(px, py+5); |
| 54 | cr->move_to(px-5, py); |
| 55 | cr->line_to(px+5, py); |
| 56 | cr->stroke(); |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | AxisWidget::set_x_axis(double x_) |
| 63 | { |
| 64 | x = x_; |
| 65 | queue_draw(); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | AxisWidget::set_y_axis(double y_) |
| 70 | { |
| 71 | y = y_; |
| 72 | queue_draw(); |
| 73 | } |
| 74 | |
| 75 | /* EOF */ |
| 76 |