Blame synfig-studio/src/gui/timeplotdata.h

Rodolfo Ribeiro Gomes 13ab6f
/* === S Y N F I G ========================================================= */
Rodolfo Ribeiro Gomes 13ab6f
/*!	\file timeplotdata.h
Rodolfo Ribeiro Gomes 13ab6f
**	\brief Template Header
Rodolfo Ribeiro Gomes 13ab6f
**
Rodolfo Ribeiro Gomes 13ab6f
**	$Id$
Rodolfo Ribeiro Gomes 13ab6f
**
Rodolfo Ribeiro Gomes 13ab6f
**	\legal
Rodolfo Ribeiro Gomes 13ab6f
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Rodolfo Ribeiro Gomes 13ab6f
**	......... ... 2019 Rodolfo R. Gomes
Rodolfo Ribeiro Gomes 13ab6f
**
Rodolfo Ribeiro Gomes 13ab6f
**	This package is free software; you can redistribute it and/or
Rodolfo Ribeiro Gomes 13ab6f
**	modify it under the terms of the GNU General Public License as
Rodolfo Ribeiro Gomes 13ab6f
**	published by the Free Software Foundation; either version 2 of
Rodolfo Ribeiro Gomes 13ab6f
**	the License, or (at your option) any later version.
Rodolfo Ribeiro Gomes 13ab6f
**
Rodolfo Ribeiro Gomes 13ab6f
**	This package is distributed in the hope that it will be useful,
Rodolfo Ribeiro Gomes 13ab6f
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Rodolfo Ribeiro Gomes 13ab6f
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Rodolfo Ribeiro Gomes 13ab6f
**	General Public License for more details.
Rodolfo Ribeiro Gomes 13ab6f
**	\endlegal
Rodolfo Ribeiro Gomes 13ab6f
*/
Rodolfo Ribeiro Gomes 13ab6f
/* ========================================================================= */
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
/* === S T A R T =========================================================== */
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
#ifndef __SYNFIG_STUDIO_TIMEPLOTDATA_H
Rodolfo Ribeiro Gomes 13ab6f
#define __SYNFIG_STUDIO_TIMEPLOTDATA_H
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
/* === H E A D E R S ======================================================= */
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
#include "gui/timemodel.h"
Rodolfo Ribeiro Gomes 13ab6f
#include <synfig time.h=""></synfig>
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
#include <gtkmm widget.h=""></gtkmm>
Rodolfo Ribeiro Gomes 13ab6f
#include <gtkmm adjustment.h=""></gtkmm>
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
/* === M A C R O S ========================================================= */
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
/* === T Y P E D E F S ===================================================== */
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
/* === C L A S S E S & S T R U C T S ======================================= */
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
namespace studio {
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
/// Helper class that connects widget geometry to visible timeline and vice versa
Rodolfo Ribeiro Gomes 12c51e
/**
Rodolfo Ribeiro Gomes 12c51e
 * Some widgets show data that must be in sync to the project timeline, eg.
Rodolfo Ribeiro Gomes 12c51e
 * the waypoint 'editor'.
Rodolfo Ribeiro Gomes 12c51e
 * This class helps to map pixel coordinate <-> time, being updated automatically
Rodolfo Ribeiro Gomes 12c51e
 * when the timeline changes (by zooming or scrolling, for example) or widget size
Rodolfo Ribeiro Gomes 12c51e
 * changes.
Rodolfo Ribeiro Gomes 12c51e
 *
Rodolfo Ribeiro Gomes 12c51e
 * For widgets that uses another axis that can be scrolled and/or zoomed (like
Rodolfo Ribeiro Gomes 12c51e
 * Widget_Curves), \ref vertical_adjustment should be used.
Rodolfo Ribeiro Gomes 12c51e
 *
Rodolfo Ribeiro Gomes 12c51e
 * \sa TimeModel
Rodolfo Ribeiro Gomes 12c51e
 */
Rodolfo Ribeiro Gomes 12c51e
class TimePlotData {
Rodolfo Ribeiro Gomes 13ab6f
	bool invalid;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
public:
Rodolfo Ribeiro Gomes 13ab6f
	etl::handle<timemodel> time_model;</timemodel>
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// Current Time \sa TimeModel::get_time
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Time time;
Rodolfo Ribeiro Gomes 12c51e
	/// Start visible Time \sa TimeModel::get_visible_lower()
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Time lower;
Rodolfo Ribeiro Gomes 12c51e
	/// Final visible Time \sa TimeModel::get_visible_upper()
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Time upper;
Rodolfo Ribeiro Gomes 12c51e
	/// How many pixels per second
Rodolfo Ribeiro Gomes 13ab6f
	double k;
Rodolfo Ribeiro Gomes 12c51e
	/// How long a pixel last. Inverse of \ref k
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Time dt;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// How many extra pixels beyond regular bounds \sa set_extra_time_margin()
Rodolfo Ribeiro Gomes 12c51e
	double extra_margin;
Rodolfo Ribeiro Gomes 12c51e
	/// How long last the extra pixels
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Time extra_time;
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Time lower_ex;
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Time upper_ex;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
private:
Rodolfo Ribeiro Gomes 12c51e
	/// If vertical adjustment is set
Rodolfo Ribeiro Gomes 13ab6f
	bool has_vertical;
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Real range_lower;
Rodolfo Ribeiro Gomes 13ab6f
	synfig::Real range_upper;
Rodolfo Ribeiro Gomes 13ab6f
	double range_k;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
	sigc::connection widget_resized;
Rodolfo Ribeiro Gomes 13ab6f
	sigc::connection time_model_changed;
Rodolfo Ribeiro Gomes 13ab6f
	sigc::connection vertical_changed;
Rodolfo Ribeiro Gomes 13ab6f
	sigc::connection vertical_value_changed;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
	Gtk::Widget &widget;
Rodolfo Ribeiro Gomes 13ab6f
	Glib::RefPtr<gtk::adjustment> vertical_adjustment;</gtk::adjustment>
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
public:
Rodolfo Ribeiro Gomes 12c51e
	/**
Rodolfo Ribeiro Gomes 12c51e
	 * \param widget The widget that must zoom and scroll in sync with the timeline
Rodolfo Ribeiro Gomes 12c51e
	 * \param vertical_adjustment If widget displays info in another axis that can be scrolled/zoomed
Rodolfo Ribeiro Gomes 12c51e
	 */
Rodolfo Ribeiro Gomes 12c51e
	TimePlotData(Gtk::Widget & widget, Glib::RefPtr<gtk::adjustment> vertical_adjustment = Glib::RefPtr<gtk::adjustment>());</gtk::adjustment></gtk::adjustment>
Rodolfo Ribeiro Gomes 12c51e
	virtual ~TimePlotData();
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
	void set_time_model(const etl::handle<timemodel> &time_model);</timemodel>
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// Sets an extra margin, creating a new and wider range. \sa is_time_visible_extra()
Rodolfo Ribeiro Gomes 13ab6f
	void set_extra_time_margin(double margin);
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// Checks whether this data is valid (it has valid size and valid time info)
Rodolfo Ribeiro Gomes 12c51e
	bool is_invalid() const;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// If \ref t is in \ref lower - \ref upper range
Rodolfo Ribeiro Gomes 12c51e
	bool is_time_visible(const synfig::Time & t) const;
Rodolfo Ribeiro Gomes 12c51e
	/// If \ref t is in expanded range (\ref lower_ex - \ref upper_ex)
Rodolfo Ribeiro Gomes f56b2a
	bool is_time_visible_extra(const synfig::Time & t) const;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes f56b2a
	bool is_y_visible(synfig::Real y) const;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// What pixel time t is mapped to. Uses ::etl::round_to_int()
Rodolfo Ribeiro Gomes f56b2a
	int get_pixel_t_coord(const synfig::Time & t) const;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// Similar to get_pixel_t_coord(), but rounded by regular round()
Rodolfo Ribeiro Gomes 12c51e
	/** Maybe it was an error and should be replaced by get_pixel_t_coord() */
Rodolfo Ribeiro Gomes 12c51e
	double get_double_pixel_t_coord(const synfig::Time & t) const;
Rodolfo Ribeiro Gomes 12c51e
Rodolfo Ribeiro Gomes f56b2a
	int get_pixel_y_coord(synfig::Real y) const;
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 12c51e
	/// What time a pixel represents.
Rodolfo Ribeiro Gomes 12c51e
	synfig::Time get_t_from_pixel_coord(double pixel) const;
Rodolfo Ribeiro Gomes 12c51e
Rodolfo Ribeiro Gomes 12c51e
	double get_y_from_pixel_coord(double pixel) const;
Rodolfo Ribeiro Gomes 12c51e
Rodolfo Ribeiro Gomes eb6db5
	synfig::Time get_delta_t_from_delta_pixel_coord(int delta_pixel) const;
Rodolfo Ribeiro Gomes eb6db5
Rodolfo Ribeiro Gomes eb6db5
	double get_delta_y_from_delta_pixel_coord(int delta_pixel) const;
Rodolfo Ribeiro Gomes eb6db5
Rodolfo Ribeiro Gomes eb6db5
	int get_delta_pixel_from_delta_t_coord(double delta_t) const;
Rodolfo Ribeiro Gomes eb6db5
Rodolfo Ribeiro Gomes eb6db5
	int get_delta_pixel_from_delta_y_coord(double delta_y) const;
Rodolfo Ribeiro Gomes eb6db5
Rodolfo Ribeiro Gomes 13ab6f
private:
Rodolfo Ribeiro Gomes 13ab6f
	bool on_widget_resize(GdkEventConfigure * /*configure*/);
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
	void recompute_time_bounds();
Rodolfo Ribeiro Gomes 13ab6f
	void recompute_geometry_data();
Rodolfo Ribeiro Gomes 13ab6f
	void recompute_extra_time();
Rodolfo Ribeiro Gomes 13ab6f
	void recompute_vertical();
Rodolfo Ribeiro Gomes 13ab6f
}; // END of class TimePlotData
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
}; // END of namespace studio
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
/* === E N D =============================================================== */
Rodolfo Ribeiro Gomes 13ab6f
Rodolfo Ribeiro Gomes 13ab6f
#endif // TIMEPLOTDATA_H