import { SiteSettings } from './../settings/SiteSettings'; import BrowserDetect from '../../conf/BrowserDetect'; import VideoData from '../video-data/VideoData'; import Settings from '../Settings'; import { Stretch } from '../../../common/interfaces/StretchInterface'; import { ComponentLogger } from '../logging/ComponentLogger'; // računa vrednosti za transform-scale (x, y) // transform: scale(x,y) se uporablja za raztegovanje videa, ne pa za približevanje // calculates values for transform scale(x, y) // transform: scale(x,y) is used for stretching, not zooming. class Stretcher { //#region flags //#endregion //#region helper objects conf: VideoData; logger: ComponentLogger; settings: Settings; siteSettings: SiteSettings; //#endregion stretch: Stretch; // functions constructor(videoData) { this.conf = videoData; this.logger = new ComponentLogger(videoData.logAggregator, 'Stretcher', {});; this.siteSettings = videoData.siteSettings; this.settings = videoData.settings; this.setStretchMode(this.siteSettings.getDefaultOption('stretch') as Stretch); } setStretchMode(stretch: Stretch) { this.stretch = stretch; } applyConditionalStretch(stretchFactors, actualAr){ let playerAr = this.conf.player.aspectRatio; let videoAr = this.conf.aspectRatio; if (! actualAr){ actualAr = playerAr; } let newWidth = this.conf.video.offsetWidth * stretchFactors.xFactor; let newHeight = this.conf.video.offsetHeight * stretchFactors.yFactor; let actualWidth, actualHeight; // determine the dimensions of the video (sans black bars) after scaling if(actualAr < videoAr){ actualHeight = newHeight; actualWidth = newHeight * actualAr; } else { actualHeight = newWidth / actualAr; actualWidth = newWidth; } let minW = this.conf.player.dimensions.width * (1 - this.stretch.limit); let maxW = this.conf.player.dimensions.width * (1 + this.stretch.limit); let minH = this.conf.player.dimensions.height * (1 - this.stretch.limit); let maxH = this.conf.player.dimensions.height * (1 + this.stretch.limit); if (actualWidth >= minW && actualWidth <= maxW) { stretchFactors.xFactor *= this.conf.player.dimensions.width / actualWidth; } if (actualHeight >= minH && actualHeight <= maxH) { stretchFactors.yFactor *= this.conf.player.dimensions.height / actualHeight; } } calculateBasicStretch() { // video.videoWidth and video.videoHeight describe the size of the video file. // Size of the video file can be different than the size of the