• 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
16/// <reference path='./import.ts' />
17/// <reference path="./ArkCommonShape.ts" />
18class ShapeViewPortModifier extends ModifierWithKey<{
19  x?: string | number |
20  undefined; y?: string | number | undefined; width?: string | number |
21  undefined; height?: string | number | undefined;
22}> {
23  constructor(value: {
24    x?: string | number | undefined; y?: string |
25    number | undefined; width?: string | number | undefined;
26    height?: string | number | undefined;
27  }) {
28    super(value);
29  }
30  static identity: Symbol = Symbol('shapeViewPort');
31  applyPeer(node: KNode, reset: boolean): void {
32    if (reset) {
33      getUINativeModule().shape.resetShapeViewPort(node);
34    } else {
35      getUINativeModule().shape.setShapeViewPort(node, this.value.x, this.value.y, this.value.width, this.value.height);
36    }
37  }
38  checkObjectDiff(): boolean {
39    return !(this.stageValue.x === this.value.x && this.stageValue.y === this.value.y &&
40      this.stageValue.width === this.value.width && this.stageValue.height === this.value.height);
41  }
42}
43class ShapeMeshModifier extends ModifierWithKey<ArkMesh> {
44  constructor(value: ArkMesh) {
45    super(value);
46  }
47  static identity: Symbol = Symbol('shapeMesh');
48  applyPeer(node: KNode, reset: boolean): void {
49    if (reset) {
50      getUINativeModule().shape.resetShapeMesh(node);
51    } else {
52      getUINativeModule().shape.setShapeMesh(node, this.value.value, this.value.column, this.value.row);
53    }
54  }
55  checkObjectDiff(): boolean {
56    return !(this.stageValue as ArkMesh).isEqual(this.value as ArkMesh);
57  }
58}
59class ShapeHeightModifier extends ModifierWithKey<Length> {
60  constructor(value: Length) {
61    super(value);
62  }
63  static identity: Symbol = Symbol('shapeHeight');
64  applyPeer(node: KNode, reset: boolean): void {
65    if (reset) {
66      getUINativeModule().common.resetHeight(node);
67    } else {
68      getUINativeModule().common.setHeight(node, this.value);
69    }
70  }
71  checkObjectDiff(): boolean {
72    return !isBaseOrResourceEqual(this.stageValue, this.value);
73  }
74}
75class ShapeWidthModifier extends ModifierWithKey<Length> {
76  constructor(value: Length) {
77    super(value);
78  }
79  static identity: Symbol = Symbol('shapeWidth');
80  applyPeer(node: KNode, reset: boolean): void {
81    if (reset) {
82      getUINativeModule().common.resetWidth(node);
83    } else {
84      getUINativeModule().common.setWidth(node, this.value);
85    }
86  }
87  checkObjectDiff(): boolean {
88    return !isBaseOrResourceEqual(this.stageValue, this.value);
89  }
90}
91class ArkShapeComponent extends ArkCommonShapeComponent implements ShapeAttribute {
92  constructor(nativePtr: KNode, classType?: ModifierType) {
93    super(nativePtr, classType);
94  }
95  viewPort(value: {
96    x?: string | number | undefined;
97    y?: string | number | undefined; width?: string | number | undefined;
98    height?: string | number | undefined;
99  }): this {
100    if (value === null) {
101      value = undefined;
102    }
103    modifierWithKey(this._modifiersWithKeys, ShapeViewPortModifier.identity, ShapeViewPortModifier, value);
104    return this;
105  }
106  mesh(value: Array<any> | undefined, column: number | undefined, row: number | undefined): this {
107    let arkMesh = new ArkMesh();
108    if (value !== null && column !== null && row !== null) {
109      arkMesh.value = value;
110      arkMesh.column = column;
111      arkMesh.row = row;
112    }
113    modifierWithKey(this._modifiersWithKeys, ShapeMeshModifier.identity, ShapeMeshModifier, arkMesh);
114    return this;
115  }
116  height(value: Length): this {
117    modifierWithKey(this._modifiersWithKeys, ShapeHeightModifier.identity, ShapeHeightModifier, value);
118    return this;
119  }
120  width(value: Length): this {
121    modifierWithKey(this._modifiersWithKeys, ShapeWidthModifier.identity, ShapeWidthModifier, value);
122    return this;
123  }
124}
125
126// @ts-ignore
127globalThis.Shape.attributeModifier = function (modifier: ArkComponent): void {
128  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
129    return new ArkShapeComponent(nativePtr);
130  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
131    return new modifierJS.ShapeModifier(nativePtr, classType);
132  });
133};
134