/* timeline.cpp - Implementation of the timeline widget 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 #include #include "timeline-body.hpp" #include "../timeline-widget.hpp" #include "../../window-manager.hpp" #include "timeline-arrow-tool.hpp" #include "timeline-ibeam-tool.hpp" using namespace Gtk; using namespace std; using namespace lumiera::gui; using namespace lumiera::gui::widgets; using namespace lumiera::gui::widgets::timeline; namespace lumiera { namespace gui { namespace widgets { namespace timeline { TimelineBody::TimelineBody(lumiera::gui::widgets::TimelineWidget *timeline_widget) : Glib::ObjectBase("TimelineBody"), tool(NULL), dragType(None), mouseDownX(0), mouseDownY(0), beginShiftTimeOffset(0), selectionAlpha(0.5), timelineWidget(timeline_widget) { REQUIRE(timelineWidget != NULL); // Connect up some events timelineWidget->view_changed_signal().connect(sigc::mem_fun( this, &TimelineBody::on_update_view) ); // Install style properties register_styles(); } TimelineBody::~TimelineBody() { REQUIRE(tool != NULL); if(tool != NULL) delete tool; } ToolType TimelineBody::get_tool() const { REQUIRE(tool != NULL); if(tool != NULL) return tool->get_type(); return lumiera::gui::widgets::timeline::None; } void TimelineBody::set_tool(timeline::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 ArrowTool(this); break; case timeline::IBeam: tool = new IBeamTool(this); break; } // Apply the cursor if possible tool->apply_cursor(); } void TimelineBody::on_update_view() { queue_draw(); } void TimelineBody::on_realize() { Widget::on_realize(); // We wish to receive event notifications add_events( Gdk::POINTER_MOTION_MASK | Gdk::SCROLL_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); // Apply the cursor if possible tool->apply_cursor(); } bool TimelineBody::on_expose_event(GdkEventExpose* event) { Cairo::Matrix view_matrix; REQUIRE(event != NULL); REQUIRE(timelineWidget != NULL); // This is where we draw on the window Glib::RefPtr window = get_window(); if(!window) return false; // Makes sure the widget styles have been loaded read_styles(); // Prepare to render via cairo Glib::RefPtr