|
Carlos Lopez |
a09598 |
/* === S Y N F I G ========================================================= */
|
|
Carlos Lopez |
a09598 |
/*! \file widget_timeslider.cpp
|
|
Carlos Lopez |
a09598 |
** \brief Time Slider Widget Implementation File
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** $Id$
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** \legal
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2004 Adrian Bentley
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2007, 2008 Chris Moore
|
|
Carlos Lopez |
a63df6 |
** Copyright (c) 2012, Carlos Lรณpez
|
|
|
b440da |
** ......... ... 2018 Ivan Mahonin
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is free software; you can redistribute it and/or
|
|
Carlos Lopez |
a09598 |
** modify it under the terms of the GNU General Public License as
|
|
Carlos Lopez |
a09598 |
** published by the Free Software Foundation; either version 2 of
|
|
Carlos Lopez |
a09598 |
** the License, or (at your option) any later version.
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is distributed in the hope that it will be useful,
|
|
Carlos Lopez |
a09598 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Carlos Lopez |
a09598 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Carlos Lopez |
a09598 |
** General Public License for more details.
|
|
Carlos Lopez |
a09598 |
** \endlegal
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
/* ========================================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === H E A D E R S ======================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#ifdef USING_PCH
|
|
Carlos Lopez |
a09598 |
# include "pch.h"
|
|
Carlos Lopez |
a09598 |
#else
|
|
Carlos Lopez |
a09598 |
#ifdef HAVE_CONFIG_H
|
|
Carlos Lopez |
a09598 |
# include <config.h></config.h>
|
|
Carlos Lopez |
a09598 |
#endif
|
|
Carlos Lopez |
a09598 |
|
|
|
f98e3a |
#include <cmath></cmath>
|
|
|
491f32 |
|
|
|
b440da |
#include <gdkmm general.h=""></gdkmm>
|
|
|
b440da |
|
|
Carlos Lopez |
a09598 |
#include <etl misc=""></etl>
|
|
Carlos Lopez |
a09598 |
|
|
|
491f32 |
#include <synfig general.h=""></synfig>
|
|
|
491f32 |
|
|
|
491f32 |
#include <gui app.h=""></gui>
|
|
|
491f32 |
|
|
|
491f32 |
#include "widget_timeslider.h"
|
|
Carlos Lopez |
a09598 |
|
|
|
abdbf2 |
#include <gui localization.h=""></gui>
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
#include "gui/timeplotdata.h"
|
|
Rodolfo Ribeiro Gomes |
50789e |
|
|
Carlos Lopez |
a09598 |
#endif
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === U S I N G =========================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
using namespace synfig;
|
|
|
b440da |
using namespace studio;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === M A C R O S ========================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === G L O B A L S ======================================================= */
|
|
|
b440da |
|
|
|
b440da |
const double zoominfactor = 1.25;
|
|
Carlos Lopez |
a09598 |
const double zoomoutfactor = 1/zoominfactor;
|
|
|
b440da |
const int fullheight = 20;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === P R O C E D U R E S ================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === M E T H O D S ======================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
static void
|
|
|
b440da |
calc_divisions(float fps, double range, double sub_range, double &out_step, int &out_subdivisions)
|
|
|
b440da |
{
|
|
|
b440da |
int ifps = etl::round_to_int(fps);
|
|
|
b440da |
if (ifps < 1) ifps = 1;
|
|
|
f98e3a |
|
|
|
b440da |
// build a list of all the factors of the frame rate
|
|
|
b440da |
int pos = 0;
|
|
|
b440da |
std::vector<double> ranges;</double>
|
|
|
b440da |
for(int i = 1; i*i <= ifps; i++)
|
|
|
b440da |
if (ifps % i == 0) {
|
|
|
b440da |
ranges.insert(ranges.begin() + pos, i/fps);
|
|
|
b440da |
if (i*i != ifps)
|
|
|
b440da |
ranges.insert(ranges.begin() + pos + 1, ifps/i/fps);
|
|
|
b440da |
pos++;
|
|
|
b440da |
}
|
|
|
b440da |
|
|
|
b440da |
{ // fill in any gaps where one factor is more than 2 times the previous
|
|
|
b440da |
std::vector<double>::iterator iter, next;</double>
|
|
|
b440da |
pos = 0;
|
|
|
b440da |
for(int pos = 0; pos < (int)ranges.size()-1; pos++) {
|
|
|
b440da |
next = ranges.begin() + pos;
|
|
|
b440da |
iter = next++;
|
|
|
b440da |
if (*iter*2 < *next)
|
|
|
b440da |
ranges.insert(next, *iter*2);
|
|
|
b440da |
}
|
|
|
b440da |
}
|
|
|
b440da |
|
|
|
b440da |
double more_ranges[] = {
|
|
|
b440da |
2, 3, 5, 10, 20, 30, 60, 90, 120, 180,
|
|
|
b440da |
300, 600, 1200, 1800, 2700, 3600, 3600*2,
|
|
|
b440da |
3600*4, 3600*8, 3600*16, 3600*32, 3600*64,
|
|
|
b440da |
3600*128, 3600*256, 3600*512, 3600*1024 };
|
|
|
b440da |
ranges.insert(ranges.end(), more_ranges, more_ranges + sizeof(more_ranges)/sizeof(double));
|
|
|
b440da |
|
|
|
b440da |
double mid_range = (range + sub_range)/2;
|
|
|
b440da |
|
|
|
b440da |
// find most ideal scale
|
|
|
b440da |
double scale;
|
|
|
b440da |
{
|
|
|
b440da |
std::vector<double>::iterator next = etl::binary_find(ranges.begin(), ranges.end(), mid_range);</double>
|
|
|
b440da |
std::vector<double>::iterator iter = next++;</double>
|
|
|
b440da |
if (iter == ranges.end()) iter--;
|
|
|
b440da |
if (next == ranges.end()) next--;
|
|
|
b440da |
if (fabs(*next - mid_range) < fabs(*iter - mid_range))
|
|
|
b440da |
iter = next;
|
|
|
b440da |
scale = *iter;
|
|
|
b440da |
}
|
|
|
b440da |
|
|
|
b440da |
// subdivide into this many tick marks (8 or less)
|
|
|
b440da |
int subdiv = etl::round_to_int(scale * ifps);
|
|
|
b440da |
if (subdiv > 8) {
|
|
|
b440da |
const int ideal = subdiv;
|
|
|
b440da |
|
|
|
b440da |
// find a number of tick marks that nicely divides the scale
|
|
|
b440da |
// (5 minutes divided by 6 is 50s, but that's not 'nice' -
|
|
|
b440da |
// 5 ticks of 1m each is much simpler than 6 ticks of 50s)
|
|
|
b440da |
for (subdiv = 8; subdiv > 0; subdiv--)
|
|
|
b440da |
if ((ideal <= ifps*2 && (ideal % (subdiv )) == 0) ||
|
|
|
b440da |
(ideal <= ifps*2*60 && (ideal % (subdiv*ifps )) == 0) ||
|
|
|
b440da |
(ideal <= ifps*2*60*60 && (ideal % (subdiv*ifps*60 )) == 0) ||
|
|
|
b440da |
(true && (ideal % (subdiv*ifps*60*60)) == 0))
|
|
|
b440da |
break;
|
|
|
b440da |
|
|
|
b440da |
// if we didn't find anything, use 4 ticks
|
|
|
b440da |
if (!subdiv)
|
|
|
b440da |
subdiv = 4;
|
|
|
b440da |
}
|
|
|
b440da |
|
|
|
b440da |
out_step = scale;
|
|
|
b440da |
out_subdivisions = subdiv;
|
|
|
b440da |
}
|
|
|
b440da |
|
|
|
b440da |
/* === E N T R Y P O I N T ================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
|
ab539e |
Widget_Timeslider::Widget_Timeslider():
|
|
|
ab539e |
layout(Pango::Layout::create(get_pango_context())),
|
|
|
2a96c7 |
lastx()
|
|
Carlos Lopez |
a09598 |
{
|
|
|
ab539e |
set_size_request(-1, fullheight);
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
{ // prepare pattern for play bounds
|
|
|
2a96c7 |
const int pattern_step = 32;
|
|
|
2a96c7 |
Cairo::RefPtr<cairo::imagesurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, pattern_step, pattern_step);</cairo::imagesurface>
|
|
|
2a96c7 |
Cairo::RefPtr<cairo::context> cr = Cairo::Context::create(surface);</cairo::context>
|
|
|
2a96c7 |
cr->set_source_rgba(0.0, 0.0, 0.0, 0.25);
|
|
|
2a96c7 |
cr->scale((double)pattern_step, (double)pattern_step);
|
|
|
2a96c7 |
cr->set_line_width(0.375);
|
|
|
2a96c7 |
cr->move_to(1.75, -1.0);
|
|
|
2a96c7 |
cr->line_to(-1.0, 1.75);
|
|
|
2a96c7 |
cr->stroke();
|
|
|
2a96c7 |
cr->move_to(2.0, -0.25);
|
|
|
2a96c7 |
cr->line_to(-0.25, 2.0);
|
|
|
2a96c7 |
cr->stroke();
|
|
|
2a96c7 |
surface->flush();
|
|
|
2a96c7 |
|
|
|
2a96c7 |
play_bounds_pattern = Cairo::SurfacePattern::create(surface);
|
|
|
2a96c7 |
play_bounds_pattern->set_filter(Cairo::FILTER_NEAREST);
|
|
|
2a96c7 |
play_bounds_pattern->set_extend(Cairo::EXTEND_REPEAT);
|
|
|
2a96c7 |
}
|
|
|
2a96c7 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
time_plot_data = new TimePlotData(*this);
|
|
Rodolfo Ribeiro Gomes |
50789e |
time_plot_data->set_extra_time_margin(get_height());
|
|
Rodolfo Ribeiro Gomes |
50789e |
|
|
|
c2a017 |
// click / scroll / zoom
|
|
|
b440da |
add_events( Gdk::BUTTON_PRESS_MASK
|
|
|
b440da |
| Gdk::BUTTON_RELEASE_MASK
|
|
|
b440da |
| Gdk::BUTTON_MOTION_MASK
|
|
|
b440da |
| Gdk::SCROLL_MASK );
|
|
Rodolfo Ribeiro Gomes |
50789e |
|
|
Rodolfo Ribeiro Gomes |
50789e |
signal_configure_event().connect(
|
|
Rodolfo Ribeiro Gomes |
50789e |
sigc::mem_fun(*this, &Widget_Timeslider::on_configure_event));
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Widget_Timeslider::~Widget_Timeslider()
|
|
|
0a5bed |
{
|
|
|
0a5bed |
time_change.disconnect();
|
|
|
0a5bed |
time_bounds_change.disconnect();
|
|
Rodolfo Ribeiro Gomes |
50789e |
delete time_plot_data;
|
|
Rodolfo Ribeiro Gomes |
50789e |
}
|
|
Rodolfo Ribeiro Gomes |
50789e |
|
|
Rodolfo Ribeiro Gomes |
50789e |
const etl::handle<timemodel>&</timemodel>
|
|
Rodolfo Ribeiro Gomes |
50789e |
Widget_Timeslider::get_time_model() const
|
|
Rodolfo Ribeiro Gomes |
50789e |
{
|
|
Rodolfo Ribeiro Gomes |
50789e |
return time_plot_data->time_model;
|
|
|
0a5bed |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
void
|
|
|
2a96c7 |
Widget_Timeslider::set_time_model(const etl::handle<timemodel> &x)</timemodel>
|
|
Carlos Lopez |
a09598 |
{
|
|
Rodolfo Ribeiro Gomes |
50789e |
time_plot_data->set_time_model(x);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
void
|
|
|
2a96c7 |
Widget_Timeslider::draw_background(const Cairo::RefPtr<cairo::context> &cr)</cairo::context>
|
|
Carlos Lopez |
a09598 |
{
|
|
|
961c01 |
//draw grey rectangle
|
|
|
961c01 |
cr->save();
|
|
|
961c01 |
cr->set_source_rgb(0.5, 0.5, 0.5);
|
|
|
d421d7 |
cr->rectangle(0.0, 0.0, (double)get_width(), (double)get_height());
|
|
|
961c01 |
cr->fill();
|
|
|
961c01 |
cr->restore();
|
|
|
d421d7 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
bool Widget_Timeslider::on_configure_event(GdkEventConfigure* configure)
|
|
Rodolfo Ribeiro Gomes |
50789e |
{
|
|
Rodolfo Ribeiro Gomes |
50789e |
time_plot_data->set_extra_time_margin(configure->height);
|
|
Rodolfo Ribeiro Gomes |
50789e |
return false;
|
|
Rodolfo Ribeiro Gomes |
50789e |
}
|
|
Rodolfo Ribeiro Gomes |
50789e |
|
|
|
2a96c7 |
bool
|
|
|
2a96c7 |
Widget_Timeslider::on_draw(const Cairo::RefPtr<cairo::context> &cr)</cairo::context>
|
|
|
d421d7 |
{
|
|
|
b440da |
const double mark_height = 12.0;
|
|
|
b440da |
const double sub_mark_height = 4.0;
|
|
|
d421d7 |
|
|
|
d421d7 |
draw_background(cr);
|
|
|
d421d7 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
if (!time_plot_data->time_model || get_width() <= 0 || get_height() <= 0) return true;
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
const etl::handle<timemodel> & time_model = time_plot_data->time_model;</timemodel>
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
// Draw the time line...
|
|
Rodolfo Ribeiro Gomes |
50789e |
double tpx = time_plot_data->get_pixel_t_coord(time_plot_data->time) + 0.5;
|
|
|
961c01 |
cr->save();
|
|
|
961c01 |
cr->set_source_rgb(1.0, 175.0/255.0, 0.0);
|
|
|
961c01 |
cr->set_line_width(1.0);
|
|
|
961c01 |
cr->move_to(tpx, 0.0);
|
|
|
961c01 |
cr->line_to(tpx, fullheight);
|
|
|
961c01 |
cr->stroke();
|
|
|
961c01 |
cr->restore();
|
|
|
961c01 |
|
|
|
b440da |
// draw marks
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
// get divisions
|
|
|
b440da |
double big_step_value;
|
|
|
b440da |
int subdivisions;
|
|
|
b440da |
calc_divisions(
|
|
|
b440da |
time_model->get_frame_rate(),
|
|
Rodolfo Ribeiro Gomes |
50789e |
140.0/time_plot_data->k,
|
|
Rodolfo Ribeiro Gomes |
50789e |
280.0/time_plot_data->k,
|
|
|
b440da |
big_step_value,
|
|
|
b440da |
subdivisions );
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
step = time_model->round_time(Time(big_step_value/(double)subdivisions));
|
|
|
b440da |
step = std::max(time_model->get_step_increment(), step);
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
Time big_step = step * (double)subdivisions;
|
|
Rodolfo Ribeiro Gomes |
50789e |
Time current = big_step * floor((double)time_plot_data->lower_ex/(double)big_step);
|
|
|
b440da |
current = time_model->round_time(current);
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
// draw
|
|
|
961c01 |
cr->save();
|
|
|
961c01 |
cr->set_source_rgb(51.0/255.0,51.0/255.0,51.0/255.0);
|
|
|
961c01 |
cr->set_line_width(1.0);
|
|
Rodolfo Ribeiro Gomes |
50789e |
for(int i = 0; current <= time_plot_data->upper_ex; ++i, current = time_model->round_time(current + step)) {
|
|
Rodolfo Ribeiro Gomes |
50789e |
double x = time_plot_data->get_pixel_t_coord(current) + 0.5;
|
|
|
b440da |
if (i % subdivisions == 0) {
|
|
|
b440da |
// draw big
|
|
|
b440da |
cr->move_to(x, 0.0);
|
|
|
b440da |
cr->line_to(x, mark_height);
|
|
|
961c01 |
cr->stroke();
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
layout->set_text(
|
|
|
b440da |
current.get_string(
|
|
|
b440da |
time_model->get_frame_rate(),
|
|
|
b440da |
App::get_time_format() ));
|
|
|
b440da |
|
|
luz.paz |
99f3ef |
// Approximately a font size of 8 pixels.
|
|
Carlos Lopez |
a09598 |
// Pango::SCALE = 1024
|
|
Carlos Lopez |
a09598 |
// create_attr_size waits a number in 1000th of pixels.
|
|
Carlos Lopez |
a09598 |
// Should be user customizable in the future. Now it is fixed to 10
|
|
|
b440da |
Pango::AttrList attr_list;
|
|
Carlos Lopez |
a09598 |
Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*10));
|
|
Carlos Lopez |
a09598 |
pango_size.set_start_index(0);
|
|
Carlos Lopez |
a09598 |
pango_size.set_end_index(64);
|
|
Carlos Lopez |
a09598 |
attr_list.change(pango_size);
|
|
Carlos Lopez |
a09598 |
layout->set_attributes(attr_list);
|
|
|
b440da |
cr->move_to(x + 1.0, 0.0);
|
|
|
961c01 |
layout->show_in_cairo_context(cr);
|
|
|
b440da |
} else {
|
|
|
b440da |
// draw small
|
|
|
b440da |
cr->move_to(x, 0.0);
|
|
|
b440da |
cr->line_to(x, sub_mark_height);
|
|
|
961c01 |
cr->stroke();
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
}
|
|
|
961c01 |
cr->restore();
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
// Draw the time line
|
|
|
b440da |
Gdk::Cairo::set_source_color(cr, Gdk::Color("#ffaf00"));
|
|
|
b440da |
cr->set_line_width(3.0);
|
|
Rodolfo Ribeiro Gomes |
50789e |
double x = time_plot_data->get_pixel_t_coord(time_plot_data->time);
|
|
|
b440da |
cr->move_to(x, 0.0);
|
|
|
b440da |
cr->line_to(x, fullheight);
|
|
|
961c01 |
cr->stroke();
|
|
[d.j.a.y] Jerome Blanchi |
a3e898 |
|
|
|
2a96c7 |
// Draw play bounds
|
|
|
2a96c7 |
if (time_model->get_play_bounds_enabled()) {
|
|
Rodolfo Ribeiro Gomes |
50789e |
double offset = time_plot_data->get_double_pixel_t_coord(0);
|
|
|
2a96c7 |
Time bounds[2][2] {
|
|
Rodolfo Ribeiro Gomes |
50789e |
{ time_plot_data->lower_ex, time_model->get_play_bounds_lower() },
|
|
Rodolfo Ribeiro Gomes |
50789e |
{ time_model->get_play_bounds_upper(), time_plot_data->upper_ex } };
|
|
|
2a96c7 |
for(int i = 0; i < 2; ++i) {
|
|
|
2a96c7 |
if (bounds[i][0] < bounds[i][1]) {
|
|
Rodolfo Ribeiro Gomes |
50789e |
double x0 = time_plot_data->get_double_pixel_t_coord(bounds[i][0]);
|
|
Rodolfo Ribeiro Gomes |
50789e |
double x1 = time_plot_data->get_double_pixel_t_coord(bounds[i][1]);
|
|
|
2a96c7 |
double w = x1 - x0;
|
|
|
2a96c7 |
|
|
|
2a96c7 |
cr->save();
|
|
|
2a96c7 |
cr->rectangle(x0, 0.0, w, (double)get_height());
|
|
|
2a96c7 |
cr->clip();
|
|
|
2a96c7 |
cr->translate(offset, 0.0);
|
|
|
2a96c7 |
cr->set_source(play_bounds_pattern);
|
|
|
2a96c7 |
cr->paint();
|
|
|
2a96c7 |
cr->restore();
|
|
|
2a96c7 |
|
|
|
2a96c7 |
cr->save();
|
|
|
61adfd |
cr->set_line_width(1.0);
|
|
|
2a96c7 |
cr->set_source_rgba(0.0, 0.0, 0.0, 0.25);
|
|
|
61adfd |
cr->rectangle(x0 + 1.0, 1.0, w - 2.0, (double)get_height() - 2.0);
|
|
|
61adfd |
cr->stroke();
|
|
|
61adfd |
cr->set_source_rgba(0.0, 0.0, 0.0, 0.3);
|
|
|
61adfd |
cr->rectangle(x0 + 0.5, 0.5, w - 1.0, (double)get_height() - 1.0);
|
|
|
2a96c7 |
cr->stroke();
|
|
|
2a96c7 |
cr->restore();
|
|
|
2a96c7 |
}
|
|
|
2a96c7 |
}
|
|
|
2a96c7 |
}
|
|
|
2a96c7 |
|
|
Carlos Lopez |
a09598 |
return true;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
bool
|
|
|
2a96c7 |
Widget_Timeslider::on_button_press_event(GdkEventButton *event) //for clicking
|
|
Carlos Lopez |
a09598 |
{
|
|
|
b440da |
lastx = (double)event->x;
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
if (!time_plot_data->time_model || get_width() <= 0 || get_height() <= 0)
|
|
|
b440da |
return false;
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
if (event->button == 1) {
|
|
Rodolfo Ribeiro Gomes |
50789e |
Time time = time_plot_data->get_t_from_pixel_coord(event->x);
|
|
Rodolfo Ribeiro Gomes |
50789e |
time_plot_data->time_model->set_time(time);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
return event->button == 1 || event->button == 2;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
bool
|
|
|
2a96c7 |
Widget_Timeslider::on_button_release_event(GdkEventButton *event){
|
|
|
b440da |
lastx = (double)event->x;
|
|
|
b440da |
return event->button == 1 || event->button == 2;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
bool
|
|
|
2a96c7 |
Widget_Timeslider::on_motion_notify_event(GdkEventMotion* event) //for dragging
|
|
Carlos Lopez |
a09598 |
{
|
|
|
b440da |
double dx = (double)event->x - lastx;
|
|
|
b440da |
lastx = (double)event->x;
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
if (!time_plot_data->time_model || get_width() <= 0 || get_height() <= 0)
|
|
|
b440da |
return false;
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
Gdk::ModifierType mod = Gdk::ModifierType(event->state);
|
|
|
b440da |
if (mod & Gdk::BUTTON1_MASK) {
|
|
|
b440da |
// scrubbing
|
|
Rodolfo Ribeiro Gomes |
50789e |
Time time = time_plot_data->get_t_from_pixel_coord(event->x);
|
|
Rodolfo Ribeiro Gomes |
50789e |
time_plot_data->time_model->set_time(time);
|
|
|
b440da |
return true;
|
|
|
b440da |
} else
|
|
|
b440da |
if (mod & Gdk::BUTTON2_MASK) {
|
|
|
b440da |
// scrolling
|
|
Rodolfo Ribeiro Gomes |
ff22c3 |
Time dt(-dx*time_plot_data->dt);
|
|
Rodolfo Ribeiro Gomes |
50789e |
time_plot_data->time_model->move_by(dt);
|
|
|
b440da |
return true;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
return false;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
2a96c7 |
bool
|
|
|
2a96c7 |
Widget_Timeslider::on_scroll_event(GdkEventScroll* event) //for zooming
|
|
Carlos Lopez |
a09598 |
{
|
|
Rodolfo Ribeiro Gomes |
50789e |
etl::handle<timemodel> &time_model = time_plot_data->time_model;</timemodel>
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
if (!time_model || get_width() <= 0 || get_height() <= 0)
|
|
|
b440da |
return false;
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
50789e |
Time time = time_plot_data->get_t_from_pixel_coord(event->x);
|
|
Carlos Lopez |
a09598 |
|
|
|
b440da |
switch(event->direction) {
|
|
|
b440da |
case GDK_SCROLL_UP: //zoom in
|
|
|
b440da |
time_model->zoom(zoominfactor, time);
|
|
|
b440da |
return true;
|
|
|
b440da |
case GDK_SCROLL_DOWN: //zoom out
|
|
|
b440da |
time_model->zoom(zoomoutfactor, time);
|
|
|
b440da |
return true;
|
|
|
b440da |
case GDK_SCROLL_RIGHT:
|
|
|
b440da |
time_model->move_by(step);
|
|
|
b440da |
return true;
|
|
|
b440da |
case GDK_SCROLL_LEFT:
|
|
|
b440da |
time_model->move_by(-step);
|
|
|
b440da |
return true;
|
|
|
b440da |
default:
|
|
|
b440da |
break;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return false;
|
|
Carlos Lopez |
a09598 |
}
|