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));
74 bool ShapeUbuntu::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 ShapeUbuntu::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 ShapeUbuntu::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 ShapeUbuntu::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 ShapeUbuntu::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 ShapeUbuntu::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 ShapeUbuntu::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 ShapeUbuntu::SetFillColor(Vector4 color)
221 #ifdef THORVG_SUPPORT
224 DALI_LOG_ERROR("Shape is null [%p]\n", this);
228 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)
230 DALI_LOG_ERROR("SetFillColor fail [%p]\n", this);
233 Drawable::SetChanged(true);
240 Vector4 ShapeUbuntu::GetFillColor() const
242 #ifdef THORVG_SUPPORT
245 DALI_LOG_ERROR("Shape is null [%p]\n", this);
246 return Vector4(0, 0, 0, 0);
250 if(static_cast<tvg::Shape*>(mTvgShape)->fillColor(&r, &g, &b, &a) != tvg::Result::Success)
252 DALI_LOG_ERROR("GetFillColor fail [%p]\n", this);
253 return Vector4(0, 0, 0, 0);
255 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
257 return Vector4::ZERO;
261 bool ShapeUbuntu::SetFillRule(Dali::CanvasRenderer::Shape::FillRule rule)
263 #ifdef THORVG_SUPPORT
266 DALI_LOG_ERROR("Shape is null\n");
269 if(static_cast<tvg::Shape*>(mTvgShape)->fill(static_cast<tvg::FillRule>(rule)) != tvg::Result::Success)
271 DALI_LOG_ERROR("SetFillRule fail.\n");
274 Drawable::SetChanged(true);
281 Dali::CanvasRenderer::Shape::FillRule ShapeUbuntu::GetFillRule() const
283 #ifdef THORVG_SUPPORT
286 DALI_LOG_ERROR("Shape is null\n");
287 return Dali::CanvasRenderer::Shape::FillRule::WINDING;
290 tvg::FillRule rule = static_cast<tvg::Shape*>(mTvgShape)->fillRule();
292 return static_cast<Dali::CanvasRenderer::Shape::FillRule>(rule);
294 return Dali::CanvasRenderer::Shape::FillRule::WINDING;
297 bool ShapeUbuntu::SetStrokeWidth(float width)
299 #ifdef THORVG_SUPPORT
302 DALI_LOG_ERROR("Shape is null\n");
306 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(width) != tvg::Result::Success)
308 DALI_LOG_ERROR("SetStrokeWidth fail.\n");
311 Drawable::SetChanged(true);
318 float ShapeUbuntu::GetStrokeWidth() const
320 #ifdef THORVG_SUPPORT
323 DALI_LOG_ERROR("Shape is null\n");
326 return static_cast<tvg::Shape*>(mTvgShape)->strokeWidth();
332 bool ShapeUbuntu::SetStrokeColor(Vector4 color)
334 #ifdef THORVG_SUPPORT
337 DALI_LOG_ERROR("Shape is null\n");
341 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)
343 DALI_LOG_ERROR("SetStrokeColor fail.\n");
346 Drawable::SetChanged(true);
353 Vector4 ShapeUbuntu::GetStrokeColor() const
355 #ifdef THORVG_SUPPORT
358 DALI_LOG_ERROR("Shape is null\n");
359 return Vector4(0, 0, 0, 0);
364 if(static_cast<tvg::Shape*>(mTvgShape)->strokeColor(&r, &g, &b, &a) != tvg::Result::Success)
366 DALI_LOG_ERROR("GetStrokeColor fail.\n");
367 return Vector4(0, 0, 0, 0);
369 return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
371 return Vector4(0, 0, 0, 0);
375 bool ShapeUbuntu::SetStrokeDash(const Dali::Vector<float> dashPattern)
377 #ifdef THORVG_SUPPORT
380 DALI_LOG_ERROR("Shape is null\n");
384 float* tvgDashPattern = (float*)alloca(sizeof(float) * dashPattern.Count());
386 for(unsigned int i = 0u; i < dashPattern.Count(); ++i)
388 tvgDashPattern[i] = dashPattern[i];
391 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(tvgDashPattern, dashPattern.Count()) != tvg::Result::Success)
393 DALI_LOG_ERROR("SetStrokeDash fail.\n");
396 Drawable::SetChanged(true);
403 Dali::Vector<float> ShapeUbuntu::GetStrokeDash() const
405 #ifdef THORVG_SUPPORT
408 DALI_LOG_ERROR("Shape is null\n");
409 return Vector<float>();
411 const float* tvgDashPattern = nullptr;
414 count = static_cast<tvg::Shape*>(mTvgShape)->strokeDash(&tvgDashPattern);
415 if(!tvgDashPattern || count <= 0)
417 DALI_LOG_ERROR("GetStrokeDash() fail.\n");
418 return Vector<float>();
421 Dali::Vector<float> dashPattern;
423 dashPattern.Reserve(count);
425 for(unsigned int i = 0u; i < count; ++i)
427 dashPattern.PushBack(tvgDashPattern[i]);
431 return Vector<float>();
435 bool ShapeUbuntu::SetStrokeCap(Dali::CanvasRenderer::Shape::StrokeCap cap)
437 #ifdef THORVG_SUPPORT
440 DALI_LOG_ERROR("Shape is null\n");
443 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeCap>(cap)) != tvg::Result::Success)
445 DALI_LOG_ERROR("SetStrokeCap fail.\n");
448 Drawable::SetChanged(true);
455 Dali::CanvasRenderer::Shape::StrokeCap ShapeUbuntu::GetStrokeCap() const
457 #ifdef THORVG_SUPPORT
460 DALI_LOG_ERROR("Shape is null\n");
461 return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
464 tvg::StrokeCap cap = static_cast<tvg::Shape*>(mTvgShape)->strokeCap();
466 return static_cast<Dali::CanvasRenderer::Shape::StrokeCap>(cap);
468 return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
471 bool ShapeUbuntu::SetStrokeJoin(Dali::CanvasRenderer::Shape::StrokeJoin join)
473 #ifdef THORVG_SUPPORT
476 DALI_LOG_ERROR("Shape is null\n");
480 if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeJoin>(join)) != tvg::Result::Success)
482 DALI_LOG_ERROR("SetStrokejoin fail.\n");
485 Drawable::SetChanged(true);
492 Dali::CanvasRenderer::Shape::StrokeJoin ShapeUbuntu::GetStrokeJoin() const
494 #ifdef THORVG_SUPPORT
497 DALI_LOG_ERROR("Shape is null\n");
498 return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
501 tvg::StrokeJoin join = static_cast<tvg::Shape*>(mTvgShape)->strokeJoin();
503 return static_cast<Dali::CanvasRenderer::Shape::StrokeJoin>(join);
505 return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
508 } // namespace Adaptor
510 } // namespace Internal