more cleanup: use the propagated timelineState directly

This commit is contained in:
Fischlurch 2011-10-10 01:42:03 +02:00
parent 5fe1debd5b
commit fb28592082
4 changed files with 65 additions and 80 deletions

View file

@ -71,6 +71,13 @@ TimelineBody::~TimelineBody()
WARN_IF(!tool, gui, "An invalid tool pointer is unexpected here");
}
TimelineViewWindow&
TimelineBody::viewWindow() const
{
REQUIRE(timelineState);
return timelineState->get_view_window();
}
TimelineWidget&
TimelineBody::getTimelineWidget () const
{
@ -149,7 +156,7 @@ TimelineBody::on_expose_event(GdkEventExpose* event)
// Makes sure the widget styles have been loaded
read_styles();
if(timelineWidget.get_state())
if (timelineState)
{
// Prepare to render via cairo
const Allocation allocation = get_allocation();
@ -171,9 +178,9 @@ TimelineBody::on_scroll_event (GdkEventScroll* event)
{
REQUIRE(event != NULL);
if(timelineWidget.get_state())
if (timelineState)
{
TimelineViewWindow &window = view_window();
TimelineViewWindow &window = viewWindow();
const Allocation allocation = get_allocation();
if(event->state & GDK_CONTROL_MASK)
@ -257,17 +264,16 @@ TimelineBody::on_motion_notify_event(GdkEventMotion *event)
{
REQUIRE(event != NULL);
if(timelineWidget.get_state())
if (timelineState)
{
// Handle a middle-mouse drag if one is occuring
switch(dragType)
{
case Shift:
{
TimelineViewWindow &window = view_window();
/////////////////////////////TICKET #795 : don't reach in from outside and manipulate internals of the timeline view!
///////////////////////////// : either encapsulate this entirely here, or leave it to the timeline view!
TimelineViewWindow &window = viewWindow();
const int64_t scale = window.get_time_scale();
window.set_time_offset(beginShiftTimeOffset
+ TimeValue(scale * (mouseDownX - event->x)));
@ -308,7 +314,7 @@ TimelineBody::propagateStateChange()
if (timelineState)
{
// Connect up some events
view_window().changed_signal().connect(
viewWindow().changed_signal().connect(
sigc::mem_fun(this, &TimelineBody::on_update_view) );
}
@ -382,7 +388,7 @@ TimelineBody::draw_track(Cairo::RefPtr<Cairo::Context> cr,
// Render the track
cr->save();
TimelineViewWindow &window = view_window();
TimelineViewWindow &window = viewWindow();
timeline_track->draw_track(cr, &window);
cr->restore();
}
@ -395,12 +401,11 @@ TimelineBody::draw_selection(Cairo::RefPtr<Cairo::Context> cr)
// Prepare
const Allocation allocation = get_allocation();
shared_ptr<TimelineState> state = timelineWidget.get_state();
REQUIRE(state);
REQUIRE(timelineState);
TimelineViewWindow const& window = state->get_view_window();
const int start_x = window.time_to_x(state->getSelectionStart());
const int end_x = window.time_to_x(state->getSelectionEnd());
TimelineViewWindow const& window = timelineState->get_view_window();
const int start_x = window.time_to_x(timelineState->getSelectionStart());
const int end_x = window.time_to_x(timelineState->getSelectionEnd());
// Draw the cover
if(end_x > 0 && start_x < allocation.get_width())
@ -436,16 +441,13 @@ TimelineBody::draw_playback_point(Cairo::RefPtr<Cairo::Context> cr)
{
REQUIRE(cr);
// Prepare
shared_ptr<TimelineState> state = timelineWidget.get_state();
if(state)
if (timelineState)
{
if (!state->isPlaying()) return;
if (!timelineState->isPlaying()) return;
const Allocation allocation = get_allocation();
Time point = state->getPlaybackPoint();
const int x = view_window().time_to_x(point);
Time point = timelineState->getPlaybackPoint();
const int x = viewWindow().time_to_x(point);
// Set source
cr->set_source(playbackPointColour);
@ -464,10 +466,10 @@ TimelineBody::draw_playback_point(Cairo::RefPtr<Cairo::Context> cr)
void
TimelineBody::begin_shift_drag()
{
if(timelineWidget.get_state())
if (timelineState)
{
dragType = Shift;
beginShiftTimeOffset = view_window().get_time_offset();
beginShiftTimeOffset = viewWindow().get_time_offset();
beginShiftVerticalOffset = get_vertical_offset();
}
}
@ -484,14 +486,6 @@ TimelineBody::set_vertical_offset(int offset)
timelineWidget.verticalAdjustment.set_value(offset);
}
TimelineViewWindow&
TimelineBody::view_window() const
{
shared_ptr<TimelineState> state = timelineWidget.get_state();
REQUIRE(state);
return state->get_view_window();
}
void
TimelineBody::register_styles() const
{

View file

@ -68,10 +68,7 @@ public:
*/
TimelineBody(gui::widgets::TimelineWidget &timeline_widget);
/**
* Destructor
*/
~TimelineBody();
virtual ~TimelineBody();
TimelineWidget&
getTimelineWidget () const;
@ -131,6 +128,12 @@ protected:
/* ===== Internals ===== */
private:
/**
* Access the current timeline view window
* @warning must not be called unless the TimlineWidget
* has a valid state.
*/
TimelineViewWindow& viewWindow() const;
/**
* Draws the timeline tracks.
@ -162,14 +165,7 @@ private:
/** adjust to the new timeline state */
void propagateStateChange();
/**
* A helper function to get the view window
* @remarks This function must not be called unless the TimlineWidget
* has a valid state.
*/
TimelineViewWindow& view_window() const;
/**
* Registers all the styles that this class will respond to.
*/

View file

@ -75,6 +75,14 @@ TimelineRuler::TimelineRuler (TimelineWidget &timeline_widget)
register_styles();
}
TimelineViewWindow&
TimelineRuler::viewWindow() const
{
REQUIRE(timelineState);
return timelineState->get_view_window();
}
void
TimelineRuler::set_mouse_chevron_offset(int offset)
{
@ -114,7 +122,7 @@ TimelineRuler::on_expose_event(GdkEventExpose* event)
if(!window)
return false;
if(timelineWidget.get_state())
if (timelineState)
{
// Prepare to render via cairo
const Allocation allocation = get_allocation();
@ -160,11 +168,11 @@ TimelineRuler::on_button_press_event(GdkEventButton* event)
{
REQUIRE(event != NULL);
if(timelineWidget.get_state())
if (timelineState)
{
if(event->button == 1)
{
pinnedDragTime = view_window().x_to_time(event->x);
pinnedDragTime = viewWindow().x_to_time(event->x);
isDragging = true;
}
}
@ -231,7 +239,7 @@ void
TimelineRuler::propagateStateChange()
{
// Connect up some events
view_window().changed_signal().connect(
viewWindow().changed_signal().connect(
sigc::mem_fun(this, &TimelineRuler::on_update_view) );
// Redraw
@ -243,18 +251,16 @@ TimelineRuler::propagateStateChange()
void
TimelineRuler::set_leading_x(const int x)
{
shared_ptr<TimelineState> state = timelineWidget.get_state();
if(state)
if (timelineState)
{
TimeVar newStartPoint (view_window().x_to_time(x));
TimeVar newStartPoint (viewWindow().x_to_time(x));
Offset selectionLength (pinnedDragTime, newStartPoint);
if (newStartPoint > pinnedDragTime)
newStartPoint=pinnedDragTime; // use the smaller one as selection start
state->setPlaybackPeriod (Mutation::changeTime(newStartPoint) );
state->setPlaybackPeriod (Mutation::changeDuration(selectionLength));
timelineState->setPlaybackPeriod (Mutation::changeTime(newStartPoint) );
timelineState->setPlaybackPeriod (Mutation::changeDuration(selectionLength));
//////////////////////////////////////////////////////TICKET #797 : this is cheesy. Should provide a single Mutation to change all at once
////////////////////TODO : code duplication with timeline-ibeam-tool 205
}
@ -268,7 +274,7 @@ TimelineRuler::draw_ruler(Cairo::RefPtr<Cairo::Context> cr,
REQUIRE(ruler_rect.get_width() > 0);
REQUIRE(ruler_rect.get_height() > 0);
const TimelineViewWindow &window = view_window();
const TimelineViewWindow &window = viewWindow();
const gavl_time_t left_offset = _raw(window.get_time_offset());
const int64_t time_scale = window.get_time_scale();
@ -369,16 +375,15 @@ TimelineRuler::draw_selection(Cairo::RefPtr<Cairo::Context> cr,
REQUIRE(cr);
REQUIRE(ruler_rect.get_width() > 0);
REQUIRE(ruler_rect.get_height() > 0);
REQUIRE(timelineState);
shared_ptr<TimelineState> state = timelineWidget.get_state();
REQUIRE(state);
const TimelineViewWindow &window = state->get_view_window();
const TimelineViewWindow &window = timelineState->get_view_window();
Glib::RefPtr<Style> style = get_style();
Gdk::Cairo::set_source_color(cr, style->get_fg(STATE_NORMAL));
// Draw the selection start chevron
const int a = 1 + window.time_to_x(state->getSelectionStart());
const int a = 1 + window.time_to_x(timelineState->getSelectionStart());
if(a >= 0 && a < ruler_rect.get_width())
{
cr->move_to(a, ruler_rect.get_height());
@ -388,7 +393,7 @@ TimelineRuler::draw_selection(Cairo::RefPtr<Cairo::Context> cr,
}
// Draw the selection end chevron
const int b = window.time_to_x(state->getSelectionEnd());
const int b = window.time_to_x(timelineState->getSelectionEnd());
if(b >= 0 && b < ruler_rect.get_width())
{
cr->move_to(b, ruler_rect.get_height());
@ -405,18 +410,17 @@ TimelineRuler::draw_playback_period(Cairo::RefPtr<Cairo::Context> cr,
REQUIRE(cr);
REQUIRE(ruler_rect.get_width() > 0);
REQUIRE(ruler_rect.get_height() > 0);
REQUIRE(timelineState);
shared_ptr<TimelineState> state = timelineWidget.get_state();
REQUIRE(state);
const TimelineViewWindow &window = state->get_view_window();
const TimelineViewWindow &window = timelineState->get_view_window();
// Calculate coordinates
const float halfSize = playbackPeriodArrowSize / 2;
const float a = 1.5f + window.time_to_x(state->getPlaybackPeriodStart());
const float a = 1.5f + window.time_to_x(timelineState->getPlaybackPeriodStart());
const float b = a + halfSize;
const float d = 0.5f + window.time_to_x(state->getPlaybackPeriodEnd());
const float d = 0.5f + window.time_to_x(timelineState->getPlaybackPeriodEnd());
const float c = d - halfSize;
@ -473,14 +477,12 @@ TimelineRuler::draw_playback_point(Cairo::RefPtr<Cairo::Context> cr,
REQUIRE(cr);
REQUIRE(ruler_rect.get_width() > 0);
REQUIRE(ruler_rect.get_height() > 0);
REQUIRE(timelineState);
shared_ptr<TimelineState> state = timelineWidget.get_state();
REQUIRE(state);
if (!state->isPlaying()) return;
if (!timelineState->isPlaying()) return;
TimelineViewWindow const& window = state->get_view_window();
Time point = state->getPlaybackPoint();
const int x = window.time_to_x(point);
Time point = timelineState->getPlaybackPoint();
const int x = viewWindow().time_to_x(point);
cr->move_to(x + 0.5, ruler_rect.get_height());
cr->rel_line_to(0, -playbackPointSize);
@ -502,7 +504,6 @@ TimelineRuler::calculate_major_spacing() const
{
unsigned int i;
const int64_t time_scale = view_window().get_time_scale();
const gavl_time_t major_spacings[] = {
GAVL_TIME_SCALE / 1000,
GAVL_TIME_SCALE / 400,
@ -528,6 +529,8 @@ TimelineRuler::calculate_major_spacing() const
60ll * 60ll * GAVL_TIME_SCALE
};
const int64_t time_scale = viewWindow().get_time_scale();
for(i = 0; i < sizeof(major_spacings) / sizeof(gavl_time_t); i++)
{
const int64_t division_width = major_spacings[i] / time_scale;
@ -539,14 +542,6 @@ TimelineRuler::calculate_major_spacing() const
return major_spacings[i];
}
TimelineViewWindow&
TimelineRuler::view_window() const
{
shared_ptr<TimelineState> state = timelineWidget.get_state();
REQUIRE(state);
return state->get_view_window();
}
void
TimelineRuler::register_styles() const
{

View file

@ -176,9 +176,9 @@ private:
gavl_time_t calculate_major_spacing() const;
/**
* A helper function to get the view window
* Access current timeline view window
*/
TimelineViewWindow& view_window() const;
TimelineViewWindow& viewWindow() const;
/**
* Registers all the styles that this class will respond to.