public override void TouchesBegan(NSSet touches, UIEvent evt) { if (evt.TouchesForView(this).Count == 2 && linesInProcess.Count < 1) { bool firstTouch = true; Circle newCircle = new Circle(); string key = ""; foreach (UITouch t in touches) { // Is this a double tap? if (t.TapCount > 1) { this.clearAll(); return; } // Create a circle for the value CGPoint loc = t.LocationInView(this); if (firstTouch) { // Use the touch object (packed in an string, as the key) key = NSValue.ValueFromNonretainedObject(t).ToString(); newCircle.center = loc; firstTouch = false; } else { newCircle.point2 = loc; } } newCircle.setColor(); circlesInProcess.Add(key, newCircle); } else { foreach (UITouch t in touches) { // Is this a double tap? if (t.TapCount > 1) { this.clearAll(); return; } // Use the touch object (packed in an string, as the key) string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Create a line for the value CGPoint loc = t.LocationInView(this); Line newLine = new Line(); newLine.begin = loc; newLine.end = loc; // Put pair in dictionary newLine.setColor(); linesInProcess.Add(key, newLine); } } this.SetNeedsDisplay(); }
public override void TouchesBegan(NSSet touches, UIEvent evt) { foreach (UITouch t in touches) { // // Is this a double tap? // if (t.TapCount > 1) { // this.clearAll(); // return; // } // Use the touch object (packed in an string, as the key) string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Create a line for the value CGPoint loc = t.LocationInView(this); Line newLine = new Line(); newLine.begin = loc; newLine.end = loc; // Put pair in dictionary //newLine.setColor(); newLine.setColor(selectedColor); newLine.lineWidth = 30.0f; newLine.fastest = 0.0f; linesInProcess.Add(key, newLine); } this.SetNeedsDisplay(); }
public override void TouchesMoved(NSSet touches, UIEvent evt) { if (evt.TouchesForView(this).Count == 2 && linesInProcess.Count < 1) { bool firstTouch = true; Circle circle = null; string key; foreach (UITouch t in touches) { CGPoint loc = t.LocationInView(this); if (firstTouch) { key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the circle for this touch bool gotCircle = circlesInProcess.TryGetValue(key, out circle); // Update the Circle center if (gotCircle) { circle.center = loc; } firstTouch = false; } else { // Update the circle outside if (circle != null) { circle.point2 = loc; circle.setColor(); } } } } else { foreach (UITouch t in touches) { string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the line for this touch Line line; bool gotLine = linesInProcess.TryGetValue(key, out line); // Update the line CGPoint loc = t.LocationInView(this); if (gotLine) { line.end = loc; line.setColor(); Console.WriteLine("beginx = {0}, beginy = {1}, endx = {2}, endy = {3}", line.begin.X, line.begin.Y, line.end.X, line.end.Y); } } } this.SetNeedsDisplay(); }
public void endTouches(NSSet touches, UIEvent evt) { if (linesInProcess.Count < 1) { bool firstTouch = true; Circle circle = null; string key = ""; // Remove ending touches from Dictionary foreach (UITouch t in touches) { if (firstTouch) { key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the circle for this touch circlesInProcess.TryGetValue(key, out circle); firstTouch = false; } } // If this is a double tap, "line" will be nil // so make sure not to add it to the array if (circle != null) { LineStore.addCompletedCircle(circle); circlesInProcess.Remove(key); } } else { // Remove ending touches from Dictionary foreach (UITouch t in touches) { string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the line for this touch Line line = new Line(); linesInProcess.TryGetValue(key, out line); // If this is a double tap, "line" will be nil // so make sure not to add it to the array if (line != null) { LineStore.addCompletedLine(line); linesInProcess.Remove(key); } } } this.SetNeedsDisplay(); }
public override void TouchesMoved(NSSet touches, UIEvent evt) { foreach (UITouch t in touches) { string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the line for this touch Line line; bool gotLine = linesInProcess.TryGetValue(key, out line); // Update the line CGPoint loc = t.LocationInView(this); if (gotLine) { // but before we do, see how much distance has changed since last update // and use to set the line width // Using velocity from moverecognizer // PointF drawVelocity = moveRecognizer.VelocityInView(this); // drawVelocity.X = Math.Abs(drawVelocity.X); // drawVelocity.Y = Math.Abs(drawVelocity.Y); // // float drawSpeed = (float)Math.Sqrt(Math.Pow(drawVelocity.X, 2) + Math.Pow(drawVelocity.Y, 2)); // if (drawSpeed > line.fastest) { // line.fastest = (drawSpeed + line.fastest)/2; // } // // line.lineWidth = Math.Min(1200/line.fastest, 30); // Using the difference betseen the length of the line as an indicator of velocity - I like this better float oldLength = (float)Math.Sqrt(Math.Pow(line.beginx - line.endx, 2) + Math.Pow(line.beginy - line.endy, 2)); float newLength = (float)Math.Sqrt(Math.Pow(line.beginx - loc.X, 2) + Math.Pow(line.beginy - loc.Y, 2)); if (Math.Abs(newLength - oldLength) > line.fastest) { line.fastest = (Math.Abs(newLength - oldLength) + line.fastest) / 2; } line.lineWidth = Math.Min(30 / line.fastest, 20); // OK back to our regularly scheduled programming line.end = loc; //line.setColor(); // Set color based on the angle of the line //Console.WriteLine("beginx = {0}, beginy = {1}, endx = {2}, endy = {3}", line.begin.X, line.begin.Y, line.end.X, line.end.Y); } } this.SetNeedsDisplay(); }
public void endTouches(NSSet touches) { // Remove ending touches from Dictionary foreach (UITouch t in touches) { string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the line for this touch Line line = new Line(); linesInProcess.TryGetValue(key, out line); // If this is a double tap, "line" will be nil // so make sure not to add it to the array if (line != null) { LineStore.addCompletedLine(line); linesInProcess.Remove(key); } } this.SetNeedsDisplay(); }