diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index a71e94b7a..07728475a 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -58,7 +58,7 @@ TimelineWidget::TimelineWidget( { REQUIRE(sequence); - body = new TimelineBody(this); + body = new TimelineBody(*this); ENSURE(body != NULL); headerContainer = new TimelineHeaderContainer(*this); ENSURE(headerContainer != NULL); diff --git a/src/gui/widgets/timeline/timeline-arrow-tool.cpp b/src/gui/widgets/timeline/timeline-arrow-tool.cpp index 52acb661e..c211e3ace 100644 --- a/src/gui/widgets/timeline/timeline-arrow-tool.cpp +++ b/src/gui/widgets/timeline/timeline-arrow-tool.cpp @@ -26,7 +26,7 @@ namespace gui { namespace widgets { namespace timeline { -ArrowTool::ArrowTool(TimelineBody *timeline_body) : +ArrowTool::ArrowTool(TimelineBody &timeline_body) : Tool(timeline_body) { diff --git a/src/gui/widgets/timeline/timeline-arrow-tool.hpp b/src/gui/widgets/timeline/timeline-arrow-tool.hpp index 902fb0a88..74d6f8e5c 100644 --- a/src/gui/widgets/timeline/timeline-arrow-tool.hpp +++ b/src/gui/widgets/timeline/timeline-arrow-tool.hpp @@ -43,7 +43,7 @@ public: * Constructor * @param timeline_body The owner timeline body object */ - ArrowTool(TimelineBody *timeline_body); + ArrowTool(TimelineBody &timeline_body); /** * Gets the type of tool represented by this class diff --git a/src/gui/widgets/timeline/timeline-body.cpp b/src/gui/widgets/timeline/timeline-body.cpp index 67cd257ea..3e1f06d9b 100644 --- a/src/gui/widgets/timeline/timeline-body.cpp +++ b/src/gui/widgets/timeline/timeline-body.cpp @@ -38,8 +38,7 @@ namespace gui { namespace widgets { namespace timeline { -TimelineBody::TimelineBody(gui::widgets::TimelineWidget - *timeline_widget) : +TimelineBody::TimelineBody(TimelineWidget &timeline_widget) : Glib::ObjectBase("TimelineBody"), tool(NULL), mouseDownX(0), @@ -48,11 +47,9 @@ TimelineBody::TimelineBody(gui::widgets::TimelineWidget beginShiftTimeOffset(0), selectionAlpha(0.5), timelineWidget(timeline_widget) -{ - REQUIRE(timelineWidget != NULL); - +{ // Connect up some events - timelineWidget->get_view_window().changed_signal().connect( + timelineWidget.get_view_window().changed_signal().connect( sigc::mem_fun(this, &TimelineBody::on_update_view) ); // Install style properties @@ -92,11 +89,11 @@ TimelineBody::set_tool(timeline::ToolType tool_type) switch(tool_type) { case timeline::Arrow: - tool = new ArrowTool(this); + tool = new ArrowTool(*this); break; case timeline::IBeam: - tool = new IBeamTool(this); + tool = new IBeamTool(*this); break; default: @@ -133,7 +130,6 @@ bool TimelineBody::on_expose_event(GdkEventExpose* event) { REQUIRE(event != NULL); - REQUIRE(timelineWidget != NULL); // This is where we draw on the window Glib::RefPtr window = get_window(); @@ -161,9 +157,8 @@ bool TimelineBody::on_scroll_event (GdkEventScroll* event) { REQUIRE(event != NULL); - REQUIRE(timelineWidget != NULL); - TimelineViewWindow &window = timelineWidget->get_view_window(); + TimelineViewWindow &window = timelineWidget.get_view_window(); if(event->state & GDK_CONTROL_MASK) { @@ -244,14 +239,13 @@ bool TimelineBody::on_motion_notify_event(GdkEventMotion *event) { REQUIRE(event != NULL); - REQUIRE(timelineWidget != NULL); // Handle a middle-mouse drag if one is occuring switch(dragType) { case Shift: { - TimelineViewWindow &window = timelineWidget->get_view_window(); + TimelineViewWindow &window = timelineWidget.get_view_window(); const int64_t scale = window.get_time_scale(); gavl_time_t offset = beginShiftTimeOffset + @@ -272,9 +266,9 @@ TimelineBody::on_motion_notify_event(GdkEventMotion *event) // See if the track that we're hovering over has changed shared_ptr new_hovering_track( - timelineWidget->layoutHelper.track_from_y(event->y)); - if(timelineWidget->get_hovering_track() != new_hovering_track) - timelineWidget->set_hovering_track(new_hovering_track); + timelineWidget.layoutHelper.track_from_y(event->y)); + if(timelineWidget.get_hovering_track() != new_hovering_track) + timelineWidget.set_hovering_track(new_hovering_track); // false so that the message is passed up to the owner TimelineWidget return false; @@ -284,11 +278,10 @@ void TimelineBody::draw_tracks(Cairo::RefPtr cr) { REQUIRE(cr); - REQUIRE(timelineWidget != NULL); - REQUIRE(timelineWidget->sequence); + REQUIRE(timelineWidget.sequence); // Prepare - TimelineLayoutHelper &layout_helper = timelineWidget->layoutHelper; + TimelineLayoutHelper &layout_helper = timelineWidget.layoutHelper; const TimelineLayoutHelper::TrackTree &layout_tree = layout_helper.get_layout_tree(); const Allocation allocation = get_allocation(); @@ -305,7 +298,7 @@ TimelineBody::draw_tracks(Cairo::RefPtr cr) { const shared_ptr model_track(*iterator); const shared_ptr timeline_track = - timelineWidget->lookup_timeline_track(*iterator); + timelineWidget.lookup_timeline_track(*iterator); optional rect = layout_helper.get_track_header_rect(timeline_track); @@ -333,7 +326,6 @@ TimelineBody::draw_track(Cairo::RefPtr cr, { REQUIRE(cr); REQUIRE(timeline_track != NULL); - REQUIRE(timelineWidget != NULL); const int height = timeline_track->get_height(); REQUIRE(height >= 0); @@ -346,7 +338,7 @@ TimelineBody::draw_track(Cairo::RefPtr cr, // Render the track cr->save(); - timeline_track->draw_track(cr, &timelineWidget->get_view_window()); + timeline_track->draw_track(cr, &timelineWidget.get_view_window()); cr->restore(); } @@ -354,16 +346,15 @@ void TimelineBody::draw_selection(Cairo::RefPtr cr) { REQUIRE(cr); - REQUIRE(timelineWidget != NULL); // Prepare const Allocation allocation = get_allocation(); - const TimelineViewWindow &window = timelineWidget->get_view_window(); + const TimelineViewWindow &window = timelineWidget.get_view_window(); const int start_x = window.time_to_x( - timelineWidget->get_selection_start()); + timelineWidget.get_selection_start()); const int end_x = window.time_to_x( - timelineWidget->get_selection_end()); + timelineWidget.get_selection_end()); // Draw the cover if(end_x > 0 && start_x < allocation.get_width()) @@ -402,16 +393,15 @@ void TimelineBody::draw_playback_point(Cairo::RefPtr cr) { REQUIRE(cr); - REQUIRE(timelineWidget != NULL); // Prepare const Allocation allocation = get_allocation(); - const gavl_time_t point = timelineWidget->get_playback_point(); + const gavl_time_t point = timelineWidget.get_playback_point(); if(point == (gavl_time_t)GAVL_TIME_UNDEFINED) return; - const int x = timelineWidget->get_view_window().time_to_x(point); + const int x = timelineWidget.get_view_window().time_to_x(point); // Set source gdk_cairo_set_source_color(cr->cobj(), &playbackPointColour); @@ -431,20 +421,20 @@ TimelineBody::begin_shift_drag() { dragType = Shift; beginShiftTimeOffset = - timelineWidget->get_view_window().get_time_offset(); + timelineWidget.get_view_window().get_time_offset(); beginShiftVerticalOffset = get_vertical_offset(); } int TimelineBody::get_vertical_offset() const { - return (int)timelineWidget->verticalAdjustment.get_value(); + return (int)timelineWidget.verticalAdjustment.get_value(); } void TimelineBody::set_vertical_offset(int offset) { - timelineWidget->verticalAdjustment.set_value(offset); + timelineWidget.verticalAdjustment.set_value(offset); } void diff --git a/src/gui/widgets/timeline/timeline-body.hpp b/src/gui/widgets/timeline/timeline-body.hpp index 1200f56e8..a7584cdfc 100644 --- a/src/gui/widgets/timeline/timeline-body.hpp +++ b/src/gui/widgets/timeline/timeline-body.hpp @@ -54,9 +54,10 @@ public: /** * Constructor - * @param timeline_widget The owner widget of this ruler. + * @param timeline_widget A reference to the owner widget of this + * ruler. */ - TimelineBody(gui::widgets::TimelineWidget *timeline_widget); + TimelineBody(gui::widgets::TimelineWidget &timeline_widget); /** * Destructor @@ -173,7 +174,7 @@ private: float selectionAlpha; GdkColor playbackPointColour; - gui::widgets::TimelineWidget* const timelineWidget; + gui::widgets::TimelineWidget &timelineWidget; friend class Tool; friend class ArrowTool; diff --git a/src/gui/widgets/timeline/timeline-ibeam-tool.cpp b/src/gui/widgets/timeline/timeline-ibeam-tool.cpp index 07942600a..144fe9f11 100644 --- a/src/gui/widgets/timeline/timeline-ibeam-tool.cpp +++ b/src/gui/widgets/timeline/timeline-ibeam-tool.cpp @@ -37,7 +37,7 @@ const int IBeamTool::ScrollSlideEventInterval = 40; // ===== Implementation ===== // -IBeamTool::IBeamTool(TimelineBody *timeline_body) : +IBeamTool::IBeamTool(TimelineBody &timeline_body) : Tool(timeline_body), dragType(None), pinnedDragTime(0), @@ -90,32 +90,31 @@ IBeamTool::on_button_press_event(GdkEventButton* event) { Tool::on_button_press_event(event); - TimelineWidget *timeline_widget = get_timeline_widget(); - REQUIRE(timeline_widget != NULL); + TimelineWidget &timeline_widget = get_timeline_widget(); if(event->button == 1) { const gavl_time_t time = - get_timeline_widget()->get_view_window().x_to_time(event->x); + timeline_widget.get_view_window().x_to_time(event->x); if(is_mouse_in_start_drag_zone()) { // User began to drag the start of the selection dragType = GrabStart; - pinnedDragTime = timeline_widget->get_selection_end(); + pinnedDragTime = timeline_widget.get_selection_end(); } else if(is_mouse_in_end_drag_zone()) { // User began to drag the end of the selection dragType = GrabEnd; - pinnedDragTime = timeline_widget->get_selection_start(); + pinnedDragTime = timeline_widget.get_selection_start(); } else { // User began the drag in clear space, begin a Select drag dragType = Selection; pinnedDragTime = time; - timeline_widget->set_selection(time, time); + timeline_widget.set_selection(time, time); } } } @@ -174,7 +173,7 @@ IBeamTool::on_motion_notify_event(GdkEventMotion *event) bool IBeamTool::on_scroll_slide_timer() { - get_timeline_widget()->get_view_window().shift_view(scrollSlideRate); + get_timeline_widget().get_view_window().shift_view(scrollSlideRate); // Return true to keep the timer going return true; @@ -183,17 +182,16 @@ IBeamTool::on_scroll_slide_timer() void IBeamTool::set_leading_x(const int x) { - TimelineWidget *timeline_widget = get_timeline_widget(); - REQUIRE(timeline_widget != NULL); + TimelineWidget &timeline_widget = get_timeline_widget(); const bool set_playback_period = dragType == Selection; const gavl_time_t time = - timeline_widget->get_view_window().x_to_time(x); + timeline_widget.get_view_window().x_to_time(x); if(time > pinnedDragTime) - timeline_widget->set_selection( + timeline_widget.set_selection( pinnedDragTime, time, set_playback_period); else - timeline_widget->set_selection( + timeline_widget.set_selection( time, pinnedDragTime, set_playback_period); } @@ -218,10 +216,10 @@ IBeamTool::end_scroll_slide() bool IBeamTool::is_mouse_in_start_drag_zone() const { - TimelineWidget *timeline_widget = get_timeline_widget(); + TimelineWidget &timeline_widget = get_timeline_widget(); - const int start_x = timeline_widget->get_view_window().time_to_x( - timeline_widget->get_selection_start()); + const int start_x = timeline_widget.get_view_window().time_to_x( + timeline_widget.get_selection_start()); return (mousePoint.get_x() <= start_x && mousePoint.get_x() > start_x - DragZoneWidth); @@ -230,10 +228,10 @@ IBeamTool::is_mouse_in_start_drag_zone() const bool IBeamTool::is_mouse_in_end_drag_zone() const { - TimelineWidget *timeline_widget = get_timeline_widget(); + TimelineWidget &timeline_widget = get_timeline_widget(); - const int end_x = timeline_widget->get_view_window().time_to_x( - timeline_widget->get_selection_end()); + const int end_x = timeline_widget.get_view_window().time_to_x( + timeline_widget.get_selection_end()); return (mousePoint.get_x() >= end_x && mousePoint.get_x() < end_x + DragZoneWidth); diff --git a/src/gui/widgets/timeline/timeline-ibeam-tool.hpp b/src/gui/widgets/timeline/timeline-ibeam-tool.hpp index 93dcd9f60..b1ee49378 100644 --- a/src/gui/widgets/timeline/timeline-ibeam-tool.hpp +++ b/src/gui/widgets/timeline/timeline-ibeam-tool.hpp @@ -44,7 +44,7 @@ public: * Constructor * @param timeline_body The owner timeline body object */ - IBeamTool(TimelineBody *timeline_body); + IBeamTool(TimelineBody &timeline_body); /** * Gets the type of tool represented by this class diff --git a/src/gui/widgets/timeline/timeline-tool.cpp b/src/gui/widgets/timeline/timeline-tool.cpp index dc462529a..a5b1b881a 100644 --- a/src/gui/widgets/timeline/timeline-tool.cpp +++ b/src/gui/widgets/timeline/timeline-tool.cpp @@ -29,20 +29,16 @@ namespace gui { namespace widgets { namespace timeline { -Tool::Tool(TimelineBody *timeline_body) : +Tool::Tool(TimelineBody &timeline_body) : timelineBody(timeline_body), isDragging(false) { - REQUIRE(timeline_body != NULL); } bool Tool::apply_cursor() -{ - REQUIRE(timelineBody != NULL); - - Glib::RefPtr window = - timelineBody->get_window(); +{ + Glib::RefPtr window = timelineBody.get_window(); if(!window) return false; @@ -75,21 +71,18 @@ Tool::on_motion_notify_event(GdkEventMotion *event) mousePoint = Point(event->x, event->y); } -gui::widgets::TimelineWidget* +gui::widgets::TimelineWidget& Tool::get_timeline_widget() const { - REQUIRE(timelineBody != NULL); - gui::widgets::TimelineWidget *timeline_widget = - timelineBody->timelineWidget; - REQUIRE(timeline_widget != NULL); + gui::widgets::TimelineWidget &timeline_widget = + timelineBody.timelineWidget; return timeline_widget; } Gdk::Rectangle Tool::get_body_rectangle() const { - REQUIRE(timelineBody != NULL); - return timelineBody->get_allocation(); + return timelineBody.get_allocation(); } } // namespace timeline diff --git a/src/gui/widgets/timeline/timeline-tool.hpp b/src/gui/widgets/timeline/timeline-tool.hpp index e422142aa..9a6b35a2f 100644 --- a/src/gui/widgets/timeline/timeline-tool.hpp +++ b/src/gui/widgets/timeline/timeline-tool.hpp @@ -58,7 +58,7 @@ protected: * Constructor * @param timeline_body The owner timeline body object */ - Tool(TimelineBody *timeline_body); + Tool(TimelineBody &timeline_body); public: /** @@ -120,7 +120,7 @@ protected: * Helper function which retrieves the pointer to owner timeline * widget object, which is the owner of the timeline body. */ - gui::widgets::TimelineWidget *get_timeline_widget() const; + gui::widgets::TimelineWidget &get_timeline_widget() const; /** * Helper function which retrieves the rectangle of the timeline @@ -129,7 +129,7 @@ protected: Gdk::Rectangle get_body_rectangle() const; protected: - TimelineBody *timelineBody; + TimelineBody &timelineBody; bool isDragging; Gdk::Point mousePoint;