10dee0d782c915e73cf97e98b973d248c65d9783
[platform/core/uifw/dali-demo.git] / examples / particles / utils.h
1 #ifndef PARTICLES_UTILS_H_
2 #define PARTICLES_UTILS_H_
3 /*
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "dali/public-api/actors/actor.h"
21 #include "dali/public-api/actors/actor.h"
22 #include "dali/public-api/rendering/geometry.h"
23 #include "dali/public-api/rendering/renderer.h"
24 #include "dali/public-api/rendering/shader.h"
25 #include "dali/public-api/rendering/texture.h"
26 #include "dali/public-api/math/vector3.h"
27 #include <cmath>
28
29 //
30 // Maths
31 //
32 inline
33 float FastFloor(float x)
34 {
35   return static_cast<int>(x) - static_cast<int>(x < 0);
36 }
37
38 ///@brief Converts RGB values (in the 0..1 range) to HSL, where hue is in degrees,
39 /// in the 0..360 range, and saturation and lightness are in the 0..1 range.
40 Dali::Vector3 ToHueSaturationLightness(Dali::Vector3 rgb);
41
42 ///@brief Converts HSL values, where hue is in degrees, in the 0..360 range, and
43 /// saturation and lightness are in 0..1  to RGB (in the 0..1 range)
44 Dali::Vector3 FromHueSaturationLightness(Dali::Vector3 hsl);
45
46 //
47 // Dali entities
48 //
49 ///@brief Creates geometry for a unit cube wireframe (i.e. vertex positions between
50 /// -.5 and .5)..
51 Dali::Geometry CreateCuboidWireframeGeometry();
52
53 enum RendererOptions
54 {
55   OPTION_NONE = 0x0,
56   OPTION_BLEND = 0x01,
57   OPTION_DEPTH_TEST = 0x02,
58   OPTION_DEPTH_WRITE = 0x04
59 };
60
61 ///@brief Creates a renderer with the given @a textures set, @a geometry, @a shader
62 /// and @a options from above.
63 ///@note Back face culling is on.
64 ///@note If textures is not a valid handle, an empty texture set will be created.
65 Dali::Renderer CreateRenderer(Dali::TextureSet textures, Dali::Geometry geometry,
66   Dali::Shader shader, uint32_t options = OPTION_NONE);
67
68 ///@brief Sets @a actor's anchor point and parent origin to center.
69 void CenterActor(Dali::Actor actor);
70
71 ///@brief Creates an empty and centered actor.
72 Dali::Actor CreateActor();
73
74 ///@brief Creates a copy of @a original, sharing the same geometry and shader and
75 /// copying each properties.
76 ///@note Breaks if @a original has any custom properties. TODO: fix.
77 Dali::Renderer CloneRenderer(Dali::Renderer original);
78
79 ///@brief Creates a copy of @a original, cloning each renderer, and a select set
80 /// of properties: parent origin, anchor point, size, position, orientation, scale,
81 /// visible, color and name.
82 ///@note Does not copy resize policy related properties, as setting those, even if
83 /// default, will break the ability to specify a size for the actor in Z.
84 Dali::Actor CloneActor(Dali::Actor original);
85
86 #endif //PARTICLES_UTILS_H_