Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1417 → Rev 1418

/akStopWatch/trunk/MainForm.Designer.cs
85,6 → 85,7
this.Load+=new System.EventHandler(this.MainForm_Load);
this.FormClosed+=new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
this.KeyPress+=new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
this.KeyDown+=new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
 
/akStopWatch/trunk/MainForm.cs
66,19 → 66,6
 
private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
{
int n;
try {
n = int.Parse(e.KeyChar.ToString());
}
catch(Exception ex) {
n = -1; // NaN
}
 
if(n >= 0 && n < times.Length)
{
times[n].Reset(DateTime.Now);
ShowTime();
}
}
 
private void MainForm_Load(object sender, EventArgs e)
157,6 → 144,10
g.DrawString(i.ToString(), fontSmall, brushSmall, x, y + dy * i);
g.DrawString(str, fontBig, brushBig, x + dx, y + dy * i);
 
if(times[i].Paused) {
g.DrawString("\u25CF", fontSmall, brushSmall, x, y + dy * (i + 0.3f));
}
}
}
catch(Exception ex)
176,13 → 167,46
Start(Count);
}
}
 
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) {
int n = (e.KeyCode - Keys.D0);
 
if(n >= 0 && n < times.Length)
{
TimeState time = times[n];
DateTime now = DateTime.Now;
 
if(e.Control) {
if(time.Paused) {
time.Continue(now);
}
else {
time.Pause(now);
}
}
else {
time.Reset(now);
}
 
ShowTime();
}
}
}
}
 
class TimeState
{
private TimeSpan collected;
private DateTime begin;
private DateTime last;
 
private bool paused;
public bool Paused {
get { return paused; }
}
 
public TimeState(DateTime now)
{
Reset(now);
190,21 → 214,45
 
public void Reset(DateTime now)
{
begin = now;
last = DateTime.MinValue;
collected = TimeSpan.Zero;
begin = now;
last = DateTime.MinValue;
paused = false;
}
 
public void Pause(DateTime now)
{
collected = collected.Add(now.Subtract(begin));
paused = true;
}
 
public void Continue(DateTime now)
{
begin = now;
last = DateTime.MinValue;
paused = false;
}
 
public bool IsChanged(DateTime now)
{
TimeSpan diff = now.Subtract(last);
return (diff.TotalSeconds > 0);
 
return (diff.TotalSeconds >= 1.0);
}
 
public TimeSpan GetDiff(DateTime now)
{
last = now;
return now.Subtract(begin);
 
TimeSpan diff;
if(paused) {
diff = collected;
}
else {
diff = now.Subtract(begin).Add(collected);
}
 
return diff;
}
}
}