Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1416 → Rev 1415

/akStopWatch/trunk/SettingsForm.resx
File deleted
\ No newline at end of file
/akStopWatch/trunk/SettingsForm.Designer.cs
File deleted
\ No newline at end of file
/akStopWatch/trunk/SettingsForm.cs
File deleted
\ No newline at end of file
/akStopWatch/trunk/MainForm.Designer.cs
29,49 → 29,28
private void InitializeComponent()
{
this.components=new System.ComponentModel.Container();
this.timeLabel=new System.Windows.Forms.Label();
this.timer=new System.Windows.Forms.Timer(this.components);
this.panel1=new System.Windows.Forms.Panel();
this.settingsButton=new System.Windows.Forms.Button();
this.timeLabel=new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// timer
//
this.timer.Interval=50;
this.timer.Tick+=new System.EventHandler(this.timer_Tick);
//
// panel1
//
this.panel1.Controls.Add(this.settingsButton);
this.panel1.Location=new System.Drawing.Point(2, 2);
this.panel1.Name="panel1";
this.panel1.Size=new System.Drawing.Size(289, 30);
this.panel1.TabIndex=1;
//
// settingsButton
//
this.settingsButton.Location=new System.Drawing.Point(3, 4);
this.settingsButton.Name="settingsButton";
this.settingsButton.Size=new System.Drawing.Size(75, 23);
this.settingsButton.TabIndex=3;
this.settingsButton.Text="Settings";
this.settingsButton.UseVisualStyleBackColor=true;
this.settingsButton.Click+=new System.EventHandler(this.settingsButton_Click);
//
// timeLabel
//
this.timeLabel.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top|System.Windows.Forms.AnchorStyles.Bottom)
|System.Windows.Forms.AnchorStyles.Left)
|System.Windows.Forms.AnchorStyles.Right)));
this.timeLabel.BackColor=System.Drawing.SystemColors.Control;
this.timeLabel.Font=new System.Drawing.Font("Courier New", 72F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.timeLabel.Location=new System.Drawing.Point(0, 35);
this.timeLabel.Location=new System.Drawing.Point(0, 0);
this.timeLabel.Name="timeLabel";
this.timeLabel.Size=new System.Drawing.Size(293, 239);
this.timeLabel.TabIndex=2;
this.timeLabel.Size=new System.Drawing.Size(293, 275);
this.timeLabel.TabIndex=0;
this.timeLabel.Paint+=new System.Windows.Forms.PaintEventHandler(this.timeLabel_Paint);
this.timeLabel.Click+=new System.EventHandler(this.MainForm_Click);
//
// timer
//
this.timer.Interval=1000;
this.timer.Tick+=new System.EventHandler(this.timer_Tick);
//
// MainForm
//
this.AutoScaleDimensions=new System.Drawing.SizeF(6F, 13F);
78,14 → 57,12
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=new System.Drawing.Size(292, 273);
this.Controls.Add(this.timeLabel);
this.Controls.Add(this.panel1);
this.KeyPreview=true;
this.Name="MainForm";
this.Text="akStopWatch";
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.panel1.ResumeLayout(false);
this.Resize+=new System.EventHandler(this.MainForm_Resize);
this.ResumeLayout(false);
 
}
92,10 → 69,8
 
#endregion
 
private System.Windows.Forms.Label timeLabel;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label timeLabel;
private System.Windows.Forms.Button settingsButton;
}
}
 
