Merge "Added style name for styling TextEditor ScrollBar" 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     Rect< int > border;                           ///< The size of the border
66   };
67
68 public:
69
70   /**
71    * Constructor
72    */
73   NPatchLoader();
74
75   /**
76    * Destructor, non-virtual as not a base class
77    */
78   ~NPatchLoader();
79
80   /**
81    * @brief Retrieve a texture matching the n-patch url.
82    *
83    * @param [in] url to retrieve
84    * @param [in] border The border size of the image
85    * @return id of the texture.
86    */
87   std::size_t Load( const std::string& url, const Rect< int >& border );
88
89   /**
90    * @brief Retrieve N patch data matching to an id
91    * @param [in] id of data
92    * @param [out] data const pointer to the data
93    * @return true if data matching to id was really found
94    */
95   bool GetNPatchData( std::size_t id, const Data*& data );
96
97 protected:
98
99   /**
100    * Undefined copy constructor.
101    */
102   NPatchLoader(const NPatchLoader&);
103
104   /**
105    * Undefined assignment operator.
106    */
107   NPatchLoader& operator=(const NPatchLoader& rhs);
108
109 private:
110
111   OwnerContainer< Data* > mCache;
112
113 };
114
115 } // name Internal
116
117 } // namespace Toolkit
118
119 } // namespace Dali
120
121 #endif // DALI_TOOLKIT_NPATCH_LOADER_H