diff layer/TimeValueLayer.cpp @ 13:01849cd277e6

* Hook up tool selection buttons to switch the cursor mode * Implement simple and multi-selection, snapping to the resolution of the current layer. You can't actually do anything with a selection yet
author Chris Cannam
date Mon, 23 Jan 2006 17:02:57 +0000
parents 2d5005f2b3d9
children 1deb5f87a18c
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp	Thu Jan 19 17:59:11 2006 +0000
+++ b/layer/TimeValueLayer.cpp	Mon Jan 23 17:02:57 2006 +0000
@@ -268,6 +268,38 @@
 		   points.begin()->label);
 }
 
+int
+TimeValueLayer::getNearestFeatureFrame(int frame,
+				       size_t &resolution,
+				       bool snapRight) const
+{
+    if (!m_model) {
+	return Layer::getNearestFeatureFrame(frame, resolution, snapRight);
+    }
+
+    resolution = m_model->getResolution();
+    SparseTimeValueModel::PointList points(m_model->getPoints(frame, frame));
+
+    int returnFrame = frame;
+
+    for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
+	 i != points.end(); ++i) {
+
+	if (snapRight) {
+	    if (i->frame > frame) {
+		returnFrame = i->frame;
+		break;
+	    }
+	} else {
+	    if (i->frame <= frame) {
+		returnFrame = i->frame;
+	    }
+	}
+    }
+
+    return returnFrame;
+}
+
 void
 TimeValueLayer::paint(QPainter &paint, QRect rect) const
 {