Initial attempt at i18n support using gettext
[synfig.git] / synfig-studio / trunk / src / gtkmm / widget_timeslider.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file widget_timeslider.cpp
3 **      \brief Time Slider Widget Implementation File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "widget_timeslider.h"
34
35 #include <ETL/misc>
36
37 #include <cmath>
38
39 #include "general.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48
49 using studio::Widget_Timeslider;
50
51 /* === M A C R O S ========================================================= */
52
53 /* === G L O B A L S ======================================================= */
54 const double zoominfactor = 0.75;
55 const double zoomoutfactor = 1/zoominfactor;
56
57 /* === P R O C E D U R E S ================================================= */
58
59 Gdk::Color get_interp_color(synfig::Interpolation x)
60 {
61         switch(x)
62         {
63         case INTERPOLATION_TCB:
64                 return Gdk::Color("#00B000");
65
66                 break;
67
68         case INTERPOLATION_LINEAR:
69                 return Gdk::Color("#B0B000");
70                 break;
71
72         case INTERPOLATION_CONSTANT:
73                 return Gdk::Color("#C70000");
74                 break;
75
76         case INTERPOLATION_HALT:
77                 return Gdk::Color("#00b0b0");
78                 break;
79
80         case INTERPOLATION_MANUAL:
81                 return Gdk::Color("#B000B0");
82                 break;
83
84         case INTERPOLATION_UNDEFINED: default:
85                 return Gdk::Color("#808080");
86                 break;
87         }
88 }
89
90 static Gdk::Color
91 color_darken(Gdk::Color x, float amount)
92 {
93         double   red = x.get_red_p()   * amount;
94         double green = x.get_green_p() * amount;
95         double  blue = x.get_blue_p()  * amount;
96
97         x.set_rgb_p(  red > 1 ? 1 : red,
98                                 green > 1 ? 1 : green,
99                                  blue > 1 ? 1 : blue);
100
101         return x;
102 }
103
104 void
105 studio::render_time_point_to_window(
106         const Glib::RefPtr<Gdk::Drawable>& window,
107         const Gdk::Rectangle& area,
108         const synfig::TimePoint &tp,
109         bool selected
110 )
111 {
112         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window));
113         const Gdk::Color black("#000000");
114
115         if(selected)
116                 gc->set_line_attributes(2,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
117         else
118                 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
119
120         Gdk::Color color;
121         std::vector<Gdk::Point> points;
122
123 /*-     BEFORE ------------------------------------- */
124
125         color=get_interp_color(tp.get_before());
126         color=color_darken(color,1.0f);
127         if(selected)color=color_darken(color,1.3f);
128         gc->set_rgb_fg_color(color);
129
130         switch(tp.get_before())
131         {
132         case INTERPOLATION_TCB:
133                 window->draw_arc(
134                         gc,
135                         true,
136                         area.get_x(),
137                         area.get_y(),
138                         area.get_width(),
139                         area.get_height(),
140                         64*90,
141                         64*180
142                 );
143                 gc->set_rgb_fg_color(black);
144                 window->draw_arc(
145                         gc,
146                         false,
147                         area.get_x(),
148                         area.get_y(),
149                         area.get_width(),
150                         area.get_height(),
151                         64*90,
152                         64*180
153                 );
154                 break;
155
156         case INTERPOLATION_HALT:
157                 window->draw_arc(
158                         gc,
159                         true,
160                         area.get_x(),
161                         area.get_y(),
162                         area.get_width(),
163                         area.get_height()*2,
164                         64*90,
165                         64*90
166                 );
167                 gc->set_rgb_fg_color(black);
168                 window->draw_arc(
169                         gc,
170                         false,
171                         area.get_x(),
172                         area.get_y(),
173                         area.get_width(),
174                         area.get_height()*2,
175                         64*90,
176                         64*90
177                 );
178                 break;
179
180         case INTERPOLATION_LINEAR:
181                 points.clear();
182                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
183                 points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()));
184                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
185                 window->draw_polygon(gc,true,points);
186                 gc->set_rgb_fg_color(black);
187                 window->draw_lines(gc,points);
188                 break;
189
190         case INTERPOLATION_CONSTANT:
191                 points.clear();
192                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
193                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/4,area.get_y()));
194                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/4,area.get_y()+area.get_height()/2));
195                 points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()/2));
196                 points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()));
197                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
198                 window->draw_polygon(gc,true,points);
199                 gc->set_rgb_fg_color(black);
200                 window->draw_lines(gc,points);
201                 break;
202
203         case INTERPOLATION_UNDEFINED: default:
204                 points.clear();
205                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
206                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/3,area.get_y()));
207                 points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()/3));
208                 points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()*2/3));
209                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/3,area.get_y()+area.get_height()));
210                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
211                 window->draw_polygon(gc,true,points);
212                 gc->set_rgb_fg_color(black);
213                 window->draw_lines(gc,points);
214                 break;
215         }
216
217 /*-     AFTER -------------------------------------- */
218
219         color=get_interp_color(tp.get_after());
220         color=color_darken(color,0.8f);
221         if(selected)color=color_darken(color,1.3f);
222         gc->set_rgb_fg_color(color);
223
224
225         switch(tp.get_after())
226         {
227         case INTERPOLATION_TCB:
228                 window->draw_arc(
229                         gc,
230                         true,
231                         area.get_x(),
232                         area.get_y(),
233                         area.get_width(),
234                         area.get_height(),
235                         64*270,
236                         64*180
237                 );
238                 gc->set_rgb_fg_color(black);
239                 window->draw_arc(
240                         gc,
241                         false,
242                         area.get_x(),
243                         area.get_y(),
244                         area.get_width(),
245                         area.get_height(),
246                         64*270,
247                         64*180
248                 );
249                 break;
250
251         case INTERPOLATION_HALT:
252                 window->draw_arc(
253                         gc,
254                         true,
255                         area.get_x(),
256                         area.get_y()-area.get_height(),
257                         area.get_width(),
258                         area.get_height()*2,
259                         64*270,
260                         64*90
261                 );
262                 gc->set_rgb_fg_color(black);
263                 window->draw_arc(
264                         gc,
265                         false,
266                         area.get_x(),
267                         area.get_y()-area.get_height(),
268                         area.get_width(),
269                         area.get_height()*2,
270                         64*270,
271                         64*90
272                 );
273                 break;
274
275         case INTERPOLATION_LINEAR:
276                 points.clear();
277                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
278                 points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()));
279                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
280                 window->draw_polygon(gc,true,points);
281                 gc->set_rgb_fg_color(black);
282                 window->draw_lines(gc,points);
283                 break;
284
285         case INTERPOLATION_CONSTANT:
286                 points.clear();
287                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
288                 points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()));
289                 points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()+area.get_height()/2));
290                 points.push_back(Gdk::Point(area.get_x()+area.get_width()*3/4,area.get_y()+area.get_height()/2));
291                 points.push_back(Gdk::Point(area.get_x()+area.get_width()*3/4,area.get_y()+area.get_height()));
292                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
293                 window->draw_polygon(gc,true,points);
294                 gc->set_rgb_fg_color(black);
295                 window->draw_lines(gc,points);
296                 break;
297
298         case INTERPOLATION_UNDEFINED: default:
299                 points.clear();
300                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
301                 points.push_back(Gdk::Point(area.get_x()+area.get_width()*2/3,area.get_y()));
302                 points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()+area.get_height()/3));
303                 points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()+area.get_height()*2/3));
304                 points.push_back(Gdk::Point(area.get_x()+area.get_width()*2/3,area.get_y()+area.get_height()));
305                 points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
306                 window->draw_polygon(gc,true,points);
307                 gc->set_rgb_fg_color(black);
308                 window->draw_lines(gc,points);
309                 break;
310         }
311
312 }
313
314 /* === M E T H O D S ======================================================= */
315
316 /* === E N T R Y P O I N T ================================================= */
317 double defaultfps = 24;
318 const int fullheight = 20;
319
320 Widget_Timeslider::Widget_Timeslider()
321 :layout(Pango::Layout::create(get_pango_context())),
322 adj_default(0,0,2,1/defaultfps,10/defaultfps),
323 adj_timescale(0),
324 //invalidated(false),
325 last_event_time(0),
326 fps(defaultfps),
327 dragscroll(false)
328 {
329         set_size_request(-1,fullheight);
330
331         //                click                    scroll                     zoom
332         add_events( Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK
333                                 | Gdk::BUTTON_MOTION_MASK | Gdk::SCROLL_MASK );
334
335         set_time_adjustment(&adj_default);
336         //update_times();
337 }
338
339 Widget_Timeslider::~Widget_Timeslider()
340 {
341 }
342
343 void Widget_Timeslider::set_time_adjustment(Gtk::Adjustment *x)
344 {
345         //disconnect old connections
346         time_value_change.disconnect();
347         time_other_change.disconnect();
348
349         //connect update function to new adjustment
350         adj_timescale = x;
351
352         if(x)
353         {
354                 time_value_change = x->signal_value_changed().connect(sigc::mem_fun(*this,&Widget_Timeslider::queue_draw));
355                 time_other_change = x->signal_changed().connect(sigc::mem_fun(*this,&Widget_Timeslider::queue_draw));
356                 //invalidated = true;
357                 //refresh();
358         }
359 }
360
361 void Widget_Timeslider::set_global_fps(float d)
362 {
363         if(fps != d)
364         {
365                 fps = d;
366
367                 //update everything since we need to redraw already
368                 //invalidated = true;
369                 //refresh();
370                 queue_draw();
371         }
372 }
373
374 /*void Widget_Timeslider::update_times()
375 {
376         if(adj_timescale)
377         {
378                 start = adj_timescale->get_lower();
379                 end = adj_timescale->get_upper();
380                 current = adj_timescale->get_value();
381         }
382 }*/
383
384 void Widget_Timeslider::refresh()
385 {
386 }
387 /*
388 {
389         if(invalidated)
390         {
391                 queue_draw();
392         }else if(adj_timescale)
393         {
394                 double  l = adj_timescale->get_lower(),
395                                 u = adj_timescale->get_upper(),
396                                 v = adj_timescale->get_value();
397
398                 bool invalid = (l != start) || (u != end) || (v != current);
399
400                 start = l;
401                 end = u;
402                 current = v;
403
404                 if(invalid) queue_draw();
405         }
406 }*/
407
408 bool Widget_Timeslider::redraw(bool /*doublebuffer*/)
409 {
410         Glib::RefPtr<Gdk::Window> window = get_window();
411
412         if(!window) return false;
413
414         Glib::RefPtr<Gdk::GC>   gc = Gdk::GC::create(window);
415         if(!gc) return false;
416
417         //synfig::info("Drawing Timeslider");
418         //clear and update to current values
419         //invalidated = false;
420         //update_times();
421
422         //draw grey rectangle
423         Gdk::Color      c("#7f7f7f");
424         gc->set_rgb_fg_color(c);
425         gc->set_background(c);
426
427         //Get the data for the window and the params to draw it...
428         int w = get_width(), h = get_height();
429
430         window->draw_rectangle(gc,true,0,0,w,h);
431
432         const double EPSILON = 1e-6;
433         if(!adj_timescale || w == 0) return true;
434
435         //Get the time information since we now know it's valid
436         double  start = adj_timescale->get_lower(),
437                         end = adj_timescale->get_upper(),
438                         current = adj_timescale->get_value();
439
440         if(end-start < EPSILON) return true;
441
442         //synfig::info("Drawing Lines");
443
444         //draw all the time stuff
445         double dtdp = (end - start)/get_width();
446         double dpdt = 1/dtdp;
447
448         //lines
449
450         //Draw the time line...
451         double tpx = (current-start)*dpdt;
452         gc->set_rgb_fg_color(Gdk::Color("#ffaf00"));
453         window->draw_line(gc,round_to_int(tpx),0,round_to_int(tpx),fullheight);
454
455         //normal line/text color
456         gc->set_rgb_fg_color(Gdk::Color("#333333"));
457
458         //draw these lines... (always 5 between) maybe 6?
459         const int subdiv = 4;
460
461         //1h 45 30 20 10 5
462         //..., 3m, 2m, 1m30s, 1m, 30s, 20s, 10s, 5s, 3s, 2s, 1s, 0.5s
463         //frames... (how???)
464         double ranges[] =
465         { 1.0/fps,subdiv/fps,0.25,0.5, 1, 2, 3, 5, 10, 20, 30, 60, 90, 120, 180, 300, 600, 1200, 1800, 2700, 3600 };
466         //{ 3600, 2700, 1800, 1200, 600, 300, 180, 120, 90, 60, 30, 20, 10, 5, 3, 2, 1, 0.5 };
467         const int ranges_size = sizeof(ranges)/sizeof(double);
468
469         double lowerrange = dtdp*75, upperrange = dtdp*150;
470         double midrange = (lowerrange + upperrange)/2;
471
472         //find most ideal scale
473         double scale = ranges[0];
474         {
475                 double *val = binary_find(ranges, ranges+ranges_size, midrange);
476                 double *after = val+1;
477
478                 if(val >= ranges+ranges_size)
479                 {
480                         val = ranges+ranges_size-1;
481                 }
482
483                 if(after >= ranges+ranges_size)
484                 {
485                         after = ranges+ranges_size-1;
486                 }
487
488                 scale = *val;
489
490                 double diff = abs(scale - midrange), diff2 = abs(*after - midrange);
491                 if(diff2 < diff)
492                         scale = *after;
493         }
494
495         //synfig::info("Range found: (l %.2lf,u %.2lf - m %.2lf) -> %.2lf",lowerrange,upperrange,midrange,scale);
496
497         //search around this area to get the right one
498
499
500         //get first valid line and its position in pixel space
501         double time = 0;
502         double pixel = 0;
503
504         int sdindex = 0;
505
506         double subr = scale / subdiv;
507
508         //get its position inside...
509         time = ceil(start/subr)*subr - start;
510         pixel = time*dpdt;
511
512         //absolute time of the line to be drawn
513         time += start;
514
515         { //inside the big'n
516                 double t = (time/scale - floor(time/scale))*subdiv; // the difference from the big mark in 0:1
517                 //sdindex = (int)floor(t + 0.5); //get how far through the range it is...
518                 sdindex = round_to_int(t); //get how far through the range it is...
519
520                 //synfig::info("Extracted fr %.2lf -> %d", t, sdindex);
521         }
522
523         //synfig::info("Initial values: %.4lf t, %.1lf pixels, %d i", time,pixel,sdindex);
524
525         //loop to draw
526         const int heightbig = 12;
527         const int heightsmall = 4;
528
529         int width = get_width();
530         while( pixel < width )
531         {
532                 int xpx = round_to_int(pixel);
533
534                 //draw big
535                 if(sdindex == 0)
536                 {
537                         window->draw_line(gc,xpx,0,xpx,heightbig);
538                         //round the time to nearest frame and draw the text
539                         Time tm((double)time);
540                         if(get_global_fps()) tm.round(get_global_fps());
541                         Glib::ustring timecode(tm.get_string(get_global_fps(),App::get_time_format()));
542
543                         //gc->set_rgb_fg_color(Gdk::Color("#000000"));
544                         layout->set_text(timecode);
545                         window->draw_layout(gc,xpx+2,heightsmall,layout);
546                 }else
547                 {
548                         window->draw_line(gc,xpx,0,xpx,heightsmall);
549                 }
550
551                 //increment time and position
552                 pixel += subr / dtdp;
553                 time += subr;
554
555                 //increment index
556                 if(++sdindex >= subdiv) sdindex -= subdiv;
557         }
558
559         return true;
560 }
561
562 bool Widget_Timeslider::on_motion_notify_event(GdkEventMotion* event) //for dragging
563 {
564         if(!adj_timescale) return false;
565
566         Gdk::ModifierType mod = Gdk::ModifierType(event->state);
567
568         //scrolling...
569
570         //NOTE: we might want to address the possibility of dragging with both buttons held down
571
572         if(mod & Gdk::BUTTON2_MASK)
573         {
574
575                 //we need this for scrolling by dragging
576                 double  curx = event->x;
577
578                 double  start = adj_timescale->get_lower(),
579                                 end = adj_timescale->get_upper();
580
581
582                 if(dragscroll)
583                 {
584                         if(event->time-last_event_time<30)
585                                 return false;
586                         else
587                                 last_event_time=event->time;
588
589                         if(abs(lastx - curx) < 1 && end != start) return true;
590                         //translate the window and correct it
591
592                         //update our stuff so we are operating correctly
593                         //invalidated = true;
594                         //update_times();
595
596                         //Note: Use inverse of mouse movement because of conceptual space relationship
597                         double diff = lastx - curx; //curx - lastx;
598
599                         //NOTE: This might be incorrect...
600                         //fraction to move...
601                         double dpx = (end - start)/get_width();
602                         lastx = curx;
603
604                         diff *= dpx;
605
606                         //Adjust...
607                         start += diff;
608                         end += diff;
609
610                         //But clamp to bounds if they exist...
611                         //HACK - bounds should not be required for this slider
612                         if(adj_bounds)
613                         {
614                                 if(start < adj_bounds->get_lower())
615                                 {
616                                         diff = adj_bounds->get_lower() - start;
617                                         start += diff;
618                                         end += diff;
619                                 }
620
621                                 if(end > adj_bounds->get_upper())
622                                 {
623                                         diff = adj_bounds->get_upper() - end;
624                                         start += diff;
625                                         end += diff;
626                                 }
627                         }
628
629                         //synfig::info("Scrolling timerange to (%.4f,%.4f)",start,end);
630
631                         adj_timescale->set_lower(start);
632                         adj_timescale->set_upper(end);
633
634                         adj_timescale->changed();
635                 }else
636                 {
637                         dragscroll = true;
638                         lastx = curx;
639                         //lasty = cury;
640                 }
641
642                 return true;
643         }
644
645         if(mod & Gdk::BUTTON1_MASK)
646         {
647                 double curx = event->x;
648
649                 //get time from drag...
650                 double  start = adj_timescale->get_lower(),
651                                 end = adj_timescale->get_upper(),
652                                 current = adj_timescale->get_value();
653                 double t = start + curx*(end - start)/get_width();
654
655                 //snap it to fps - if they exist...
656                 if(fps)
657                 {
658                         t = floor(t*fps + 0.5)/fps;
659                 }
660
661                 //set time if needed
662                 if(current != t)
663                 {
664                         adj_timescale->set_value(t);
665
666                         //Fixed this to actually do what it's supposed to...
667                         if(event->time-last_event_time>50)
668                         {
669                                 adj_timescale->value_changed();
670                                 last_event_time = event->time;
671                         }
672                 }
673
674                 return true;
675         }
676
677         return false;
678 }
679
680 bool Widget_Timeslider::on_scroll_event(GdkEventScroll* event) //for zooming
681 {
682         if(!adj_timescale) return false;
683
684         //Update so we are calculating based on current values
685         //update_times();
686
687         //figure out if we should center ourselves on the current time
688         bool center = false;
689
690         //we want to zoom in on the time value if control is held down
691         if(Gdk::ModifierType(event->state) & Gdk::CONTROL_MASK)
692         {
693                 center = true;
694         }
695
696         switch(event->direction)
697         {
698                 case GDK_SCROLL_UP: //zoom in
699                 {
700                         zoom_in(center);
701
702                         return true;
703                 }
704                 case GDK_SCROLL_DOWN: //zoom out
705                 {
706                         zoom_out(center);
707
708                         return true;
709                 }
710
711                 default:
712                 {
713                         return false;
714                 }
715         }
716 }
717
718 void Widget_Timeslider::zoom_in(bool centerontime)
719 {
720         if(!adj_timescale) return;
721
722         double  start = adj_timescale->get_lower(),
723                         end = adj_timescale->get_upper(),
724                         current = adj_timescale->get_value();
725
726         double focuspoint = centerontime ? current : (start + end)/2;
727
728         //calculate new beginning and end
729         end = focuspoint + (end-focuspoint)*zoominfactor;
730         start = focuspoint + (start-focuspoint)*zoominfactor;
731
732         //synfig::info("Zooming in timerange to (%.4f,%.4f)",start,end);
733         if(adj_bounds)
734         {
735                 if(start < adj_bounds->get_lower())
736                 {
737                         start = adj_bounds->get_lower();
738                 }
739
740                 if(end > adj_bounds->get_upper())
741                 {
742                         end = adj_bounds->get_upper();
743                 }
744         }
745
746         //reset values
747         adj_timescale->set_lower(start);
748         adj_timescale->set_upper(end);
749
750         //call changed function
751         adj_timescale->changed();
752 }
753
754 void Widget_Timeslider::zoom_out(bool centerontime)
755 {
756         if(!adj_timescale) return;
757
758         double  start = adj_timescale->get_lower(),
759                         end = adj_timescale->get_upper(),
760                         current = adj_timescale->get_value();
761
762         double focuspoint = centerontime ? current : (start + end)/2;
763
764         //calculate new beginning and end
765         end = focuspoint + (end-focuspoint)*zoomoutfactor;
766         start = focuspoint + (start-focuspoint)*zoomoutfactor;
767
768         //synfig::info("Zooming out timerange to (%.4f,%.4f)",start,end);
769         if(adj_bounds)
770         {
771                 if(start < adj_bounds->get_lower())
772                 {
773                         start = adj_bounds->get_lower();
774                 }
775
776                 if(end > adj_bounds->get_upper())
777                 {
778                         end = adj_bounds->get_upper();
779                 }
780         }
781
782         //reset values
783         adj_timescale->set_lower(start);
784         adj_timescale->set_upper(end);
785
786         //call changed function
787         adj_timescale->changed();
788 }
789
790 bool Widget_Timeslider::on_button_press_event(GdkEventButton *event) //for clicking
791 {
792         switch(event->button)
793         {
794                 //time click...
795                 case 1:
796                 {
797                         double  start = adj_timescale->get_lower(),
798                                         end = adj_timescale->get_upper(),
799                                         current = adj_timescale->get_value();
800
801                         double w = get_width();
802                         double t = start + (end - start) * event->x / w;
803
804                         t = floor(t*fps + 0.5)/fps;
805
806                         /*synfig::info("Clicking time from %.3lf to %.3lf [(%.2lf,%.2lf) %.2lf / %.2lf ... %.2lf",
807                                                 current, vt, start, end, event->x, w, fps);*/
808
809                         if(t != current)
810                         {
811                                 current = t;
812
813                                 if(adj_timescale)
814                                 {
815                                         adj_timescale->set_value(current);
816                                         adj_timescale->value_changed();
817                                 }
818                         }
819
820                         break;
821                 }
822
823                 //scroll click
824                 case 2:
825                 {
826                         //start dragging
827                         dragscroll = true;
828                         lastx = event->x;
829                         //lasty = event->y;
830
831                         return true;
832                 }
833
834                 default:
835                 {
836                         break;
837                 }
838         }
839
840         return false;
841 }
842
843 bool Widget_Timeslider::on_button_release_event(GdkEventButton *event) //end drag
844 {
845         switch(event->button)
846         {
847                 case 2:
848                 {
849                         //start dragging
850                         dragscroll = false;
851                         return true;
852                 }
853
854                 default:
855                 {
856                         break;
857                 }
858         }
859
860         return false;
861 }