Merge "C# Bindings for Transition Policy properties" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch-loader.h
1 #ifndef DALI_TOOLKIT_NPATCH_LOADER_H
2 #define DALI_TOOLKIT_NPATCH_LOADER_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 // EXTERNAL INCLUDES
21 #include <string>
22 #include <dali/public-api/rendering/texture-set.h>
23 #include <dali/devel-api/common/owner-container.h>
24 #include <dali/devel-api/images/nine-patch-image.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * The manager for loading Npatch textures.
40  * It caches them internally for better performance; i.e. to avoid loading and
41  * parsing the files over and over.
42  *
43  * Cache is not cleaned during app lifecycle as N patches take considerably
44  * small space and there's not usually a lot of them. Usually N patches are specified in
45  * toolkit default style and there is 1-2 per control that are shared across the whole application.
46  */
47 class NPatchLoader
48 {
49 public:
50
51   enum
52   {
53     UNINITIALIZED_ID = 0 ///< uninitialised id, use to initialize ids
54   };
55
56   struct Data
57   {
58     std::string url;                              ///< Url of the N-Patch
59     TextureSet textureSet;                        ///< Texture containing the cropped image
60     NinePatchImage::StretchRanges stretchPixelsX; ///< X stretch pixels
61     NinePatchImage::StretchRanges stretchPixelsY; ///< Y stretch pixels
62     std::size_t hash;                             ///< Hash code for the Url
63     uint32_t croppedWidth;                        ///< Width of the cropped middle part of N-patch
64     uint32_t croppedHeight;                       ///< Height of the cropped middle part of N-patch
65   };
66
67 public:
68
69   /**
70    * Constructor
71    */
72   NPatchLoader();
73
74   /**
75    * Destructor, non-virtual as not a base class
76    */
77   ~NPatchLoader();
78
79   /**
80    * @brief Retrieve a texture matching the n-patch url.
81    *
82    * @param [in] url to retrieve
83    * @param [in] border The border size of the image
84    * @return id of the texture.
85    */
86   std::size_t Load( const std::string& url, const Rect< int >& border );
87
88   /**
89    * @brief Retrieve N patch data matching to an id
90    * @param [in] id of data
91    * @param [out] data const pointer to the data
92    * @return true if data matching to id was really found
93    */
94   bool GetNPatchData( std::size_t id, const Data*& data );
95
96 protected:
97
98   /**
99    * Undefined copy constructor.
100    */
101   NPatchLoader(const NPatchLoader&);
102
103   /**
104    * Undefined assignment operator.
105    */
106   NPatchLoader& operator=(const NPatchLoader& rhs);
107
108 private:
109
110   OwnerContainer< Data* > mCache;
111
112 };
113
114 } // name Internal
115
116 } // namespace Toolkit
117
118 } // namespace Dali
119
120 #endif // DALI_TOOLKIT_NPATCH_LOADER_H