add comment/doxygen doc
[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         , scissors (0)
30         , trimmer (0)
31         , right_side_trim (0)
32         , anchored_right_side_trim (0)
33         , left_side_trim (0)
34         , anchored_left_side_trim (0)
35         , right_side_trim_left_only (0)
36         , left_side_trim_right_only (0)
37         , fade_in (0)
38         , fade_out (0)
39         , selector (0)
40         , grabber (0)
41         , grabber_note (0)
42         , grabber_edit_point (0)
43         , zoom_in (0)
44         , zoom_out (0)
45         , time_fx (0)
46         , fader (0)
47         , speaker (0)
48         , midi_pencil (0)
49         , midi_select (0)
50         , midi_resize (0)
51         , midi_erase (0)
52         , up_down (0)
53         , wait (0)
54         , timebar (0)
55         , transparent (0)
56         , resize_left (0)
57         , resize_top_left (0)
58         , resize_top (0)
59         , resize_top_right (0)
60         , resize_right (0)
61         , resize_bottom_right (0)
62         , resize_bottom (0)
63         , resize_bottom_left (0)
64         , move (0)
65         , expand_left_right (0)
66         , expand_up_down (0)
67 {
68 }
69
70 void
71 MouseCursors::drop_all ()
72 {
73         delete cross_hair; cross_hair = 0;
74         delete scissors; scissors = 0;
75         delete trimmer; trimmer = 0;
76         delete right_side_trim; right_side_trim = 0;
77         delete anchored_right_side_trim; anchored_right_side_trim = 0;
78         delete left_side_trim; left_side_trim = 0;
79         delete anchored_left_side_trim; anchored_left_side_trim = 0;
80         delete right_side_trim_left_only; right_side_trim_left_only = 0;
81         delete left_side_trim_right_only; left_side_trim_right_only = 0;
82         delete fade_in; fade_in = 0;
83         delete fade_out; fade_out = 0;
84         delete selector; selector = 0;
85         delete grabber; grabber = 0;
86         delete grabber_note; grabber_note = 0;
87         delete grabber_edit_point; grabber_edit_point = 0;
88         delete zoom_in; zoom_in = 0;
89         delete zoom_out; zoom_out = 0;
90         delete time_fx; time_fx = 0;
91         delete fader; fader = 0;
92         delete speaker; speaker = 0;
93         delete midi_pencil; midi_pencil = 0;
94         delete midi_select; midi_select = 0;
95         delete midi_resize; midi_resize = 0;
96         delete midi_erase; midi_erase = 0;
97         delete up_down; up_down = 0;
98         delete wait; wait = 0;
99         delete timebar; timebar = 0;
100         delete transparent; transparent = 0;
101         delete resize_left; resize_left = 0;
102         delete resize_top_left; resize_top_left = 0;
103         delete resize_top; resize_top = 0;
104         delete resize_top_right; resize_top_right = 0;
105         delete resize_right; resize_right = 0;
106         delete resize_bottom_right; resize_bottom_right = 0;
107         delete resize_bottom; resize_bottom = 0;
108         delete resize_bottom_left; resize_bottom_left = 0;
109         delete move; move = 0;
110         delete expand_left_right; expand_left_right = 0;
111         delete expand_up_down; expand_up_down = 0;
112 }
113
114 void
115 MouseCursors::set_cursor_set (const std::string& name)
116 {
117         using namespace Glib;
118         using namespace Gdk;
119         
120         drop_all ();
121         _cursor_set = name;
122
123         {
124                 RefPtr<Pixbuf> p (::get_icon ("zoom_in_cursor", _cursor_set));
125                 zoom_in = new Cursor (Display::get_default(), p, 10, 5);
126         }
127
128         {
129                 RefPtr<Pixbuf> p (::get_icon ("zoom_out_cursor", _cursor_set));
130                 zoom_out = new Cursor (Display::get_default(), p, 5, 5);
131         }
132
133         Color fbg ("#ffffff");
134         Color ffg ("#000000");
135
136         {
137                 RefPtr<Bitmap> source = Bitmap::create ((char const *) fader_cursor_bits, fader_cursor_width, fader_cursor_height);
138                 RefPtr<Bitmap> mask = Bitmap::create ((char const *) fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
139                 fader = new Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
140         }
141
142         {
143                 RefPtr<Bitmap> source = Bitmap::create ((char const *) speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
144                 RefPtr<Bitmap> mask = Bitmap::create ((char const *) speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
145                 speaker = new Cursor (source, mask, ffg, fbg, speaker_cursor_width >> 1, speaker_cursor_height >> 1);
146         }
147
148         {
149                 char pix[4] = { 0, 0, 0, 0 };
150                 RefPtr<Bitmap> bits = Bitmap::create (pix, 2, 2);
151                 Color c;
152                 transparent = new Cursor (bits, bits, c, c, 0, 0);
153         }
154
155         {
156                 char pix[4] = { 0, 0, 0, 0 };
157                 RefPtr<Bitmap> bits = Bitmap::create (pix, 2, 2);
158                 Color c;
159                 transparent = new Cursor (bits, bits, c, c, 0, 0);
160         }
161
162         {
163                 RefPtr<Pixbuf> p (::get_icon ("scissors", _cursor_set));
164                 scissors = new Cursor (Display::get_default(), p, 5, 0);
165         }
166
167         {
168                 RefPtr<Pixbuf> p (::get_icon ("grabber", _cursor_set));
169                 grabber = new Cursor (Display::get_default(), p, 5, 0);
170         }
171
172         {
173                 RefPtr<Pixbuf> p (::get_icon ("grabber_note", _cursor_set));
174                 grabber_note = new Cursor (Display::get_default(), p, 5, 10);
175         }
176
177         {
178                 RefPtr<Pixbuf> p (::get_icon ("grabber_edit_point", _cursor_set));
179                 grabber_edit_point = new Cursor (Display::get_default(), p, 5, 17);
180         }
181
182         cross_hair = new Cursor (CROSSHAIR);
183         trimmer =  new Cursor (SB_H_DOUBLE_ARROW);
184
185         {
186                 RefPtr<Pixbuf> p (::get_icon ("trim_left_cursor", _cursor_set));
187                 left_side_trim = new Cursor (Display::get_default(), p, 5, 11);
188         }
189
190         {
191                 RefPtr<Pixbuf> p (::get_icon ("anchored_trim_left_cursor", _cursor_set));
192                 anchored_left_side_trim = new Cursor (Display::get_default(), p, 5, 11);
193         }
194
195         {
196                 RefPtr<Pixbuf> p (::get_icon ("trim_right_cursor", _cursor_set));
197                 right_side_trim = new Cursor (Display::get_default(), p, 23, 11);
198         }
199
200         {
201                 RefPtr<Pixbuf> p (::get_icon ("anchored_trim_right_cursor", _cursor_set));
202                 anchored_right_side_trim = new Cursor (Display::get_default(), p, 23, 11);
203         }
204
205         {
206                 RefPtr<Pixbuf> p (::get_icon ("trim_left_cursor_right_only", _cursor_set));
207                 left_side_trim_right_only = new Cursor (Display::get_default(), p, 5, 11);
208         }
209
210         {
211                 RefPtr<Pixbuf> p (::get_icon ("trim_right_cursor_left_only", _cursor_set));
212                 right_side_trim_left_only = new Cursor (Display::get_default(), p, 23, 11);
213         }
214
215         {
216                 RefPtr<Pixbuf> p (::get_icon ("fade_in_cursor", _cursor_set));
217                 fade_in = new Cursor (Display::get_default(), p, 0, 0);
218         }
219
220         {
221                 RefPtr<Pixbuf> p (::get_icon ("fade_out_cursor", _cursor_set));
222                 fade_out = new Cursor (Display::get_default(), p, 29, 0);
223         }
224
225         {
226                 RefPtr<Pixbuf> p (::get_icon ("resize_left_cursor", _cursor_set));
227                 resize_left = new Cursor (Display::get_default(), p, 3, 10);
228         }
229
230         {
231                 RefPtr<Pixbuf> p (::get_icon ("resize_top_left_cursor", _cursor_set));
232                 resize_top_left = new Cursor (Display::get_default(), p, 3, 3);
233         }
234
235         {
236                 RefPtr<Pixbuf> p (::get_icon ("resize_top_cursor", _cursor_set));
237                 resize_top = new Cursor (Display::get_default(), p, 10, 3);
238         }
239
240         {
241                 RefPtr<Pixbuf> p (::get_icon ("resize_top_right_cursor", _cursor_set));
242                 resize_top_right = new Cursor (Display::get_default(), p, 18, 3);
243         }
244
245         {
246                 RefPtr<Pixbuf> p (::get_icon ("resize_right_cursor", _cursor_set));
247                 resize_right = new Cursor (Display::get_default(), p, 24, 10);
248         }
249
250         {
251                 RefPtr<Pixbuf> p (::get_icon ("resize_bottom_right_cursor", _cursor_set));
252                 resize_bottom_right = new Cursor (Display::get_default(), p, 18, 18);
253         }
254
255         {
256                 RefPtr<Pixbuf> p (::get_icon ("resize_bottom_cursor", _cursor_set));
257                 resize_bottom = new Cursor (Display::get_default(), p, 10, 24);
258         }
259
260         {
261                 RefPtr<Pixbuf> p (::get_icon ("resize_bottom_left_cursor", _cursor_set));
262                 resize_bottom_left = new Cursor (Display::get_default(), p, 3, 18);
263         }
264
265         {
266                 RefPtr<Pixbuf> p (::get_icon ("move_cursor", _cursor_set));
267                 move = new Cursor (Display::get_default(), p, 11, 11);
268         }
269
270         {
271                 RefPtr<Pixbuf> p (::get_icon ("expand_left_right_cursor", _cursor_set));
272                 expand_left_right = new Cursor (Display::get_default(), p, 11, 4);
273         }
274
275         {
276                 RefPtr<Pixbuf> p (::get_icon ("expand_up_down_cursor", _cursor_set));
277                 expand_up_down = new Cursor (Display::get_default(), p, 4, 11);
278         }
279
280         {
281                 RefPtr<Pixbuf> p (::get_icon ("i_beam_cursor", _cursor_set));
282                 selector = new Cursor (Display::get_default(), p, 4, 11);
283         }
284
285         time_fx = new Cursor (SIZING);
286         wait = new Cursor (WATCH);
287         timebar = new Cursor(LEFT_PTR);
288         midi_pencil = new Cursor (PENCIL);
289         midi_select = new Cursor (CENTER_PTR);
290         midi_resize = new Cursor (SIZING);
291         midi_erase = new Cursor (DRAPED_BOX);
292         up_down = new Cursor (SB_V_DOUBLE_ARROW);
293 }