Added basic support for multiple tools in the timeline view

This commit is contained in:
Joel Holdsworth 2008-07-30 00:12:37 +01:00
parent ecf392968b
commit 17d0883d09
14 changed files with 469 additions and 43 deletions

View file

@ -62,6 +62,12 @@ lumigui_SOURCES = \
$(lumigui_srcdir)/widgets/timeline/timeline-body.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-ruler.cpp \
$(lumigui_srcdir)/widgets/timeline/timeline-ruler.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-tool.cpp \
$(lumigui_srcdir)/widgets/timeline/timeline-tool.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-arrow-tool.cpp \
$(lumigui_srcdir)/widgets/timeline/timeline-arrow-tool.hpp \
$(lumigui_srcdir)/widgets/timeline/timeline-ibeam-tool.cpp \
$(lumigui_srcdir)/widgets/timeline/timeline-ibeam-tool.hpp \
$(lumigui_srcdir)/model/project.cpp \
$(lumigui_srcdir)/model/project.hpp \
$(lumigui_srcdir)/output/displayer.cpp \

View file

@ -25,6 +25,7 @@
using namespace Gtk;
using namespace sigc;
using namespace lumiera::gui::widgets;
namespace lumiera {
namespace gui {
@ -34,23 +35,44 @@ const int TimelinePanel::ZoomToolSteps = 2; // 2 seems comfortable
TimelinePanel::TimelinePanel() :
Panel("timeline", _("Timeline"), "timeline_panel"),
arrowTool(Gtk::StockID("arrow")),
iBeamTool(Gtk::StockID("i_beam")),
zoomIn(Stock::ZOOM_IN),
zoomOut(Stock::ZOOM_OUT)
{
// Setup the toolbar
toolbar.append(arrowTool, mem_fun(this,
&TimelinePanel::on_arrow_tool));
toolbar.append(iBeamTool, mem_fun(this,
&TimelinePanel::on_ibeam_tool));
toolbar.append(zoomIn, mem_fun(this, &TimelinePanel::on_zoom_in));
toolbar.append(zoomOut, mem_fun(this, &TimelinePanel::on_zoom_out));
toolbar.set_icon_size(IconSize(ICON_SIZE_SMALL_TOOLBAR));
toolbar.set_icon_size(IconSize(ICON_SIZE_LARGE_TOOLBAR));
toolbar.set_toolbar_style(TOOLBAR_ICONS);
// Add the toolbar
pack_start(toolbar, PACK_SHRINK);
pack_start(timelineWidget, PACK_EXPAND_WIDGET);
update_tool_buttons();
update_zoom_buttons();
}
void
TimelinePanel::on_arrow_tool()
{
timelineWidget.set_tool(timeline::Arrow);
update_tool_buttons();
}
void
TimelinePanel::on_ibeam_tool()
{
timelineWidget.set_tool(timeline::IBeam);
update_tool_buttons();
}
void
TimelinePanel::on_zoom_in()
{
@ -65,6 +87,22 @@ TimelinePanel::on_zoom_out()
update_zoom_buttons();
}
void
TimelinePanel::update_tool_buttons()
{
// This is included to prevent recursion
static bool updating = false;
if(!updating)
{
updating = true;
const timeline::ToolType tool = timelineWidget.get_tool();
arrowTool.set_active(tool == timeline::Arrow);
iBeamTool.set_active(tool == timeline::IBeam);
updating = false;
}
}
void
TimelinePanel::update_zoom_buttons()
{

View file

@ -42,10 +42,14 @@ public:
private:
//----- Event Handlers -----//
void on_arrow_tool();
void on_ibeam_tool();
void on_zoom_in();
void on_zoom_out();
private:
void update_tool_buttons();
void update_zoom_buttons();
private:
@ -57,6 +61,9 @@ private:
TimelineWidget timelineWidget;
// Toolbar Widgets
Gtk::ToggleToolButton arrowTool;
Gtk::ToggleToolButton iBeamTool;
Gtk::ToolButton zoomIn;
Gtk::ToolButton zoomOut;

View file

@ -21,6 +21,8 @@
* *****************************************************/
#include "timeline-widget.hpp"
#include "timeline/timeline-arrow-tool.hpp"
#include "timeline/timeline-ibeam-tool.hpp"
#include <boost/foreach.hpp>
@ -45,7 +47,8 @@ TimelineWidget::TimelineWidget() :
horizontalAdjustment(0, 0, 0),
verticalAdjustment(0, 0, 0),
horizontalScroll(horizontalAdjustment),
verticalScroll(verticalAdjustment)
verticalScroll(verticalAdjustment),
tool(NULL)
{
body = new TimelineBody(this);
ENSURE(body != NULL);
@ -71,14 +74,23 @@ TimelineWidget::TimelineWidget() :
tracks.push_back(&video2);
update_tracks();
set_tool(timeline::Arrow);
}
TimelineWidget::~TimelineWidget()
{
REQUIRE(body != NULL);
body->unreference();
if(body != NULL)
body->unreference();
REQUIRE(headerContainer != NULL);
headerContainer->unreference();
if(headerContainer != NULL)
headerContainer->unreference();
REQUIRE(tool != NULL);
if(tool != NULL)
delete tool;
}
gavl_time_t
@ -111,15 +123,6 @@ TimelineWidget::set_time_scale(int64_t time_scale)
horizontalAdjustment.set_page_size(timeScale * view_width);
}
void
TimelineWidget::shift_view(int shift_size)
{
const int view_width = body->get_allocation().get_width();
set_time_offset(get_time_offset() +
shift_size * timeScale * view_width / 16);
}
void
TimelineWidget::zoom_view(int zoom_size)
{
@ -151,6 +154,50 @@ TimelineWidget::zoom_view(int point, int zoom_size)
set_time_scale(new_time_scale);
}
void
TimelineWidget::shift_view(int shift_size)
{
const int view_width = body->get_allocation().get_width();
set_time_offset(get_time_offset() +
shift_size * timeScale * view_width / 16);
}
ToolType
TimelineWidget::get_tool() const
{
REQUIRE(tool != NULL);
if(tool != NULL)
return tool->get_type();
return None;
}
void
TimelineWidget::set_tool(ToolType tool_type)
{
// Tidy up old tool
if(tool != NULL)
{
// Do we need to change tools?
if(tool->get_type() == tool_type)
return;
delete tool;
}
// Create the new tool
switch(tool_type)
{
case timeline::Arrow:
tool = new timeline::ArrowTool();
break;
case timeline::IBeam:
tool = new timeline::IBeamTool();
break;
}
}
void
TimelineWidget::on_scroll()
{

View file

@ -30,6 +30,7 @@
#include "timeline/header-container.hpp"
#include "timeline/timeline-body.hpp"
#include "timeline/timeline-ruler.hpp"
#include "timeline/timeline-tool.hpp"
#include "timeline/track.hpp"
namespace lumiera {
@ -95,6 +96,10 @@ public:
**/
void shift_view(int shift_size);
timeline::ToolType get_tool() const;
void set_tool(timeline::ToolType tool_type);
/* ===== Events ===== */
protected:
void on_scroll();
@ -130,6 +135,8 @@ protected:
Gtk::HScrollbar horizontalScroll;
Gtk::VScrollbar verticalScroll;
timeline::Tool *tool;
/* ===== Constants ===== */
public:
static const int64_t MaxScale;

View file

@ -0,0 +1,45 @@
/*
timeline-arrow-tool.cpp - Implementation of the ArrowTool class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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 "timeline-arrow-tool.hpp"
namespace lumiera {
namespace gui {
namespace widgets {
namespace timeline {
ArrowTool::ArrowTool()
{
}
ToolType
ArrowTool::get_type() const
{
return Arrow;
}
} // namespace timeline
} // namespace widgets
} // namespace gui
} // namespace lumiera

View file

@ -0,0 +1,50 @@
/*
timeline-arrow-tool.hpp - Declaration of the ArrowTool class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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-arrow-tool.hpp
** This file contains the definition of the arrow tool class
*/
#ifndef TIMELINE_ARROW_TOOL_HPP
#define TIMELINE_ARROW_TOOL_HPP
#include <gtkmm.h>
#include "timeline-tool.hpp"
namespace lumiera {
namespace gui {
namespace widgets {
namespace timeline {
class ArrowTool : public Tool
{
public:
ArrowTool();
ToolType get_type() const;
};
} // namespace timeline
} // namespace widgets
} // namespace gui
} // namespace lumiera
#endif // TIMELINE_ARROW_TOOL_HPP

View file

@ -0,0 +1,45 @@
/*
timeline-ibeam-tool.cpp - Implementation of the IBeamTool class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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 "timeline-ibeam-tool.hpp"
namespace lumiera {
namespace gui {
namespace widgets {
namespace timeline {
IBeamTool::IBeamTool()
{
}
ToolType
IBeamTool::get_type() const
{
return IBeam;
}
} // namespace timeline
} // namespace widgets
} // namespace gui
} // namespace lumiera

View file

@ -0,0 +1,51 @@
/*
timeline-ibeam-tool.hpp - Declaration of the ArrowTool class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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-ibeam-tool.hpp
** This file contains the definition of ibeam tool class
** tool objects
*/
#ifndef TIMELINE_IBEAM_TOOL_HPP
#define TIMELINE_IBEAM_TOOL_HPP
#include <gtkmm.h>
#include "timeline-tool.hpp"
namespace lumiera {
namespace gui {
namespace widgets {
namespace timeline {
class IBeamTool : public Tool
{
public:
IBeamTool();
ToolType get_type() const;
};
} // namespace timeline
} // namespace widgets
} // namespace gui
} // namespace lumiera
#endif // TIMELINE_IBEAM_TOOL_HPP

View file

@ -0,0 +1,39 @@
/*
timeline-tool.hpp - Implementation of the Tool class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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 "timeline-tool.hpp"
namespace lumiera {
namespace gui {
namespace widgets {
namespace timeline {
Tool::Tool()
{
}
} // namespace timeline
} // namespace widgets
} // namespace gui
} // namespace lumiera

View file

@ -0,0 +1,58 @@
/*
timeline-tool.hpp - Declaration of the Tool class
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
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-tool.hpp
** This file contains the definition of base class for timeline
** tool objects
*/
#ifndef TIMELINE_TOOL_HPP
#define TIMELINE_TOOL_HPP
#include <gtkmm.h>
namespace lumiera {
namespace gui {
namespace widgets {
namespace timeline {
enum ToolType
{
None,
Arrow,
IBeam
};
class Tool
{
public:
Tool();
virtual ToolType get_type() const = 0;
};
} // namespace timeline
} // namespace widgets
} // namespace gui
} // namespace lumiera
#endif // TIMELINE_TOOL_HPP

View file

@ -34,22 +34,22 @@ namespace widgets {
namespace timeline {
class Track
{
public:
Track();
{
public:
Track();
Glib::ustring get_title();
Glib::ustring get_title();
Gtk::Widget& get_header_widget();
Gtk::Widget& get_header_widget();
int get_height();
int get_height();
void draw_track(Cairo::RefPtr<Cairo::Context> cairo);
void draw_track(Cairo::RefPtr<Cairo::Context> cairo);
protected:
Gtk::VBox headerWidget;
Gtk::Label label;
};
protected:
Gtk::VBox headerWidget;
Gtk::Label label;
};
} // namespace timeline

View file

@ -95,37 +95,65 @@ void
Actions::register_stock_items()
{
RefPtr<IconFactory> factory = IconFactory::create();
add_stock_item(factory, "assets-panel.png", "assets_panel", _("_Assets"));
add_stock_item(factory, "timeline-panel.png", "timeline_panel", _("_Timeline"));
add_stock_item(factory, "viewer-panel.png", "viewer_panel", _("_Viewer"));
add_stock_item_set(factory, "assets-panel.png", "assets_panel", _("_Assets"));
add_stock_item_set(factory, "timeline-panel.png", "timeline_panel", _("_Timeline"));
add_stock_item_set(factory, "viewer-panel.png", "viewer_panel", _("_Viewer"));
add_stock_item_set(factory, "arrow.png", "arrow", _("_Arrow"));
add_stock_item_set(factory, "i-beam.png", "i_beam", _("_I-Beam"));
factory->add_default(); //Add factory to list of factories.
}
void
Actions::add_stock_item(const Glib::RefPtr<IconFactory>& factory,
const Glib::ustring& filepath,
const Glib::ustring& id, const Glib::ustring& label)
bool
Actions::add_stock_item_set(const Glib::RefPtr<IconFactory>& factory,
const Glib::ustring& filename,
const Glib::ustring& id,
const Glib::ustring& label)
{
Gtk::IconSet icon_set;
add_stock_icon_source(icon_set, 16, filename);
add_stock_icon_source(icon_set, 22, filename);
add_stock_icon_source(icon_set, 24, filename);
add_stock_icon_source(icon_set, 32, filename);
add_stock_icon_source(icon_set, 48, filename);
if(!icon_set.get_sizes().empty())
{
const Gtk::StockID stock_id(id);
factory->add(stock_id, icon_set);
Gtk::Stock::add(Gtk::StockItem(stock_id, label));
return true;
}
return false;
}
bool
Actions::add_stock_icon_source(Gtk::IconSet &icon_set,
int size, const Glib::ustring& filename)
{
Gtk::IconSource source;
try
{
//This throws an exception if the file is not found:
source.set_pixbuf( Gdk::Pixbuf::create_from_file(filepath) );
source.set_pixbuf( Gdk::Pixbuf::create_from_file(
Glib::ustring::compose("icons/%1x%1/%2", size, filename) ) );
}
catch(const Glib::Exception& ex)
{
g_message(ex.what().c_str());
return false;
}
source.set_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
source.set_size_wildcarded(); //Icon may be scaled.
source.set_size(IconSize(size));
//source.set_size_wildcarded(); // Icon may be scaled.
Gtk::IconSet icon_set;
icon_set.add_source(source); //More than one source per set is allowed.
icon_set.add_source(source);
const Gtk::StockID stock_id(id);
factory->add(stock_id, icon_set);
Gtk::Stock::add(Gtk::StockItem(stock_id, label));
return true;
}
void

View file

@ -53,9 +53,14 @@ class WorkspaceWindow;
* labels associated with IDs */
static void register_stock_items();
static void add_stock_item(const Glib::RefPtr<Gtk::IconFactory>& factory,
const Glib::ustring& filepath,
const Glib::ustring& id, const Glib::ustring& label);
static bool add_stock_item_set(
const Glib::RefPtr<Gtk::IconFactory>& factory,
const Glib::ustring& filename,
const Glib::ustring& id,
const Glib::ustring& label);
static bool add_stock_icon_source(Gtk::IconSet &icon_set,
int size, const Glib::ustring& filename);
/**
* Updates the state of the menu/toolbar actions