Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var bounds             = View.Bounds;
            var screenBounds       = UIScreen.MainScreen.Bounds;
            var maxScreenDimension = NMath.Max(screenBounds.Width, screenBounds.Height);

            UIViewAutoresizing flexibleDimensions = FlexibleWidth | FlexibleHeight;

            scrollView = new UIScrollView(bounds)
            {
                AutoresizingMask = flexibleDimensions
            };
            View.AddSubview(scrollView);

            var frame = new CGRect(CGPoint.Empty, new CGSize(maxScreenDimension, maxScreenDimension));

            cgView = new StrokeCGView(frame)
            {
                AutoresizingMask = flexibleDimensions
            };

            View.BackgroundColor = UIColor.White;

            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.AddSubview(canvasContainerView);
            scrollView.BackgroundColor  = canvasContainerView.BackgroundColor;
            scrollView.MaximumZoomScale = 3;
            scrollView.MinimumZoomScale = 0.5f;
            scrollView.PanGestureRecognizer.AllowedTouchTypes   = TouchTypes(UITouchType.Direct);
            scrollView.PinchGestureRecognizer.AllowedTouchTypes = TouchTypes(UITouchType.Direct);

            scrollView.Delegate = this;

            // 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 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);
            }

            clearButton = AddButton("clear", ClearButtonAction);
            SetupPencilUI();
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			var bounds = View.Bounds;
			var screenBounds = UIScreen.MainScreen.Bounds;
			var maxScreenDimension = NMath.Max (screenBounds.Width, screenBounds.Height);

			UIViewAutoresizing flexibleDimensions = FlexibleWidth | FlexibleHeight;

			scrollView = new UIScrollView (bounds) {
				AutoresizingMask = flexibleDimensions
			};
			View.AddSubview (scrollView);

			var frame = new CGRect (CGPoint.Empty, new CGSize (maxScreenDimension, maxScreenDimension));
			cgView = new StrokeCGView (frame) {
				AutoresizingMask = flexibleDimensions
			};

			View.BackgroundColor = UIColor.White;

			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.AddSubview (canvasContainerView);
			scrollView.BackgroundColor = canvasContainerView.BackgroundColor;
			scrollView.MaximumZoomScale = 3;
			scrollView.MinimumZoomScale = 0.5f;
			scrollView.PanGestureRecognizer.AllowedTouchTypes = TouchTypes (UITouchType.Direct);
			scrollView.PinchGestureRecognizer.AllowedTouchTypes = TouchTypes (UITouchType.Direct);

			scrollView.Delegate = this;

			// 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 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);
			}

			clearButton = AddButton ("clear", ClearButtonAction);
			SetupPencilUI ();
		}