diff layer/TimeInstantLayer.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 02a718909b2d
line wrap: on
line diff
--- a/layer/TimeInstantLayer.cpp	Thu Jan 19 17:59:11 2006 +0000
+++ b/layer/TimeInstantLayer.cpp	Mon Jan 23 17:02:57 2006 +0000
@@ -224,6 +224,38 @@
 		   points.begin()->label);
 }
 
+int
+TimeInstantLayer::getNearestFeatureFrame(int frame,
+					 size_t &resolution,
+					 bool snapRight) const
+{
+    if (!m_model) {
+	return Layer::getNearestFeatureFrame(frame, resolution, snapRight);
+    }
+
+    resolution = m_model->getResolution();
+    SparseOneDimensionalModel::PointList points(m_model->getPoints(frame, frame));
+
+    int returnFrame = frame;
+
+    for (SparseOneDimensionalModel::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
 TimeInstantLayer::paint(QPainter &paint, QRect rect) const
 {