MCPcopy Create free account
hub / github.com/devforth/painterro / setZoom

Method setZoom

js/main.js:1284–1330  ·  view source on GitHub ↗
(zoomPercentage)

Source from the content-addressed store, hash-verified

1282 }
1283
1284 setZoom(zoomPercentage) {
1285 if (!this.size) {
1286 return;
1287 }
1288
1289 this.zoomFactor = zoomPercentage / 100;
1290
1291 let minFactor = 1;
1292 if (this.size.w > this.wrapper.documentClientWidth) {
1293 minFactor = Math.min(minFactor, this.wrapper.documentClientWidth / this.size.w);
1294 }
1295 if (this.size.h > this.wrapper.documentClientHeight) {
1296 minFactor = Math.min(minFactor, this.wrapper.documentClientHeight / this.size.h);
1297 }
1298
1299 if (!this.zoom && this.zoomFactor > minFactor) {
1300 this.zoomFactor = minFactor;
1301 }
1302
1303 if (this.zoomFactor < minFactor) {
1304 this.zoom = false;
1305 this.zoomFactor = minFactor;
1306 } else {
1307 this.zoom = true;
1308 }
1309
1310 this.adjustSizeFull();
1311 this.select.adjustPosition();
1312
1313 const canvas = this.canvas;
1314 const gbr = canvas.getBoundingClientRect();
1315
1316 this.curCord = [
1317 (gbr.right / 2 - this.elLeft()) + this.scroller.scrollLeft,
1318 (gbr.bottom / 2 - this.elTop()) + this.scroller.scrollTop,
1319 ];
1320
1321 const scale = this.getScale();
1322 this.curCord = [this.curCord[0] * scale, this.curCord[1] * scale];
1323
1324 if (this.zoom) {
1325 this.scroller.scrollLeft = (this.curCord[0] / this.getScale()) -
1326 (gbr.right / 2 - this.wrapper.documentOffsetLeft);
1327 this.scroller.scrollTop = (this.curCord[1] / this.getScale()) -
1328 (gbr.bottom / 2 - this.wrapper.documentOffsetTop);
1329 }
1330 }
1331
1332 doScale({width, height, scale}) {
1333 if (scale) {

Callers

nothing calls this directly

Calls 5

adjustSizeFullMethod · 0.95
elLeftMethod · 0.95
elTopMethod · 0.95
getScaleMethod · 0.95
adjustPositionMethod · 0.80

Tested by

no test coverage detected