black bg for meters, font fixups for startup message, new notebook widget (incomplete)
[ardour.git] / gtk2_ardour / editor_hscroller.cc
1 /*
2     Copyright (C) 2002 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     $Id$
19 */
20
21 #include "editor.h"
22
23 #include <ardour/session.h>
24
25 using namespace std;
26 using namespace ARDOUR;
27
28 void
29 Editor::hscroll_slider_allocate (Gtk::Allocation &alloc)
30 {
31         //edit_hscroll_slider_width = alloc->width;
32         //edit_hscroll_slider_height = alloc->height ;
33
34         if (session) {
35                 track_canvas_scroller.get_hadjustment()->set_upper (session->current_end_frame() / frames_per_unit);
36         }
37
38 }
39
40 gint
41 Editor::hscroll_slider_expose (GdkEventExpose *ev)
42 {
43         GdkRectangle draw_rect;
44         GdkRectangle bar_rect;
45         gint bar_max = edit_hscroll_slider_width - 2;
46
47         bar_rect.y = 1;
48         bar_rect.height = edit_hscroll_slider_height - 2;
49
50         if (session) {
51                 bar_rect.width = (gint) floor (bar_max * ((canvas_width * frames_per_unit) / session->current_end_frame()));
52
53                 if (bar_rect.width > bar_max) {
54                         bar_rect.x = 1;
55                         bar_rect.width = bar_max;
56                 } else {
57                         bar_rect.x = 1 + (gint) floor (bar_max * ((double) leftmost_frame / session->current_end_frame()));
58                 }
59                 
60         } else {
61                 bar_rect.x = 1;
62                 bar_rect.width = bar_max;
63         }
64
65         /* make sure we can see the bar at all times, and have enough to do zoom-trim on */
66
67         bar_rect.width = max ((guint16) (edit_hscroll_edge_width+5), (guint16) bar_rect.width);
68
69         gdk_rectangle_intersect (&ev->area, &bar_rect, &draw_rect);
70
71         gtk_paint_box (edit_hscroll_slider.get_style()->gobj(),
72                        edit_hscroll_slider.get_window()->gobj(),
73                        GTK_STATE_ACTIVE, 
74                        GTK_SHADOW_IN, 
75                        &ev->area, 
76                        GTK_WIDGET(edit_hscroll_slider.gobj()),
77                        "trough",
78                        0, 0, -1, -1);
79
80         gtk_paint_box (edit_hscroll_slider.get_style()->gobj(),
81                        edit_hscroll_slider.get_window()->gobj(),
82                        GTK_STATE_NORMAL, 
83                        GTK_SHADOW_OUT, 
84                        &draw_rect,
85                        GTK_WIDGET(edit_hscroll_slider.gobj()),
86                        "hscale",
87                        bar_rect.x, bar_rect.y, bar_rect.width, bar_rect.height);
88
89
90         return TRUE;
91 }
92
93 gint
94 Editor::hscroll_slider_button_press (GdkEventButton *ev)
95 {
96         if (!session) {
97                 return TRUE;
98         }
99
100         edit_hscroll_dragging = true;
101         //cerr << "PRESS" << endl;
102
103         return TRUE;
104         
105         gint start;
106         gint width;
107         gint end;
108         gint x;
109
110         start = (gint) floor (edit_hscroll_slider_width * ((double) leftmost_frame / session->current_end_frame()));
111         width = (gint) floor (edit_hscroll_slider_width * ((canvas_width * frames_per_unit) / session->current_end_frame()));
112
113         end = start + width - 1;
114         x = (gint) max (0.0, ev->x);
115         
116         if (x >= start && x <= end) {
117                 
118                 edit_hscroll_drag_last = x;
119                 edit_hscroll_dragging = true;
120                 edit_hscroll_slider.add_modal_grab();
121         }
122
123         return TRUE;
124 }
125
126 gint
127 Editor::hscroll_slider_button_release (GdkEventButton *ev)
128 {
129         if (!session) {
130                 return TRUE;
131         }
132
133         gint start;
134         gint width;
135         gint end;
136         gint x;
137         gint bar_max = edit_hscroll_slider_width - 2;
138         jack_nframes_t new_leftmost = 0;
139
140         //cerr << "RELESAE" << endl;
141
142         if (edit_hscroll_dragging) {
143                 // lets do a tempo redisplay now only, because it is dog slow
144                 tempo_map_changed (Change (0));
145                 edit_hscroll_dragging = false;
146         }
147         
148         return TRUE;
149
150         start = (gint) floor (bar_max * ((double) leftmost_frame / session->current_end_frame()));
151         width = (gint) floor (bar_max * ((canvas_width * frames_per_unit) / session->current_end_frame()));
152
153         end = start + width - 1;
154         x = (gint) max (0.0, ev->x);
155
156         if (!edit_hscroll_dragging) {
157
158                 new_leftmost = (jack_nframes_t) floor (((double) x/bar_max) * session->current_end_frame());
159                 reposition_x_origin (new_leftmost);
160         }
161
162         if (edit_hscroll_dragging) {
163                 // lets do a tempo redisplay now only, because it is dog slow
164                 tempo_map_changed (Change (0));
165                 edit_hscroll_dragging = false;
166                 edit_hscroll_slider.remove_modal_grab();
167         } 
168
169         return TRUE;
170 }
171
172 gint
173 Editor::hscroll_slider_motion (GdkEventMotion *ev)
174 {
175         gint x, y;
176         Gdk::ModifierType state;
177         gint bar_max = edit_hscroll_slider_width - 2;
178
179         if (!session || !edit_hscroll_dragging) {
180                 return TRUE;
181         }
182
183         edit_hscroll_slider.get_window()->get_pointer (x, y, state);
184
185         jack_nframes_t new_frame;
186         jack_nframes_t frames;
187         double distance;
188         double fract;
189
190         distance = x - edit_hscroll_drag_last;
191         fract = fabs (distance) / bar_max;
192         frames = (jack_nframes_t) floor (session->current_end_frame() * fract);
193
194         if (distance < 0) {
195                 if (leftmost_frame < frames) {
196                         new_frame = 0;
197                 } else {
198                         new_frame = leftmost_frame - frames;
199                 }
200         } else {
201                 if (leftmost_frame > max_frames - frames) {
202                         new_frame = max_frames;
203                 } else {
204                         new_frame = leftmost_frame + frames;
205                 }
206         }
207
208         if (new_frame != leftmost_frame) {
209                 reposition_x_origin (new_frame);
210         }
211
212         edit_hscroll_drag_last = x;
213         
214         return TRUE;
215 }
216
217 void
218 Editor::update_hscroller ()
219 {
220         //edit_hscroll_slider.queue_draw ();
221 //      if (session) {
222 //              track_canvas_scroller.get_hadjustment()->set_upper (session->current_end_frame() / frames_per_unit);
223 //              track_canvas_scroller.get_hadjustment()->set_value (leftmost_frame/frames_per_unit);
224 //      }
225 }
226
227 gint
228 Editor::hscroll_left_arrow_button_press (GdkEventButton *ev)
229 {
230         if (!session) {
231                 return FALSE;
232         }
233
234         start_canvas_autoscroll (-1);
235         return TRUE;
236 }
237
238 gint
239 Editor::hscroll_right_arrow_button_press (GdkEventButton *ev)
240 {
241         if (!session) {
242                 return FALSE;
243         }
244
245         start_canvas_autoscroll (1);
246         return TRUE;
247 }
248
249 gint
250 Editor::hscroll_left_arrow_button_release (GdkEventButton *ev)
251 {
252         if (!session) {
253                 return FALSE;
254         }
255
256         stop_canvas_autoscroll ();
257         return TRUE;
258 }
259
260 gint
261 Editor::hscroll_right_arrow_button_release (GdkEventButton *ev)
262 {
263         if (!session) {
264                 return FALSE;
265         }
266
267         stop_canvas_autoscroll ();
268         return TRUE;
269 }