void StrokeUpdated(StrokeGestureRecognizer strokeGesture) { if (strokeGesture == pencilStrokeRecognizer) { lastSeenPencilInteraction = DateTime.Now.Ticks; } var state = strokeGesture.State; Stroke stroke = null; if (state != Cancelled) { stroke = strokeGesture.Stroke; if (state == Began || (state == Ended && strokeCollection.ActiveStroke == null)) { strokeCollection.ActiveStroke = stroke; leftRingControl.CancelInteraction(); } } else { strokeCollection.ActiveStroke = null; } if (stroke != null) { if (state == Ended) { if (strokeGesture == pencilStrokeRecognizer) { // Make sure we get the final stroke update if needed. stroke.ReceivedAllNeededUpdatesBlock = () => { ReceivedAllUpdatesForStroke(stroke); }; } strokeCollection.TakeActiveStroke(); } } cgView.StrokeCollection = strokeCollection; }
public override void ViewDidLoad() { base.ViewDidLoad(); var bounds = View.Bounds; //var bounds = new CGRect(0, 0, View.Bounds.Width, View.Bounds.Height); //var bounds = fingsize; var screenBounds = UIScreen.MainScreen.Bounds; //var maxScreenDimension = NMath.Max (screenBounds.Width, screenBounds.Height); var maxScreenDimension = NMath.Max(screenBounds.Width, screenBounds.Height); UIViewAutoresizing flexibleDimensions = FlexibleWidth | FlexibleHeight; scrollView = new UIScrollView(bounds) { AutoresizingMask = flexibleDimensions, //BackgroundColor = UIColor.Red }; View.AddSubview(scrollView); var frame = new CGRect(CGPoint.Empty, new CGSize(maxScreenDimension, maxScreenDimension)); //var frame = new CGRect(CGPoint.Empty, new CGSize(800, 800)); //var frame = bounds; cgView = new StrokeCGView(frame) { AutoresizingMask = flexibleDimensions, editing = MREditing }; View.BackgroundColor = UIColor.White; //View.BackgroundColor = UIColor.Clear; //View.BackgroundColor = UIColor.FromWhiteAlpha(1.0f, 0.4f); //View.Alpha = 1.0f; canvasContainerView = CanvasContainerView.FromCanvasSize(cgView.Frame.Size); canvasContainerView.DocumentView = cgView; scrollView.ContentSize = canvasContainerView.Frame.Size; scrollView.ContentOffset = new CGPoint((canvasContainerView.Frame.Width - scrollView.Bounds.Width) / 2, (canvasContainerView.Frame.Height - scrollView.Bounds.Height) / 2); //scrollView.ContentOffset = new CGPoint(0, 0); scrollView.AddSubview(canvasContainerView); scrollView.BackgroundColor = canvasContainerView.BackgroundColor; //scrollView.BackgroundColor = UIColor.Clear; //scrollView.BackgroundColor = UIColor.FromWhiteAlpha(1.0f, 0.4f); //scrollView.Alpha = 1.0f; scrollView.MaximumZoomScale = 3; scrollView.MinimumZoomScale = 0.5f; scrollView.PanGestureRecognizer.AllowedTouchTypes = TouchTypes(UITouchType.Direct); scrollView.PinchGestureRecognizer.AllowedTouchTypes = TouchTypes(UITouchType.Direct); scrollView.Delegate = this; if (MREditing) { filename = MREditName + "_" + "edit" + "_" + DateTime.Now.ToString("s").Replace(":", "_") + ".jpg"; //var img = UIImage.FromFile("dynapadscreenshot.png"); UIImage img = new UIImage(); switch (MREditType) { case "jpg": case "gif": case "png": img = FromUrl(MREditPath); break; case "pdf": case "doc": case "docx": var dps = new DynaPadService.DynaPadService(); //img = dps.ConvertToJPG(CommonFunctions.GetUserConfig(), MREditPath); break; default: img = FromUrl(MREditPath); break; } var imgView = new UIImageView(bounds); imgView.Image = img; imgView.ContentMode = UIViewContentMode.ScaleAspectFit; // or ScaleAspectFill //imgView.BackgroundColor = UIColor.Green; //imgView.Opaque = false; //canvasContainerView.BackgroundColor = UIColor.Clear; //canvasContainerView.Opaque = false; canvasContainerView.AddSubview(imgView); canvasContainerView.SendSubviewToBack(imgView); //imgView.Alpha = 0.5f; //scrollView.AddSubview(imgView); //scrollView.SendSubviewToBack(imgView); //View.AddSubview(imgView); //View.SendSubviewToBack(imgView); } // We put our UI elements on top of the scroll view, so we don't want any of the // delay or cancel machinery in place. scrollView.DelaysContentTouches = false; fingerStrokeRecognizer = new StrokeGestureRecognizer(StrokeUpdated) { Delegate = this, CancelsTouchesInView = false, IsForPencil = false, CoordinateSpaceView = cgView }; scrollView.AddGestureRecognizer(fingerStrokeRecognizer); pencilStrokeRecognizer = new StrokeGestureRecognizer(StrokeUpdated) { Delegate = this, CancelsTouchesInView = false, CoordinateSpaceView = cgView, IsForPencil = true }; scrollView.AddGestureRecognizer(pencilStrokeRecognizer); SetupConfigurations(); var onPhone = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; var ringDiameter = onPhone ? 66f : 74f; var ringImageInset = onPhone ? 12f : 14f; var borderWidth = 1f; var ringOutset = ringDiameter / 2 - (NMath.Floor(NMath.Sqrt((ringDiameter * ringDiameter) / 8) - borderWidth)); //var ringFrame = new CGRect (-ringOutset, View.Bounds.Height - ringDiameter + ringOutset, ringDiameter, ringDiameter); //var ringFrame = new CGRect(ringOutset, 800 - ringDiameter - ringOutset, ringDiameter, ringDiameter); var ringFrame = new CGRect(ringOutset, View.Bounds.Height - ringDiameter + ringOutset - 50, ringDiameter, ringDiameter); var ringControl = new RingControl(ringFrame, configurations.Length); ringControl.AutoresizingMask = FlexibleRightMargin | FlexibleTopMargin; View.AddSubview(ringControl); leftRingControl = ringControl; string [] imageNames = { "Calligraphy", "Ink", "Debug" }; for (int index = 0; index < leftRingControl.RingViews.Count; index++) { var ringView = leftRingControl.RingViews [index]; ringView.ActionClosure = configurations [index]; var imageView = new UIImageView(ringView.Bounds.Inset(ringImageInset, ringImageInset)); imageView.Image = UIImage.FromBundle(imageNames [index]); imageView.AutoresizingMask = FlexibleLeftMargin | FlexibleRightMargin | FlexibleTopMargin | FlexibleBottomMargin; ringView.AddSubview(imageView); } closeButton = AddButton("close", CloseButtonAction); clearButton = AddButton("clear", ClearButtonAction); saveButton = AddButton("save", SaveButtonAction); SetupPencilUI(); //cgView.SetNeedsDisplay(); //scrollView.SetNeedsDisplay(); //canvasContainerView.SetNeedsDisplay(); //cgView. //new UIAlertView("Touched", "ass", null, "OK", null).Show (); //PresentViewController(CommonFunctions.AlertPrompt("File Edit", "Saving this edit will not overwrite the original file", true, null, false, null), true, null); }
public void Activated(StrokeGestureRecognizer sender) { action(sender); }