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/drawable-impl-ubuntu.h>
22 #include <dali/devel-api/common/stage.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
32 namespace // unnamed namespace
35 Dali::BaseHandle Create()
37 return Dali::BaseHandle();
40 Dali::TypeRegistration type(typeid(Dali::CanvasRenderer::Drawable), typeid(Dali::BaseHandle), Create);
42 } // unnamed namespace
44 DrawableUbuntu* DrawableUbuntu::New()
46 return new DrawableUbuntu();
49 DrawableUbuntu::DrawableUbuntu()
52 mType(Drawable::Types::NONE)
60 DrawableUbuntu::~DrawableUbuntu()
70 bool DrawableUbuntu::SetOpacity(float opacity)
75 DALI_LOG_ERROR("Drawable is null [%p]\n", this);
78 if(mTvgPaint->opacity(round(opacity * 255.f)) != tvg::Result::Success)
80 DALI_LOG_ERROR("Set opacity fail [%p]\n", this);
90 float DrawableUbuntu::GetOpacity() const
95 DALI_LOG_ERROR("Drawable is null [%p]\n", this);
98 return (float)mTvgPaint->opacity() / 255.f;
104 bool DrawableUbuntu::Rotate(Degree degree)
106 #ifdef THORVG_SUPPORT
109 DALI_LOG_ERROR("Drawable is null\n");
113 if(mTvgPaint->rotate(degree.degree) != tvg::Result::Success)
115 DALI_LOG_ERROR("Rotate fail.\n");
125 bool DrawableUbuntu::Scale(float factor)
127 #ifdef THORVG_SUPPORT
130 DALI_LOG_ERROR("Drawable is null\n");
134 if(mTvgPaint->scale(factor) != tvg::Result::Success)
136 DALI_LOG_ERROR("Scale fail.\n");
146 bool DrawableUbuntu::Translate(Vector2 translate)
148 #ifdef THORVG_SUPPORT
151 DALI_LOG_ERROR("Drawable is null\n");
155 if(mTvgPaint->translate(translate.x, translate.y) != tvg::Result::Success)
157 DALI_LOG_ERROR("Translate fail.\n");
167 bool DrawableUbuntu::Transform(const Dali::Matrix3& matrix)
169 #ifdef THORVG_SUPPORT
172 DALI_LOG_ERROR("Drawable is null\n");
176 tvg::Matrix tvgMatrix = {matrix.AsFloat()[0], matrix.AsFloat()[1], matrix.AsFloat()[2], matrix.AsFloat()[3], matrix.AsFloat()[4], matrix.AsFloat()[5], matrix.AsFloat()[6], matrix.AsFloat()[7], matrix.AsFloat()[8]};
178 if(mTvgPaint->transform(tvgMatrix) != tvg::Result::Success)
180 DALI_LOG_ERROR("Transform fail.\n");
190 Rect<float> DrawableUbuntu::GetBoundingBox() const
192 #ifdef THORVG_SUPPORT
195 DALI_LOG_ERROR("Drawable is null\n");
196 return Rect<float>(0, 0, 0, 0);
199 float x, y, width, height;
200 x = y = width = height = 0;
202 if(mTvgPaint->bounds(&x, &y, &width, &height) != tvg::Result::Success)
204 DALI_LOG_ERROR("Get bounds fail.\n");
205 return Rect<float>(0, 0, 0, 0);
207 return Rect<float>(x, y, width, height);
209 return Rect<float>(0, 0, 0, 0);
213 void DrawableUbuntu::SetAdded(bool added)
218 bool DrawableUbuntu::IsAdded() const
223 void* DrawableUbuntu::GetObject() const
225 #ifdef THORVG_SUPPORT
226 return static_cast<void*>(mTvgPaint);
232 void DrawableUbuntu::SetObject(const void* object)
234 #ifdef THORVG_SUPPORT
237 mTvgPaint = static_cast<tvg::Paint*>((void*)object);
242 void DrawableUbuntu::SetChanged(bool changed)
244 if(!mChanged && changed) Dali::Stage::GetCurrent().KeepRendering(0.0f);
245 mChanged = !!changed;
248 bool DrawableUbuntu::GetChanged() const
253 void DrawableUbuntu::SetType(Drawable::Types type)
258 Drawable::Types DrawableUbuntu::GetType() const
262 } // namespace Adaptor
264 } // namespace Internal