Merge "[Tizen] Prepare for Tizen 4.0 Build" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / images / resource-image-impl.h
1 #ifndef __DALI_INTERNAL_RESOURCE_IMAGE_H__
2 #define __DALI_INTERNAL_RESOURCE_IMAGE_H__
3
4 /*
5  * Copyright (c) 2015 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
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/internal/event/images/image-impl.h>
27 #include <dali/integration-api/debug.h> // For DALI_LOG_OBJECT_STRING_DECLARATION
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 class ResourceImage;
36 typedef IntrusivePtr<ResourceImage> ResourceImagePtr;
37
38 /**
39  * ResourceImage is an image loaded using a URL, it is an image resource that can be added to actors etc.
40  */
41 class ResourceImage : public Image
42 {
43 public:
44
45   /**
46    * Creates a pointer to an uninitialized Image object.
47    * @return a pointer to a newly created object.
48    */
49   static ResourceImagePtr New();
50
51   /**
52    * Creates object and loads image from filesystem
53    * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
54    * @param [in] url The URL of the image file.
55    * @param [in] attributes requested parameters for loading (size, scaling etc.)
56    *                        if width or height is specified as 0, the natural size will be used.
57    * @return a pointer to a newly created object.
58    */
59   static ResourceImagePtr New( const std::string& url,
60                           const ImageAttributes& attributes );
61
62   /**
63    * @copydoc Dali::ResourceImage::GetLoadingState()
64    */
65   Dali::LoadingState GetLoadingState() const { return mLoadingState; }
66
67   /**
68    * @copydoc Dali::ResourceImage::LoadingFinishedSignal()
69    */
70   Dali::ResourceImage::ResourceImageSignal& LoadingFinishedSignal() { return mLoadingFinished; }
71
72   /**
73    * Connects a callback function with the object's signals.
74    * @param[in] object The object providing the signal.
75    * @param[in] tracker Used to disconnect the signal.
76    * @param[in] signalName The signal to connect to.
77    * @param[in] functor A newly allocated FunctorDelegate.
78    * @return True if the signal was connected.
79    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
80    */
81   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
82
83   /**
84    * Get the attributes of the image.
85    * Only to be used after the image has finished loading.
86    * (Ticket's LoadingSucceeded callback was called)
87    * Reflects the last cached values after a LoadComplete.
88    * If requested width or height was 0, they are replaced by concrete dimensions.
89    * @return a copy of the attributes
90    */
91   const ImageAttributes& GetAttributes() const;
92
93   /**
94    * @copydoc Dali::ResourceImage::GetUrl()
95    * virtual so deriving class can override it
96    */
97   virtual const std::string& GetUrl() const;
98
99   /**
100    * @copydoc Dali::ResourceImage::Reload()
101    */
102   void Reload();
103
104   /**
105    * @copydoc Dali::Image::GetWidth()
106    */
107   virtual unsigned int GetWidth() const;
108
109   /**
110    * @copydoc Dali::Image::GetWidth()
111    */
112   virtual unsigned int GetHeight() const;
113
114   /**
115    * @copydoc Dali::Internal::Image::GetNaturalSize()
116    */
117   virtual Vector2 GetNaturalSize() const;
118
119
120 protected:
121
122   /**
123    * A reference counted object may only be deleted by calling Unreference()
124    */
125   virtual ~ResourceImage();
126
127   /**
128    * Constructor, with default parameters
129    */
130   ResourceImage();
131
132   /**
133    * Constructor, with url and attributes
134    */
135   ResourceImage( const std::string& url, const ImageAttributes& attributes);
136
137 private:
138   Dali::ResourceImage::ResourceImageSignal mLoadingFinished;
139   ImageAttributes mAttributes;
140   std::string mUrl;
141   Dali::LoadingState mLoadingState;
142
143   // Changes scope, should be at end of class
144   DALI_LOG_OBJECT_STRING_DECLARATION;
145 };
146
147 } // namespace Internal
148
149 /**
150  * Helper methods for public API.
151  */
152 inline Internal::ResourceImage& GetImplementation(Dali::ResourceImage& image)
153 {
154   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
155
156   BaseObject& handle = image.GetBaseObject();
157
158   return static_cast<Internal::ResourceImage&>(handle);
159 }
160
161 inline const Internal::ResourceImage& GetImplementation(const Dali::ResourceImage& image)
162 {
163   DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
164
165   const BaseObject& handle = image.GetBaseObject();
166
167   return static_cast<const Internal::ResourceImage&>(handle);
168 }
169
170 } // namespace Dali
171 #endif // __DALI_INTERNAL_RESOURCE_IMAGE_H__