aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/ProgressBar.cs
blob: c816535362c1bbb9bff64442885d2ff9d6fcdafd (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cairo;
using System.Diagnostics;
using System.Xml.Serialization;
using System.ComponentModel;

namespace Crow
{
	[Serializable]
	public class ProgressBar : Border
    {
		#region CTOR
		public ProgressBar() : base(){}
		public ProgressBar(int _max) : base()
		{
			Maximum = _max;
		}
		#endregion

		#region private fields
		int _currentValue = 0;
		int _minimum = 0;
		int _maximum = 100;
		#endregion

		#region public properties
		[XmlAttributeAttribute()][DefaultValue(0)]
		public int Value
		{
			get { return _currentValue; }
			set
			{
				if (_currentValue == value)
					return;

				_currentValue = value;

				if (_currentValue > Maximum)
					_currentValue = Maximum;

				registerForGraphicUpdate();
			}
		}
		[XmlAttributeAttribute()][DefaultValue(0)]
		public int Minimum {
			get {return _minimum;}
			set {
				if (_minimum == value || _minimum >= Maximum)
					return;
				_minimum = value;
				registerForGraphicUpdate ();
			}
		}
		[XmlAttributeAttribute()][DefaultValue(100)]
		public int Maximum {
			get {return _maximum;}
			set {
				if (_maximum == value || _maximum <= _minimum)
					return;
				_maximum = value;
				registerForGraphicUpdate();
			}
		}
		#endregion

		#region GraphicObject overrides
		[XmlAttributeAttribute()][DefaultValue("Gray")]
		public override Fill Background {
			get { return base.Background; }
			set { base.Background = value; }
		}
		[XmlAttributeAttribute()][DefaultValue(0)]
		public override int BorderWidth {
			get { return base.BorderWidth; }
			set { base.BorderWidth = value; }
		}
		[XmlAttributeAttribute()][DefaultValue("BlueCrayola")]
		public override Fill Foreground {
			get { return base.Foreground; }
			set { base.Foreground = value; }
		}

		protected override void onDraw (Context gr)
		{
			base.onDraw (gr);

			Rectangle rBack = Slot.Size;

			if (BorderWidth > 0)
				rBack.Inflate(-BorderWidth, -BorderWidth);

			rBack.Width = (int)((double)rBack.Width / Maximum * Value);

			Foreground.SetAsSource (gr, rBack);

			CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);
			gr.Fill();
		}
		#endregion
    }
}