PageRenderTime 14ms CodeModel.GetById 10ms 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
  1. module gui.progressbar;
  2. import gui.widget;
  3. import core.color;
  4. import core.definitions;
  5. import core.string;
  6. import graphics.graphics;
  7. template ControlPrintCSTRList() {
  8. const char[] ControlPrintCSTRList = `
  9. this(int x, int y, int width, int height) {
  10. super(x,y,width,height);
  11. }
  12. `;
  13. }
  14. class ProgressBar : Widget {
  15. // Description: This will create a button with the specified dimensions and text.
  16. this(int x, int y, int width, int height) {
  17. super(x,y,width,height);
  18. }
  19. override void onDraw(ref Graphics g) {
  20. Brush brsh = new Brush(Color.Red);
  21. g.brush = brsh;
  22. g.drawRect(this.left, this.top, this.width, this.height);
  23. int barWidth;
  24. barWidth = cast(int)(cast(float)this.width * (cast(float)(_value - _min) / cast(float)(_max - _min)));
  25. //writefln("barwidth: ", barWidth, " width: ", this.width, " value: ", _value, " max: ", _max);
  26. brsh.setColor(Color.Green);
  27. g.brush = brsh;
  28. g.drawRect(this.left, this.right, barWidth, this.height);
  29. }
  30. // Properties
  31. void range(long[2] value) {
  32. _min = value[0];
  33. _max = value[1];
  34. if (_min > _max) { _min = _max; }
  35. if (_value < _min) { _value = _min; }
  36. if (_value > _max) { _value = _max; }
  37. }
  38. long[] range() {
  39. return [_min, _max];
  40. }
  41. void value(long val) {
  42. _value = val;
  43. if (_value < _min) { _value = _min; }
  44. if (_value > _max) { _value = _max; }
  45. }
  46. long value() {
  47. return _value;
  48. }
  49. protected:
  50. long _min = 0;
  51. long _max = 100;
  52. long _value = 0;
  53. }