aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/AnalogMeter.cs
blob: 80e0e850c6eb28e3f8fa895a7a86e9e1a6c6f918 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Xml.Serialization;
using System.ComponentModel;
using Cairo;

namespace Crow
{
	[DefaultTemplate("#Crow.Templates.AnalogMeter0.goml")]
	public class AnalogMeter : NumericControl
	{
		#region CTOR
		public AnalogMeter() : base()
		{}
		public AnalogMeter(double minimum, double maximum, double step)
			: base(minimum,maximum,step)
		{
		}
		#endregion

		#region GraphicObject Overrides
		protected override void onDraw (Context gr)
		{			
			base.onDraw (gr);

			Rectangle r = ClientRectangle;
			Point m = r.Center;

			gr.Save ();


			double aUnit = Math.PI*2.0 / (Maximum - Minimum);
			gr.Translate (m.X, r.Height *1.1);
			gr.Rotate (Value/4.0 * aUnit - Math.PI/4.0);
			gr.Translate (-m.X, -m.Y);

			gr.LineWidth = 2;
			Foreground.SetAsSource (gr);
			gr.MoveTo (m.X,0.0);
			gr.LineTo (m.X, -m.Y*0.5);
			gr.Stroke ();

			gr.Restore ();
		}
		#endregion
	}
}