|
1 | | -_progressBar = new Window('palette', configs.title, undefined, { |
2 | | - resizeable : false, |
3 | | - borderless : 'not quite true', |
4 | | -}); |
5 | | - |
6 | | -_progressBar.preferredSize = [420, 40]; |
7 | | -_progressBar.bar = _progressBar.add("progressbar", undefined, 0, 100); |
8 | | -_progressBar.bar.value = 0; |
9 | | -_progressBar.bar.preferredSize.width = 400; |
10 | | -_progressBar.bar.show() |
11 | | - |
12 | | -_progressBar.barInfos = _progressBar.add("statictext", undefined, 'Loading, please wait', { |
13 | | - justify: 'center' |
14 | | -}); |
15 | | -_progressBar.barInfos.preferredSize = [400, 17]; |
16 | | - |
17 | | -_progressBar.make = function (min, max, current) { |
18 | | - this.barProps = { |
19 | | - min : min, |
20 | | - max : max, |
21 | | - current : current, |
| 1 | +function ProgressBar(min, max, current) { |
| 2 | + |
| 3 | + var _window, |
| 4 | + _progressBar, |
| 5 | + _infos, |
| 6 | + _real, |
| 7 | + _cursor, |
| 8 | + _isVisible; |
| 9 | + |
| 10 | + this.testInfos = 'Processing element :current on :max'; |
| 11 | + |
| 12 | + this.constructor = function(min, max, current) { |
| 13 | + |
| 14 | + _this = this; |
| 15 | + _isVisible = false; |
| 16 | + |
| 17 | + _real = { min : min, max : max, current : current }; |
| 18 | + _cursor = { min : 0, max : 100, current : 0 }; |
| 19 | + |
| 20 | + _cursor.max = (_real.max - _real.min) + 1; |
| 21 | + |
| 22 | + // Instanciate the window |
| 23 | + _window = new Window('palette', configs.title, undefined, { |
| 24 | + resizeable : false, |
| 25 | + borderless : 'not quite true', |
| 26 | + }); |
| 27 | + _window.preferredSize = [420, 40]; |
| 28 | + |
| 29 | + // Instanciate the progress bar |
| 30 | + _progressBar = _window.add("progressbar", undefined, _cursor.min, _cursor.max); |
| 31 | + _progressBar.preferredSize.width = 400; |
| 32 | + _progressBar.show(); |
| 33 | + |
| 34 | + // Instanciate text infos |
| 35 | + _infos = _window.add("statictext", undefined, 'Loading, please wait', { |
| 36 | + justify: 'center' |
| 37 | + }); |
| 38 | + _infos.preferredSize = [400, 17]; |
| 39 | + |
| 40 | + this.update(current); |
| 41 | + |
| 42 | + |
| 43 | + return this; |
| 44 | + |
22 | 45 | } |
23 | | - this.barProps.total = (this.barProps.max - this.barProps.min) + 1; |
24 | | - this.barProps.step = (this.barProps.current - this.barProps.min) + 1; |
25 | | -} |
26 | 46 |
|
27 | | -_progressBar.updateBar = function () { |
28 | | - this.bar.value = Math.round(( (this.barProps.step) * 100) / this.barProps.max) |
29 | | - consLog('Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total); |
30 | | - this.barInfos.text = 'Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total; |
31 | | -} |
| 47 | + this.start = function () { |
| 48 | + _isVisible = true; |
| 49 | + this.update(_real.current) |
| 50 | + _window.show(); |
| 51 | + } |
| 52 | + |
| 53 | + this.end = function () { |
| 54 | + _window.hide(); |
| 55 | + } |
| 56 | + |
| 57 | + this.update = function(step) { |
| 58 | + |
| 59 | + _real.current = step; |
| 60 | + _cursor.current = (_real.current + 1) - _real.min; |
| 61 | + |
| 62 | + var infos = this.testInfos |
| 63 | + .replace(':current', _cursor.current) |
| 64 | + .replace(':max', _cursor.max); |
32 | 65 |
|
33 | | -_progressBar.showBar = function () { this.show(); } |
| 66 | + _progressBar.value = _cursor.current; |
| 67 | + _infos.text = infos; |
34 | 68 |
|
35 | | -_progressBar.hideBar = function () { this.hide(); } |
| 69 | + cDebug(infos); |
| 70 | + |
| 71 | + updateGraphics(); |
| 72 | + } |
| 73 | + |
| 74 | + function updateGraphics() { |
| 75 | + if(!_isVisible) return; |
| 76 | + _window.update(); |
| 77 | + } |
| 78 | + |
| 79 | + return this.constructor(min, max, current); |
36 | 80 |
|
37 | | -_progressBar.setCurrent = function (current, text) { |
38 | | - this.barProps.current = current; |
39 | | - this.barProps.step = (this.barProps.current - this.barProps.min) + 1; |
40 | | - this.updateBar(); |
41 | | - this.update(); |
42 | 81 | } |
| 82 | + |
| 83 | +// this.bar.value = Math.round(( (this.barProps.step) * 100) / this.barProps.max) |
0 commit comments