1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import DisplayCalculator from '../setting/DisplayCalculator'; 17import { Log } from './Log'; 18 19export class ComponentPosition { 20 private static TAG: string = '[ComponentPosition]:' 21 private static shutterButtonWidth: number = 76 22 private static shutterButtonWidthVideo: number = 56 23 private static footBarComponentWidth: number = 98 24 private static footBarInPreviewMaxMargin: number = 98 25 private static tarBarHeight: number = 360 26 private static tarBarWidth: number = 48 27 private static tabBarInPreviewMaxMargin: number = 48 28 private static tabBarLeftDistance: number = 10 29 private static tabBarBottomDistance: number = 40 30 private static zoomViewComponentWidth: number = 82 31 private static zoomViewToPreview: number = 75 32 private static zoomViewWidthVideo: number = 60 33 private static zoomViewRightDistance: number = 4 34 private static foldControlHeight: number = 650 35 private static controlItemHeight: number = 32 36 37 public static previewPosition(screenWidth: number, screenHeight: number, previewWidth: number, 38 previewHeight: number) { 39 Log.info(`${this.TAG} previewPosition `) 40 let position = (Math.abs(screenWidth - previewWidth) < 1) ? { x: 0, y: (screenHeight - previewHeight) / 2 } 41 : { x: (screenWidth - previewWidth) / 2, y: 0 } 42 return position 43 } 44 45 public static previewTabletPosition(screenWidth: number, screenHeight: number, previewWidth: number, 46 previewHeight: number) { 47 Log.info(`${this.TAG} previewTabletPosition ` + previewHeight + previewWidth) 48 if ((screenHeight == previewHeight && previewWidth > previewHeight)) { 49 return { x: 0, y: 0 } 50 } 51 let position = (Math.abs(screenWidth - previewWidth) < 1) ? { x: 0, y: (screenHeight - previewHeight) / 2 } 52 : { x: (screenWidth - previewWidth) / 2, y: 0 } 53 return position 54 } 55 56 public static footBarPosition(screenWidth: number, screenHeight: number, previewWidth: number, 57 previewHeight: number) { 58 Log.info(`${this.TAG} footBarPosition `) 59 if (screenWidth == previewWidth && (3 * previewWidth > 4 * previewHeight)) { 60 let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3) 61 previewWidth = previewSize.width 62 previewHeight = previewSize.height 63 } 64 let position = screenWidth <= previewWidth + this.footBarInPreviewMaxMargin * 2 ? 65 { x: (screenWidth / 2 + previewWidth / 2 - this.footBarComponentWidth), y: 0 } : 66 { x: (screenWidth * 3 / 4 + previewWidth / 4 - this.footBarComponentWidth / 2), y: 0 } 67 return position 68 } 69 70 public static tabBarPosition(screenWidth: number, screenHeight: number, previewWidth: number, previewHeight: number) { 71 Log.info(`${this.TAG} tabBarPosition `) 72 if (screenWidth == previewWidth && (3 * previewWidth > 4 * previewHeight)) { 73 let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3) 74 previewWidth = previewSize.width 75 previewHeight = previewSize.height 76 } 77 let xPosition: number = (screenWidth == previewWidth) ? this.tabBarLeftDistance : 78 ((screenWidth >= previewWidth + this.tabBarInPreviewMaxMargin * 2) ? 79 ((screenWidth - previewWidth) / 4) - this.tarBarWidth / 2 : 80 ((screenWidth - previewWidth) / 2) + this.tabBarLeftDistance) 81 let yPosition: number = (screenWidth * 9 <= screenHeight * 16) ? 82 (screenHeight / 2 + screenWidth * 9 / 32 - this.tarBarHeight) : 83 (screenHeight - this.tarBarHeight - this.tabBarBottomDistance) 84 let position = { x: xPosition, y: 44 } 85 return position 86 } 87 88 public static zoomViewPosition(screenWidth: number, screenHeight: number, previewWidth: number, previewHeight: number, 89 videoState: string) { 90 Log.info(`${this.TAG} zoomViewPosition `) 91 let zoomViewWidth: number 92 let shutterButtonWidth: number 93 if (screenWidth == previewWidth && (3 * previewWidth > 4 * previewHeight)) { 94 let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3) 95 previewWidth = previewSize.width 96 previewHeight = previewSize.height 97 } 98 if (videoState === "beforeTakeVideo") { 99 zoomViewWidth = this.zoomViewComponentWidth 100 shutterButtonWidth = this.shutterButtonWidth 101 } else { 102 zoomViewWidth = this.zoomViewWidthVideo 103 shutterButtonWidth = this.shutterButtonWidthVideo 104 } 105 let xPosition: number = 0; 106 if (screenWidth < previewWidth + this.footBarInPreviewMaxMargin * 2) { 107 xPosition = (screenWidth / 2 + previewWidth / 2 - ((this.footBarComponentWidth + this.zoomViewComponentWidth 108 + zoomViewWidth + shutterButtonWidth) / 2 + this.zoomViewRightDistance)) 109 } else if (screenWidth < previewWidth + zoomViewWidth * 4 + shutterButtonWidth * 2) { 110 xPosition = screenWidth / 2 + previewWidth / 2 - this.zoomViewToPreview 111 } else { 112 xPosition = screenWidth * 5 / 8 + previewWidth * 3 / 8 - shutterButtonWidth / 4 - this.zoomViewComponentWidth / 2 113 } 114 let position = { x: xPosition, y: 0 } 115 return position 116 } 117 118 public static getControlHeight(width: number, height: number) { 119 let position = this.isUnfoldControl(width, height) ? this.controlItemHeight * 5 : this.controlItemHeight * 3 120 return position 121 } 122 123 public static isUnfoldControl(width: number, height: number) { 124 Log.info(`${this.TAG} isUnfoldControl `) 125 let previewSize = DisplayCalculator.calcSurfaceDisplaySize(width, height, 4, 3) 126 return (previewSize.height > this.foldControlHeight) 127 } 128 129 public static getShutterButtonMargin(screenWidth: number, screenHeight: number, previewHeight: number) { 130 Log.info(`${this.TAG} getShutterButtonMargin `) 131 if (previewHeight < 400) { 132 return 24 133 } 134 let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3) 135 let x = previewSize.height * 3 / 100 + 24 136 return x 137 } 138 139 public static getFootBarHeight(screenWidth: number, screenHeight: number, previewHeight: number) { 140 let x = this.getShutterButtonMargin(screenWidth, screenHeight, previewHeight) * 2 + 164 141 return x 142 } 143 144 public static getFootBarMargin(screenWidth: number, screenHeight: number, previewHeight: number) { 145 Log.info(`${this.TAG} getFootBarMargin `) 146 if (previewHeight < 400) { 147 return 0 148 } 149 let previewSize = DisplayCalculator.calcSurfaceDisplaySize(screenWidth, screenHeight, 4, 3) 150 let x = previewSize.height * 12 / 100 - 48 151 return x 152 } 153 154 public static getFootBarPosition(previewHeight: number) { 155 return (previewHeight < 400) ? { x: 0, y: -30 } : { x: 0, y: 0 } 156 } 157 158 public static getControlPosition(previewHeight: number) { 159 return (previewHeight < 400) ? { x: 0, y: -40 } : { x: 0, y: 0 } 160 } 161}