diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 53f7c8452..e463100d4 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -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 \ diff --git a/src/gui/panels/timeline-panel.cpp b/src/gui/panels/timeline-panel.cpp index 3b6bfed84..ea46da0a0 100644 --- a/src/gui/panels/timeline-panel.cpp +++ b/src/gui/panels/timeline-panel.cpp @@ -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() { diff --git a/src/gui/panels/timeline-panel.hpp b/src/gui/panels/timeline-panel.hpp index a14288c41..06e71ff71 100644 --- a/src/gui/panels/timeline-panel.hpp +++ b/src/gui/panels/timeline-panel.hpp @@ -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; diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index 3146824d7..a56c29672 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -21,6 +21,8 @@ * *****************************************************/ #include "timeline-widget.hpp" +#include "timeline/timeline-arrow-tool.hpp" +#include "timeline/timeline-ibeam-tool.hpp" #include @@ -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() { diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index c179a4d59..cc49f7897 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -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; diff --git a/src/gui/widgets/timeline/timeline-arrow-tool.cpp b/src/gui/widgets/timeline/timeline-arrow-tool.cpp new file mode 100644 index 000000000..28c63e1ee --- /dev/null +++ b/src/gui/widgets/timeline/timeline-arrow-tool.cpp @@ -0,0 +1,45 @@ +/* + timeline-arrow-tool.cpp - Implementation of the ArrowTool class + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + 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 + diff --git a/src/gui/widgets/timeline/timeline-arrow-tool.hpp b/src/gui/widgets/timeline/timeline-arrow-tool.hpp new file mode 100644 index 000000000..edf287767 --- /dev/null +++ b/src/gui/widgets/timeline/timeline-arrow-tool.hpp @@ -0,0 +1,50 @@ +/* + timeline-arrow-tool.hpp - Declaration of the ArrowTool class + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + 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 +#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 diff --git a/src/gui/widgets/timeline/timeline-ibeam-tool.cpp b/src/gui/widgets/timeline/timeline-ibeam-tool.cpp new file mode 100644 index 000000000..f6c9bf0cc --- /dev/null +++ b/src/gui/widgets/timeline/timeline-ibeam-tool.cpp @@ -0,0 +1,45 @@ +/* + timeline-ibeam-tool.cpp - Implementation of the IBeamTool class + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + 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 + diff --git a/src/gui/widgets/timeline/timeline-ibeam-tool.hpp b/src/gui/widgets/timeline/timeline-ibeam-tool.hpp new file mode 100644 index 000000000..848c75b60 --- /dev/null +++ b/src/gui/widgets/timeline/timeline-ibeam-tool.hpp @@ -0,0 +1,51 @@ +/* + timeline-ibeam-tool.hpp - Declaration of the ArrowTool class + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + 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 +#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 diff --git a/src/gui/widgets/timeline/timeline-tool.cpp b/src/gui/widgets/timeline/timeline-tool.cpp new file mode 100644 index 000000000..e1b8f5c0f --- /dev/null +++ b/src/gui/widgets/timeline/timeline-tool.cpp @@ -0,0 +1,39 @@ +/* + timeline-tool.hpp - Implementation of the Tool class + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + 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 + diff --git a/src/gui/widgets/timeline/timeline-tool.hpp b/src/gui/widgets/timeline/timeline-tool.hpp new file mode 100644 index 000000000..1007aace6 --- /dev/null +++ b/src/gui/widgets/timeline/timeline-tool.hpp @@ -0,0 +1,58 @@ +/* + timeline-tool.hpp - Declaration of the Tool class + + Copyright (C) Lumiera.org + 2008, Joel Holdsworth + + 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 + +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 diff --git a/src/gui/widgets/timeline/track.hpp b/src/gui/widgets/timeline/track.hpp index 3abbf036d..b5f193019 100644 --- a/src/gui/widgets/timeline/track.hpp +++ b/src/gui/widgets/timeline/track.hpp @@ -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); + void draw_track(Cairo::RefPtr cairo); - protected: - Gtk::VBox headerWidget; - Gtk::Label label; - }; +protected: + Gtk::VBox headerWidget; + Gtk::Label label; +}; } // namespace timeline diff --git a/src/gui/workspace/actions.cpp b/src/gui/workspace/actions.cpp index deade71fa..64bc6bb07 100644 --- a/src/gui/workspace/actions.cpp +++ b/src/gui/workspace/actions.cpp @@ -95,37 +95,65 @@ void Actions::register_stock_items() { RefPtr 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& factory, - const Glib::ustring& filepath, - const Glib::ustring& id, const Glib::ustring& label) +bool +Actions::add_stock_item_set(const Glib::RefPtr& 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 diff --git a/src/gui/workspace/actions.hpp b/src/gui/workspace/actions.hpp index 235ae29ef..c3b21c384 100644 --- a/src/gui/workspace/actions.hpp +++ b/src/gui/workspace/actions.hpp @@ -53,9 +53,14 @@ class WorkspaceWindow; * labels associated with IDs */ static void register_stock_items(); - static void add_stock_item(const Glib::RefPtr& factory, - const Glib::ustring& filepath, - const Glib::ustring& id, const Glib::ustring& label); + static bool add_stock_item_set( + const Glib::RefPtr& 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