public IDisposable Subscribe(ReactiveSpace spaceListener) { CompositeDisposable subscriptions = new CompositeDisposable(); subscriptions.Add(spaceListener .LockedHands() .ObserveOn(UI) .Subscribe(o => { HandsCount++; })); subscriptions.Add(spaceListener .LockedHands() .Select(o => o .ObserveOn(UI) .Subscribe(oo => { }, () => { HandsCount--; })) .Subscribe()); subscriptions.Add(SubscribeCore(spaceListener)); subscriptions.Add(Disposable.Create(()=>HandsCount = 0)); return subscriptions; }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { CompositeDisposable subscriptions = new CompositeDisposable(); subscriptions.Add(spaceListener .LockedHands() .ObserveOn(UI) .SelectMany(h => h .Select(hh => new { Group = h, Hand = hh })) .Subscribe(h => { var diff = 1000 + (h.Hand.PalmPosition.y - h.Group.Key.PalmPosition.y); var bin = (int)(diff / MinInterval); if(bin < PreviousBin) { if(OnMoveDown != null) OnMoveDown(); } if(bin > PreviousBin) { if(OnMoveUp != null) OnMoveUp(); } PreviousBin = bin; })); return subscriptions; }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { var deselectWhenUnlocked = spaceListener.IsLocked() .ObserveOn(UI) .Subscribe(isLocked => { if(!isLocked) ClearCurrent(); }); var updatePosition = spaceListener .LockedHands() .ObserveOn(UI) .Select(g => new { Group = g, CenterPosition = g.Key.PalmPosition }) .SelectMany(g => g .Group .Select(p => new { Position = p, GroupContext = g })) .Subscribe((hand) => { var offset = hand.Position.PalmPosition.To2D() - hand.GroupContext.CenterPosition.To2D(); if(-ZoneHeight/2f < offset.y && offset.y < ZoneHeight / 2f && -ZoneHeight/2f < offset.x && offset.x < ZoneHeight / 2f) GoTo(Center); if(-ZoneHeight / 2f < offset.y && offset.y < ZoneHeight / 2f) { if(-ZoneHeight / 2f >= offset.x) { GoTo(Left); } if(offset.x >= ZoneHeight / 2f) { GoTo(Right); } } if(-ZoneHeight / 2f < offset.x && offset.x < ZoneHeight / 2f) { if(-ZoneHeight / 2f >= offset.y) { GoTo(Down); } if(offset.y >= ZoneHeight / 2f) { GoTo(Up); } } }); CompositeDisposable subscriptions = new CompositeDisposable(); subscriptions.Add(deselectWhenUnlocked); subscriptions.Add(updatePosition); subscriptions.Add(Disposable.Create(ClearCurrent)); return subscriptions; }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { return spaceListener .LockedHands() .SelectMany(l => l) .Where(h => Math.Abs(h.PalmVelocity.y) > VelocityThreshold || Math.Abs(h.PalmVelocity.x) > VelocityThreshold) .Sample(MinInterval) .ObserveOn(UI) .Subscribe(h => { if(OnClicked != null) { LastSide = "Center"; OnClicked(); } if(Math.Abs(h.PalmVelocity.y) > VelocityThreshold) { var isDown = h.PalmVelocity.y < 0.0; var upOrDown = isDown ? OnDown : OnUp; var side = isDown ? "Down" : "Up"; if(upOrDown != null) { LastSide = side; upOrDown(); } } else { var isLeft = h.PalmVelocity.x < 0.0; var leftOrRight = isLeft ? OnLeft : OnRight; var side = isLeft ? "Left" : "Right"; if(leftOrRight != null) { LastSide = side; leftOrRight(); } } }); }
protected override IDisposable SubscribeCore(ReactiveSpace spaceListener) { return spaceListener.LockedHands() .ObserveOn(UI) .Select(g => new { Group = g, StartValue = Value, StartHeight = g.Key.PalmPosition.y }) .SelectMany(g => g .Group .Select(p => new { Position = p, GroupContext = g })) .Subscribe((hand) => { double heightRange = 150.0; var maxHeight = hand.GroupContext.StartHeight + heightRange * ((MaxValue - hand.GroupContext.StartValue) / (MaxValue - MinValue)); var minHeight = maxHeight - heightRange; double height = hand.Position.PalmPosition.y; height = Math.Max(minHeight, height); height = Math.Min(maxHeight, height); Value = Helper.Map(height, minHeight, maxHeight, MinValue, MaxValue); }); }
private void Subscribe(ReactiveSpace spaceListener) { var minimized = spaceListener .ReactiveListener .FingersMoves() .SelectMany(m => m) .ThrottleWithDefault(TimeSpan.FromSeconds(1)) .ObserveOn(UI) .Subscribe(b => { if(!ShowConfig) { State = MainViewState.Minimized; } }); //var maximize = // spaceListener // .ReactiveListener // .Gestures // .Where(g => g.Key.Type == Gesture.GestureType.TYPECIRCLE) // .SelectMany(g => g.ToList().Select(l => new // { // Key = g.Key, // Values = l // })) // .Buffer(() => spaceListener.ReactiveListener.Gestures.SelectMany(g => g).OnlyTimeout(TimeSpan.FromMilliseconds(500))) // .Where(b => b.Count > 0) // .Take(1) // .Repeat() // .ObserveOn(UI) // .Subscribe(l => // { // var distinct = l.SelectMany(oo => oo.Values.SelectMany(o => o.Pointables)).Select(p => p.Id).Distinct().Count(); // State = MainViewState.Navigating; // }); var maximize = spaceListener .LockedHands() .SelectMany(h => h) .ObserveOn(UI) .Subscribe(h => { if(State == MainViewState.Minimized) State = MainViewState.Navigating; }); var lockedSubs = spaceListener .IsLocked() .ObserveOn(UI) .CombineLatest(Helper.PropertyChanged(this, () => this.State), (l, s) => new { Locked = l, State = s }) .Where(o => o.State != MainViewState.Minimized) .Subscribe(o => { State = o.Locked ? MainViewState.Locked : MainViewState.Navigating; }); _Subscriptions.Add(lockedSubs); _Subscriptions.Add(maximize); _Subscriptions.Add(minimized); }