1 module source.d2d.ProgressBar; 2 3 import d2d; 4 5 /** 6 * A progress bar to be displayed at any point on the screen 7 * Fills from left to right its progress 8 * TODO: allow bar direction to be modified 9 */ 10 class ProgressBar(T) : Component { 11 12 iRectangle _location; ///The location and dimensions of the bar 13 T maxVal; ///The maximum value of the quantity measured 14 T currentVal; ///The current value of the quantity measured 15 Color backColor; ///The background color of the bar 16 Color foreColor; ///The forground color of the bar 17 18 /** 19 * Constructs a new health bar at the given location with the given values 20 */ 21 this(Display container, iRectangle location, Color backColor, Color foreColor, T maxVal, 22 T currentVal = 0) { 23 super(container); 24 this._location = location; 25 this.backColor = backColor; 26 this.foreColor = foreColor; 27 this.maxVal = maxVal, 28 this.currentVal = currentVal; 29 } 30 31 /** 32 * Returns the location of the progress bar 33 */ 34 override @property iRectangle location() { 35 return this._location; 36 } 37 38 /** 39 * Sets the location of the progress bar 40 */ 41 override @property void location(iRectangle newLocation) { 42 this._location = newLocation; 43 } 44 45 /** 46 * Draws the progress bar to the screen 47 */ 48 override void draw() { 49 this.container.renderer.fillRect(this._location, this.backColor); 50 if(this.currentVal >= 0) { 51 this.container.renderer.fillRect(new iRectangle(this._location.x, this._location.y, 52 cast(int)(this._location.w * (this.currentVal / this.maxVal)), this._location.h), this.foreColor); 53 } 54 } 55 56 }