/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "frameworks/bridge/declarative_frontend/jsview/js_polyline.h" #include "core/common/container.h" #include "core/components_ng/pattern/shape/polygon_model.h" #include "frameworks/base/memory/referenced.h" namespace OHOS::Ace::Framework { void JSPolyline::Create(const JSCallbackInfo& info) { PolygonModel::GetInstance()->Create(false); JSShapeAbstract::SetSize(info); } void JSPolyline::JSBind(BindingTarget globalObj) { JSClass::Declare("Polyline"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSPolyline::Create, opt); JSClass::StaticMethod("width", &JSShapeAbstract::JsWidth); JSClass::StaticMethod("height", &JSShapeAbstract::JsHeight); JSClass::StaticMethod("points", &JSPolyline::JSPoints); JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); JSClass::StaticMethod("onHover", &JSInteractableView::JsOnHover); JSClass::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey); JSClass::StaticMethod("onClick", &JSInteractableView::JsOnClick); JSClass::InheritAndBind(globalObj); } void JSPolyline::JSPoints(const JSCallbackInfo& info) { ShapePoints points; PolygonModel::GetInstance()->SetPoints(points); if (info.Length() < 1 || !info[0]->IsArray()) { return; } ShapePoint point; JSRef pointsArray = JSRef::Cast(info[0]); if (pointsArray->Length() < 2) { return; } for (size_t i = 0; i < pointsArray->Length(); i++) { JSRef val = pointsArray->GetValueAt(i); if (!val->IsArray()) { continue; } JSRef pointArray = JSRef::Cast(val); if (pointArray->GetValueAt(0)->IsNumber()) { point.first = Dimension(pointArray->GetValueAt(0)->ToNumber(), DimensionUnit::VP); } else if (pointArray->GetValueAt(0)->IsString()) { point.first = StringUtils::StringToDimension(pointArray->GetValueAt(0)->ToString(), true); } else { return; } if (pointArray->GetValueAt(1)->IsNumber()) { point.second = Dimension(pointArray->GetValueAt(1)->ToNumber(), DimensionUnit::VP); } else if (pointArray->GetValueAt(1)->IsString()) { point.second = StringUtils::StringToDimension(pointArray->GetValueAt(1)->ToString(), true); } else { return; } points.push_back(point); } PolygonModel::GetInstance()->SetPoints(points); } } // namespace OHOS::Ace::Framework