1 #ifndef DALI_INTERNAL_RESOURCE_IMAGE_H
2 #define DALI_INTERNAL_RESOURCE_IMAGE_H
5 * Copyright (c) 2019 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.
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/internal/event/images/image-impl.h>
27 #include <dali/internal/common/image-attributes.h>
28 #include <dali/integration-api/debug.h> // For DALI_LOG_OBJECT_STRING_DECLARATION
37 typedef IntrusivePtr<ResourceImage> ResourceImagePtr;
40 * ResourceImage is an image loaded using a URL, it is an image resource that can be added to actors etc.
42 class ResourceImage : public Image
47 * Creates a pointer to an uninitialized Image object.
48 * @return a pointer to a newly created object.
50 static ResourceImagePtr New();
53 * Creates object and loads image from filesystem
54 * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
55 * @param [in] url The URL of the image file.
56 * @param [in] attributes requested parameters for loading (size, scaling etc.)
57 * if width or height is specified as 0, the natural size will be used.
58 * @return a pointer to a newly created object.
60 static ResourceImagePtr New( const std::string& url,
61 const ImageAttributes& attributes );
64 * @copydoc Dali::ResourceImage::GetLoadingState()
66 Dali::LoadingState GetLoadingState() const { return mLoadingState; }
69 * @copydoc Dali::ResourceImage::LoadingFinishedSignal()
71 Dali::ResourceImage::ResourceImageSignal& LoadingFinishedSignal() { return mLoadingFinished; }
74 * Get the attributes of the image.
75 * Only to be used after the image has finished loading.
76 * (Ticket's LoadingSucceeded callback was called)
77 * Reflects the last cached values after a LoadComplete.
78 * If requested width or height was 0, they are replaced by concrete dimensions.
79 * @return a copy of the attributes
81 const ImageAttributes& GetAttributes() const;
84 * @copydoc Dali::ResourceImage::GetUrl()
85 * virtual so deriving class can override it
87 virtual const std::string& GetUrl() const;
90 * @copydoc Dali::ResourceImage::Reload()
95 * @copydoc Dali::Image::GetWidth()
97 virtual unsigned int GetWidth() const;
100 * @copydoc Dali::Image::GetWidth()
102 virtual unsigned int GetHeight() const;
105 * @copydoc Dali::Internal::Image::GetNaturalSize()
107 virtual Vector2 GetNaturalSize() const;
113 * A reference counted object may only be deleted by calling Unreference()
115 virtual ~ResourceImage();
118 * Constructor, with default parameters
123 * Constructor, with url and attributes
125 ResourceImage( const std::string& url, const ImageAttributes& attributes);
128 Dali::ResourceImage::ResourceImageSignal mLoadingFinished;
129 ImageAttributes mAttributes;
131 Dali::LoadingState mLoadingState;
133 // Changes scope, should be at end of class
134 DALI_LOG_OBJECT_STRING_DECLARATION;
137 } // namespace Internal
140 * Helper methods for public API.
142 inline Internal::ResourceImage& GetImplementation(Dali::ResourceImage& image)
144 DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
146 BaseObject& handle = image.GetBaseObject();
148 return static_cast<Internal::ResourceImage&>(handle);
151 inline const Internal::ResourceImage& GetImplementation(const Dali::ResourceImage& image)
153 DALI_ASSERT_ALWAYS( image && "Image handle is empty" );
155 const BaseObject& handle = image.GetBaseObject();
157 return static_cast<const Internal::ResourceImage&>(handle);
161 #endif // DALI_INTERNAL_RESOURCE_IMAGE_H