private void VotableTouchButton2_Click(object sender, RoutedEventArgs e) { if (IsVotable) { if (_voteState == VoteTouchButton2State.VOTING) { if (voteHandler != null && voteHandler.CastVote(this)) { voteHandler.CancelVote(this); //cancels the vote on this button DoubleAnimation danim = new DoubleAnimation(colorSaturator.ColorSaturation, 0.0, new Duration(TimeSpan.FromMilliseconds(1500))); colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, null);// colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, danim); danim = new DoubleAnimation(0.3, new Duration(TimeSpan.FromMilliseconds(1500))); Storyboard board = new Storyboard(); Storyboard.SetTarget(danim, this); Storyboard.SetTargetProperty(danim, new PropertyPath(OpacityProperty)); board.Children.Add(danim); board.Begin(); OnAction(); } }//even though there are currently only 2 possible states, i am performing this check anyway. else if(_voteState == VoteTouchButton2State.WAITING && VoteRequestWhen == VoteRequestFlags.OnClick) { //request vote will update the state of the button if (voteHandler != null && voteHandler.RequestVote(this)) { _voteState = VoteTouchButton2State.VOTING; if (voteHandler.CastVote(this)) //should never execute unless there is 1 person { voteHandler.CancelVote(this); //will reset OnAction(); } else { ResetTimer(); timer.Interval = VoteAutoCancelInterval; timer.Elapsed += new ElapsedEventHandler(delegate(object src, ElapsedEventArgs evt) { Dispatcher.BeginInvoke(new VoidDelegate(timerVoteCancelIntevalElapsed), DispatcherPriority.Normal); }); timer.Start(); //use transitionizor. DoubleAnimation danim = new DoubleAnimation(colorSaturator.ColorSaturation, 0.5, new Duration(TimeSpan.FromMilliseconds(1500))); colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, null);// colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, danim); danim = new DoubleAnimation(0.9, new Duration(TimeSpan.FromMilliseconds(1500))); Storyboard board = new Storyboard(); Storyboard.SetTarget(danim, this); Storyboard.SetTargetProperty(danim, new PropertyPath(OpacityProperty)); board.Children.Add(danim); board.Begin(); } } } } }
/// <summary> /// Callback METHOD /// </summary> private void timerRequestVoteIntervalElapsed() { //make sure that the value hasnt changed. if (VoteRequestWhen == VoteRequestFlags.OnInterval) { if (voteHandler != null && voteHandler.RequestVote(this)) { _voteState = VoteTouchButton2State.VOTING; //updates itself. ResetTimer(); timer.Interval = VoteAutoCancelInterval; timer.Elapsed += new ElapsedEventHandler(delegate(object src, ElapsedEventArgs evt) { Dispatcher.BeginInvoke(new VoidDelegate(timerVoteCancelIntevalElapsed), DispatcherPriority.Normal); }); timer.Start(); DoubleAnimation danim = new DoubleAnimation(colorSaturator.ColorSaturation, 0.5, new Duration(TimeSpan.FromMilliseconds(1500))); colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, null);// colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, danim); danim = new DoubleAnimation(0.9, new Duration(TimeSpan.FromMilliseconds(1500))); Storyboard board = new Storyboard(); Storyboard.SetTarget(danim, this); Storyboard.SetTargetProperty(danim, new PropertyPath(OpacityProperty)); board.Children.Add(danim); board.Begin(); } else //assumed because it could not request the vote { ResetTimer(); timer.Interval = VoteRequestInterval; timer.Elapsed += new ElapsedEventHandler( delegate(object obj, ElapsedEventArgs args) { Dispatcher.BeginInvoke(new VoidDelegate(timerRequestVoteIntervalElapsed), DispatcherPriority.Normal); }); timer.Start(); } } }
/// <summary> /// Called /// </summary> public void ForceWaiting(double time) { _voteState = VoteTouchButton2State.WAITING; if (VoteRequestWhen == VoteRequestFlags.OnInterval) { ResetTimer(); timer.Interval = time; timer.Elapsed += new ElapsedEventHandler( delegate(object obj, ElapsedEventArgs args) { Dispatcher.BeginInvoke(new VoidDelegate(timerRequestVoteIntervalElapsed), DispatcherPriority.Normal); }); timer.Start(); } }
/// <summary> /// CALLBACK METHOD /// </summary> public void timerVoteCancelIntevalElapsed() { if (voteHandler != null) { //let the handler know we want to stop the vote for this button voteHandler.CancelVote(this); _voteState = VoteTouchButton2State.WAITING; ResetTimer(); if (VoteRequestWhen == VoteRequestFlags.OnInterval) { timer.Interval = VoteRequestInterval; timer.Elapsed += new ElapsedEventHandler( delegate(object obj, ElapsedEventArgs args) { Dispatcher.BeginInvoke(new VoidDelegate(timerRequestVoteIntervalElapsed), DispatcherPriority.Normal); }); timer.Start(); } // DoubleAnimation danim = new DoubleAnimation(colorSaturator.ColorSaturation, 0.0, new Duration(TimeSpan.FromMilliseconds(1500))); colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, null);// colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, danim); } }
public void ForceRequest() { if (voteHandler != null && voteHandler.RequestVote(this)) { _voteState = VoteTouchButton2State.VOTING; ResetTimer(); timer.Interval = VoteAutoCancelInterval; timer.Elapsed += new ElapsedEventHandler(delegate(object src, ElapsedEventArgs evt) { Dispatcher.BeginInvoke(new VoidDelegate(timerVoteCancelIntevalElapsed), DispatcherPriority.Normal); }); timer.Start(); DoubleAnimation danim = new DoubleAnimation(colorSaturator.ColorSaturation, 0.5, new Duration(TimeSpan.FromMilliseconds(1500))); colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, null);// colorSaturator.BeginAnimation(ColorSaturatorEffect.ColorSaturationProperty, danim); danim = new DoubleAnimation(0.9, new Duration(TimeSpan.FromMilliseconds(1500))); Storyboard board = new Storyboard(); Storyboard.SetTarget(danim, this); Storyboard.SetTargetProperty(danim, new PropertyPath(OpacityProperty)); board.Children.Add(danim); board.Begin(); } }