Fix missing namespace
[ardour.git] / gtk2_ardour / matrix.h
1 #ifndef __gtk_ardour_matrix_h__
2 #define __gtk_ardour_matrix_h__
3
4 #include <list>
5 #include <vector>
6 #include <string>
7 #include <stdint.h>
8
9 #include <gtkmm/eventbox.h>
10 #include <gtkmm/widget.h>
11
12 #include "port_group.h"
13
14 class OtherPort {
15 public:
16     OtherPort (const std::string& n, PortGroup& g)
17             : _name (n), _group (g) {}
18
19     std::string name() const { return _name; }
20     PortGroup& group() const { return _group; }
21     bool visible() const { return _group.visible; }
22
23 public:
24     std::string _name;
25     PortGroup& _group;
26 };
27
28 class MatrixNode {
29   public:
30     MatrixNode (std::string a, OtherPort o, int32_t x, int32_t y)
31             : _name (a), them (o), _connected (random()%3), _x(x), _y(y) {}
32     ~MatrixNode() {}
33
34     PortGroup& get_group() const { return them.group(); }
35
36     std::string our_name() const { return _name; }
37     std::string their_name() const { return them.name(); }
38
39     bool connected() const { return _connected; }
40     void set_connected (bool yn) { _connected = yn; }
41     int32_t x() const { return _x; }
42     int32_t y() const { return _y; }
43
44   private:
45     std::string _name;
46     OtherPort them;
47     bool _connected;
48     int32_t _x;
49     int32_t _y;
50 };
51
52 class Matrix : public Gtk::EventBox
53 {
54   public: 
55     Matrix();
56
57     void set_ports (const std::list<std::string>&);
58     void add_group (PortGroup&);
59     void remove_group (PortGroup&);
60     void hide_group (PortGroup&);
61     void show_group (PortGroup&);
62     void clear ();
63
64     int row_spacing () const { return xstep; }
65
66   protected:
67     bool on_button_press_event (GdkEventButton* ev);
68     bool on_expose_event (GdkEventExpose* ev);
69     void on_size_allocate (Gtk::Allocation&);
70     void on_size_request (Gtk::Requisition*);
71     void on_realize ();
72     bool on_motion_notify_event (GdkEventMotion*);
73     bool on_leave_notify_event (GdkEventCrossing*);
74
75     MatrixNode* get_node (int32_t x, int32_t y);
76
77 private: 
78     int height;
79     int width;
80     int alloc_width;
81     int alloc_height;
82     bool drawn;
83     int labels_y_shift;
84     int labels_x_shift;
85     float angle_radians;
86     int border;
87     int ystep;
88     int xstep;
89     uint32_t line_height;
90     uint32_t line_width;
91     int arc_radius;
92     int32_t motion_x;
93     int32_t motion_y;
94
95     std::list<std::string> ours;
96     std::list<OtherPort> others;
97     std::vector<MatrixNode*> nodes;
98
99     void reset_size ();
100     void redraw (GdkDrawable*, GdkRectangle*);
101     void alloc_pixmap ();
102     void setup_nodes ();
103
104     GdkPixmap* pixmap;
105 };
106
107 #endif /* __gtk_ardour_matrix_h__ */