Merge changes I7066e6c1,I3f0c228e 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    * @return id of the texture.
84    */
85   std::size_t Load( const std::string& url );
86
87   /**
88    * @brief Retrieve N patch data matching to an id
89    * @param [in] id of data
90    * @param [out] data const pointer to the data
91    * @return true if data matching to id was really found
92    */
93   bool GetNPatchData( std::size_t id, const Data*& data );
94
95 protected:
96
97   /**
98    * Undefined copy constructor.
99    */
100   NPatchLoader(const NPatchLoader&);
101
102   /**
103    * Undefined assignment operator.
104    */
105   NPatchLoader& operator=(const NPatchLoader& rhs);
106
107 private:
108
109   OwnerContainer< Data* > mCache;
110
111 };
112
113 } // name Internal
114
115 } // namespace Toolkit
116
117 } // namespace Dali
118
119 #endif // DALI_TOOLKIT_NPATCH_LOADER_H