• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "ani_round_rect.h"
17 
18 namespace OHOS::Rosen {
19 namespace Drawing {
20 const char* ANI_CLASS_ROUND_RECT_NAME = "L@ohos/graphics/drawing/drawing/RoundRect;";
21 
AniInit(ani_env * env)22 ani_status AniRoundRect::AniInit(ani_env *env)
23 {
24     ani_class cls = nullptr;
25     ani_status ret = env->FindClass(ANI_CLASS_ROUND_RECT_NAME, &cls);
26     if (ret != ANI_OK) {
27         ROSEN_LOGE("[ANI] can't find class: %{public}s", ANI_CLASS_ROUND_RECT_NAME);
28         return ANI_NOT_FOUND;
29     }
30 
31     std::array methods = {
32         ani_native_function { "constructorNative", "L@ohos/graphics/common2D/common2D/Rect;DD:V",
33             reinterpret_cast<void*>(ConstructorWithRect) },
34         ani_native_function { "constructorNative", "L@ohos/graphics/drawing/drawing/RoundRect;:V",
35             reinterpret_cast<void*>(ConstructorWithRoundRect) },
36     };
37 
38     ret = env->Class_BindNativeMethods(cls, methods.data(), methods.size());
39     if (ret != ANI_OK) {
40         ROSEN_LOGE("[ANI] bind methods fail: %{public}s", ANI_CLASS_ROUND_RECT_NAME);
41         return ANI_NOT_FOUND;
42     }
43 
44     return ANI_OK;
45 }
46 
ConstructorWithRect(ani_env * env,ani_object obj,ani_object aniRectObj,ani_double xRadii,ani_double yRadii)47 void AniRoundRect::ConstructorWithRect(ani_env* env, ani_object obj, ani_object aniRectObj, ani_double xRadii,
48     ani_double yRadii)
49 {
50     Drawing::Rect drawingRect;
51     if (!GetRectFromAniRectObj(env, aniRectObj, drawingRect)) {
52         AniThrowError(env, "Invalid params. ");
53         return;
54     }
55     AniRoundRect* aniRoundRect = new AniRoundRect(drawingRect, xRadii, yRadii);
56     if (ANI_OK != env->Object_SetFieldByName_Long(obj, NATIVE_OBJ, reinterpret_cast<ani_long>(aniRoundRect))) {
57         ROSEN_LOGE("AniRoundRect::Constructor failed create AniRoundRect");
58         delete aniRoundRect;
59         return;
60     }
61 }
62 
ConstructorWithRoundRect(ani_env * env,ani_object obj,ani_object aniRoundRectObj)63 void AniRoundRect::ConstructorWithRoundRect(ani_env* env, ani_object obj, ani_object aniRoundRectObj)
64 {
65     auto aniRoundRect = GetNativeFromObj<AniRoundRect>(env, aniRoundRectObj);
66     if (aniRoundRect == nullptr) {
67         AniThrowError(env, "Invalid params. "); // message length must be a multiple of 4, for example 16, 20, etc
68         return;
69     }
70 
71     AniRoundRect* newAniRoundRect = new AniRoundRect(aniRoundRect->GetRoundRect());
72     if (ANI_OK != env->Object_SetFieldByName_Long(obj, NATIVE_OBJ, reinterpret_cast<ani_long>(newAniRoundRect))) {
73         ROSEN_LOGE("AniRoundRect::Constructor failed create AniRoundRect");
74         delete newAniRoundRect;
75         return;
76     }
77 }
78 
GetRoundRect()79 RoundRect& AniRoundRect::GetRoundRect()
80 {
81     return roundRect_;
82 }
83 } // namespace Drawing
84 } // namespace OHOS::Rosen