merge with master.
[ardour.git] / gtk2_ardour / mouse_cursors.cc
1 /*
2     Copyright (C) 2000-2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <gdkmm/cursor.h>
21 #include "utils.h"
22 #include "mouse_cursors.h"
23 #include "editor_xpms"
24
25 using namespace ARDOUR_UI_UTILS;
26
27 MouseCursors::MouseCursors ()
28         : cross_hair (0)
29         , trimmer (0)
30         , right_side_trim (0)
31         , anchored_right_side_trim (0)
32         , left_side_trim (0)
33         , anchored_left_side_trim (0)
34         , right_side_trim_left_only (0)
35         , left_side_trim_right_only (0)
36         , fade_in (0)
37         , fade_out (0)
38         , selector (0)
39         , grabber (0)
40         , grabber_note (0)
41         , grabber_edit_point (0)
42         , zoom_in (0)
43         , zoom_out (0)
44         , time_fx (0)
45         , fader (0)
46         , speaker (0)
47         , midi_pencil (0)
48         , midi_select (0)
49         , midi_resize (0)
50         , midi_erase (0)
51         , up_down (0)
52         , wait (0)
53         , timebar (0)
54         , transparent (0)
55         , resize_left (0)
56         , resize_top_left (0)
57         , resize_top (0)
58         , resize_top_right (0)
59         , resize_right (0)
60         , resize_bottom_right (0)
61         , resize_bottom (0)
62         , resize_bottom_left (0)
63         , move (0)
64         , expand_left_right (0)
65         , expand_up_down (0)
66 {
67 }
68
69 void
70 MouseCursors::drop_all ()
71 {
72         delete cross_hair; cross_hair = 0;
73         delete trimmer; trimmer = 0;
74         delete right_side_trim; right_side_trim = 0;
75         delete anchored_right_side_trim; anchored_right_side_trim = 0;
76         delete left_side_trim; left_side_trim = 0;
77         delete anchored_left_side_trim; anchored_left_side_trim = 0;
78         delete right_side_trim_left_only; right_side_trim_left_only = 0;
79         delete left_side_trim_right_only; left_side_trim_right_only = 0;
80         delete fade_in; fade_in = 0;
81         delete fade_out; fade_out = 0;
82         delete selector; selector = 0;
83         delete grabber; grabber = 0;
84         delete grabber_note; grabber_note = 0;
85         delete grabber_edit_point; grabber_edit_point = 0;
86         delete zoom_in; zoom_in = 0;
87         delete zoom_out; zoom_out = 0;
88         delete time_fx; time_fx = 0;
89         delete fader; fader = 0;
90         delete speaker; speaker = 0;
91         delete midi_pencil; midi_pencil = 0;
92         delete midi_select; midi_select = 0;
93         delete midi_resize; midi_resize = 0;
94         delete midi_erase; midi_erase = 0;
95         delete up_down; up_down = 0;
96         delete wait; wait = 0;
97         delete timebar; timebar = 0;
98         delete transparent; transparent = 0;
99         delete resize_left; resize_left = 0;
100         delete resize_top_left; resize_top_left = 0;
101         delete resize_top; resize_top = 0;
102         delete resize_top_right; resize_top_right = 0;
103         delete resize_right; resize_right = 0;
104         delete resize_bottom_right; resize_bottom_right = 0;
105         delete resize_bottom; resize_bottom = 0;
106         delete resize_bottom_left; resize_bottom_left = 0;
107         delete move; move = 0;
108         delete expand_left_right; expand_left_right = 0;
109         delete expand_up_down; expand_up_down = 0;
110 }
111
112 void
113 MouseCursors::set_cursor_set (const std::string& name)
114 {
115         using namespace Glib;
116         using namespace Gdk;
117         
118         drop_all ();
119         _cursor_set = name;
120
121         {
122                 RefPtr<Pixbuf> p (::get_icon ("zoom_in_cursor", _cursor_set));
123                 zoom_in = new Cursor (Display::get_default(), p, 10, 5);
124         }
125
126         {
127                 RefPtr<Pixbuf> p (::get_icon ("zoom_out_cursor", _cursor_set));
128                 zoom_out = new Cursor (Display::get_default(), p, 5, 5);
129         }
130
131         Color fbg ("#ffffff");
132         Color ffg ("#000000");
133
134         {
135                 RefPtr<Bitmap> source = Bitmap::create ((char const *) fader_cursor_bits, fader_cursor_width, fader_cursor_height);
136                 RefPtr<Bitmap> mask = Bitmap::create ((char const *) fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
137                 fader = new Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
138         }
139
140         {
141                 RefPtr<Bitmap> source = Bitmap::create ((char const *) speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
142                 RefPtr<Bitmap> mask = Bitmap::create ((char const *) speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
143                 speaker = new Cursor (source, mask, ffg, fbg, speaker_cursor_width >> 1, speaker_cursor_height >> 1);
144         }
145
146         {
147                 char pix[4] = { 0, 0, 0, 0 };
148                 RefPtr<Bitmap> bits = Bitmap::create (pix, 2, 2);
149                 Color c;
150                 transparent = new Cursor (bits, bits, c, c, 0, 0);
151         }
152
153         {
154                 char pix[4] = { 0, 0, 0, 0 };
155                 RefPtr<Bitmap> bits = Bitmap::create (pix, 2, 2);
156                 Color c;
157                 transparent = new Cursor (bits, bits, c, c, 0, 0);
158         }
159
160         {
161                 RefPtr<Pixbuf> p (::get_icon ("grabber", _cursor_set));
162                 grabber = new Cursor (Display::get_default(), p, 5, 0);
163         }
164
165         {
166                 RefPtr<Pixbuf> p (::get_icon ("grabber_note", _cursor_set));
167                 grabber_note = new Cursor (Display::get_default(), p, 5, 10);
168         }
169
170         {
171                 RefPtr<Pixbuf> p (::get_icon ("grabber_edit_point", _cursor_set));
172                 grabber_edit_point = new Cursor (Display::get_default(), p, 5, 17);
173         }
174
175         cross_hair = new Cursor (CROSSHAIR);
176         trimmer =  new Cursor (SB_H_DOUBLE_ARROW);
177
178         {
179                 RefPtr<Pixbuf> p (::get_icon ("trim_left_cursor", _cursor_set));
180                 left_side_trim = new Cursor (Display::get_default(), p, 5, 11);
181         }
182
183         {
184                 RefPtr<Pixbuf> p (::get_icon ("anchored_trim_left_cursor", _cursor_set));
185                 anchored_left_side_trim = new Cursor (Display::get_default(), p, 5, 11);
186         }
187
188         {
189                 RefPtr<Pixbuf> p (::get_icon ("trim_right_cursor", _cursor_set));
190                 right_side_trim = new Cursor (Display::get_default(), p, 23, 11);
191         }
192
193         {
194                 RefPtr<Pixbuf> p (::get_icon ("anchored_trim_right_cursor", _cursor_set));
195                 anchored_right_side_trim = new Cursor (Display::get_default(), p, 23, 11);
196         }
197
198         {
199                 RefPtr<Pixbuf> p (::get_icon ("trim_left_cursor_right_only", _cursor_set));
200                 left_side_trim_right_only = new Cursor (Display::get_default(), p, 5, 11);
201         }
202
203         {
204                 RefPtr<Pixbuf> p (::get_icon ("trim_right_cursor_left_only", _cursor_set));
205                 right_side_trim_left_only = new Cursor (Display::get_default(), p, 23, 11);
206         }
207
208         {
209                 RefPtr<Pixbuf> p (::get_icon ("fade_in_cursor", _cursor_set));
210                 fade_in = new Cursor (Display::get_default(), p, 0, 0);
211         }
212
213         {
214                 RefPtr<Pixbuf> p (::get_icon ("fade_out_cursor", _cursor_set));
215                 fade_out = new Cursor (Display::get_default(), p, 29, 0);
216         }
217
218         {
219                 RefPtr<Pixbuf> p (::get_icon ("resize_left_cursor", _cursor_set));
220                 resize_left = new Cursor (Display::get_default(), p, 3, 10);
221         }
222
223         {
224                 RefPtr<Pixbuf> p (::get_icon ("resize_top_left_cursor", _cursor_set));
225                 resize_top_left = new Cursor (Display::get_default(), p, 3, 3);
226         }
227
228         {
229                 RefPtr<Pixbuf> p (::get_icon ("resize_top_cursor", _cursor_set));
230                 resize_top = new Cursor (Display::get_default(), p, 10, 3);
231         }
232
233         {
234                 RefPtr<Pixbuf> p (::get_icon ("resize_top_right_cursor", _cursor_set));
235                 resize_top_right = new Cursor (Display::get_default(), p, 18, 3);
236         }
237
238         {
239                 RefPtr<Pixbuf> p (::get_icon ("resize_right_cursor", _cursor_set));
240                 resize_right = new Cursor (Display::get_default(), p, 24, 10);
241         }
242
243         {
244                 RefPtr<Pixbuf> p (::get_icon ("resize_bottom_right_cursor", _cursor_set));
245                 resize_bottom_right = new Cursor (Display::get_default(), p, 18, 18);
246         }
247
248         {
249                 RefPtr<Pixbuf> p (::get_icon ("resize_bottom_cursor", _cursor_set));
250                 resize_bottom = new Cursor (Display::get_default(), p, 10, 24);
251         }
252
253         {
254                 RefPtr<Pixbuf> p (::get_icon ("resize_bottom_left_cursor", _cursor_set));
255                 resize_bottom_left = new Cursor (Display::get_default(), p, 3, 18);
256         }
257
258         {
259                 RefPtr<Pixbuf> p (::get_icon ("move_cursor", _cursor_set));
260                 move = new Cursor (Display::get_default(), p, 11, 11);
261         }
262
263         {
264                 RefPtr<Pixbuf> p (::get_icon ("expand_left_right_cursor", _cursor_set));
265                 expand_left_right = new Cursor (Display::get_default(), p, 11, 4);
266         }
267
268         {
269                 RefPtr<Pixbuf> p (::get_icon ("expand_up_down_cursor", _cursor_set));
270                 expand_up_down = new Cursor (Display::get_default(), p, 4, 11);
271         }
272
273         {
274                 RefPtr<Pixbuf> p (::get_icon ("i_beam_cursor", _cursor_set));
275                 selector = new Cursor (Display::get_default(), p, 4, 11);
276         }
277
278         time_fx = new Cursor (SIZING);
279         wait = new Cursor (WATCH);
280         timebar = new Cursor(LEFT_PTR);
281         midi_pencil = new Cursor (PENCIL);
282         midi_select = new Cursor (CENTER_PTR);
283         midi_resize = new Cursor (SIZING);
284         midi_erase = new Cursor (DRAPED_BOX);
285         up_down = new Cursor (SB_V_DOUBLE_ARROW);
286 }