1 #ifndef DALI_TOOLKIT_NPATCH_LOADER_H
2 #define DALI_TOOLKIT_NPATCH_LOADER_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
35 namespace NPatchBuffer
38 void GetRedOffsetAndMask( Dali::Pixel::Format pixelFormat, int& byteOffset, int& bitMask );
40 } // namespace NPatchBuffer
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.
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.
55 typedef Dali::Vector< Uint16Pair > StretchRanges;
59 UNINITIALIZED_ID = 0 ///< uninitialised id, use to initialize ids
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
82 * Destructor, non-virtual as not a base class
87 * @brief Retrieve a texture matching the n-patch url.
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.
95 std::size_t Load( const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad );
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
103 bool GetNPatchData( std::size_t id, const Data*& data );
108 * Undefined copy constructor.
110 NPatchLoader(const NPatchLoader&);
113 * Undefined assignment operator.
115 NPatchLoader& operator=(const NPatchLoader& rhs);
119 OwnerContainer< Data* > mCache;
125 } // namespace Toolkit
129 #endif // DALI_TOOLKIT_NPATCH_LOADER_H