/// <summary> /// "Tick" event for the timer, which is called every time the interval for the timer passes. /// </summary> private void timer1_Tick(object sender, EventArgs e) { if (isScreenPressed == false) { RawDataField rdf = new RawDataField(); int centerScreenX = this.Width / 2; int centerScreenY = this.Height / 2; rdf.IsPressed = false; rdf.IsTimedOut = true; DateTime trialEnd = DateTime.Now; TimeSpan ts = trialEnd.Subtract(trialStart); rdf.Start = trialStart; rdf.End = trialEnd; rdf.Time = ts; rdf.ButtonX = centerX; rdf.ButtonY = centerY; rdf.CircleRadius = radius; rdf.TrialNumber = trialCount; ls.Add(rdf); } else if (isScreenPressed == true) { if (isCirclePressed == false) { RawDataField rdf = new RawDataField(); int centerScreenX = this.Width / 2; int centerScreenY = this.Height / 2; rdf.IsPressed = false; rdf.IsTimedOut = true; DateTime trialEnd = DateTime.Now; TimeSpan ts = trialEnd.Subtract(trialStart); rdf.Start = trialStart; rdf.End = trialEnd; rdf.Time = ts; rdf.ButtonX = centerX; rdf.ButtonY = centerY; rdf.CircleRadius = radius; rdf.TrialNumber = trialCount; rdf.IsTimedOut = true; ls.Add(rdf); } } trialsCompleted++; if (trialsCompleted < numTrials) { drawCircle(); } else { timer.Enabled = false; this.Dispose(); } }
/// <summary> /// Handles data collection whenever a press, whether by mouse /// or by touch, is registered on the screen. This method also /// handles what should be done if the timer is enabled but a /// press is registered. In its current implementation, the /// result will be that the timer's "Tick" event will be triggered, /// causing a circle to be drawn without waiting for the timer. /// </summary> private void MonkeyPress(object sender, MouseEventArgs e) { RawDataField rdf = new RawDataField(); int centerScreenX = this.Width / 2; int centerScreenY = this.Height / 2; int x2 = e.X; int y2 = e.Y; int distance = (int)ShapeCalculator.PointDistance(centerX, centerY, x2, y2); DateTime trialEnd = DateTime.Now; TimeSpan ts = trialEnd.Subtract(trialStart); rdf.Start = trialStart; rdf.End = trialEnd; rdf.Time = ts; rdf.ClickX = x2; rdf.ClickY = y2; rdf.ButtonX = centerX; rdf.ButtonY = centerY; rdf.Distance = distance; rdf.CircleRadius = radius; rdf.TrialNumber = trialCount; ls.Add(rdf); if (centerX > centerScreenX) { if (centerY < centerScreenY) { rdf.Quadrant = "Quadrant I"; } else { rdf.Quadrant = "Quadrant IV"; } } else { if (centerY < centerScreenY) { rdf.Quadrant = "Quadrant II"; } else { rdf.Quadrant = "Quadrant III"; } } if (distance < radius) { isCirclePressed = true; rdf.IsPressed = true; rdf.IsTimedOut = false; if (soundEnabled == true) { player.Play(); } if (isTimed == true) { resetTimer(); //resets the interval of the Timer so that trial durations are not interrupted by a redraw of the circle. timer1_Tick(null, null); } else { drawCircle(); } } else { isCirclePressed = false; rdf.IsPressed = false; rdf.IsTimedOut = false; } if (x2 > centerScreenX) { if (y2 < centerScreenY) { rdf.ClickQuadrant = "Quadrant I"; } else { rdf.ClickQuadrant = "Quadrant IV"; } } else { if (y2 < centerScreenY) { rdf.ClickQuadrant = "Quadrant II"; } else { rdf.ClickQuadrant = "Quadrant III"; } } isScreenPressed = true; }