private void InitializeMouseHandler() { mouseButtonEvent = new FirableEvent<MouseStatus>(); mouseMoveEvent = new FirableEvent<MouseEventArgs>(); mouseButtonBehavior = mouseButtonEvent.Hold(MouseStatus.Up); this.mouseButtonDown = new EqualityPredicate<MouseStatus>(mouseButtonBehavior, MouseStatus.Down); mouseDragEvent = mouseMoveEvent.Gate(this.mouseButtonDown); mouseButtonBehavior.SubscribeWithInitialFire(a => { status.Text = string.Format("{0} {1}", a, DateTime.Now); }); mouseDragEvent.Map(e => new Tuple<string, string>(e.X.ToString(), e.Y.ToString())).Subscribe(t => { x.Text = t.Item1; y.Text = t.Item2; }); MouseMove += (s, e) => mouseMoveEvent.Fire(e); MouseDown += (s, e) => mouseButtonEvent.Fire(MouseStatus.Down); MouseUp += (s, e) => mouseButtonEvent.Fire(MouseStatus.Up); }
public void TestGate() { var enabled = new IdentityPredicate(true); var ec = new FirableEvent<char>(); var epred = new QueryPredicate(() => enabled.Value); var o = new List<char>(); var l = ec.Gate(epred).Subscribe(o.Add); ec.Fire('H'); enabled = new IdentityPredicate(false); ec.Fire('O'); enabled = new IdentityPredicate(true); ec.Fire('I'); l.Dispose(); AssertArraysEqual(Arrays<char>.AsList('H', 'I'), o); }