ardour
mouse_cursors.cc
Go to the documentation of this file.
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 
22 #include "gtkmm2ext/cursors.h"
23 
24 #include "utils.h"
25 #include "mouse_cursors.h"
26 #include "editor_xpms"
27 
28 using namespace ARDOUR_UI_UTILS;
29 
30 Gdk::Cursor* MouseCursors::_invalid = 0;
31 
33  : cross_hair (0)
34  , scissors (0)
35  , trimmer (0)
36  , right_side_trim (0)
37  , anchored_right_side_trim (0)
38  , left_side_trim (0)
39  , anchored_left_side_trim (0)
40  , right_side_trim_left_only (0)
41  , left_side_trim_right_only (0)
42  , fade_in (0)
43  , fade_out (0)
44  , selector (0)
45  , grabber (0)
46  , grabber_note (0)
47  , grabber_edit_point (0)
48  , zoom_in (0)
49  , zoom_out (0)
50  , time_fx (0)
51  , fader (0)
52  , speaker (0)
53  , midi_pencil (0)
54  , midi_select (0)
55  , midi_resize (0)
56  , midi_erase (0)
57  , up_down (0)
58  , wait (0)
59  , timebar (0)
60  , transparent (0)
61  , resize_left (0)
62  , resize_top_left (0)
63  , resize_top (0)
64  , resize_top_right (0)
65  , resize_right (0)
66  , resize_bottom_right (0)
67  , resize_bottom (0)
68  , resize_bottom_left (0)
69  , move (0)
70  , expand_left_right (0)
71  , expand_up_down (0)
72 {
73 }
74 
75 void
77 {
78  delete cross_hair; cross_hair = 0;
79  delete scissors; scissors = 0;
80  delete trimmer; trimmer = 0;
81  delete right_side_trim; right_side_trim = 0;
83  delete left_side_trim; left_side_trim = 0;
87  delete fade_in; fade_in = 0;
88  delete fade_out; fade_out = 0;
89  delete selector; selector = 0;
90  delete grabber; grabber = 0;
91  delete grabber_note; grabber_note = 0;
93  delete zoom_in; zoom_in = 0;
94  delete zoom_out; zoom_out = 0;
95  delete time_fx; time_fx = 0;
96  delete fader; fader = 0;
97  delete speaker; speaker = 0;
98  delete midi_pencil; midi_pencil = 0;
99  delete midi_select; midi_select = 0;
100  delete midi_resize; midi_resize = 0;
101  delete midi_erase; midi_erase = 0;
102  delete up_down; up_down = 0;
103  delete wait; wait = 0;
104  delete timebar; timebar = 0;
105  delete transparent; transparent = 0;
106  delete resize_left; resize_left = 0;
107  delete resize_top_left; resize_top_left = 0;
108  delete resize_top; resize_top = 0;
110  delete resize_right; resize_right = 0;
112  delete resize_bottom; resize_bottom = 0;
114  delete move; move = 0;
116  delete expand_up_down; expand_up_down = 0;
117 }
118 
119 Gdk::Cursor*
120 MouseCursors::make_cursor (const char* name, int hotspot_x, int hotspot_y)
121 {
123 
124  if (info) {
125  hotspot_x = info->x;
126  hotspot_y = info->y;
127  }
128 
129  Glib::RefPtr<Gdk::Pixbuf> p (::get_icon (name, _cursor_set));
130  return new Gdk::Cursor (Gdk::Display::get_default(), p, hotspot_x, hotspot_y);
131 }
132 
133 void
134 MouseCursors::set_cursor_set (const std::string& name)
135 {
136  using namespace Glib;
137  using namespace Gdk;
138 
139  drop_all ();
141  _cursor_set = name;
142 
143  std::string hotspot_info_path = get_icon_path ("hotspots", _cursor_set, false);
144 
145  if (!hotspot_info_path.empty()) {
146  Gtkmm2ext::CursorInfo::load_cursor_info (hotspot_info_path);
147  }
148 
149  /* these will throw exceptions if their images cannot be found.
150 
151  the default hotspot coordinates will be overridden by any
152  data found by Gtkmm2ext::Cursors::load_cursor_info(). the values
153  here from the set of cursors used by Ardour; new cursor/icon
154  sets should come with a hotspot info file.
155  */
156 
157  zoom_in = make_cursor ("zoom_in_cursor", 10, 5);
158  zoom_out = make_cursor ("zoom_out_cursor", 5, 5);
159  scissors = make_cursor ("scissors", 5, 0);
160  grabber = make_cursor ("grabber", 5, 0);
161  grabber_note = make_cursor ("grabber_note", 5, 10);
162  grabber_edit_point = make_cursor ("grabber_edit_point", 5, 17);
163  left_side_trim = make_cursor ("trim_left_cursor", 5, 11);
164  anchored_left_side_trim = make_cursor ("anchored_trim_left_cursor", 5, 11);
165  right_side_trim = make_cursor ("trim_right_cursor", 23, 11);
166  anchored_right_side_trim = make_cursor ("anchored_trim_right_cursor", 23, 11);
167  left_side_trim_right_only = make_cursor ("trim_left_cursor_right_only", 5, 11);
168  right_side_trim_left_only = make_cursor ("trim_right_cursor_left_only", 23, 11);
169  fade_in = make_cursor ("fade_in_cursor", 0, 0);
170  fade_out = make_cursor ("fade_out_cursor", 29, 0);
171  resize_left = make_cursor ("resize_left_cursor", 3, 10);
172  resize_top_left = make_cursor ("resize_top_left_cursor", 3, 3);
173  resize_top = make_cursor ("resize_top_cursor", 10, 3);
174  resize_top_right = make_cursor ("resize_top_right_cursor", 18, 3);
175  resize_right = make_cursor ("resize_right_cursor", 24, 10);
176  resize_bottom_right = make_cursor ("resize_bottom_right_cursor", 18, 18);
177  resize_bottom = make_cursor ("resize_bottom_cursor", 10, 24);
178  resize_bottom_left = make_cursor ("resize_bottom_left_cursor", 3, 18);
179  move = make_cursor ("move_cursor", 11, 11);
180  expand_left_right = make_cursor ("expand_left_right_cursor", 11, 4);
181  expand_up_down = make_cursor ("expand_up_down_cursor", 4, 11);
182  selector = make_cursor ("i_beam_cursor", 4, 11);
183 
184  Gdk::Color fbg ("#ffffff");
185  Gdk::Color ffg ("#000000");
186 
187  {
188  RefPtr<Bitmap> source = Bitmap::create ((char const *) fader_cursor_bits, fader_cursor_width, fader_cursor_height);
189  RefPtr<Bitmap> mask = Bitmap::create ((char const *) fader_cursor_mask_bits, fader_cursor_width, fader_cursor_height);
190  fader = new Cursor (source, mask, ffg, fbg, fader_cursor_x_hot, fader_cursor_y_hot);
191  }
192 
193  {
194  RefPtr<Bitmap> source = Bitmap::create ((char const *) speaker_cursor_bits, speaker_cursor_width, speaker_cursor_height);
195  RefPtr<Bitmap> mask = Bitmap::create ((char const *) speaker_cursor_mask_bits, speaker_cursor_width, speaker_cursor_height);
196  speaker = new Cursor (source, mask, ffg, fbg, speaker_cursor_width >> 1, speaker_cursor_height >> 1);
197  }
198 
199  {
200  char pix[4] = { 0, 0, 0, 0 };
201  RefPtr<Bitmap> bits = Bitmap::create (pix, 2, 2);
202  Color c;
203  transparent = new Cursor (bits, bits, c, c, 0, 0);
204  }
205 
206  cross_hair = new Cursor (CROSSHAIR);
207  trimmer = new Cursor (SB_H_DOUBLE_ARROW);
208  time_fx = new Cursor (SIZING);
209  wait = new Cursor (WATCH);
210  timebar = new Cursor(LEFT_PTR);
211  midi_pencil = new Cursor (PENCIL);
212  midi_select = new Cursor (CENTER_PTR);
213  midi_resize = new Cursor (SIZING);
214  midi_erase = new Cursor (DRAPED_BOX);
215  up_down = new Cursor (SB_V_DOUBLE_ARROW);
216 }
217 
218 void
220 {
221  char pix[4] = { 0, 0, 0, 0 };
222  Glib::RefPtr<Gdk::Bitmap> bits = Gdk::Bitmap::create (pix, 2, 2);
223  Gdk::Color c;
224  _invalid = new Gdk::Cursor (bits, bits, c, c, 0, 0);
225 }
Gdk::Cursor * resize_left
Definition: mouse_cursors.h:64
Gdk::Cursor * selector
Definition: mouse_cursors.h:47
Gdk::Cursor * resize_bottom
Definition: mouse_cursors.h:70
Gdk::Cursor * grabber
Definition: mouse_cursors.h:48
static CursorInfo * lookup_cursor_info(const std::string &image_name)
Definition: cursors.cc:97
static void drop_cursor_info()
Definition: cursors.cc:91
Gdk::Cursor * timebar
Definition: mouse_cursors.h:62
Gdk::Cursor * make_cursor(const char *name, int hotspot_x=0, int hotspot_y=0)
Gdk::Cursor * left_side_trim_right_only
Definition: mouse_cursors.h:44
Gdk::Cursor * grabber_note
Definition: mouse_cursors.h:49
Gdk::Cursor * move
Definition: mouse_cursors.h:72
static void create_invalid()
Gdk::Cursor * right_side_trim_left_only
Definition: mouse_cursors.h:43
Gdk::Cursor * midi_pencil
Definition: mouse_cursors.h:56
Gdk::Cursor * resize_top_left
Definition: mouse_cursors.h:65
Gdk::Cursor * grabber_edit_point
Definition: mouse_cursors.h:50
Gdk::Cursor * expand_up_down
Definition: mouse_cursors.h:74
LIBARDOUR_API PBD::PropertyDescriptor< boost::shared_ptr< AutomationList > > fade_out
Definition: audioregion.cc:69
Gdk::Cursor * fade_in
Definition: mouse_cursors.h:45
LIBARDOUR_API PBD::PropertyDescriptor< boost::shared_ptr< AutomationList > > fade_in
Definition: audioregion.cc:67
Gdk::Cursor * right_side_trim
Definition: mouse_cursors.h:39
Gdk::Cursor * resize_top
Definition: mouse_cursors.h:66
Gdk::Cursor * time_fx
Definition: mouse_cursors.h:53
Gdk::Cursor * fade_out
Definition: mouse_cursors.h:46
void set_cursor_set(const std::string &name)
Gdk::Cursor * fader
Definition: mouse_cursors.h:54
LIBPBD_API Transmitter info
Gdk::Cursor * resize_top_right
Definition: mouse_cursors.h:67
Gdk::Cursor * midi_erase
Definition: mouse_cursors.h:59
Gdk::Cursor * trimmer
Definition: mouse_cursors.h:38
Gdk::Cursor * midi_resize
Definition: mouse_cursors.h:58
Gdk::Cursor * scissors
Definition: mouse_cursors.h:37
Gdk::Cursor * speaker
Definition: mouse_cursors.h:55
Gdk::Cursor * anchored_left_side_trim
Definition: mouse_cursors.h:42
Gdk::Cursor * midi_select
Definition: mouse_cursors.h:57
const char * name
Gdk::Cursor * wait
Definition: mouse_cursors.h:61
Gdk::Cursor * resize_bottom_right
Definition: mouse_cursors.h:69
Gdk::Cursor * up_down
Definition: mouse_cursors.h:60
std::string _cursor_set
Definition: mouse_cursors.h:87
Gdk::Cursor * zoom_out
Definition: mouse_cursors.h:52
Gdk::Cursor * anchored_right_side_trim
Definition: mouse_cursors.h:40
Gdk::Cursor * transparent
Definition: mouse_cursors.h:63
Gdk::Cursor * resize_right
Definition: mouse_cursors.h:68
Gdk::Cursor * resize_bottom_left
Definition: mouse_cursors.h:71
Gdk::Cursor * cross_hair
Definition: mouse_cursors.h:36
std::string get_icon_path(const char *, std::string icon_set=std::string(), bool is_image=true)
Gdk::Cursor * left_side_trim
Definition: mouse_cursors.h:41
static int load_cursor_info(const std::string &path)
Definition: cursors.cc:42
Glib::RefPtr< Gdk::Pixbuf > get_icon(const char *cname)
Definition: utils.cc:674
Gdk::Cursor * zoom_in
Definition: mouse_cursors.h:51
static Gdk::Cursor * _invalid
Definition: mouse_cursors.h:91
Gdk::Cursor * expand_left_right
Definition: mouse_cursors.h:73