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()
56 ShapeTizen::~ShapeTizen()
60 void ShapeTizen::Initialize()
63 mTvgShape = tvg::Shape::gen().release();
66 DALI_LOG_ERROR("Shape is null [%p]\n", this);
70 Drawable::SetObject(static_cast<void*>(mTvgShape));
74 bool ShapeTizen::AddRect(Rect<float> rect, Vector2 roundedCorner)
79 DALI_LOG_ERROR("Shape is null [%p]\n", this);
82 if(static_cast<tvg::Shape*>(mTvgShape)->appendRect(rect.x, rect.y, rect.width, rect.height, roundedCorner.x, roundedCorner.y) != tvg::Result::Success)
84 DALI_LOG_ERROR("Add Rect Fail [%p]\n", this);
87 Drawable::SetChanged(true);
94 bool ShapeTizen::AddCircle(Vector2 center, Vector2 radius)
99 DALI_LOG_ERROR("Shape is null [%p]\n", this);
102 if(static_cast<tvg::Shape*>(mTvgShape)->appendCircle(center.x, center.y, radius.x, radius.y) != tvg::Result::Success)
104 DALI_LOG_ERROR("Add Circle Fail [%p]\n", this);
107 Drawable::SetChanged(true);
114 bool ShapeTizen::AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie)
116 #ifdef THORVG_SUPPORT
119 DALI_LOG_ERROR("Shape is null\n");
123 if(static_cast<tvg::Shape*>(mTvgShape)->appendArc(center.x, center.y, radius, startAngle, sweep, pie) != tvg::Result::Success)
125 DALI_LOG_ERROR("Add arc fail.\n");
128 Drawable::SetChanged(true);
135 bool ShapeTizen::AddMoveTo(Vector2 point)
137 #ifdef THORVG_SUPPORT
140 DALI_LOG_ERROR("Shape is null\n");
144 if(static_cast<tvg::Shape*>(mTvgShape)->moveTo(point.x, point.y) != tvg::Result::Success)
146 DALI_LOG_ERROR("AddMoveTo() fail.\n");
149 Drawable::SetChanged(true);
156 bool ShapeTizen::AddLineTo(Vector2 line)
158 #ifdef THORVG_SUPPORT
161 DALI_LOG_ERROR("Shape is null\n");
165 if(static_cast<tvg::Shape*>(mTvgShape)->lineTo(line.x, line.y) != tvg::Result::Success)
167 DALI_LOG_ERROR("AddLineTo() fail.\n");
170 Drawable::SetChanged(true);
177 bool ShapeTizen::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint)
179 #ifdef THORVG_SUPPORT
182 DALI_LOG_ERROR("Shape is null\n");
186 if(static_cast<tvg::Shape*>(mTvgShape)->cubicTo(controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, endPoint.x, endPoint.y) != tvg::Result::Success)
188 DALI_LOG_ERROR("cubicTo() fail.\n");
191 Drawable::SetChanged(true);
198 bool ShapeTizen::Close()
200 #ifdef THORVG_SUPPORT
203 DALI_LOG_ERROR("Shape is null\n");
207 if(static_cast<tvg::Shape*>(mTvgShape)->close() != tvg::Result::Success)
209 DALI_LOG_ERROR("close() fail.\n");
212 Drawable::SetChanged(true);
219 bool ShapeTizen::ResetPath()
221 #ifdef THORVG_SUPPORT
224 DALI_LOG_ERROR("Shape is null\n");
228 if(static_cast<tvg::Shape*>(mTvgShape)->reset() != tvg::Result::Success)
230 DALI_LOG_ERROR("reset() fail.\n");
233 Drawable::SetChanged(true);
240 bool ShapeTizen::SetFillColor(Vector4 color)
242 #ifdef THORVG_SUPPORT
245 DALI_LOG_ERROR("Shape is null [%p]\n", this);
249 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)
251 DALI_LOG_ERROR("SetFillColor fail [%p]\n", this);
254 Drawable::SetChanged(true);
261 Vector4 ShapeTizen::GetFillColor() const
263 #ifdef THORVG_SUPPORT
266 DALI_LOG_ERROR("Shape is null [%p]\n", this);
267 return Vector4(0, 0, 0, 0);
271 if(static_cast<tvg::Shape*>(mTvgShape)->fillColor(&r, &g, &b, &a) != tvg::Result::Success)
273 DALI_LOG_ERROR("GetFillColor fail [%p]\n", this);
274 return Vector4(0, 0, 0, 0);
276 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
278 return Vector4::ZERO;
282 bool ShapeTizen::SetFillRule(Dali::CanvasRenderer::Shape::FillRule rule)
284 #ifdef THORVG_SUPPORT
287 DALI_LOG_ERROR("Shape is null\n");
290 if(static_cast<tvg::Shape*>(mTvgShape)->fill(static_cast<tvg::FillRule>(rule)) != tvg::Result::Success)
292 DALI_LOG_ERROR("SetFillRule fail.\n");
295 Drawable::SetChanged(true);
302 Dali::CanvasRenderer::Shape::FillRule ShapeTizen::GetFillRule() const
304 #ifdef THORVG_SUPPORT
307 DALI_LOG_ERROR("Shape is null\n");
308 return Dali::CanvasRenderer::Shape::FillRule::WINDING;
311 tvg::FillRule rule = static_cast<tvg::Shape*>(mTvgShape)->fillRule();
313 return static_cast<Dali::CanvasRenderer::Shape::FillRule>(rule);
315 return Dali::CanvasRenderer::Shape::FillRule::WINDING;
318 bool ShapeTizen::SetStrokeWidth(float width)
320 #ifdef THORVG_SUPPORT
323 DALI_LOG_ERROR("Shape is null\n");
327 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(width) != tvg::Result::Success)
329 DALI_LOG_ERROR("SetStrokeWidth fail.\n");
332 Drawable::SetChanged(true);
339 float ShapeTizen::GetStrokeWidth() const
341 #ifdef THORVG_SUPPORT
344 DALI_LOG_ERROR("Shape is null\n");
347 return static_cast<tvg::Shape*>(mTvgShape)->strokeWidth();
353 bool ShapeTizen::SetStrokeColor(Vector4 color)
355 #ifdef THORVG_SUPPORT
358 DALI_LOG_ERROR("Shape is null\n");
362 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)
364 DALI_LOG_ERROR("SetStrokeColor fail.\n");
367 Drawable::SetChanged(true);
374 Vector4 ShapeTizen::GetStrokeColor() const
376 #ifdef THORVG_SUPPORT
379 DALI_LOG_ERROR("Shape is null\n");
380 return Vector4(0, 0, 0, 0);
385 if(static_cast<tvg::Shape*>(mTvgShape)->strokeColor(&r, &g, &b, &a) != tvg::Result::Success)
387 DALI_LOG_ERROR("GetStrokeColor fail.\n");
388 return Vector4(0, 0, 0, 0);
390 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
392 return Vector4(0, 0, 0, 0);
396 bool ShapeTizen::SetStrokeDash(const Dali::Vector<float> dashPattern)
398 #ifdef THORVG_SUPPORT
401 DALI_LOG_ERROR("Shape is null\n");
405 float* tvgDashPattern = (float*)alloca(sizeof(float) * dashPattern.Count());
407 for(unsigned int i = 0u; i < dashPattern.Count(); ++i)
409 tvgDashPattern[i] = dashPattern[i];
412 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(tvgDashPattern, dashPattern.Count()) != tvg::Result::Success)
414 DALI_LOG_ERROR("SetStrokeDash fail.\n");
417 Drawable::SetChanged(true);
424 Dali::Vector<float> ShapeTizen::GetStrokeDash() const
426 #ifdef THORVG_SUPPORT
429 DALI_LOG_ERROR("Shape is null\n");
430 return Vector<float>();
432 const float* tvgDashPattern = nullptr;
435 count = static_cast<tvg::Shape*>(mTvgShape)->strokeDash(&tvgDashPattern);
436 if(!tvgDashPattern || count <= 0)
438 DALI_LOG_ERROR("GetStrokeDash() fail.\n");
439 return Vector<float>();
442 Dali::Vector<float> dashPattern;
444 dashPattern.Reserve(count);
446 for(unsigned int i = 0u; i < count; ++i)
448 dashPattern.PushBack(tvgDashPattern[i]);
452 return Vector<float>();
456 bool ShapeTizen::SetStrokeCap(Dali::CanvasRenderer::Shape::StrokeCap cap)
458 #ifdef THORVG_SUPPORT
461 DALI_LOG_ERROR("Shape is null\n");
465 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeCap>(cap)) != tvg::Result::Success)
467 DALI_LOG_ERROR("SetStrokeCap fail.\n");
470 Drawable::SetChanged(true);
477 Dali::CanvasRenderer::Shape::StrokeCap ShapeTizen::GetStrokeCap() const
479 #ifdef THORVG_SUPPORT
482 DALI_LOG_ERROR("Shape is null\n");
483 return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
486 tvg::StrokeCap cap = static_cast<tvg::Shape*>(mTvgShape)->strokeCap();
488 return static_cast<Dali::CanvasRenderer::Shape::StrokeCap>(cap);
490 return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
493 bool ShapeTizen::SetStrokeJoin(Dali::CanvasRenderer::Shape::StrokeJoin join)
495 #ifdef THORVG_SUPPORT
498 DALI_LOG_ERROR("Shape is null\n");
502 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeJoin>(join)) != tvg::Result::Success)
504 DALI_LOG_ERROR("SetStrokejoin fail.\n");
507 Drawable::SetChanged(true);
514 Dali::CanvasRenderer::Shape::StrokeJoin ShapeTizen::GetStrokeJoin() const
516 #ifdef THORVG_SUPPORT
519 DALI_LOG_ERROR("Shape is null\n");
520 return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
523 tvg::StrokeJoin join = static_cast<tvg::Shape*>(mTvgShape)->strokeJoin();
525 return static_cast<Dali::CanvasRenderer::Shape::StrokeJoin>(join);
527 return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
530 } // namespace Adaptor
532 } // namespace Internal