f859a881c78a003b3a080e0970e5dbac6b00e83d
[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
63     int row_spacing () const { return xstep; }
64
65   protected:
66     bool on_button_press_event (GdkEventButton* ev);
67     bool on_expose_event (GdkEventExpose* ev);
68     void on_size_allocate (Gtk::Allocation&);
69     void on_size_request (Gtk::Requisition*);
70     void on_realize ();
71     bool on_motion_notify_event (GdkEventMotion*);
72     bool on_leave_notify_event (GdkEventCrossing*);
73
74     MatrixNode* get_node (int32_t x, int32_t y);
75
76 private: 
77     int height;
78     int width;
79     int alloc_width;
80     int alloc_height;
81     bool drawn;
82     int labels_y_shift;
83     int labels_x_shift;
84     float angle_radians;
85     int border;
86     int ystep;
87     int xstep;
88     uint32_t line_height;
89     uint32_t line_width;
90     int arc_radius;
91     int32_t motion_x;
92     int32_t motion_y;
93
94     std::list<std::string> ours;
95     std::list<OtherPort> others;
96     std::vector<MatrixNode*> nodes;
97
98     void reset_size ();
99     void redraw (GdkDrawable*, GdkRectangle*);
100     void alloc_pixmap ();
101     void setup_nodes ();
102
103     GdkPixmap* pixmap;
104 };
105
106 #endif /* __gtk_ardour_matrix_h__ */