- speedtracker.zip
- SpeedTracker
- Screenshots
- Screen01.png
- Screen02.png
- Screen03.png
- Screen04.png
- Screen05.png
- Screen06.png
- Screen07.png
- Screen08.png
- Screen09.png
- Screen10.png
- ScreenShot.jpg
- ScreenShot.png
- ScreenShot1.Jpeg
- ScreenShot2.Jpeg
- ScreenShot3.Jpeg
- speed.png
- SpeedTracker36x36.png
- SpeedTracker45x45.png
- SpeedTracker60x60.png
- SpeedTracker64x64.png
- SpeedTracker90x90.png
- shortcut.xml
- SpeedTracker.4.5.resharper.user
- SpeedTracker.Common
- SpeedTracker.ico
- SpeedTracker.jpg
- SpeedTracker.png
- SpeedTracker.sln
- SpeedTracker
- SpeedTrackerInstaller
- Release
- CabWiz.log
- SpeedTrackerInstaller.CAB
- SpeedTrackerInstaller.inf
- SpeedTrackerInstaller.vddproj
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SpeedTracker
{
public partial class SpeedGauge : Control
{
class Shape
{
public Point[] PointList { get; set; }
public Color FillColor { get; set; }
public Color PenColor { get; set; }
}
private Shape[][] _markerList = null;
private Shape[] _readoutIndicator = null;
private Shape[][] MarkerList
{
get
{
return _markerList;
}
set { _markerList = value; }
}
//public Color _backgroundColor;
public Color _majorMarkerColor;
public Color _minorMarkerColor;
public Color _highSpeedMarkerColor;
public Color _needleColor;
public Color _normalTextColor;
private bool _gaugeMetricsChanged;
private int _highSpeed = 70;
private LedReadout _ledReadout;
public double Radius
{
get ;
internal set;
}
public bool GaugeMetricsChanged
{
get { return _gaugeMetricsChanged; }
set { _gaugeMetricsChanged = value; }
}
private double _maximumReading = 100d;
private int _majorMarkInterval = 5;
public int MajorMarkInterval
{
get { return _majorMarkInterval; }
set
{
_majorMarkInterval = value;
SetAsModified();
}
}
public double MaximumReading
{
get { return _maximumReading; }
set
{
_maximumReading = value;
Invalidate();
SetAsModified();
}
}
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
this._ledReadout.SetColor(LedDigit.PaletteIndex.Background,value);
}
}
//public Color BackgroundColor
//{
// get { return _backgroundColor; }
// set { _backgroundColor = value; }
//}
public Color HighSpeedMarkerColor
{
get { return _highSpeedMarkerColor; }
set { _highSpeedMarkerColor = value; }
}
public Color MajorMarkerColor
{
get { return _majorMarkerColor; }
set
{
_ledReadout.SetColor(LedDigit.PaletteIndex.Foreground, value);
_majorMarkerColor = value;
SetAsModified();
}
}
public Color MinorMarkerColor
{
get { return _minorMarkerColor; }
set
{
_minorMarkerColor = value;
SetAsModified();
}
}
public Color NeedleColor
{
get { return _needleColor; }
set
{
_needleColor = value;
SetAsModified();
}
}
public Color NormalTextColor
{
get { return _normalTextColor; }
set { _normalTextColor = value; }
}
public int HighSpeed
{
get { return _highSpeed; }
set
{
_highSpeed = value;
SetAsModified();
}
}
private int _value = 0;
public int Value
{
get { return _value; }
set
{
_value = value;
if (_value > MaximumReading)
MaximumReading = _value;
if(_ledReadout!=null)
_ledReadout.Value = value;
ResetReadout();
Invalidate();
}
}
void SetAsModified()
{
GaugeMetricsChanged = true;
}
public SpeedGauge()
{
InitializeComponent();
this.
_ledReadout = new LedReadout();
_ledReadout.Name = "_ledReadout";
this.Controls.Add(_ledReadout);
_ledReadout.DigitCount = 3;
}
void ResetReadout()
{
if (_readoutIndicator == null)
{
_readoutIndicator = new Shape[2];
_readoutIndicator[0] = new Shape();
_readoutIndicator[1] = new Shape();
_readoutIndicator[0].PointList = new Point[3];
_readoutIndicator[1].PointList = new Point[3];
_readoutIndicator[0].FillColor = Color.FromArgb(0x80, 0x80, 0xff);
_readoutIndicator[1].FillColor = Color.FromArgb(0xE0, 0xE0, 0xff);
}
float radius = (float)Math.Min(Width, Height) / 2f;
int centerX = Width / 2;
int centerY = Height / 2;
var markerCount = (int)Math.Floor(MaximumReading + 1);
float angleStep = (float)(Math.PI * 2d * 0.75d) / (float)markerCount;
float angularDisplace = angleStep*2;
float currentAngle = (float)(Math.PI * 0.75)+((float)Value)*angleStep;
_readoutIndicator[0].PointList[0].X = centerX + (int)(Math.Cos(currentAngle) * (float)radius * 0.85f);
_readoutIndicator[0].PointList[0].Y = centerY + (int)(Math.Sin(currentAngle) * (float)radius * 0.85f);
_readoutIndicator[0].PointList[1].X = centerX + (int)(Math.Cos(currentAngle + angularDisplace) * (float)radius * 0.75);
_readoutIndicator[0].PointList[1].Y = centerY + (int)(Math.Sin(currentAngle + angularDisplace) * (float)radius * 0.75);
_readoutIndicator[0].PointList[2].X = centerX + (int)(Math.Cos(currentAngle - angularDisplace) * (float)radius * 0.75);
_readoutIndicator[0].PointList[2].Y = centerY + (int)(Math.Sin(currentAngle - angularDisplace) * (float)radius * 0.75);
//----
_readoutIndicator[0].PointList[0].X = centerX + (int)(Math.Cos(currentAngle) * (float)radius * 0.90f);
_readoutIndicator[0].PointList[0].Y = centerY + (int)(Math.Sin(currentAngle) * (float)radius * 0.90f);
_readoutIndicator[0].PointList[1].X = centerX + (int)(Math.Cos(currentAngle + angularDisplace * 1.1) * (float)radius * 0.7f);
_readoutIndicator[0].PointList[1].Y = centerY + (int)(Math.Sin(currentAngle + angularDisplace * 1.1) * (float)radius * 0.7f);
_readoutIndicator[0].PointList[2].X = centerX + (int)(Math.Cos(currentAngle - angularDisplace * 1.1) * (float)radius * 0.7f);
_readoutIndicator[0].PointList[2].Y = centerY + (int)(Math.Sin(currentAngle - angularDisplace * 1.1) * (float)radius * 0.7f);
}
void ResetGauge(int width, int height)
{
float radius = (float)Math.Min(width, height) / 2f;
int centerX = width / 2;
int centerY = height / 2;
int gaugeWidth = Math.Min(width, height);
_ledReadout.Width = gaugeWidth/2;
_ledReadout.Height = gaugeWidth/3;
_ledReadout.Left = centerX - _ledReadout.Width/2;
_ledReadout.Top = centerY - _ledReadout.Height/2;
float angularWidth = (float)((Math.PI*2.0d)/(MaximumReading));
;
var markerCount = (int)Math.Floor(MaximumReading+1);
//Ensure the shape array is the right
if((_markerList==null)||(_markerList.Length!=markerCount))
{
_markerList = new Shape[markerCount][];
}
float angleStep = (float)(Math.PI * 2d * 0.75d) / (float)markerCount;
float currentAngle = (float)(Math.PI * 0.75);
for(var i=0;i<=(int)MaximumReading;++i)
{
_markerList[i] = new Shape[1];
_markerList[i][0]=new Shape();
int x1, y1, x2, y2, x3, y3, x4, y4;
Color fillColor;
if ((i % MajorMarkInterval) == 0)
{
x1 = centerX + (int)(Math.Cos(currentAngle) * (float)radius);
y1 = centerY + (int)(Math.Sin(currentAngle) * (float)radius);
x2 = centerX + (int)(Math.Cos(currentAngle) * (float)radius * 0.8f);
y2 = centerY + (int)(Math.Sin(currentAngle) * (float)radius * 0.8f);
x3 = centerX + (int)(Math.Cos(currentAngle + angularWidth) * (float)radius * 0.8f);
y3 = centerY + (int)(Math.Sin(currentAngle + angularWidth) * (float)radius * 0.8f);
x4 = centerX + (int)(Math.Cos(currentAngle + angularWidth) * (float)radius);
y4 = centerY + (int)(Math.Sin(currentAngle + angularWidth) * (float)radius);
fillColor = MajorMarkerColor;
}
else
{
x1 = centerX + (int) (Math.Cos(currentAngle)*(float) radius);
y1 = centerY + (int) (Math.Sin(currentAngle)*(float) radius);
x2 = centerX + (int) (Math.Cos(currentAngle)*(float) radius*0.9f);
y2 = centerY + (int) (Math.Sin(currentAngle)*(float) radius*0.9f);
x3 = centerX + (int) (Math.Cos(currentAngle + angularWidth)*(float) radius*0.9f);
y3 = centerY + (int) (Math.Sin(currentAngle + angularWidth)*(float) radius*0.9f);
x4 = centerX + (int) (Math.Cos(currentAngle + angularWidth)*(float) radius);
y4 = centerY + (int) (Math.Sin(currentAngle + angularWidth)*(float) radius);
fillColor = MinorMarkerColor;
}
if(i>=HighSpeed)
{
fillColor = HighSpeedMarkerColor;
}
_markerList[i][0].FillColor = fillColor;
_markerList[i][0].PenColor = Color.Black;
_markerList[i][0].PointList = new Point[]
{
new Point(){ X=x1, Y=y1},
new Point(){ X=x2, Y=y2},
new Point(){ X=x3, Y=y3},
new Point(){ X=x4, Y=y4},
new Point(){ X=x1, Y=y1}
};
currentAngle += angleStep;
}
}
void RenderGauge(Graphics target, int width, int height)
{
if(GaugeMetricsChanged)
{
ResetGauge(Width, Height);
GaugeMetricsChanged = false;
}
var radius=(double) Math.Min(width, height)/2d;
var centerX = (double) width/2d;
var centerY = (double) height/2d;
var angleStep = Math.PI*2.0d*0.75/(double) MaximumReading;
var currentAngle = Math.PI*.75;
var majorCount = 0;
var minorCount = 0;
for(var i=0d;i<=MaximumReading;++i)
{
bool isMajor = (majorCount == 0);
if(isMajor)
{
majorCount = MajorMarkInterval;
}
currentAngle += angleStep;
--majorCount;
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
DestroyBackBuffer();
ResetGauge(Width, Height);
ResetReadout();
Invalidate();
}
private Bitmap _offBitmap = null;
protected override void OnPaintBackground(PaintEventArgs e)
{
}
void DestroyBackBuffer()
{
if (_offBitmap != null)
{
_offBitmap.Dispose();
_offBitmap = null;
}
}
protected override void OnPaint(PaintEventArgs pe)
{
if(_offBitmap==null)
{
_offBitmap = new Bitmap(ClientSize.Width, ClientSize.Height);
}
var gOff = Graphics.FromImage(_offBitmap);
var g = pe.Graphics;
gOff.Clear(BackColor);
//base.OnPaint(pe);
RenderGauge(pe.Graphics, this.Width, this.Height);
SolidBrush currentBrush = new SolidBrush(_readoutIndicator[0].FillColor);
for(var i=0;i<_markerList.Length;++i)
{
for(var k=0;k<_markerList[i].Length;++k)
{
if ((currentBrush.Color != _markerList[i][k].FillColor))
{
currentBrush.Dispose();
currentBrush = new SolidBrush(_markerList[i][k].FillColor);
}
gOff.FillPolygon(new SolidBrush(_markerList[i][k].FillColor), _markerList[i][k].PointList);
//g.DrawPolygon(new Pen(_markerList[i][k].PenColor),_markerList[i][k].PointList );
}
}
for(var i=0;i<_readoutIndicator.Length;++i)
{
if ((currentBrush.Color != _readoutIndicator[i].FillColor))
{
currentBrush.Dispose();
currentBrush = new SolidBrush(_readoutIndicator[i].FillColor);
}
gOff.FillPolygon((currentBrush), _readoutIndicator[i].PointList);
}
currentBrush.Dispose();
g.DrawImage(_offBitmap,0,0);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.