Exemple #1
0
		private void TimerTickState()
		{
			bool fade = false;
			FadeItem init = new FadeItem {
				Color = this.settings.RunningColor,
				Time = this.settings.Duration
			};

			FadeItem dest = new FadeItem {
				Color = default(Color),
				Time = default(int),
			};

			switch (this.TimerState) {
			case TimerState.Running:
				{
					if (this.settings.HasFirstWarning) 
					{
						fade = true;
						init.Color = this.settings.RunningColor;
						init.Time = this.settings.Duration;
						if (this.settings.CounterMode == TimerViewSettings.TimerCounterMode.CountUp) {
							init.Time = 0;
						}

						dest.Color = this.settings.WarningColor;
						dest.Time = this.settings.WarningTime;
					}

					break;
				}

			case TimerState.FirstWarning:
				{
				
					fade = true;
					init.Color = this.settings.WarningColor;
					init.Time = this.settings.WarningTime;

					if (this.settings.HasSecondWarning) {
						dest.Color = this.settings.SecondWarningColor;
						dest.Time = this.settings.SecondWarningTime;
					} else {
						dest.Color = this.settings.ExpiredColor;
						dest.Time = 0;	
						if (this.settings.CounterMode == TimerViewSettings.TimerCounterMode.CountUp) {
							dest.Time = this.settings.Duration;
						}
					}

//					this.TimerColor = this.settings.WarningColor;
					break;
				}

			case TimerState.SecondWarning:
				{
					fade = true;
					init.Color = this.settings.SecondWarningColor;
					init.Time = this.settings.SecondWarningTime;

					dest.Color = this.settings.ExpiredColor;
					dest.Time = 0;	
					if (this.settings.CounterMode == TimerViewSettings.TimerCounterMode.CountUp) {
						dest.Time = this.settings.Duration;
					}
					
//					this.TimerColor = this.settings.WarningColor;
					break;
				}

			case TimerState.Expired:
				{
					this.TimerColor = this.settings.ExpiredColor;
					if (this.settings.BlinkOnExpired) {
						if (!this.blinkManager.IsBlinking) {
							this.blinkManager.StartBlinking ();
							this.OnTimeExpired ();
						}
					} else {
						this.OnTimeExpired ();
					}

					break;
				}

				
			case TimerState.Stopped:
				{
					this.StopTimer ();
					if (!this.DisplayFinalMessage ()) {
						this.DisplayTimeElapsed (this.CurrentTime);
					}

					break;
				}

			default:
				break;
			}

			if (fade) 
			{
				this.FadeTimerColor (init, dest);
			}
		}
Exemple #2
0
		private void FadeTimerColor(FadeItem init, FadeItem dest)
		{
			int fadeIndex = (int)(init.Time - this.CurrentTime);
			int steps = (int)(init.Time - dest.Time);
			if (fadeIndex < steps && steps > 1) {
				var oldR = init.Color.R;
				var oldG = init.Color.G;
				var oldB = init.Color.B;

				var newR = dest.Color.R;
				var newG = dest.Color.G;
				var newB = dest.Color.B;

				var r = oldR + ((fadeIndex * (newR - oldR)) / (steps - 1));
				var g = oldG + ((fadeIndex * (newG - oldG)) / (steps - 1));
				var b = oldB + ((fadeIndex * (newB - oldB)) / (steps - 1));

				this.TimerColor = Color.FromArgb (r, g, b);
			}
		}