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.
21 Vector3 ToHueSaturationLightness(Vector3 rgb)
23 float min = std::min(rgb.r, std::min(rgb.g, rgb.b));
24 float max = std::max(rgb.r, std::max(rgb.g, rgb.b));
26 Vector3 hsl(max - min, 0.f, (max + min) * .5f);
27 if(hsl.x * hsl.x > .0f)
32 hsl.x = (rgb.g - rgb.b) / hsl.x;
36 hsl.x = 2.f + (rgb.b - rgb.r) / hsl.x;
40 hsl.x = 4.f + (rgb.r - rgb.g) / hsl.x;
56 Vector3 FromHueSaturationLightness(Vector3 hsl)
59 if(hsl.y * hsl.y > 0.f)
67 int i = FastFloor(hsl.x);
69 float p = hsl.z * (1.0 - hsl.y);
70 float q = hsl.z * (1.0 - (hsl.y * ff));
71 float t = hsl.z * (1.0 - (hsl.y * (1.f - ff)));
115 rgb = Vector3::ONE * hsl.z;
121 Geometry CreateCuboidWireframeGeometry()
132 Vector3 vertexData[] = {
133 Vector3(-.5, -.5, -.5),
134 Vector3(.5, -.5, -.5),
135 Vector3(-.5, .5, -.5),
136 Vector3(.5, .5, -.5),
137 Vector3(-.5, -.5, .5),
138 Vector3(.5, -.5, .5),
139 Vector3(-.5, .5, .5),
143 uint16_t indices[] = {
144 0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 1, 5, 3, 7, 2, 6, 4, 5, 5, 7, 7, 6, 6, 4};
145 VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map()
146 .Add("aPosition", Property::VECTOR3));
147 vertexBuffer.SetData(vertexData, std::extent<decltype(vertexData)>::value);
149 Geometry geometry = Geometry::New();
150 geometry.AddVertexBuffer(vertexBuffer);
151 geometry.SetIndexBuffer(indices, std::extent<decltype(indices)>::value);
152 geometry.SetType(Geometry::LINES);
156 Renderer CreateRenderer(TextureSet textures, Geometry geometry, Shader shader, uint32_t options)
158 Renderer renderer = Renderer::New(geometry, shader);
159 renderer.SetProperty(Renderer::Property::BLEND_MODE,
160 (options & OPTION_BLEND) ? BlendMode::ON : BlendMode::OFF);
161 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE,
162 (options & OPTION_DEPTH_TEST) ? DepthTestMode::ON : DepthTestMode::OFF);
163 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE,
164 (options & OPTION_DEPTH_WRITE) ? DepthWriteMode::ON : DepthWriteMode::OFF);
165 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
169 textures = TextureSet::New();
172 renderer.SetTextures(textures);
176 void CenterActor(Actor actor)
178 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
179 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
184 auto actor = Actor::New();
189 Renderer CloneRenderer(Renderer original)
191 Geometry geom = original.GetGeometry();
192 Shader shader = original.GetShader();
193 Renderer clone = Renderer::New(geom, shader);
196 Property::IndexContainer indices;
197 original.GetPropertyIndices(indices);
199 for(auto& i : indices)
201 auto actualIndex = PropertyRanges::DEFAULT_RENDERER_PROPERTY_START_INDEX + i;
202 clone.SetProperty(actualIndex, original.GetProperty(actualIndex));
205 // Copy texture references (and create TextureSet, if there's any textures).
206 TextureSet ts = original.GetTextures();
207 clone.SetTextures(ts);
212 Actor CloneActor(Actor original)
214 using namespace Dali;
216 auto clone = Actor::New();
217 clone.SetProperty(Actor::Property::NAME, original.GetProperty(Actor::Property::NAME));
220 // Don't copy every single one of them.
221 // Definitely don't copy resize policy related things, which will internally enable
222 // relayout, which in turn will result in losing the ability to set Z size.
224 Actor::Property::PARENT_ORIGIN,
225 Actor::Property::ANCHOR_POINT,
226 Actor::Property::SIZE,
227 Actor::Property::POSITION,
228 Actor::Property::ORIENTATION,
229 Actor::Property::SCALE,
230 Actor::Property::VISIBLE,
231 Actor::Property::COLOR,
232 Actor::Property::NAME,
235 clone.SetProperty(i, original.GetProperty(i));
239 for(unsigned int i = 0; i < original.GetRendererCount(); ++i)
241 auto rClone = CloneRenderer(original.GetRendererAt(i));
242 clone.AddRenderer(rClone);
245 // Recurse into children.
246 for(unsigned int i = 0; i < original.GetChildCount(); ++i)
248 Actor newChild = CloneActor(original.GetChildAt(i));