File: plotwidget.h

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (82 lines) | stat: -rw-r--r-- 2,448 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef PLOT_WIDGET_H
#define PLOT_WIDGET_H

#include <gtkmm/drawingarea.h>

#include "plotbase.h"

class PlotWidget : public Gtk::DrawingArea {
 public:
  PlotWidget();
  ~PlotWidget();

  sigc::signal<void()>& OnMouseLeaveEvent() { return _onMouseLeft; }
  sigc::signal<void(double, double)>& OnButtonReleasedEvent() {
    return _onButtonReleased;
  }
  sigc::signal<void(double, double, int)>& OnScrollEvent() { return _onScroll; }
  sigc::signal<void()>& BeforeDrawSignal() { return _beforeDrawSignal; }

  void Update();

  PlotBase& Plot() { return *_plot; }
  const PlotBase& Plot() const { return *_plot; }

  void SetPlot(PlotBase& plot) {
    _linkedRedrawConnection.disconnect();
    _plot = &plot;
    _linkedRedrawConnection = _plot->SignalLinkedRedraw().connect(
        sigc::mem_fun(*this, &PlotWidget::Update));
    queue_draw();
  }

  void Clear() {
    _linkedRedrawConnection.disconnect();
    _plot = nullptr;
    queue_draw();
  }

  /**
   * A signal that gets called when the mouse moves over the plot.
   * The function handler should have two double parameters, which will
   * receive the x and y positions of the mouse, in units of the plot.
   */
  sigc::signal<void(double, double)>& OnMouseMovedEvent() {
    return _onMouseMoved;
  }
  bool IsMouseInImage() const { return _mouseIsIn; }
  size_t MouseX() { return _mouseX; }
  size_t MouseY() { return _mouseY; }
  void SavePdf(const std::string& filename) {
    _plot->SavePdf(filename, get_width(), get_height());
  }
  void SaveSvg(const std::string& filename) {
    _plot->SaveSvg(filename, get_width(), get_height());
  }
  void SavePng(const std::string& filename) {
    _plot->SavePng(filename, get_width(), get_height());
  }

 private:
  bool onDraw(const Cairo::RefPtr<Cairo::Context>& cr);
  bool onMotion(GdkEventMotion* event);
  bool onLeave(GdkEventCrossing* event);
  bool onButtonPress(GdkEventButton* event);
  bool onButtonRelease(GdkEventButton* event);
  bool onScroll(GdkEventScroll* event);

  PlotBase* _plot;
  bool _mouseIsIn;
  double _mouseX, _mouseY;
  bool _isButtonPressed, _isZooming, _isPanning;
  double _bpressStartX, _bpressStartY;

  sigc::signal<void(double, double)> _onMouseMoved;
  sigc::signal<void()> _onMouseLeft;
  sigc::signal<void(double, double)> _onButtonReleased;
  sigc::signal<void(double, double, int)> _onScroll;
  sigc::signal<void()> _beforeDrawSignal;
  sigc::connection _linkedRedrawConnection;
};

#endif