PageRenderTime 18ms CodeModel.GetById 7ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/gui/progressbar.d

http://github.com/wilkie/djehuty
D | 79 lines | 50 code | 26 blank | 3 comment | 5 complexity | a9a095f9e609e1654319b6a9106b4b97 MD5 | raw file
 1module gui.progressbar;
 2
 3import gui.widget;
 4
 5import core.color;
 6import core.definitions;
 7import core.string;
 8
 9import graphics.graphics;
10
11template ControlPrintCSTRList() {
12	const char[] ControlPrintCSTRList = `
13	this(int x, int y, int width, int height) {
14		super(x,y,width,height);
15	}
16
17
18	`;
19}
20
21class ProgressBar : Widget {
22
23	// Description: This will create a button with the specified dimensions and text.
24	this(int x, int y, int width, int height) {
25		super(x,y,width,height);
26	}
27
28	override void onDraw(ref Graphics g) {
29		Brush brsh = new Brush(Color.Red);
30
31		g.brush = brsh;
32
33		g.drawRect(this.left, this.top, this.width, this.height);
34
35		int barWidth;
36
37		barWidth = cast(int)(cast(float)this.width * (cast(float)(_value - _min) / cast(float)(_max - _min)));
38
39		//writefln("barwidth: ", barWidth, " width: ", this.width, " value: ", _value, " max: ", _max);
40
41		brsh.setColor(Color.Green);
42		g.brush = brsh;
43
44		g.drawRect(this.left, this.right, barWidth, this.height);
45
46	}
47
48	// Properties
49
50	void range(long[2] value) {
51		_min = value[0];
52		_max = value[1];
53
54		if (_min > _max) { _min = _max; }
55		if (_value < _min) { _value = _min; }
56		if (_value > _max) { _value = _max; }
57	}
58
59	long[] range() {
60		return [_min, _max];
61	}
62
63	void value(long val) {
64		_value = val;
65
66		if (_value < _min) { _value = _min; }
67		if (_value > _max) { _value = _max; }
68	}
69
70	long value() {
71		return _value;
72	}
73
74protected:
75
76	long _min = 0;
77	long _max = 100;
78	long _value = 0;
79}