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