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/ubuntu/shape-impl-ubuntu.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 ShapeUbuntu* ShapeUbuntu::New()
45 return new ShapeUbuntu();
48 ShapeUbuntu::ShapeUbuntu()
56 ShapeUbuntu::~ShapeUbuntu()
60 void ShapeUbuntu::Initialize()
63 mTvgShape = tvg::Shape::gen().release();
66 DALI_LOG_ERROR("Shape is null [%p]\n", this);
70 Drawable::SetObject(static_cast<void*>(mTvgShape));
75 bool ShapeUbuntu::AddRect(Rect<float> rect, Vector2 roundedCorner)
80 DALI_LOG_ERROR("Shape is null [%p]\n", this);
83 if(static_cast<tvg::Shape*>(mTvgShape)->appendRect(rect.x, rect.y, rect.width, rect.height, roundedCorner.x, roundedCorner.y) != tvg::Result::Success)
85 DALI_LOG_ERROR("Add Rect Fail [%p]\n", this);
88 Drawable::SetChanged(true);
95 bool ShapeUbuntu::AddCircle(Vector2 center, Vector2 radius)
100 DALI_LOG_ERROR("Shape is null [%p]\n", this);
103 if(static_cast<tvg::Shape*>(mTvgShape)->appendCircle(center.x, center.y, radius.x, radius.y) != tvg::Result::Success)
105 DALI_LOG_ERROR("Add Circle Fail [%p]\n", this);
108 Drawable::SetChanged(true);
115 bool ShapeUbuntu::AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie)
117 #ifdef THORVG_SUPPORT
120 DALI_LOG_ERROR("Shape is null\n");
124 if(static_cast<tvg::Shape*>(mTvgShape)->appendArc(center.x, center.y, radius, startAngle, sweep, pie) != tvg::Result::Success)
126 DALI_LOG_ERROR("Add arc fail.\n");
129 Drawable::SetChanged(true);
136 bool ShapeUbuntu::AddMoveTo(Vector2 point)
138 #ifdef THORVG_SUPPORT
141 DALI_LOG_ERROR("Shape is null\n");
145 if(static_cast<tvg::Shape*>(mTvgShape)->moveTo(point.x, point.y) != tvg::Result::Success)
147 DALI_LOG_ERROR("AddMoveTo() fail.\n");
150 Drawable::SetChanged(true);
157 bool ShapeUbuntu::AddLineTo(Vector2 line)
159 #ifdef THORVG_SUPPORT
162 DALI_LOG_ERROR("Shape is null\n");
166 if(static_cast<tvg::Shape*>(mTvgShape)->lineTo(line.x, line.y) != tvg::Result::Success)
168 DALI_LOG_ERROR("AddLineTo() fail.\n");
171 Drawable::SetChanged(true);
178 bool ShapeUbuntu::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint)
180 #ifdef THORVG_SUPPORT
183 DALI_LOG_ERROR("Shape is null\n");
187 if(static_cast<tvg::Shape*>(mTvgShape)->cubicTo(controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, endPoint.x, endPoint.y) != tvg::Result::Success)
189 DALI_LOG_ERROR("cubicTo() fail.\n");
192 Drawable::SetChanged(true);
199 bool ShapeUbuntu::Close()
201 #ifdef THORVG_SUPPORT
204 DALI_LOG_ERROR("Shape is null\n");
208 if(static_cast<tvg::Shape*>(mTvgShape)->close() != tvg::Result::Success)
210 DALI_LOG_ERROR("close() fail.\n");
213 Drawable::SetChanged(true);
220 bool ShapeUbuntu::SetFillColor(Vector4 color)
222 #ifdef THORVG_SUPPORT
225 DALI_LOG_ERROR("Shape is null [%p]\n", this);
229 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)
231 DALI_LOG_ERROR("SetFillColor fail [%p]\n", this);
234 Drawable::SetChanged(true);
241 Vector4 ShapeUbuntu::GetFillColor() const
243 #ifdef THORVG_SUPPORT
246 DALI_LOG_ERROR("Shape is null [%p]\n", this);
247 return Vector4(0, 0, 0, 0);
251 if(static_cast<tvg::Shape*>(mTvgShape)->fillColor(&r, &g, &b, &a) != tvg::Result::Success)
253 DALI_LOG_ERROR("GetFillColor fail [%p]\n", this);
254 return Vector4(0, 0, 0, 0);
256 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
258 return Vector4(0, 0, 0, 0);
262 bool ShapeUbuntu::SetFillRule(Dali::CanvasRenderer::Shape::FillRule rule)
264 #ifdef THORVG_SUPPORT
267 DALI_LOG_ERROR("Shape is null\n");
270 if(static_cast<tvg::Shape*>(mTvgShape)->fill(static_cast<tvg::FillRule>(rule)) != tvg::Result::Success)
272 DALI_LOG_ERROR("SetFillRule fail.\n");
275 Drawable::SetChanged(true);
282 Dali::CanvasRenderer::Shape::FillRule ShapeUbuntu::GetFillRule() const
284 #ifdef THORVG_SUPPORT
287 DALI_LOG_ERROR("Shape is null\n");
288 return Dali::CanvasRenderer::Shape::FillRule::WINDING;
291 tvg::FillRule rule = static_cast<tvg::Shape*>(mTvgShape)->fillRule();
293 return static_cast<Dali::CanvasRenderer::Shape::FillRule>(rule);
295 return Dali::CanvasRenderer::Shape::FillRule::WINDING;
298 bool ShapeUbuntu::SetStrokeWidth(float width)
300 #ifdef THORVG_SUPPORT
303 DALI_LOG_ERROR("Shape is null\n");
307 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(width) != tvg::Result::Success)
309 DALI_LOG_ERROR("SetStrokeWidth fail.\n");
312 Drawable::SetChanged(true);
319 float ShapeUbuntu::GetStrokeWidth() const
321 #ifdef THORVG_SUPPORT
324 DALI_LOG_ERROR("Shape is null\n");
327 return static_cast<tvg::Shape*>(mTvgShape)->strokeWidth();
333 bool ShapeUbuntu::SetStrokeColor(Vector4 color)
335 #ifdef THORVG_SUPPORT
338 DALI_LOG_ERROR("Shape is null\n");
342 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)
344 DALI_LOG_ERROR("SetStrokeColor fail.\n");
347 Drawable::SetChanged(true);
354 Vector4 ShapeUbuntu::GetStrokeColor() const
356 #ifdef THORVG_SUPPORT
359 DALI_LOG_ERROR("Shape is null\n");
360 return Vector4(0, 0, 0, 0);
365 if(static_cast<tvg::Shape*>(mTvgShape)->strokeColor(&r, &g, &b, &a) != tvg::Result::Success)
367 DALI_LOG_ERROR("GetStrokeColor fail.\n");
368 return Vector4(0, 0, 0, 0);
370 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
372 return Vector4(0, 0, 0, 0);
376 bool ShapeUbuntu::SetStrokeDash(const Dali::Vector<float> dashPattern)
378 #ifdef THORVG_SUPPORT
381 DALI_LOG_ERROR("Shape is null\n");
385 float* tvgDashPattern = (float*)alloca(sizeof(float) * dashPattern.Count());
387 for(unsigned int i = 0u; i < dashPattern.Count(); ++i)
389 tvgDashPattern[i] = dashPattern[i];
392 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(tvgDashPattern, dashPattern.Count()) != tvg::Result::Success)
394 DALI_LOG_ERROR("SetStrokeDash fail.\n");
397 Drawable::SetChanged(true);
404 Dali::Vector<float> ShapeUbuntu::GetStrokeDash() const
406 #ifdef THORVG_SUPPORT
409 DALI_LOG_ERROR("Shape is null\n");
410 return Vector<float>();
412 const float* tvgDashPattern = nullptr;
415 count = static_cast<tvg::Shape*>(mTvgShape)->strokeDash(&tvgDashPattern);
416 if(!tvgDashPattern || count <= 0)
418 DALI_LOG_ERROR("GetStrokeDash() fail.\n");
419 return Vector<float>();
422 Dali::Vector<float> dashPattern;
424 dashPattern.Reserve(count);
426 for(unsigned int i = 0u; i < count; ++i)
428 dashPattern.PushBack(tvgDashPattern[i]);
432 return Vector<float>();
436 bool ShapeUbuntu::SetStrokeCap(Dali::CanvasRenderer::Shape::StrokeCap cap)
438 #ifdef THORVG_SUPPORT
441 DALI_LOG_ERROR("Shape is null\n");
444 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeCap>(cap)) != tvg::Result::Success)
446 DALI_LOG_ERROR("SetStrokeCap fail.\n");
449 Drawable::SetChanged(true);
456 Dali::CanvasRenderer::Shape::StrokeCap ShapeUbuntu::GetStrokeCap() const
458 #ifdef THORVG_SUPPORT
461 DALI_LOG_ERROR("Shape is null\n");
462 return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
465 tvg::StrokeCap cap = static_cast<tvg::Shape*>(mTvgShape)->strokeCap();
467 return static_cast<Dali::CanvasRenderer::Shape::StrokeCap>(cap);
469 return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
472 bool ShapeUbuntu::SetStrokeJoin(Dali::CanvasRenderer::Shape::StrokeJoin join)
474 #ifdef THORVG_SUPPORT
477 DALI_LOG_ERROR("Shape is null\n");
481 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeJoin>(join)) != tvg::Result::Success)
483 DALI_LOG_ERROR("SetStrokejoin fail.\n");
486 Drawable::SetChanged(true);
493 Dali::CanvasRenderer::Shape::StrokeJoin ShapeUbuntu::GetStrokeJoin() const
495 #ifdef THORVG_SUPPORT
498 DALI_LOG_ERROR("Shape is null\n");
499 return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
502 tvg::StrokeJoin join = static_cast<tvg::Shape*>(mTvgShape)->strokeJoin();
504 return static_cast<Dali::CanvasRenderer::Shape::StrokeJoin>(join);
506 return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
509 } // namespace Adaptor
511 } // namespace Internal