• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 cameraDemo from 'libentry.so';
17import Logger from '../model/Logger';
18
19const TAG: string = 'FocusAreaPage';
20
21// Focus Area
22@Component
23export struct FocusAreaPage {
24  @Link focusPointBol: boolean;
25  @Link focusPointVal: Array<number>;
26  // Display where scale, focal length value, and focus box cannot coexist
27  @Link exposureBol: boolean;
28  // Exposure value
29  @Link exposureNum: number;
30  @Prop xComponentWidth: number;
31  @Prop xComponentHeight: number;
32  // Focusing area display box timer
33  private areaTimer: number = -1;
34  // Sliding Exposure Up and Down
35  private panOption: PanGestureOptions = new PanGestureOptions({
36    direction: PanDirection.Up | PanDirection.Down,
37    fingers: 1
38  });
39
40  build() {
41    Row() {
42    }
43    .width(this.xComponentWidth)
44    .height(this.xComponentHeight)
45    .opacity(1)
46    .id('FocusArea')
47    .onTouch((e: TouchEvent) => {
48      if (e.type === TouchType.Down) {
49        this.focusPointBol = true;
50        this.focusPointVal[0] = e.touches[0].screenX;
51        this.focusPointVal[1] = e.touches[0].screenY;
52        // Focus point
53        cameraDemo.isFocusPoint(
54          e.touches[0].screenX / this.xComponentWidth,
55          e.touches[0].screenY / this.xComponentHeight
56        );
57        cameraDemo.isMeteringPoint(
58          e.touches[0].screenX / this.xComponentWidth,
59          e.touches[0].screenY / this.xComponentHeight + 50
60        );
61      }
62      if (e.type === TouchType.Up) {
63        if (this.areaTimer) {
64          clearTimeout(this.areaTimer);
65        }
66        this.areaTimer = setTimeout(() => {
67          this.focusPointBol = false;
68        }, 3500);
69      }
70    })
71    // Trigger this gesture event by dragging vertically with one finger
72    .gesture(
73      PanGesture(this.panOption)
74        .onActionStart(() => {
75          Logger.info(TAG, 'PanGesture onActionStart');
76          this.exposureBol = false;
77        })
78        .onActionUpdate((event: GestureEvent) => {
79          let offset = -event.offsetY;
80          if (offset > 200) {
81            this.exposureNum = 4;
82          }
83          if (offset < -200) {
84            this.exposureNum = -4;
85          }
86          if (offset > -200 && offset < 200) {
87            this.exposureNum = Number((offset / 50).toFixed(1));
88          }
89          // Exposure Compensation -4 +4
90          cameraDemo.isExposureBiasRange(this.exposureNum);
91          Logger.info(TAG, `PanGesture onActionUpdate offset: ${offset}, exposureNum: ${this.exposureNum}`);
92        })
93        .onActionEnd(() => {
94          this.exposureNum = 0;
95          this.exposureBol = true;
96          Logger.info(TAG, 'PanGesture onActionEnd end');
97        })
98    )
99  }
100}