Merge "TextVisual implementation." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / visual-factory / visual-factory.h
1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/images/image-operations.h>
24 #include <dali/public-api/object/property-map.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
28
29 namespace Dali
30 {
31 class Image;
32 class Vector4;
33
34 namespace Toolkit
35 {
36
37 namespace Internal DALI_INTERNAL
38 {
39 class VisualFactory;
40 }
41
42 /**
43  * @brief VisualFactory is a singleton object that provides and shares visuals between controls
44  *
45  * By setting environment variable 'DALI_DEBUG_RENDERING', a debug visual is used which renders a quad wireframe.
46  *
47  * The visual type is required in the property map for requesting a visual.
48  *
49  * | %Property Name           | Type              |
50  * |--------------------------|-------------------|
51  * | visualType               | INTEGER or STRING |
52  * | shader                   | MAP               |
53  */
54 class DALI_IMPORT_API VisualFactory : public BaseHandle
55 {
56 public:
57
58   /**
59    * @brief Create or retrieve VisualFactory singleton.
60    *
61    * @return A handle to the VisualFactory control.
62    */
63   static VisualFactory Get();
64
65   /**
66    * @brief Create a VisualFactory handle.
67    *
68    * Calling member functions with an uninitialised handle is not allowed.
69    */
70   VisualFactory();
71
72   /**
73    * @brief Destructor
74    *
75    * This is non-virtual since derived Handle types must not contain data or virtual methods.
76    */
77   ~VisualFactory();
78
79   /**
80    * @brief This copy constructor is required for (smart) pointer semantics.
81    *
82    * @param[in] handle A reference to the copied handle.
83    */
84   VisualFactory( const VisualFactory& handle );
85
86   /**
87    * @brief This assignment operator is required for (smart) pointer semantics.
88    *
89    * @param [in] handle  A reference to the copied handle.
90    * @return A reference to this.
91    */
92   VisualFactory& operator=( const VisualFactory& handle );
93
94   /**
95    * @brief Request the visual
96    *
97    * @param[in] propertyMap The map contains the properties required by the visual.
98    *            The content of the map determines the type of visual that will be returned.
99    * @return The handle to the created visual
100    */
101   Visual::Base CreateVisual( const Property::Map& propertyMap  );
102
103   /**
104    * @brief Request the visual to render the image.
105    *
106    * @param[in] image The image to be rendered.
107    * @return The pointer pointing to the visual
108    */
109   Visual::Base CreateVisual( const Image& image );
110
111   /**
112    * @brief Request the visual to render the given resource at the url.
113    *
114    * @param[in] url The URL to the resource to be rendered.
115    * @param[in] size The width and height to fit the loaded image to.
116    * @return The pointer pointing to the visual
117    */
118   Visual::Base CreateVisual( const std::string& url, ImageDimensions size );
119
120 private:
121
122   explicit DALI_INTERNAL VisualFactory(Internal::VisualFactory *impl);
123
124 };
125
126
127 /**
128  * @brief Template to allow discard old visual, get new one and set it on stage if possible
129  *
130  * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
131  * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
132  * @SINCE_1_0.39
133  * @param[in] actor Actor for which the visual will be replaced
134  * @param[in,out] visual The visual to be replaced
135  * @param[in] param0 First template based argument passed to the visual factory
136  * @param[in] param1 Second template based argument passed to the visual factory
137  */
138 template< class ParameterType0, class ParameterType1 >
139 void InitializeVisual( Actor& actor, Visual::Base& visual, ParameterType0& param0, ParameterType1& param1 )
140 {
141   visual.RemoveAndReset( actor );
142   visual = Toolkit::VisualFactory::Get().CreateVisual( param0, param1 );
143   if( visual && actor && actor.OnStage() )
144   {
145     visual.SetOnStage( actor );
146   }
147 }
148
149 /**
150  * @brief Template to allow discard old visual, get new one and set it on stage if possible
151  *
152  * @tparam ParameterType The type of argument passed to the CreateVisual()
153  * @SINCE_1_0.39
154  * @param[in] actor Actor for which the visual will be replaced
155  * @param[in,out] visual The visual to be replaced
156  * @param[in] param Template based argument passed to the visual factory
157  */
158 template< class ParameterType >
159 void InitializeVisual( Actor& actor, Visual::Base& visual, ParameterType& param )
160 {
161   visual.RemoveAndReset( actor );
162   visual =  Toolkit::VisualFactory::Get().CreateVisual( param );
163   if( visual && actor && actor.OnStage() )
164   {
165     visual.SetOnStage( actor );
166   }
167 }
168
169 } // namespace Toolkit
170
171 } // namespace Dali
172
173 #endif // DALI_TOOLKIT_VISUAL_FACTORY_H