• 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 { Action } from '../../redux/actions/Action'
17import { Log } from '../../utils/Log'
18import { SettingManager } from '../../setting/SettingManager'
19import { getStore } from '../../redux/store'
20
21let localState = (state) => {
22  return {
23    xComponentWidth: state.PreviewReducer.xComponentWidth,
24    xComponentHeight: state.PreviewReducer.xComponentHeight,
25  }
26}
27
28let localDispatcher = (dispatch) => {
29  return {}
30}
31
32class StateStruct {
33  xComponentWidth
34  xComponentHeight
35}
36
37@Component
38export struct AssistiveGridView {
39  private TAG: string = '[AssistiveGridView]:'
40  private curX: number = 0
41  private curY: number = 0
42  private mGlobalAlpha: number = 0.5
43  private mLineWidth: number = 0.5
44  private mShadowBlur: number = 5
45  private mShadowColor: string = 'argb(#7F000000)'
46  private mShadowOffsetX: number = 0
47  private mShadowOffsetY: number = 0
48  private mStrokeStyle: string = '#FFFFFF'
49
50  private scaleLen: number = 4
51  private settings: RenderingContextSettings = new RenderingContextSettings(true)
52  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
53  private settingManager = SettingManager.getInstance()
54  private xCWidth: number = 0
55  private xCHeight: number = 0
56  @State state: StateStruct = new StateStruct()
57
58  aboutToAppear(): void {
59    Log.info(`${this.TAG} aboutToAppear invoke E`)
60    getStore().connect(localState, localDispatcher)(this.state)
61    Log.info(`${this.TAG} aboutToAppear invoke X`)
62  }
63
64  build() {
65    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
66      Canvas(this.context)
67        .width('100%')
68        .height('100%')
69        .onReady(() => {
70          this.context.clearRect(0, 0, parseInt(this.state.xComponentWidth), parseInt(this.state.xComponentHeight))
71          this.drawRuler()
72        })
73    }
74    .width(this.state.xComponentWidth)
75    .height(this.state.xComponentHeight)
76  }
77
78  drawRuler() {
79    let xCWidth = this.state.xComponentWidth
80    let xCHeight = this.state.xComponentHeight
81    let curX = xCWidth / 3
82    let curY = xCHeight / 3
83    this.context.beginPath()
84    this.context.globalAlpha = this.mGlobalAlpha
85    this.context.lineWidth = this.mLineWidth
86    this.context.strokeStyle = this.mStrokeStyle
87    this.context.shadowColor = this.mShadowColor
88    this.context.shadowOffsetX = this.mShadowOffsetX
89    this.context.shadowOffsetY = this.mShadowOffsetY
90    for (let i = 1; i <= this.scaleLen; i++) {
91      if (i <= this.scaleLen / 2) {
92        this.context.moveTo(curX * i, 0)
93        this.context.lineTo(curX * i, xCHeight)
94      } else {
95        let n = Math.floor(i / 2)
96        this.context.moveTo(0, curY * n)
97        this.context.lineTo(xCWidth * n, curY * n)
98      }
99    }
100    this.context.closePath()
101    this.context.stroke()
102  }
103}