ultrawidify/js/modules/Zoom.js

77 lines
1.5 KiB
JavaScript
Raw Normal View History

// računa približevanje ter računa/popravlja odmike videa
class Zoom {
2018-05-12 02:51:58 +02:00
// internal variables
2018-05-12 02:51:58 +02:00
// functions
2018-05-18 23:26:20 +02:00
constructor(videoData) {
2018-05-12 02:51:58 +02:00
this.scale = 1;
this.logScale = 0;
this.scaleStep = 0.1;
this.minScale = -1; // 50% (log2(0.5) = -1)
this.maxScale = 3; // 800% (log2(8) = 3)
2018-05-18 23:26:20 +02:00
this.conf = videoData;
2018-05-12 02:51:58 +02:00
}
2018-05-12 02:51:58 +02:00
reset(){
this.scale = 1;
}
zoomIn(){
this.logScale += this.scaleStep;
if (this.logScale >= this.maxScale) {
this.logScale = this.maxScale;
}
this.scale = Math.pow(2, this.logScale);
2018-05-12 02:51:58 +02:00
}
zoomOut(){
this.logScale -= this.scaleStep;
if (this.logScale <= this.minScale) {
this.logScale = this.minScale;
}
this.scale = Math.pow(2, this.logScale);
}
zoomStep(amount){
this.logScale += amount;
if (this.logScale <= this.minScale) {
this.logScale = this.minScale;
}
if (this.logScale >= this.maxScale) {
this.logScale = this.maxScale;
}
2018-09-13 23:47:20 +02:00
this.scale = Math.pow(2, this.logScale);
2018-09-13 23:47:20 +02:00
if (Debug.debug) {
console.log("[Zoom::zoomStep] changing zoom by", amount, ". New zoom level:", this.scale);
}
this.conf.restoreAr();
2018-05-12 02:51:58 +02:00
}
setZoom(scale){
if(scale < this.minScale) {
scale = this.minScale;
2018-05-12 02:51:58 +02:00
} else if (scale > this.maxScale) {
scale = this.maxScale;
}
this.scale = Math.pow(2, this.logScale);
this.conf.restoreAr();
2018-05-12 02:51:58 +02:00
}
applyZoom(videoDimensions){
videoDimensions.xFactor *= this.scale;
videoDimensions.yFactor *= this.scale;
2018-05-12 02:51:58 +02:00
}
}