(AnimatedVectorImage) Ensure the progress is kept according to actions
[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/public-api/math/uint-16-pair.h>
24 #include <dali/devel-api/common/owner-container.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 namespace NPatchBuffer
36 {
37
38 void GetRedOffsetAndMask( Dali::Pixel::Format pixelFormat, int& byteOffset, int& bitMask );
39
40 } // namespace NPatchBuffer
41
42 /**
43  * The manager for loading Npatch textures.
44  * It caches them internally for better performance; i.e. to avoid loading and
45  * parsing the files over and over.
46  *
47  * Cache is not cleaned during app lifecycle as N patches take considerably
48  * small space and there's not usually a lot of them. Usually N patches are specified in
49  * toolkit default style and there is 1-2 per control that are shared across the whole application.
50  */
51 class NPatchLoader
52 {
53 public:
54
55   typedef Dali::Vector< Uint16Pair > StretchRanges;
56
57   enum
58   {
59     UNINITIALIZED_ID = 0 ///< uninitialised id, use to initialize ids
60   };
61
62   struct Data
63   {
64     std::string url;                              ///< Url of the N-Patch
65     TextureSet textureSet;                        ///< Texture containing the cropped image
66     StretchRanges stretchPixelsX;                 ///< X stretch pixels
67     StretchRanges stretchPixelsY;                 ///< Y stretch pixels
68     std::size_t hash;                             ///< Hash code for the Url
69     uint32_t croppedWidth;                        ///< Width of the cropped middle part of N-patch
70     uint32_t croppedHeight;                       ///< Height of the cropped middle part of N-patch
71     Rect< int > border;                           ///< The size of the border
72   };
73
74 public:
75
76   /**
77    * Constructor
78    */
79   NPatchLoader();
80
81   /**
82    * Destructor, non-virtual as not a base class
83    */
84   ~NPatchLoader();
85
86   /**
87    * @brief Retrieve a texture matching the n-patch url.
88    *
89    * @param [in] url to retrieve
90    * @param [in] border The border size of the image
91    * @param [in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
92    *                                   image has no alpha channel
93    * @return id of the texture.
94    */
95   std::size_t Load( const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad );
96
97   /**
98    * @brief Retrieve N patch data matching to an id
99    * @param [in] id of data
100    * @param [out] data const pointer to the data
101    * @return true if data matching to id was really found
102    */
103   bool GetNPatchData( std::size_t id, const Data*& data );
104
105 protected:
106
107   /**
108    * Undefined copy constructor.
109    */
110   NPatchLoader(const NPatchLoader&);
111
112   /**
113    * Undefined assignment operator.
114    */
115   NPatchLoader& operator=(const NPatchLoader& rhs);
116
117 private:
118
119   OwnerContainer< Data* > mCache;
120
121 };
122
123 } // name Internal
124
125 } // namespace Toolkit
126
127 } // namespace Dali
128
129 #endif // DALI_TOOLKIT_NPATCH_LOADER_H