2018-12-31 01:03:07 +01:00
|
|
|
import Debug from '../../conf/Debug';
|
2021-02-08 22:45:51 +01:00
|
|
|
import Logger from '../Logger';
|
|
|
|
import VideoData from '../video-data/VideoData';
|
2018-05-06 21:32:18 +02:00
|
|
|
|
2018-12-31 01:03:07 +01:00
|
|
|
// računa približevanje ter računa/popravlja odmike videa
|
|
|
|
// calculates zooming and video offsets/panning
|
2018-05-06 21:32:18 +02:00
|
|
|
|
|
|
|
class Zoom {
|
2021-02-08 22:45:51 +01:00
|
|
|
//#region flags
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region helper objects
|
|
|
|
conf: VideoData;
|
|
|
|
logger: Logger;
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region misc data
|
|
|
|
scale: number = 1;
|
2021-10-31 23:19:32 +01:00
|
|
|
scaleY: number = 1;
|
2021-02-08 22:45:51 +01:00
|
|
|
logScale: number = 0;
|
2021-10-31 23:19:32 +01:00
|
|
|
logScaleY: number = 0;
|
|
|
|
scaleStep: number = 0.1;
|
2021-02-08 22:45:51 +01:00
|
|
|
minScale: number = -1; // 50% (log2(0.5) = -1)
|
|
|
|
maxScale: number = 3; // 800% (log2(8) = 3)
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
2019-09-03 22:55:10 +02:00
|
|
|
constructor(videoData) {
|
2019-09-03 23:01:23 +02:00
|
|
|
this.conf = videoData;
|
|
|
|
this.logger = videoData.logger;
|
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;
|
2019-11-02 02:45:24 +01:00
|
|
|
this.logScale = 0;
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
|
|
|
|
2021-10-31 23:19:32 +01:00
|
|
|
/**
|
|
|
|
* Increases zoom by a given amount. Does not allow per-axis zoom.
|
|
|
|
* Will set zoom level to x axis (+ given amount) if x and y zooms differ.
|
|
|
|
* @param amount
|
|
|
|
*/
|
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-18 23:37:33 +02:00
|
|
|
|
2021-10-31 23:19:32 +01:00
|
|
|
this.logScaleY = this.logScale;
|
2018-09-13 23:47:20 +02:00
|
|
|
|
2021-10-31 23:19:32 +01:00
|
|
|
this.scale = Math.pow(2, this.logScale);
|
2019-11-02 02:45:24 +01:00
|
|
|
|
2021-10-31 23:19:32 +01:00
|
|
|
this.logger.log('info', 'debug', "[Zoom::zoomStep] changing zoom by", amount, ". New zoom level:", this.scale);
|
|
|
|
this.processZoom();
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
|
|
|
|
2021-11-01 01:13:13 +01:00
|
|
|
setZoom(scale: number, axis?: 'x' |'y', noAnnounce?){
|
2019-07-18 21:25:58 +02:00
|
|
|
this.logger.log('info', 'debug', "[Zoom::setZoom] Setting zoom to", scale, "!");
|
2019-01-03 02:07:16 +01:00
|
|
|
|
2018-09-19 22:52:53 +02:00
|
|
|
// NOTE: SCALE IS NOT LOGARITHMIC
|
2019-01-03 02:07:16 +01:00
|
|
|
if(scale < Math.pow(2, this.minScale)) {
|
2018-09-18 23:37:33 +02:00
|
|
|
scale = this.minScale;
|
2019-01-03 02:07:16 +01:00
|
|
|
} else if (scale > Math.pow(2, 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
|
|
|
|
2021-10-31 23:19:32 +01:00
|
|
|
switch (axis) {
|
|
|
|
case 'x':
|
|
|
|
this.scale = scale;
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
this.scaleY = scale;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.scale = scale;
|
|
|
|
this.scaleY = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.processZoom();
|
|
|
|
}
|
|
|
|
|
|
|
|
processZoom() {
|
|
|
|
// this.conf.resizer.toFixedAr();
|
2018-09-18 23:37:33 +02:00
|
|
|
|
2021-11-01 01:13:13 +01:00
|
|
|
this.conf.resizer.applyScaling({xFactor: this.scale, yFactor: this.scaleY}, {noAnnounce: true});
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:44:44 +01:00
|
|
|
applyZoom(stretchFactors){
|
2019-02-15 00:26:54 +01:00
|
|
|
if (!stretchFactors) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-18 21:25:58 +02:00
|
|
|
this.logger.log('info', 'debug', "[Zoom::setZoom] Applying zoom. Stretch factors pre:", stretchFactors, " —> scale:", this.scale);
|
2019-01-03 02:07:16 +01:00
|
|
|
|
2018-11-18 18:44:44 +01:00
|
|
|
stretchFactors.xFactor *= this.scale;
|
|
|
|
stretchFactors.yFactor *= this.scale;
|
2019-01-03 02:07:16 +01:00
|
|
|
|
2019-07-18 21:25:58 +02:00
|
|
|
this.logger.log('info', 'debug', "[Zoom::setZoom] Applying zoom. Stretch factors post:", stretchFactors);
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
2018-12-31 01:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Zoom;
|