142365ec6Sopenharmony_ci/*
242365ec6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
342365ec6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
442365ec6Sopenharmony_ci * you may not use this file except in compliance with the License.
542365ec6Sopenharmony_ci * You may obtain a copy of the License at
642365ec6Sopenharmony_ci *
742365ec6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
842365ec6Sopenharmony_ci *
942365ec6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1042365ec6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1142365ec6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1242365ec6Sopenharmony_ci * See the License for the specific language governing permissions and
1342365ec6Sopenharmony_ci * limitations under the License.
1442365ec6Sopenharmony_ci */
1542365ec6Sopenharmony_ci
1642365ec6Sopenharmony_ciimport DisplayCalculator from '../setting/DisplayCalculator';
1742365ec6Sopenharmony_ciimport { Log } from './Log';
1842365ec6Sopenharmony_ci
1942365ec6Sopenharmony_ciexport class ComponentPosition {
2042365ec6Sopenharmony_ci  private static TAG: string = '[ComponentPosition]:'
2142365ec6Sopenharmony_ci  private static shutterButtonWidth: number = 76
2242365ec6Sopenharmony_ci  private static shutterButtonWidthVideo: number = 56
2342365ec6Sopenharmony_ci  private static footBarComponentWidth: number = 98
2442365ec6Sopenharmony_ci  private static footBarInPreviewMaxMargin: number = 98
2542365ec6Sopenharmony_ci  private static tarBarHeight: number = 360
2642365ec6Sopenharmony_ci  private static tarBarWidth: number = 48
2742365ec6Sopenharmony_ci  private static tabBarInPreviewMaxMargin: number = 48
2842365ec6Sopenharmony_ci  private static tabBarLeftDistance: number = 10
2942365ec6Sopenharmony_ci  private static tabBarBottomDistance: number = 40
3042365ec6Sopenharmony_ci  private static zoomViewComponentWidth: number = 82
3142365ec6Sopenharmony_ci  private static zoomViewToPreview: number = 75
3242365ec6Sopenharmony_ci  private static zoomViewWidthVideo: number = 60
3342365ec6Sopenharmony_ci  private static zoomViewRightDistance: number = 4
3442365ec6Sopenharmony_ci  private static foldControlHeight: number = 650
3542365ec6Sopenharmony_ci  private static controlItemHeight: number = 32
3642365ec6Sopenharmony_ci
3742365ec6Sopenharmony_ci  public static previewPosition(screenWidth: number, screenHeight: number, previewWidth: number, previewHeight: number) {
3842365ec6Sopenharmony_ci    Log.info(`${this.TAG} previewPosition `)
3942365ec6Sopenharmony_ci    let position = (Math.abs(screenWidth - previewWidth)  < 1) ? { x: 0, y: (screenHeight - previewHeight) / 2}
4042365ec6Sopenharmony_ci                                                       : { x: (screenWidth - previewWidth) / 2, y: 0 }
4142365ec6Sopenharmony_ci    return position
4242365ec6Sopenharmony_ci  }
4342365ec6Sopenharmony_ci
4442365ec6Sopenharmony_ci  public static previewTabletPosition(screenWidth: number, screenHeight: number, previewWidth: number, previewHeight: number) {
4542365ec6Sopenharmony_ci    Log.info(`${this.TAG} previewTabletPosition ` + previewHeight + previewWidth)
4642365ec6Sopenharmony_ci    if ((screenHeight == previewHeight &&  previewWidth > previewHeight)) {
4742365ec6Sopenharmony_ci      return {x: 0, y: 0}
4842365ec6Sopenharmony_ci    }
4942365ec6Sopenharmony_ci    let position = (Math.abs(screenWidth - previewWidth)  < 1) ? { x: 0, y: (screenHeight - previewHeight) / 2}
5042365ec6Sopenharmony_ci                                                               : { x: (screenWidth - previewWidth) / 2, y: 0 }
5142365ec6Sopenharmony_ci    return position
5242365ec6Sopenharmony_ci  }
5342365ec6Sopenharmony_ci
5442365ec6Sopenharmony_ci  public static footBarPosition(screenWidth: number, screenHeight: number, previewWidth: number, previewHeight: number) {
5542365ec6Sopenharmony_ci    Log.info(`${this.TAG} footBarPosition `)
5642365ec6Sopenharmony_ci    if (screenWidth == previewWidth && (3 * previewWidth > 4 * previewHeight)) {
5742365ec6Sopenharmony_ci      let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3)
5842365ec6Sopenharmony_ci      previewWidth = previewSize.width
5942365ec6Sopenharmony_ci      previewHeight = previewSize.height
6042365ec6Sopenharmony_ci    }
6142365ec6Sopenharmony_ci    let position = screenWidth <= previewWidth + this.footBarInPreviewMaxMargin * 2 ?
6242365ec6Sopenharmony_ci      { x: (screenWidth / 2 + previewWidth / 2 - this.footBarComponentWidth), y: 0 } :
6342365ec6Sopenharmony_ci      { x: (screenWidth * 3 / 4 + previewWidth / 4 - this.footBarComponentWidth / 2), y: 0}
6442365ec6Sopenharmony_ci    return position
6542365ec6Sopenharmony_ci  }
6642365ec6Sopenharmony_ci
6742365ec6Sopenharmony_ci  public static tabBarPosition(screenWidth: number, screenHeight: number, previewWidth: number, previewHeight: number) {
6842365ec6Sopenharmony_ci    Log.info(`${this.TAG} tabBarPosition `)
6942365ec6Sopenharmony_ci    if (screenWidth == previewWidth && (3 * previewWidth > 4 * previewHeight)) {
7042365ec6Sopenharmony_ci      let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3)
7142365ec6Sopenharmony_ci      previewWidth = previewSize.width
7242365ec6Sopenharmony_ci      previewHeight = previewSize.height
7342365ec6Sopenharmony_ci    }
7442365ec6Sopenharmony_ci    let xPosition: number = (screenWidth == previewWidth) ? this.tabBarLeftDistance :
7542365ec6Sopenharmony_ci      ((screenWidth >= previewWidth + this.tabBarInPreviewMaxMargin * 2) ?
7642365ec6Sopenharmony_ci      ((screenWidth - previewWidth) / 4) - this.tarBarWidth / 2  :
7742365ec6Sopenharmony_ci      ((screenWidth - previewWidth) / 2) + this.tabBarLeftDistance)
7842365ec6Sopenharmony_ci    let yPosition: number = (screenWidth * 9 <= screenHeight * 16) ?
7942365ec6Sopenharmony_ci      (screenHeight / 2 + screenWidth * 9 / 32 - this.tarBarHeight) :
8042365ec6Sopenharmony_ci      (screenHeight - this.tarBarHeight - this.tabBarBottomDistance)
8142365ec6Sopenharmony_ci    let position = { x: xPosition, y: 44}
8242365ec6Sopenharmony_ci    return position
8342365ec6Sopenharmony_ci  }
8442365ec6Sopenharmony_ci
8542365ec6Sopenharmony_ci  public static zoomViewPosition(screenWidth: number, screenHeight: number, previewWidth: number, previewHeight: number,
8642365ec6Sopenharmony_ci                                 videoState: string) {
8742365ec6Sopenharmony_ci    Log.info(`${this.TAG} zoomViewPosition `)
8842365ec6Sopenharmony_ci    let zoomViewWidth: number
8942365ec6Sopenharmony_ci    let shutterButtonWidth: number
9042365ec6Sopenharmony_ci    if (screenWidth == previewWidth && (3 * previewWidth > 4 * previewHeight)) {
9142365ec6Sopenharmony_ci      let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3)
9242365ec6Sopenharmony_ci      previewWidth = previewSize.width
9342365ec6Sopenharmony_ci      previewHeight = previewSize.height
9442365ec6Sopenharmony_ci    }
9542365ec6Sopenharmony_ci    if (videoState === "beforeTakeVideo") {
9642365ec6Sopenharmony_ci      zoomViewWidth = this.zoomViewComponentWidth
9742365ec6Sopenharmony_ci      shutterButtonWidth = this.shutterButtonWidth
9842365ec6Sopenharmony_ci    } else {
9942365ec6Sopenharmony_ci      zoomViewWidth = this.zoomViewWidthVideo
10042365ec6Sopenharmony_ci      shutterButtonWidth = this.shutterButtonWidthVideo
10142365ec6Sopenharmony_ci    }
10242365ec6Sopenharmony_ci    let xPosition: number = 0;
10342365ec6Sopenharmony_ci    if (screenWidth < previewWidth + this.footBarInPreviewMaxMargin * 2) {
10442365ec6Sopenharmony_ci      xPosition = (screenWidth / 2 + previewWidth / 2 - ((this.footBarComponentWidth + this.zoomViewComponentWidth
10542365ec6Sopenharmony_ci      + zoomViewWidth + shutterButtonWidth) / 2 + this.zoomViewRightDistance))
10642365ec6Sopenharmony_ci    } else if (screenWidth < previewWidth + zoomViewWidth * 4 + shutterButtonWidth * 2) {
10742365ec6Sopenharmony_ci      xPosition = screenWidth / 2 + previewWidth / 2 - this.zoomViewToPreview
10842365ec6Sopenharmony_ci    } else {
10942365ec6Sopenharmony_ci      xPosition = screenWidth * 5 / 8 + previewWidth * 3 / 8 - shutterButtonWidth / 4 - this.zoomViewComponentWidth / 2
11042365ec6Sopenharmony_ci    }
11142365ec6Sopenharmony_ci    let position = { x: xPosition, y: 0 }
11242365ec6Sopenharmony_ci    return position
11342365ec6Sopenharmony_ci  }
11442365ec6Sopenharmony_ci
11542365ec6Sopenharmony_ci  public static getControlHeight(width: number, height: number) {
11642365ec6Sopenharmony_ci    let position = this.isUnfoldControl(width, height) ? this.controlItemHeight * 5 : this.controlItemHeight * 3
11742365ec6Sopenharmony_ci    return position
11842365ec6Sopenharmony_ci  }
11942365ec6Sopenharmony_ci
12042365ec6Sopenharmony_ci  public static isUnfoldControl(width: number, height: number) {
12142365ec6Sopenharmony_ci    Log.info(`${this.TAG} isUnfoldControl `)
12242365ec6Sopenharmony_ci    let previewSize = DisplayCalculator.calcSurfaceDisplaySize(width, height, 4, 3)
12342365ec6Sopenharmony_ci    return (previewSize.height > this.foldControlHeight)
12442365ec6Sopenharmony_ci  }
12542365ec6Sopenharmony_ci
12642365ec6Sopenharmony_ci  public static getShutterButtonMargin(screenWidth: number, screenHeight: number, previewHeight: number) {
12742365ec6Sopenharmony_ci    Log.info(`${this.TAG} getShutterButtonMargin `)
12842365ec6Sopenharmony_ci    if (previewHeight < 400) {
12942365ec6Sopenharmony_ci      return 24
13042365ec6Sopenharmony_ci    }
13142365ec6Sopenharmony_ci    let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3)
13242365ec6Sopenharmony_ci    let x = previewSize.height * 3 / 100 + 24
13342365ec6Sopenharmony_ci    return x
13442365ec6Sopenharmony_ci  }
13542365ec6Sopenharmony_ci
13642365ec6Sopenharmony_ci  public static getFootBarHeight(screenWidth: number, screenHeight: number, previewHeight: number) {
13742365ec6Sopenharmony_ci    let x =  this.getShutterButtonMargin(screenWidth, screenHeight, previewHeight) * 2 + 164
13842365ec6Sopenharmony_ci    return x
13942365ec6Sopenharmony_ci  }
14042365ec6Sopenharmony_ci
14142365ec6Sopenharmony_ci  public static getFootBarMargin(screenWidth: number, screenHeight: number, previewHeight: number) {
14242365ec6Sopenharmony_ci    Log.info(`${this.TAG} getFootBarMargin `)
14342365ec6Sopenharmony_ci    if (previewHeight < 400) {
14442365ec6Sopenharmony_ci      return 0
14542365ec6Sopenharmony_ci    }
14642365ec6Sopenharmony_ci    let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3)
14742365ec6Sopenharmony_ci    let x =  previewSize.height * 12 / 100 - 48
14842365ec6Sopenharmony_ci    return x
14942365ec6Sopenharmony_ci  }
15042365ec6Sopenharmony_ci
15142365ec6Sopenharmony_ci  public static getFootBarPosition(previewHeight: number) {
15242365ec6Sopenharmony_ci    return (previewHeight < 400) ? { x: 0, y: -30 } : { x: 0, y: 0 }
15342365ec6Sopenharmony_ci  }
15442365ec6Sopenharmony_ci
15542365ec6Sopenharmony_ci  public static getControlPosition(previewHeight: number) {
15642365ec6Sopenharmony_ci    return (previewHeight < 400) ? { x: 0, y: -40 } : { x: 0, y: 0 }
15742365ec6Sopenharmony_ci  }
15842365ec6Sopenharmony_ci}