|
26 | 26 | this.resizeHeight = this.container.querySelector('[name=resize-height]');
|
27 | 27 | this.smoothResize = this.container.querySelector('[name=smooth-resize-checkbox]');
|
28 | 28 |
|
| 29 | + this.framesH = this.container.querySelector('[name=frames-h]'); |
| 30 | + this.framesV = this.container.querySelector('[name=frames-v]'); |
29 | 31 | this.frameSizeX = this.container.querySelector('[name=frame-size-x]');
|
30 | 32 | this.frameSizeY = this.container.querySelector('[name=frame-size-y]');
|
31 | 33 | this.frameOffsetX = this.container.querySelector('[name=frame-offset-x]');
|
|
34 | 36 | this.addEventListener(this.singleImportType, 'change', this.onImportTypeChange_);
|
35 | 37 | this.addEventListener(this.sheetImportType, 'change', this.onImportTypeChange_);
|
36 | 38 |
|
| 39 | + this.addEventListener(this.framesH, 'keyup', this.onFrameInputKeyUp_); |
| 40 | + this.addEventListener(this.framesV, 'keyup', this.onFrameInputKeyUp_); |
37 | 41 | this.addEventListener(this.resizeWidth, 'keyup', this.onResizeInputKeyUp_);
|
38 | 42 | this.addEventListener(this.resizeHeight, 'keyup', this.onResizeInputKeyUp_);
|
39 | 43 | this.addEventListener(this.frameSizeX, 'keyup', this.onFrameInputKeyUp_);
|
|
73 | 77 | this.importedImage_,
|
74 | 78 | {
|
75 | 79 | importType: this.getImportType_(),
|
| 80 | + framesH: this.getImportType_() === 'single' ? |
| 81 | + 1 : this.sanitizeInputValue_(this.frameSizeX, 1), |
| 82 | + frameV: this.getImportType_() === 'single' ? |
| 83 | + 1 : this.sanitizeInputValue_(this.frameSizeY, 1), |
76 | 84 | frameSizeX: this.getImportType_() === 'single' ?
|
77 | 85 | this.resizeWidth.value : this.sanitizeInputValue_(this.frameSizeX, 1),
|
78 | 86 | frameSizeY: this.getImportType_() === 'single' ?
|
|
110 | 118 |
|
111 | 119 | ns.ImageImport.prototype.onFrameInputKeyUp_ = function (evt) {
|
112 | 120 | if (this.importedImage_) {
|
| 121 | + var targetName = evt.originalTarget.name; |
| 122 | + if (!targetName.includes('offset')) { |
| 123 | + this.synchronizeDivisions(targetName); |
| 124 | + } |
113 | 125 | this.synchronizeFrameFields_(evt.target.value);
|
114 | 126 | }
|
115 | 127 | };
|
116 | 128 |
|
| 129 | + ns.ImageImport.prototype.synchronizeDivisions = function (targetName) { |
| 130 | + var divideBy = (targetName === 'frames-h' || targetName === 'frame-size-x') ? |
| 131 | + this.importedImage_.width : this.importedImage_.height; |
| 132 | + |
| 133 | + switch (targetName) { |
| 134 | + case 'frames-h': |
| 135 | + this.frameSizeX.value = Math.floor(divideBy / this.sanitizeInputValue_(this.framesH, 0)); |
| 136 | + break; |
| 137 | + case 'frame-size-x': |
| 138 | + this.framesH.value = Math.floor(divideBy / this.sanitizeInputValue_(this.frameSizeX, 1)); |
| 139 | + break; |
| 140 | + case 'frames-v': |
| 141 | + this.frameSizeY.value = Math.floor(divideBy / this.sanitizeInputValue_(this.framesV, 1)); |
| 142 | + break; |
| 143 | + case 'frame-size-y': |
| 144 | + this.framesV.value = Math.floor(divideBy / this.sanitizeInputValue_(this.frameSizeY, 1)); |
| 145 | + break; |
| 146 | + } |
| 147 | + }; |
| 148 | + |
117 | 149 | ns.ImageImport.prototype.synchronizeResizeFields_ = function (value, from) {
|
118 | 150 | value = parseInt(value, 10);
|
119 | 151 | if (isNaN(value)) {
|
|
139 | 171 | }
|
140 | 172 |
|
141 | 173 | // Parse the frame input values
|
| 174 | + var framesH = this.sanitizeInputValue_(this.framesH, 1); |
| 175 | + var framesV = this.sanitizeInputValue_(this.framesV, 1); |
142 | 176 | var frameSizeX = this.sanitizeInputValue_(this.frameSizeX, 1);
|
143 | 177 | var frameSizeY = this.sanitizeInputValue_(this.frameSizeY, 1);
|
144 | 178 | var frameOffsetX = this.sanitizeInputValue_(this.frameOffsetX, 0);
|
|
187 | 221 | this.resizeWidth.value = w;
|
188 | 222 | this.resizeHeight.value = h;
|
189 | 223 |
|
| 224 | + this.framesH.value = 1; |
| 225 | + this.framesV.value = 1; |
190 | 226 | this.frameSizeX.value = w;
|
191 | 227 | this.frameSizeY.value = h;
|
192 | 228 | this.frameOffsetX.value = 0;
|
|
0 commit comments