/// <summary> /// findShape searches through all the shapes on the current slide and checks to see if the /// given x and y value falls within any of the shapes. If so, it returns that shape, if not, /// it returns null /// </summary> /// <param name="x">x coordinate</param> /// <param name="y">y coordinate</param> /// <returns>the shape that the mouse falls on, if any</returns> public PowerPoint.Shape findShape(int x, int y) { BasicForm.fPoint curPoint = new BasicForm.fPoint(x, y); List <PowerPoint.Shape> range = allShapes(); // need to check through all shapes on the slide // iterate through range from latest to earliest for (int i = range.Count - 1; i >= 0; --i) { // once we get a hit, return it if (pointOnShape(curPoint, range[i])) { return(range[i]); } } //didn't find any shapes return(null); }
/// <summary> /// Checks whether the input fPoint is "on" the passed shape, with error SHAPEMARGIN (should we pass in margin?) /// </summary> /// <param name="curPoint">a fPoint with the x and y values in PowerPoint coordinates</param> /// <param name="shape">the PowerPoint shape. May be rotated (but not yet flipped)/</param> /// <returns>true if the point and shape coincide, false else</returns> internal bool pointOnShape(BasicForm.fPoint curPoint, PowerPoint.Shape shape) { BasicForm.fPoint p = BasicForm.rotatePointWithShape(curPoint, shape); return(shape.Left - SHAPEMARGIN < p.x && p.x < shape.Width + shape.Left + SHAPEMARGIN && shape.Top - SHAPEMARGIN < p.y && p.y < shape.Top + shape.Height + SHAPEMARGIN); }