/akStopWatch/trunk/MainForm.cs
10,106 → 10,42
{
public partial class MainForm : Form
{
public const string REGISTRY_KEY = @"Software\Anatoli Klassen\akStopWatch";
private int time = 0;
 
private int count = 3;
public int Count {
get { return count; }
set {
count = value;
 
if(count < 1) count = 1;
if(count > 10) count = 10;
}
}
 
private TimeState[] times;
 
public MainForm()
{
InitializeComponent();
}
 
private void LoadSettings()
{
Microsoft.Win32.RegistryKey subkey = null;
try
{
subkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(REGISTRY_KEY);
if(subkey != null)
{
Count = (int)subkey.GetValue("Count", Count);
}
}
finally
{
if(subkey != null)
subkey.Close();
}
}
private void MainForm_Click(object sender, EventArgs e)
{
Start();
}
 
private void SaveSettings()
{
Microsoft.Win32.RegistryKey subkey = null;
try
{
subkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(REGISTRY_KEY);
 
subkey.SetValue("Count", Count);
}
finally
{
if(subkey != null)
subkey.Close();
}
}
 
private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
{
int n = int.Parse(e.KeyChar.ToString());
 
if(n >= 0 && n < times.Length)
{
times[n].Reset(DateTime.Now);
ShowTime();
}
Start();
}
 
private void MainForm_Load(object sender, EventArgs e)
{
LoadSettings();
Start(Count);
Start();
}
 
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
private void MainForm_Resize(object sender, EventArgs e)
{
SaveSettings();
}
 
private void timer_Tick(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
bool isChanged = false;
foreach(TimeState t in times)
{
isChanged |= t.IsChanged(now);
}
 
if(isChanged) {
ShowTime();
}
++time;
ShowTime();
}
 
private void Start(int n)
private void Start()
{
times = new TimeState[n];
 
DateTime now = DateTime.Now;
for(int i = 0; i < times.Length; ++i)
{
times[i] = new TimeState(now);
}
 
timer.Stop();
time = 0;
ShowTime();
timer.Start();
}
123,35 → 59,23
{
try
{
Graphics g = e.Graphics;
SolidBrush brushBig = new SolidBrush(Color.Black);
SolidBrush brushSmall = new SolidBrush(Color.Red);
Graphics g = e.Graphics;
SolidBrush brush = new SolidBrush(Color.Black);
 
g.FillRectangle(SystemBrushes.Control, g.Clip.GetBounds(g));
 
float bigToSmall = 2.0f;
string sampleBig = string.Format("{0:00}:{1:00}:{2:00}", 0, 0, 0);
string sampleSmall = string.Format("{0:0}", 0);
SizeF sizeBig = g.MeasureString(sampleBig, timeLabel.Font);
SizeF sizeSmall = g.MeasureString(sampleSmall, timeLabel.Font);
float k = Math.Min(timeLabel.Width / (sizeBig.Width + sizeSmall.Width / bigToSmall),
timeLabel.Height / (sizeBig.Height * times.Length));
float dx = sizeSmall.Width * k / bigToSmall;
float x = (timeLabel.Width - (sizeBig.Width + sizeSmall.Width / bigToSmall) * k) / 2;
float dy = sizeBig.Height * k;
float y = (timeLabel.Height - sizeBig.Height * times.Length * k) / 2;
Font fontBig = new Font(timeLabel.Font.FontFamily, timeLabel.Font.Size * k, timeLabel.Font.Style);
Font fontSmall = new Font(timeLabel.Font.FontFamily, timeLabel.Font.Size * k / bigToSmall, timeLabel.Font.Style);
int hour = time / 60 / 60;
int min = time / 60 % 60;
int sec = time % 60 % 60;
string str = string.Format("{0:00}:{1:00}:{2:00}", hour, min, sec);
 
DateTime now = DateTime.Now;
for(int i = 0; i < times.Length; ++i)
{
TimeSpan time = times[i].GetDiff(now);
string str = string.Format("{0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds);
g.DrawString(i.ToString(), fontSmall, brushSmall, x, y + dy * i);
g.DrawString(str, fontBig, brushBig, x + dx, y + dy * i);
}
SizeF strSize = g.MeasureString(str, timeLabel.Font);
float k = Math.Min(timeLabel.Width / strSize.Width, timeLabel.Height / strSize.Height);
float x = (timeLabel.Width - strSize.Width * k) / 2;
float y = (timeLabel.Height - strSize.Height * k) / 2;
Font font = new Font(timeLabel.Font.FontFamily, timeLabel.Font.Size * k, timeLabel.Font.Style);
g.DrawString(str, font, brush, x, y);
}
catch(Exception ex)
{
158,47 → 82,5
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
}
}
 
private void settingsButton_Click(object sender, EventArgs e)
{
SettingsForm f = new SettingsForm();
 
f.countBox.Value = times.Length;
if(f.ShowDialog(this) == DialogResult.OK)
{
Count = (int)f.countBox.Value;
Start(Count);
}
}
}
 
class TimeState
{
private DateTime begin;
private DateTime last;
 
public TimeState(DateTime now)
{
Reset(now);
}
 
public void Reset(DateTime now)
{
begin = now;
last = DateTime.MinValue;
}
 
public bool IsChanged(DateTime now)
{
TimeSpan diff = now.Subtract(last);
return (diff.TotalSeconds > 0);
}
 
public TimeSpan GetDiff(DateTime now)
{
last = now;
return now.Subtract(begin);
}
}
}
/akStopWatch/trunk/Properties/AssemblyInfo.cs
6,7 → 6,7
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("akStopWatch")]
[assembly: AssemblyDescription("A simplest stop-watch - multiple counters controlled by single key press")]
[assembly: AssemblyDescription("A simplest stop-watch - restarts on click on key press")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Anatoli Klassen")]
[assembly: AssemblyProduct("akStopWatch")]
/akStopWatch/trunk/akStopWatch.csproj
53,10 → 53,6
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="SettingsForm.resx">
<SubType>Designer</SubType>
<DependentUpon>SettingsForm.cs</DependentUpon>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
70,12 → 66,6
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="SettingsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SettingsForm.Designer.cs">
<DependentUpon>SettingsForm.cs</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.