2018-05-06 21:32:18 +02:00
|
|
|
// računa približevanje ter računa/popravlja odmike videa
|
|
|
|
|
|
|
|
|
|
|
|
class Zoom {
|
2018-05-12 02:51:58 +02:00
|
|
|
// internal variables
|
2018-05-06 21:32:18 +02:00
|
|
|
|
|
|
|
|
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;
|
2018-09-18 23:37:33 +02:00
|
|
|
this.logScale = 0;
|
2018-05-24 20:50:37 +02:00
|
|
|
this.scaleStep = 0.1;
|
2018-09-18 23:37:33 +02:00
|
|
|
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-06 21:32:18 +02:00
|
|
|
|
2018-05-12 02:51:58 +02:00
|
|
|
reset(){
|
|
|
|
this.scale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
zoomIn(){
|
2018-09-18 23:37:33 +02:00
|
|
|
this.logScale += this.scaleStep;
|
2018-05-24 20:50:37 +02:00
|
|
|
|
2018-09-18 23:37:33 +02:00
|
|
|
if (this.logScale >= this.maxScale) {
|
|
|
|
this.logScale = this.maxScale;
|
2018-05-24 20:50:37 +02:00
|
|
|
}
|
2018-09-18 23:37:33 +02:00
|
|
|
|
|
|
|
this.scale = Math.pow(2, this.logScale);
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zoomOut(){
|
2018-09-18 23:37:33 +02:00
|
|
|
this.logScale -= this.scaleStep;
|
2018-05-24 20:50:37 +02:00
|
|
|
|
2018-09-18 23:37:33 +02:00
|
|
|
if (this.logScale <= this.minScale) {
|
|
|
|
this.logScale = this.minScale;
|
2018-05-24 20:50:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 23:37:33 +02:00
|
|
|
this.scale = Math.pow(2, this.logScale);
|
2018-05-24 20:50:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zoomStep(amount){
|
2018-09-18 23:37:33 +02:00
|
|
|
this.logScale += amount;
|
2018-05-24 20:50:37 +02:00
|
|
|
|
2018-09-18 23:37:33 +02:00
|
|
|
if (this.logScale <= this.minScale) {
|
|
|
|
this.logScale = this.minScale;
|
2018-05-24 20:50:37 +02:00
|
|
|
}
|
2018-09-18 23:37:33 +02:00
|
|
|
if (this.logScale >= this.maxScale) {
|
|
|
|
this.logScale = this.maxScale;
|
2018-05-24 20:50:37 +02:00
|
|
|
}
|
2018-09-13 23:47:20 +02:00
|
|
|
|
2018-09-18 23:37:33 +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) {
|
2018-09-18 23:37:33 +02:00
|
|
|
scale = this.minScale;
|
2018-05-12 02:51:58 +02:00
|
|
|
} else if (scale > this.maxScale) {
|
2018-09-18 23:37:33 +02:00
|
|
|
scale = this.maxScale;
|
2018-05-06 21:32:18 +02:00
|
|
|
}
|
2018-09-18 23:37:33 +02:00
|
|
|
|
|
|
|
this.scale = Math.pow(2, this.logScale);
|
|
|
|
|
|
|
|
this.conf.restoreAr();
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
applyZoom(videoDimensions){
|
2018-05-24 23:29:30 +02:00
|
|
|
videoDimensions.xFactor *= this.scale;
|
|
|
|
videoDimensions.yFactor *= this.scale;
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
2018-05-06 21:32:18 +02:00
|
|
|
}
|