summaryrefslogtreecommitdiff
path: root/gtk2_ardour/port_matrix_component.h
blob: 4286c1bf54debc533244f52331dbb5d0132ee7d0 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __gtk_ardour_port_matrix_component_h__
#define __gtk_ardour_port_matrix_component_h__

#include <stdint.h>
#include <gtkmm/eventbox.h>
#include <boost/shared_ptr.hpp>

class PortMatrix;
class PortMatrixBody;
class PortMatrixNode;
class PortGroup;
class PortGroupList;

namespace ARDOUR {
	class Bundle;
	class BundleChannel;
}

/** One component of the PortMatrix.  This is a cairo-rendered
 *  Pixmap.
 */
class PortMatrixComponent
{
public:
	PortMatrixComponent (PortMatrix *, PortMatrixBody *);
	virtual ~PortMatrixComponent ();

	virtual double component_to_parent_x (double x) const = 0;
	virtual double parent_to_component_x (double x) const = 0;
	virtual double component_to_parent_y (double y) const = 0;
	virtual double parent_to_component_y (double y) const = 0;
	virtual void mouseover_changed (std::list<PortMatrixNode> const &) = 0;
	virtual void draw_extra (cairo_t *) = 0;
	virtual void button_press (double, double, GdkEventButton *) {}
	virtual void button_release (double, double, GdkEventButton *) {}
	virtual void motion (double, double) {}

	void set_show_ports (bool);
	void setup ();
	GdkPixmap* get_pixmap (GdkDrawable *);
	std::pair<uint32_t, uint32_t> dimensions ();

	void require_render () {
		_render_required = true;
	}

	void require_rebuild () {
		_dimension_computation_required = true;
		_render_required = true;
	}

	void set_parent_rectangle (Gdk::Rectangle const & r) {
		_parent_rectangle = r;
	}

	Gdk::Rectangle parent_rectangle () const {
		return _parent_rectangle;
	}

	/** @return grid spacing */
	static uint32_t grid_spacing ();

protected:

	/** @return width of borders drawn around labels */
	static uint32_t label_border_width () {
		return 1;
	}

	/** @return padding between a name and the nearest line */
	static uint32_t name_pad () {
		return 8;
	}

	/** @return width of thin lines in the grid */
	static double thin_grid_line_width () {
		return 0.5;
	}

	/** @return width of thick lines in the grid */
	static double thick_grid_line_width () {
		return 1;
	}

	/** @return space around the connection indicator */
	static uint32_t connection_indicator_pad () {
		return 6;
	}

	static uint32_t mouseover_line_width () {
		return 4;
	}

	/** @return angle of column labels, in radians */
	static double angle () {
		return M_PI / 4;
	}

	/** @return background colour */
	Gdk::Color background_colour ();

	/* XXX I guess these colours should come from a theme, or something */

	/** @return text colour */
	static Gdk::Color text_colour () {
		return Gdk::Color ("#ffffff");
	}

	/** @return grid line colour */
	static Gdk::Color grid_colour () {
		return Gdk::Color ("#000000");
	}

	/** @return colour of association blobs */
	static Gdk::Color association_colour () {
		return Gdk::Color ("#00ff00");
	}

	/** @return colour to paint grid squares when they can't be associated */
	static Gdk::Color non_connectable_colour () {
		return Gdk::Color ("#cccccc");
	}

	/** @return colour to paint mouseover lines */
	static Gdk::Color mouseover_line_colour () {
		return Gdk::Color ("#ff0000");
	}

	/** @return colour to paint channel highlights */
	static Gdk::Color highlighted_channel_colour () {
		return Gdk::Color ("#777777");
	}

	/* XXX */
	static Gdk::Color get_a_bundle_colour (int x) {
		if ((x % 2) == 0) {
			return Gdk::Color ("#555555");
		} else {
			return Gdk::Color ("#666666");
		}
	}

	/* XXX */
	static Gdk::Color get_a_group_colour (int x) {
		if ((x % 2) == 0) {
			return Gdk::Color ("#222222");
		} else {
			return Gdk::Color ("#444444");
		}
	}

	void set_source_rgb (cairo_t *, Gdk::Color const &);
	void set_source_rgba (cairo_t *, Gdk::Color const &, double);
	uint32_t group_size (boost::shared_ptr<const PortGroup>) const;
	uint32_t channel_to_position (ARDOUR::BundleChannel, boost::shared_ptr<const PortGroup>) const;
	virtual ARDOUR::BundleChannel position_to_channel (double, double, boost::shared_ptr<const PortGroup>) const;

	/** Render the complete component to a cairo context. */
	virtual void render (cairo_t *) = 0;
	/** Compute any required dimensions.  This must set up
	 *  _width and _height.
	 */
	virtual void compute_dimensions () = 0;

	PortMatrix* _matrix;
	PortMatrixBody* _body; ///< the PortMatrixBody that we're in
	uint32_t _width; ///< full width of the contents
	uint32_t _height; ///< full height of the contents
	Gdk::Rectangle _parent_rectangle;

private:
	GdkPixmap* _pixmap; ///< pixmap
	bool _render_required; ///< true if the rendered pixmap is out of date
	bool _dimension_computation_required; ///< true if the dimensions are out of date
};

#endif