Ejemplo n.º 1
0
		public ImageOverlayView(UIImage viewToDraw, RectangleF frame) : base(frame){

			this.BackgroundColor = UIColor.Clear;

			drawableView = viewToDraw;
			this.MultipleTouchEnabled = false;
			needsPoint = true; 

			add = new FlatButton(RectangleF.Empty);
			add.SetTitle ("Add", UIControlState.Normal);
			add.SetBackgroundColor (MobileCore.Values.Colors.WhiteSeventyFivePercent.ToNative (), UIControlState.Normal);
			add.SetTitleColor (MobileCore.Values.Colors.DarkGray.ToNative (), UIControlState.Normal);
			add.TouchUpInside += AddClicked;
			Add (add);

			undo = new FlatButton(RectangleF.Empty);
			undo.SetTitle ("Undo", UIControlState.Normal);
			undo.SetBackgroundColor (MobileCore.Values.Colors.WhiteSeventyFivePercent.ToNative (), UIControlState.Normal);
			undo.SetTitleColor (MobileCore.Values.Colors.DarkGray.ToNative (), UIControlState.Normal);
			undo.TouchUpInside += UndoClicked;
			Add (undo);

			this.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints ();

			this.AddConstraints (
				undo.AtBottomOf(this, Constants.Layout.VerticalPadding),
				undo.AtRightOf(this, Constants.Layout.HorizontalPadding),
				undo.Width().GreaterThanOrEqualTo(56f),
				undo.Height().GreaterThanOrEqualTo(32f),

				add.AtBottomOf(this, Constants.Layout.VerticalPadding),
				add.ToLeftOf(undo, Constants.Layout.HorizontalPadding),
				add.Width().GreaterThanOrEqualTo(56f),
				add.Height().GreaterThanOrEqualTo(32f)
			);

			this.WhenAnyValue (vm => vm.Enabled)
				.ObserveOn(RxApp.MainThreadScheduler)
				.Subscribe (enabled => {

					UserInteractionEnabled = enabled;

					UIView.AnimateAsync(Constants.Animation.StandardAnimationDuration, () => add.Alpha = undo.Alpha =	enabled ? 1.0f : 0.0f);

				});

			this.WhenAnyValue (vm => vm.Editing)
				.ObserveOn(RxApp.MainThreadScheduler)
				.Subscribe (editing => {
					if(Enabled)
						UIView.AnimateAsync(Constants.Animation.StandardAnimationDuration, () => add.Alpha = undo.Alpha =	editing ? 0.0f : 1.0f );

				});
		}
Ejemplo n.º 2
0
		public SmoothDrawView(RectangleF frame, UIColor drawingColor, float lineThickness) : base(frame){
			paths = new ReactiveList<List<UIBezierPath>> ();

			this.BackgroundColor = UIColor.Clear;

			strokeColor = drawingColor ?? UIColor.Yellow;

			this.lineThickness = lineThickness;

			this.MultipleTouchEnabled = false;

			undo = new FlatButton(RectangleF.Empty);
			undo.Alpha = default(float);
			undo.SetTitle ("Undo", UIControlState.Normal);
			undo.SetBackgroundColor (MobileCore.Values.Colors.WhiteSeventyFivePercent.ToNative (), UIControlState.Normal);
			undo.SetTitleColor (MobileCore.Values.Colors.DarkGray.ToNative (), UIControlState.Normal);
			Add (undo);

			this.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints ();

			this.AddConstraints (
				undo.AtBottomOf(this, Constants.Layout.VerticalPadding),
				undo.AtRightOf(this, Constants.Layout.HorizontalPadding),
				undo.Width().GreaterThanOrEqualTo(56f),
				undo.Height().GreaterThanOrEqualTo(32f)
			);
				
			Observable.CombineLatest (
				this.WhenAnyValue (x => x.Enabled),
				paths.CountChanged.StartWith(0),
				(enabled, count) => enabled && count > 0)
				.ObserveOn(RxApp.MainThreadScheduler)
				.Subscribe (shouldDisplay => UIView.AnimateAsync(Constants.Animation.StandardAnimationDuration, () => undo.Alpha = shouldDisplay ? 1.0f : default(float) ));

			this.WhenAnyValue (vm => vm.Enabled)
				.ObserveOn(RxApp.MainThreadScheduler)
				.Subscribe (enabled => UserInteractionEnabled = enabled);

			Observable.FromEventPattern(h => undo.TouchUpInside += h, h => undo.TouchUpInside -= h)
				.Where(_ => paths.Any())
				.ObserveOn(RxApp.MainThreadScheduler)
				.Subscribe(_ => {
					paths.RemoveAt (paths.Count - 1);

					this.SetNeedsDisplay ();
					});
		}