2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/canvas-renderer/tizen/shape-impl-tizen.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry.h>
31 namespace // unnamed namespace
34 Dali::BaseHandle Create()
36 return Dali::BaseHandle();
39 Dali::TypeRegistration type(typeid(Dali::CanvasRenderer::Shape), typeid(Dali::BaseHandle), Create);
41 } // unnamed namespace
43 ShapeTizen* ShapeTizen::New()
45 return new ShapeTizen();
48 ShapeTizen::ShapeTizen()
54 ShapeTizen::~ShapeTizen()
58 void ShapeTizen::Initialize()
60 mTvgShape = tvg::Shape::gen().release();
63 DALI_LOG_ERROR("Shape is null [%p]\n", this);
67 Drawable::SetObject(static_cast<void*>(mTvgShape));
70 bool ShapeTizen::AddRect(Rect<float> rect, Vector2 roundedCorner)
74 DALI_LOG_ERROR("Shape is null [%p]\n", this);
77 if(static_cast<tvg::Shape*>(mTvgShape)->appendRect(rect.x, rect.y, rect.width, rect.height, roundedCorner.x, roundedCorner.y) != tvg::Result::Success)
79 DALI_LOG_ERROR("Add Rect Fail [%p]\n", this);
82 Drawable::SetChanged(true);
86 bool ShapeTizen::AddCircle(Vector2 center, Vector2 radius)
90 DALI_LOG_ERROR("Shape is null [%p]\n", this);
93 if(static_cast<tvg::Shape*>(mTvgShape)->appendCircle(center.x, center.y, radius.x, radius.y) != tvg::Result::Success)
95 DALI_LOG_ERROR("Add Circle Fail [%p]\n", this);
98 Drawable::SetChanged(true);
102 bool ShapeTizen::AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie)
106 DALI_LOG_ERROR("Shape is null\n");
110 if(static_cast<tvg::Shape*>(mTvgShape)->appendArc(center.x, center.y, radius, startAngle, sweep, pie) != tvg::Result::Success)
112 DALI_LOG_ERROR("Add arc fail.\n");
115 Drawable::SetChanged(true);
119 bool ShapeTizen::AddMoveTo(Vector2 point)
123 DALI_LOG_ERROR("Shape is null\n");
127 if(static_cast<tvg::Shape*>(mTvgShape)->moveTo(point.x, point.y) != tvg::Result::Success)
129 DALI_LOG_ERROR("AddMoveTo() fail.\n");
132 Drawable::SetChanged(true);
136 bool ShapeTizen::AddLineTo(Vector2 line)
140 DALI_LOG_ERROR("Shape is null\n");
144 if(static_cast<tvg::Shape*>(mTvgShape)->lineTo(line.x, line.y) != tvg::Result::Success)
146 DALI_LOG_ERROR("AddLineTo() fail.\n");
149 Drawable::SetChanged(true);
153 bool ShapeTizen::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint)
157 DALI_LOG_ERROR("Shape is null\n");
161 if(static_cast<tvg::Shape*>(mTvgShape)->cubicTo(controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, endPoint.x, endPoint.y) != tvg::Result::Success)
163 DALI_LOG_ERROR("cubicTo() fail.\n");
166 Drawable::SetChanged(true);
170 bool ShapeTizen::Close()
174 DALI_LOG_ERROR("Shape is null\n");
178 if(static_cast<tvg::Shape*>(mTvgShape)->close() != tvg::Result::Success)
180 DALI_LOG_ERROR("close() fail.\n");
183 Drawable::SetChanged(true);
187 bool ShapeTizen::SetFillColor(Vector4 color)
191 DALI_LOG_ERROR("Shape is null [%p]\n", this);
195 if(static_cast<tvg::Shape*>(mTvgShape)->fill((uint8_t)(color.r * 255.f), (uint8_t)(color.g * 255.f), (uint8_t)(color.b * 255.f), (uint8_t)(color.a * 255.f)) != tvg::Result::Success)
197 DALI_LOG_ERROR("SetFillColor fail [%p]\n", this);
200 Drawable::SetChanged(true);
204 Vector4 ShapeTizen::GetFillColor() const
208 DALI_LOG_ERROR("Shape is null [%p]\n", this);
209 return Vector4(0, 0, 0, 0);
213 if(static_cast<tvg::Shape*>(mTvgShape)->fillColor(&r, &g, &b, &a) != tvg::Result::Success)
215 DALI_LOG_ERROR("GetFillColor fail [%p]\n", this);
216 return Vector4(0, 0, 0, 0);
218 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
221 bool ShapeTizen::SetFillRule(Dali::CanvasRenderer::Shape::FillRule rule)
225 DALI_LOG_ERROR("Shape is null\n");
228 if(static_cast<tvg::Shape*>(mTvgShape)->fill(static_cast<tvg::FillRule>(rule)) != tvg::Result::Success)
230 DALI_LOG_ERROR("SetFillRule fail.\n");
233 Drawable::SetChanged(true);
237 Dali::CanvasRenderer::Shape::FillRule ShapeTizen::GetFillRule() const
241 DALI_LOG_ERROR("Shape is null\n");
242 return Dali::CanvasRenderer::Shape::FillRule::WINDING;
245 tvg::FillRule rule = static_cast<tvg::Shape*>(mTvgShape)->fillRule();
247 return static_cast<Dali::CanvasRenderer::Shape::FillRule>(rule);
250 bool ShapeTizen::SetStrokeWidth(float width)
254 DALI_LOG_ERROR("Shape is null\n");
258 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(width) != tvg::Result::Success)
260 DALI_LOG_ERROR("SetStrokeWidth fail.\n");
263 Drawable::SetChanged(true);
267 float ShapeTizen::GetStrokeWidth() const
271 DALI_LOG_ERROR("Shape is null\n");
274 return static_cast<tvg::Shape*>(mTvgShape)->strokeWidth();
277 bool ShapeTizen::SetStrokeColor(Vector4 color)
281 DALI_LOG_ERROR("Shape is null\n");
285 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(color.r * 255.f, color.g * 255.f, color.b * 255.f, color.a * 255.f) != tvg::Result::Success)
287 DALI_LOG_ERROR("SetStrokeColor fail.\n");
290 Drawable::SetChanged(true);
294 Vector4 ShapeTizen::GetStrokeColor() const
298 DALI_LOG_ERROR("Shape is null\n");
299 return Vector4(0, 0, 0, 0);
304 if(static_cast<tvg::Shape*>(mTvgShape)->strokeColor(&r, &g, &b, &a) != tvg::Result::Success)
306 DALI_LOG_ERROR("GetStrokeColor fail.\n");
307 return Vector4(0, 0, 0, 0);
309 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
312 bool ShapeTizen::SetStrokeDash(const Dali::Vector<float> dashPattern)
316 DALI_LOG_ERROR("Shape is null\n");
320 float* tvgDashPattern = (float*)alloca(sizeof(float) * dashPattern.Count());
322 for(unsigned int i = 0u; i < dashPattern.Count(); ++i)
324 tvgDashPattern[i] = dashPattern[i];
327 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(tvgDashPattern, dashPattern.Count()) != tvg::Result::Success)
329 DALI_LOG_ERROR("SetStrokeDash fail.\n");
332 Drawable::SetChanged(true);
336 Dali::Vector<float> ShapeTizen::GetStrokeDash() const
340 DALI_LOG_ERROR("Shape is null\n");
341 return Vector<float>();
343 const float* tvgDashPattern = nullptr;
346 count = static_cast<tvg::Shape*>(mTvgShape)->strokeDash(&tvgDashPattern);
347 if(!tvgDashPattern || count <= 0)
349 DALI_LOG_ERROR("GetStrokeDash() fail.\n");
350 return Vector<float>();
353 Dali::Vector<float> dashPattern;
355 dashPattern.Reserve(count);
357 for(unsigned int i = 0u; i < count; ++i)
359 dashPattern.PushBack(tvgDashPattern[i]);
364 bool ShapeTizen::SetStrokeCap(Dali::CanvasRenderer::Shape::StrokeCap cap)
368 DALI_LOG_ERROR("Shape is null\n");
372 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeCap>(cap)) != tvg::Result::Success)
374 DALI_LOG_ERROR("SetStrokeCap fail.\n");
377 Drawable::SetChanged(true);
381 Dali::CanvasRenderer::Shape::StrokeCap ShapeTizen::GetStrokeCap() const
385 DALI_LOG_ERROR("Shape is null\n");
386 return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
389 tvg::StrokeCap cap = static_cast<tvg::Shape*>(mTvgShape)->strokeCap();
391 return static_cast<Dali::CanvasRenderer::Shape::StrokeCap>(cap);
394 bool ShapeTizen::SetStrokeJoin(Dali::CanvasRenderer::Shape::StrokeJoin join)
398 DALI_LOG_ERROR("Shape is null\n");
402 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeJoin>(join)) != tvg::Result::Success)
404 DALI_LOG_ERROR("SetStrokejoin fail.\n");
407 Drawable::SetChanged(true);
411 Dali::CanvasRenderer::Shape::StrokeJoin ShapeTizen::GetStrokeJoin() const
415 DALI_LOG_ERROR("Shape is null\n");
416 return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
419 tvg::StrokeJoin join = static_cast<tvg::Shape*>(mTvgShape)->strokeJoin();
421 return static_cast<Dali::CanvasRenderer::Shape::StrokeJoin>(join);
424 } // namespace Adaptor
426 } // namespace Internal