Replacing zoomIn and zoomOut buttons in the TimelinePanel with a new TimelineZoomScale widget
This commit is contained in:
parent
92301a3752
commit
c79b28fe7c
2 changed files with 214 additions and 0 deletions
115
src/gui/widgets/timeline/timeline-zoom-scale.cpp
Normal file
115
src/gui/widgets/timeline/timeline-zoom-scale.cpp
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
timeline-zoom-scale.cpp - Implementation of the zoom scale widget
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2011, Michael R. Fisher <mfisher31@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
* *****************************************************/
|
||||
|
||||
#include "gui/widgets/timeline/timeline-zoom-scale.hpp"
|
||||
#include "gui/widgets/timeline-widget.hpp"
|
||||
|
||||
using namespace Gtk;
|
||||
|
||||
namespace gui {
|
||||
namespace widgets {
|
||||
|
||||
class TimelineWidget;
|
||||
|
||||
namespace timeline {
|
||||
|
||||
TimelineZoomScale::TimelineZoomScale()
|
||||
: HBox()
|
||||
, adjustment(0.5, 0.0, 1.0, 0.000001)
|
||||
, slider()
|
||||
, zoomIn(Stock::ZOOM_IN)
|
||||
, zoomOut(Stock::ZOOM_OUT)
|
||||
, smoothing_factor(9.0)
|
||||
, button_step_size(0.03)
|
||||
{
|
||||
/* Setup the Slider Control */
|
||||
slider.set_adjustment(adjustment);
|
||||
slider.set_size_request(123,10);
|
||||
slider.set_digits(6);
|
||||
slider.set_inverted(true);
|
||||
slider.set_draw_value(false);
|
||||
|
||||
/* Make our connections */
|
||||
zoomIn.signal_clicked().
|
||||
connect(sigc::mem_fun(this, &TimelineZoomScale::on_zoom_in_clicked));
|
||||
|
||||
zoomOut.signal_clicked().
|
||||
connect(sigc::mem_fun(this, &TimelineZoomScale::on_zoom_out_clicked));
|
||||
|
||||
adjustment.signal_value_changed().
|
||||
connect(sigc::mem_fun(this, &TimelineZoomScale::on_zoom));
|
||||
|
||||
/* Add Our Widgets and show them */
|
||||
pack_start(zoomOut,PACK_SHRINK);
|
||||
pack_start(slider,PACK_SHRINK);
|
||||
pack_start(zoomIn,PACK_SHRINK);
|
||||
|
||||
show_all();
|
||||
}
|
||||
|
||||
void
|
||||
TimelineZoomScale::on_zoom_in_clicked()
|
||||
{
|
||||
double newValue = adjustment.get_value() - button_step_size;
|
||||
adjustment.set_value(newValue);
|
||||
}
|
||||
|
||||
void
|
||||
TimelineZoomScale::on_zoom_out_clicked()
|
||||
{
|
||||
double newValue = adjustment.get_value() + button_step_size;
|
||||
adjustment.set_value(newValue);
|
||||
}
|
||||
|
||||
void
|
||||
TimelineZoomScale::on_zoom()
|
||||
{
|
||||
zoomSignal.emit(calculate_zoom_scale()) ;
|
||||
}
|
||||
|
||||
sigc::signal<void, int64_t>
|
||||
TimelineZoomScale::signal_zoom()
|
||||
{
|
||||
return zoomSignal;
|
||||
}
|
||||
|
||||
int64_t
|
||||
TimelineZoomScale::calculate_zoom_scale()
|
||||
{
|
||||
int64_t zoom_scale = 0;
|
||||
|
||||
double smoothed = pow(adjustment.get_value(), smoothing_factor);
|
||||
zoom_scale = (int64_t)( smoothed * (double)TimelineWidget::MaxScale);
|
||||
|
||||
/* Prevent Zooming in To Close and Far */
|
||||
if(zoom_scale < 1)
|
||||
zoom_scale = 1;
|
||||
|
||||
if(zoom_scale > TimelineWidget::MaxScale)
|
||||
zoom_scale = TimelineWidget::MaxScale;
|
||||
|
||||
return zoom_scale;
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace widgets
|
||||
} // namespace timeline
|
||||
99
src/gui/widgets/timeline/timeline-zoom-scale.hpp
Normal file
99
src/gui/widgets/timeline/timeline-zoom-scale.hpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
timeline-zoom-scale.hpp - Declaration of the zoom scale widget
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2011, Michael R. Fisher <mfisher31@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
/** @file timeline-zoom-scale.hpp
|
||||
** This file contains the definition of the zoom scale widget
|
||||
*/
|
||||
|
||||
#ifndef TIMELINE_ZOOM_SCALE_HPP
|
||||
#define TIMELINE_ZOOM_SCALE_HPP
|
||||
|
||||
#include "gui/gtk-lumiera.hpp"
|
||||
#include "gui/widgets/mini-button.hpp"
|
||||
|
||||
using namespace Gtk;
|
||||
using namespace gui::widgets;
|
||||
|
||||
namespace gui {
|
||||
namespace widgets {
|
||||
namespace timeline {
|
||||
|
||||
class TimelineZoomScale : public Gtk::HBox
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
TimelineZoomScale();
|
||||
|
||||
/**
|
||||
* Accessor method to the zoomSignal
|
||||
* @return the zoomSignal
|
||||
*/
|
||||
sigc::signal<void, int64_t> signal_zoom();
|
||||
|
||||
private:
|
||||
/* Event Handlers */
|
||||
|
||||
/**
|
||||
* Event handler for when the zoomIn Button
|
||||
* is clicked
|
||||
*/
|
||||
void on_zoom_in_clicked();
|
||||
|
||||
/**
|
||||
* Event handler for when the zoomIn Button
|
||||
* is clicked
|
||||
*/
|
||||
void on_zoom_out_clicked();
|
||||
|
||||
/**
|
||||
* Event handler for when the adjustment
|
||||
* value is changed
|
||||
*/
|
||||
void on_zoom();
|
||||
|
||||
/**
|
||||
* Calculate a Zoom Scale value based on
|
||||
* the adjustment's current value
|
||||
* @return The Zoom Scale value
|
||||
*/
|
||||
int64_t calculate_zoom_scale();
|
||||
|
||||
/* Widgets */
|
||||
Gtk::Adjustment adjustment;
|
||||
Gtk::HScale slider;
|
||||
MiniButton zoomIn;
|
||||
MiniButton zoomOut;
|
||||
|
||||
protected:
|
||||
/* Signals */
|
||||
sigc::signal<void, int64_t> zoomSignal;
|
||||
|
||||
const double smoothing_factor;
|
||||
const double button_step_size;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace widgets
|
||||
} // namespace timeline
|
||||
|
||||
#endif /* TIMELINE_ZOOM_SCALE_HPP */
|
||||
Loading…
Reference in a new issue