From: Chu Hoang Date: Mon, 13 Jul 2015 14:28:52 +0000 (+0100) Subject: Simple implementation of ImageView. X-Git-Tag: dali_1.0.50~7^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=e80261307788b4656435c4dd964beff7c85e7e8c Simple implementation of ImageView. Change-Id: Iab2e0995e97a4bfc2b8d1a8b36da6f9d896fc181 --- diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index aae9626..c75e082 100644 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -15,6 +15,7 @@ SET(TC_SOURCES utc-Dali-CubeTransitionEffect.cpp utc-Dali-EffectsView.cpp utc-Dali-GaussianBlurView.cpp + utc-Dali-ImageView.cpp utc-Dali-JsonParser.cpp utc-Dali-KeyInputFocusManager.cpp utc-Dali-PageTurnView.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp new file mode 100644 index 0000000..8e9f8fe --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -0,0 +1,452 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// Need to override adaptor classes for toolkit test harness, so include +// test harness headers before dali headers. +#include + +#include + +using namespace Dali; +using namespace Toolkit; + +void utc_dali_toolkit_image_view_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_toolkit_image_view_cleanup(void) +{ + test_return_value = TET_PASS; +} + +namespace +{ +const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg"; +} // namespace + +int UtcDaliImageViewNewP(void) +{ + TestApplication application; + + ImageView imageView = ImageView::New(); + + DALI_TEST_CHECK( imageView ); + + END_TEST; +} + +int UtcDaliImageViewNewImageP(void) +{ + TestApplication application; + + Image image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) ); + ImageView imageView = ImageView::New( image ); + + DALI_TEST_CHECK( imageView ); + DALI_TEST_EQUALS( image, imageView.GetImage(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewNewUrlP(void) +{ + TestApplication application; + + ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME ); + DALI_TEST_CHECK( imageView ); + DALI_TEST_CHECK( imageView.GetImage() ); + + Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) ); + std::string resource_url; + DALI_TEST_CHECK( val.Get( resource_url ) ); + DALI_TEST_EQUALS( resource_url, TEST_IMAGE_FILE_NAME, TEST_LOCATION ); + + Image image = imageView.GetImage(); + DALI_TEST_CHECK( image ); + + ResourceImage resourceImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resourceImage ); + DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_FILE_NAME, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewConstructorP(void) +{ + TestApplication application; + + ImageView imageView; + + DALI_TEST_CHECK( !imageView ); + + END_TEST; +} + +int UtcDaliImageViewCopyConstructorP(void) +{ + TestApplication application; + + // Initialize an object, ref count == 1 + ImageView imageView = ImageView::New(); + + ImageView copy( imageView ); + DALI_TEST_CHECK( copy ); + + END_TEST; +} + +int UtcDaliImageViewAssignmentOperatorP(void) +{ + TestApplication application; + + ImageView imageView = ImageView::New(); + + ImageView copy( imageView ); + DALI_TEST_CHECK( copy ); + DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewDownCastP(void) +{ + TestApplication application; + + ImageView imageView = ImageView::New(); + + BaseHandle object(imageView); + + ImageView imageView2 = ImageView::DownCast( object ); + DALI_TEST_CHECK(imageView2); + + ImageView imageView3 = DownCast< ImageView >( object ); + DALI_TEST_CHECK(imageView3); + + END_TEST; +} + +int UtcDaliImageViewDownCastN(void) +{ + TestApplication application; + + BaseHandle unInitializedObject; + + ImageView imageView1 = ImageView::DownCast( unInitializedObject ); + DALI_TEST_CHECK( !imageView1 ); + + ImageView imageView2 = DownCast< ImageView >( unInitializedObject ); + DALI_TEST_CHECK( !imageView2 ); + + END_TEST; +} + +int UtcDaliImageViewTypeRegistry(void) +{ + ToolkitTestApplication application; + + TypeRegistry typeRegistry = TypeRegistry::Get(); + DALI_TEST_CHECK( typeRegistry ); + + TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" ); + DALI_TEST_CHECK( typeInfo ); + + BaseHandle handle = typeInfo.CreateInstance(); + DALI_TEST_CHECK( handle ); + + ImageView imageView = ImageView::DownCast( handle ); + DALI_TEST_CHECK( imageView ); + + END_TEST; +} + +int UtcDaliImageViewSetGetProperty(void) +{ + ToolkitTestApplication application; + + ImageView imageView = ImageView::New(); + + Property::Index idx = imageView.GetPropertyIndex( "resource-url" ); + DALI_TEST_EQUALS( idx, ImageView::Property::RESOURCE_URL, TEST_LOCATION ); + + imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME ); + Property::Value val = imageView.GetProperty( idx ); + std::string resource_url; + DALI_TEST_CHECK( val.Get( resource_url ) ); + DALI_TEST_EQUALS( resource_url, TEST_IMAGE_FILE_NAME, TEST_LOCATION ); + + Image image = imageView.GetImage(); + DALI_TEST_CHECK( image ); + + ResourceImage resourceImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resourceImage ); + DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_FILE_NAME, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewSizeWithBackground(void) +{ + ToolkitTestApplication application; + + int width = 100; + int height = 200; + Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) ); + ImageView imageView = ImageView::New(); + imageView.SetBackgroundImage( image ); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( imageView.GetCurrentSize().width, width, TEST_LOCATION ); + DALI_TEST_EQUALS( imageView.GetCurrentSize().height, height, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewSizeWithBackgroundAndImage(void) +{ + ToolkitTestApplication application; + + int widthBackground = 100; + int heightBackground = 200; + int width = 300; + int height = 400; + Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) ); + Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) ); + + ImageView imageView = ImageView::New(); + imageView.SetBackgroundImage( imageBackground ); + imageView.SetImage( image ); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( imageView.GetCurrentSize().width, width, TEST_LOCATION ); + DALI_TEST_EQUALS( imageView.GetCurrentSize().height, height, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewHeightForWidthBackground(void) +{ + ToolkitTestApplication application; + + int widthBackground = 100; + int heightBackground = 200; + Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) ); + + ImageView imageView = ImageView::New(); + imageView.SetBackgroundImage( imageBackground ); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + + Control control = Control::DownCast( imageView ); + DALI_TEST_CHECK( control ); + DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION ); + DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewHeightForWidthBackgroundAndImage(void) +{ + ToolkitTestApplication application; + + int widthBackground = 100; + int heightBackground = 200; + int width = 300; + int height = 400; + Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) ); + Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) ); + + ImageView imageView = ImageView::New(); + imageView.SetBackgroundImage( imageBackground ); + imageView.SetImage( image ); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), height, TEST_LOCATION ); + DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), width, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewSetBufferImage(void) +{ + ToolkitTestApplication application; + + int width = 300; + int height = 400; + Image image = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) ); + ImageView imageView = ImageView::New(); + imageView.SetImage( image ); + + std::string resource_url; + Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) ); + DALI_TEST_CHECK( val.Get( resource_url ) ); + DALI_TEST_CHECK( resource_url.empty() ); + + END_TEST; +} + +int UtcDaliImageViewSetResourceImage(void) +{ + ToolkitTestApplication application; + + Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME ); + ImageView imageView = ImageView::New(); + imageView.SetImage( image ); + + std::string resource_url; + Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) ); + DALI_TEST_CHECK( val.Get( resource_url ) ); + DALI_TEST_EQUALS( resource_url, TEST_IMAGE_FILE_NAME, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewSetImageOnstageP(void) +{ + ToolkitTestApplication application; + + ImageView imageView = ImageView::New(); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + + Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME ); + imageView.SetImage( image1 ); + + Image image2 = imageView.GetImage(); + DALI_TEST_EQUALS( image1, image2, TEST_LOCATION ); + + int width = 300; + int height = 400; + Image image3 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) ); + imageView.SetImage( image3 ); + + Image image4 = imageView.GetImage(); + DALI_TEST_EQUALS( image3, image4, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewSetImageOnstageN(void) +{ + ToolkitTestApplication application; + + ImageView imageView = ImageView::New(); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + + Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME ); + imageView.SetImage( image1 ); + + Image image2 = imageView.GetImage(); + DALI_TEST_EQUALS( image1, image2, TEST_LOCATION ); + + Image image3; + imageView.SetImage( image3 ); + + Image image4 = imageView.GetImage(); + DALI_TEST_CHECK( !image4 ); + + END_TEST; +} + +int UtcDaliImageViewSetImageOffstageP(void) +{ + ToolkitTestApplication application; + + ImageView imageView = ImageView::New(); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + Stage::GetCurrent().Remove( imageView ); + + Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME ); + imageView.SetImage( image1 ); + + Image image2 = imageView.GetImage(); + DALI_TEST_EQUALS( image1, image2, TEST_LOCATION ); + + int width = 300; + int height = 400; + Image image3 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) ); + imageView.SetImage( image3 ); + + Image image4 = imageView.GetImage(); + DALI_TEST_EQUALS( image3, image4, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageViewSetImageOffstageN(void) +{ + ToolkitTestApplication application; + + ImageView imageView = ImageView::New(); + + Stage::GetCurrent().Add( imageView ); + application.SendNotification(); + application.Render(); + Stage::GetCurrent().Remove( imageView ); + + Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME ); + imageView.SetImage( image1 ); + + Image image2 = imageView.GetImage(); + DALI_TEST_EQUALS( image1, image2, TEST_LOCATION ); + + Image image3; + imageView.SetImage( image3 ); + + Image image4 = imageView.GetImage(); + DALI_TEST_CHECK( !image4 ); + + END_TEST; +} + +int UtcDaliImageViewSetImageN(void) +{ + ToolkitTestApplication application; + + Image image1; + ImageView imageView = ImageView::New(); + imageView.SetImage( image1 ); + + Image image2 = imageView.GetImage(); + DALI_TEST_CHECK( !image2 ); + + std::string resource_url; + Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) ); + DALI_TEST_CHECK( val.Get( resource_url ) ); + DALI_TEST_CHECK( resource_url.empty() ); + + END_TEST; +} diff --git a/build/tizen/dali-toolkit/Makefile.am b/build/tizen/dali-toolkit/Makefile.am index 17029e0..3ec8f92 100644 --- a/build/tizen/dali-toolkit/Makefile.am +++ b/build/tizen/dali-toolkit/Makefile.am @@ -125,6 +125,7 @@ publicapialignmentdir = $(publicapicontrolsdir)/alignment publicapibuttonsdir = $(publicapicontrolsdir)/buttons publicapidefaultcontrolsdir = $(publicapicontrolsdir)/default-controls publicapigaussianblurviewdir = $(publicapicontrolsdir)/gaussian-blur-view +publicapiimageviewdir = $(publicapicontrolsdir)/image-view publicapiscrollbardir = $(publicapicontrolsdir)/scroll-bar publicapiscrollabledir = $(publicapicontrolsdir)/scrollable publicapiscrollviewdir = $(publicapicontrolsdir)/scrollable/scroll-view @@ -142,6 +143,7 @@ publicapialignment_HEADERS = $(public_api_alignment_header_files) publicapibuttons_HEADERS = $(public_api_buttons_header_files) publicapidefaultcontrols_HEADERS = $(public_api_default_controls_header_files) publicapigaussianblurview_HEADERS = $(public_api_gaussian_blur_view_header_files) +publicapiimageview_HEADERS = $(public_api_image_view_header_files) publicapiitemview_HEADERS = $(public_api_item_view_header_files) publicapiscrollbar_HEADERS = $(public_api_scroll_bar_header_files) publicapiscrollable_HEADERS = $(public_api_scrollable_header_files) diff --git a/dali-toolkit/dali-toolkit.h b/dali-toolkit/dali-toolkit.h index 74229e8..a8a3e1f 100644 --- a/dali-toolkit/dali-toolkit.h +++ b/dali-toolkit/dali-toolkit.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp new file mode 100644 index 0000000..7cfdb07 --- /dev/null +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp @@ -0,0 +1,309 @@ +// Copyright (c) 2014 Samsung Electronics Co., Ltd. + +// CLASS HEADER +#include "image-view-impl.h" + +// INTERNAL INCLUDES +#include + +// EXTERNAL INCLUDES +#include +#include +#include +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +namespace +{ + +#define MAKE_SHADER(A)#A + +const char* VERTEX_SHADER = MAKE_SHADER( + attribute mediump vec2 aPosition; + attribute highp vec2 aTexCoord; + varying mediump vec2 vTexCoord; + uniform mediump mat4 uMvpMatrix; + uniform mediump vec3 uSize; + + void main() + { + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); + // TODO scale by the actor size when we are using RendererFactor generated renderers with a shared unit sized mesh: vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + + vTexCoord = aTexCoord; + gl_Position = vertexPosition; + } +); + +const char* FRAGMENT_SHADER = MAKE_SHADER( + varying mediump vec2 vTexCoord; + uniform sampler2D sTexture; + uniform lowp vec4 uColor; + + void main() + { + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; + } +); + +//TODO: remove when RendererFactory is implemented, so if there are multiple images that render as quads we only end up with one instance of geometry +Geometry CreateGeometry( int width, int height ) +{ + // Create vertices + const float halfWidth = width * .5f; + const float halfHeight = height * .5f; + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; + TexturedQuadVertex texturedQuadVertexData[4] = { { Vector2(-halfWidth, -halfHeight), Vector2(0.f, 0.f) }, + { Vector2( halfWidth, -halfHeight), Vector2(1.f, 0.f) }, + { Vector2(-halfWidth, halfHeight), Vector2(0.f, 1.f) }, + { Vector2( halfWidth, halfHeight), Vector2(1.f, 1.f) } }; + + Property::Map texturedQuadVertexFormat; + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; + texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; + PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 ); + texturedQuadVertices.SetData(texturedQuadVertexData); + + // Create indices + unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 }; + Property::Map indexFormat; + indexFormat["indices"] = Property::INTEGER; + PropertyBuffer indices = PropertyBuffer::New( indexFormat, 6 ); + indices.SetData(indexData); + + // Create the geometry object + Geometry texturedQuadGeometry = Geometry::New(); + texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); + texturedQuadGeometry.SetIndexBuffer( indices ); + + return texturedQuadGeometry; +} + +BaseHandle Create() +{ + return Toolkit::ImageView::New(); +} + +// Setup properties, signals and actions using the type-registry. +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ImageView, Toolkit::Control, Create ); +DALI_PROPERTY_REGISTRATION( Toolkit, ImageView, "resource-url", STRING, RESOURCE_URL ) +DALI_TYPE_REGISTRATION_END() + +} // anonymous namespace + +using namespace Dali; + +ImageView::ImageView() +: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) +{ +} + +ImageView::~ImageView() +{ +} + +Toolkit::ImageView ImageView::New() +{ + ImageView* impl = new ImageView(); + + Dali::Toolkit::ImageView handle = Dali::Toolkit::ImageView( *impl ); + + // Second-phase init of the implementation + // This can only be done after the CustomActor connection has been made... + impl->Initialize(); + + return handle; +} + +///////////////////////////////////////////////////////////// + +void ImageView::SetImage( Image image ) +{ + mImage = image; + + ResourceImage resourceImage = ResourceImage::DownCast( mImage ); + if( resourceImage ) + { + mImageUrl = resourceImage.GetUrl(); + } + else + { + mImageUrl.clear(); + } + + if( mImage ) + { + if( Self().OnStage() ) + { + AttachImage(); + } + RelayoutRequest(); + } + else + { + if( mRenderer ) + { + Self().RemoveRenderer( mRenderer ); + } + mSampler.Reset(); + mMaterial.Reset(); + mMesh.Reset(); + mRenderer.Reset(); + } +} + +Image ImageView::GetImage() const +{ + return mImage; +} + +Vector3 ImageView::GetNaturalSize() +{ + // if no image then use Control's natural size + Vector3 size; + + if( mImage ) + { + size.x = mImage.GetWidth(); + size.y = mImage.GetHeight(); + size.z = std::min(size.x, size.y); + } + else + { + size = Control::GetNaturalSize(); + } + return size; +} + +float ImageView::GetHeightForWidth( float width ) +{ + if( mImage ) + { + return GetHeightForWidthBase( width ); + } + else + { + return Control::GetHeightForWidth( width ); + } +} + +float ImageView::GetWidthForHeight( float height ) +{ + if( mImage ) + { + return GetWidthForHeightBase( height ); + } + else + { + return Control::GetWidthForHeight( height ); + } +} + +/////////////////////////////////////////////////////////// +// +// Private methods +// + +void ImageView::AttachImage() +{ + if( !mRenderer ) + { + Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mMaterial = Material::New( shader ); + + mSampler = Sampler::New( mImage, "sTexture" ); + mMaterial.AddSampler( mSampler ); + + Vector3 size = Self().GetCurrentSize(); + mMesh = CreateGeometry( size.width, size.height ); + mRenderer = Renderer::New( mMesh, mMaterial ); + Self().AddRenderer( mRenderer ); + } + else + { + mSampler.SetImage( mImage ); + } +} + +void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container ) +{ + Control::OnRelayout( size, container ); + + if( mRenderer ) + { + mMesh = CreateGeometry( size.width, size.height ); + mRenderer.SetGeometry( mMesh ); + } +} + +void ImageView::OnStageConnection( int depth ) +{ + if( mImage ) + { + AttachImage(); + } +} + +/////////////////////////////////////////////////////////// +// +// Properties +// + +void ImageView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( Dali::BaseHandle( object ) ); + + if ( imageView ) + { + switch ( index ) + { + case Toolkit::ImageView::Property::RESOURCE_URL: + { + std::string imageUrl; + if( value.Get( imageUrl ) ) + { + ImageView& impl = GetImpl( imageView ); + impl.mImageUrl = imageUrl; + + Image image = ResourceImage::New( imageUrl ); + impl.SetImage( image ); + } + break; + } + } + } +} + +Property::Value ImageView::GetProperty( BaseObject* object, Property::Index propertyIndex ) +{ + Property::Value value; + + Toolkit::ImageView imageview = Toolkit::ImageView::DownCast( Dali::BaseHandle( object ) ); + + if ( imageview ) + { + switch ( propertyIndex ) + { + case Toolkit::ImageView::Property::RESOURCE_URL: + { + value = GetImpl( imageview ).mImageUrl; + break; + } + } + } + + return value; +} + +} // namespace Internal +} // namespace Toolkit +} // namespace Dali diff --git a/dali-toolkit/internal/controls/image-view/image-view-impl.h b/dali-toolkit/internal/controls/image-view/image-view-impl.h new file mode 100644 index 0000000..e912e4c --- /dev/null +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.h @@ -0,0 +1,152 @@ +#ifndef __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__ +#define __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__ + +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ + +namespace Toolkit +{ + +class ImageView; + +namespace Internal +{ +class ImageView : public Control +{ + protected: + + /** + * Construct a new ImageView. + */ + ImageView(); + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~ImageView(); + +public: + /** + * Create a new ImageView. + * @return A smart-pointer to the newly allocated ImageView. + */ + static Toolkit::ImageView New(); + + /** + * @copydoc Dali::Toolkit::SetImage( Image image ) + */ + void SetImage( Image image ); + + /** + * @copydoc Dali::Toolkit::Image GetImage() const + */ + Image GetImage() const; + + // Properties + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex ); + +private: // From Control + + /** + * @copydoc Toolkit::Control::OnRelayout() + */ + virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ); + + /** + * @copydoc Toolkit::Control::OnStageConnect() + */ + virtual void OnStageConnection( int depth ); + + /** + * @copydoc Toolkit::Control::GetNaturalSize + */ + virtual Vector3 GetNaturalSize(); + + /** + * @copydoc Toolkit::Control::GetHeightForWidth() + */ + virtual float GetHeightForWidth( float width ); + + /** + * @copydoc Toolkit::Control::GetWidthForHeight() + */ + virtual float GetWidthForHeight( float height ); + +private: + /** + * Attaches mImage member to the renderer, creating the renderers, samplers, meshes and materials if needed + * + * @pre mImage has been initialised + */ + void AttachImage(); + +private: + + Sampler mSampler; + Material mMaterial; + Geometry mMesh; + Renderer mRenderer; + Image mImage; + std::string mImageUrl; +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods +inline Toolkit::Internal::ImageView& GetImpl( Toolkit::ImageView& obj ) +{ + DALI_ASSERT_ALWAYS(obj); + Dali::RefObject& handle = obj.GetImplementation(); + return static_cast(handle); +} + +inline const Toolkit::Internal::ImageView& GetImpl( const Toolkit::ImageView& obj ) +{ + DALI_ASSERT_ALWAYS(obj); + const Dali::RefObject& handle = obj.GetImplementation(); + return static_cast(handle); +} + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__ diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index 0b8b570..e96d299 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -22,6 +22,7 @@ toolkit_src_files = \ $(toolkit_src_dir)/controls/buttons/radio-button-impl.cpp \ $(toolkit_src_dir)/controls/effects-view/effects-view-impl.cpp \ $(toolkit_src_dir)/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp \ + $(toolkit_src_dir)/controls/image-view/image-view-impl.cpp \ $(toolkit_src_dir)/controls/magnifier/magnifier-impl.cpp \ $(toolkit_src_dir)/controls/popup/popup-impl.cpp \ $(toolkit_src_dir)/controls/popup/popup-style-impl.cpp \ diff --git a/dali-toolkit/public-api/controls/image-view/image-view.cpp b/dali-toolkit/public-api/controls/image-view/image-view.cpp new file mode 100644 index 0000000..8075764 --- /dev/null +++ b/dali-toolkit/public-api/controls/image-view/image-view.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER + +#include + +// INTERNAL INCLUDES +#include + +// EXTERNAL INCLUDES + +namespace Dali +{ + +namespace Toolkit +{ + +ImageView::ImageView() +{ +} + +ImageView::ImageView( const ImageView& imageView ) +: Control( imageView ) +{ +} + +ImageView& ImageView::operator=( const ImageView& imageView ) +{ + if( &imageView != this ) + { + Control::operator=( imageView ); + } + return *this; +} + +ImageView::~ImageView() +{ +} + +ImageView ImageView::New() +{ + return Internal::ImageView::New(); +} + +ImageView ImageView::New( Image image ) +{ + ImageView imageView = Internal::ImageView::New(); + imageView.SetImage( image ); + return imageView; +} + +ImageView ImageView::New( const std::string& url ) +{ + ImageView imageView = Internal::ImageView::New(); + imageView.SetProperty( ImageView::Property::RESOURCE_URL, Dali::Property::Value( url ) ); + return imageView; +} + +ImageView ImageView::DownCast( BaseHandle handle ) +{ + return Control::DownCast(handle); +} + +void ImageView::SetImage( Image image ) +{ + Dali::Toolkit::GetImpl( *this ).SetImage( image ); +} + +Image ImageView::GetImage() const +{ + return Dali::Toolkit::GetImpl( *this ).GetImage(); +} + +ImageView::ImageView( Internal::ImageView& implementation ) + : Control( implementation ) +{ +} + +ImageView::ImageView( Dali::Internal::CustomActor* internal ) + : Control( internal ) +{ + VerifyCustomActorPointer( internal ); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/public-api/controls/image-view/image-view.h b/dali-toolkit/public-api/controls/image-view/image-view.h new file mode 100644 index 0000000..639774f --- /dev/null +++ b/dali-toolkit/public-api/controls/image-view/image-view.h @@ -0,0 +1,167 @@ +#ifndef __DALI_TOOLKIT_IMAGE_VIEW_H__ +#define __DALI_TOOLKIT_IMAGE_VIEW_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal DALI_INTERNAL +{ +class ImageView; +} + +/** + * + * @brief ImageView is a class for displaying an Image. + */ +class DALI_IMPORT_API ImageView : public Control +{ +public: + /** + * @brief The start and end property ranges for this control. + */ + enum PropertyRange + { + PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices + }; + + /** + * @brief An enumeration of properties belonging to the ImageView class. + */ + struct Property + { + enum + { + RESOURCE_URL = PROPERTY_START_INDEX, ///< name "resource-url", @see SetImage(), type string + }; + }; + +public: + + /** + * @brief Create an uninitialized ImageView. + */ + ImageView(); + + /** + * @brief Create an initialized ImageView. + * + * @return A handle to a newly allocated Dali ImageView. + */ + static ImageView New(); + + /** + * @brief Create an initialized ImageView from an Image. + * + * If the handle is empty, ImageView will display nothing + * @param[in] image The Image to display. + * @return A handle to a newly allocated ImageView. + */ + static ImageView New( Image image ); + + /** + * @brief Create an initialized ImageView from an Image resource url + * + * If the string is empty, ImageView will display nothing + * @param[in] url The url of the image resource to display. + * @return A handle to a newly allocated ImageView. + */ + static ImageView New( const std::string& url ); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~ImageView(); + + /** + * @brief Copy constructor. + * + * @param[in] imageView ImageView to copy. The copied ImageView will point at the same implementation + */ + ImageView( const ImageView& imageView ); + + /** + * @brief Assignment operator. + * + * @param[in] imageView The ImageView to assign from. + * @return The updated ImageView. + */ + ImageView& operator=( const ImageView& imageView ); + + /** + * @brief Downcast an Object handle to ImageView. + * + * If handle points to a ImageView the downcast produces valid + * handle. If not the returned handle is left uninitialized. + * + * @param[in] handle Handle to an object + * @return handle to a ImageView or an uninitialized handle + */ + static ImageView DownCast( BaseHandle handle ); + + /** + * @brief Sets this ImageView from an Image + * + * If the handle is empty, ImageView will display nothing + * @param[in] image The Image to display. + */ + void SetImage( Image image ); + + /** + * @brief Gets the Image + * + * @return The Image currently set to this ImageView + */ + Image GetImage() const; + +public: // Not intended for application developers + + /** + * @brief Creates a handle using the Toolkit::Internal implementation. + * + * @param[in] implementation The ImageView implementation. + */ + DALI_INTERNAL ImageView( Internal::ImageView& implementation ); + + /** + * @brief Allows the creation of this ImageView from an Internal::CustomActor pointer. + * + * @param[in] internal A pointer to the internal CustomActor. + */ + DALI_INTERNAL ImageView( Dali::Internal::CustomActor* internal ); + +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_IMAGE_VIEW_H__ diff --git a/dali-toolkit/public-api/file.list b/dali-toolkit/public-api/file.list index 0109380..5e096b9 100755 --- a/dali-toolkit/public-api/file.list +++ b/dali-toolkit/public-api/file.list @@ -9,6 +9,7 @@ public_api_src_files = \ $(public_api_src_dir)/controls/buttons/push-button.cpp \ $(public_api_src_dir)/controls/buttons/radio-button.cpp \ $(public_api_src_dir)/controls/default-controls/solid-color-actor.cpp \ + $(public_api_src_dir)/controls/image-view/image-view.cpp \ $(public_api_src_dir)/controls/scroll-bar/scroll-bar.cpp \ $(public_api_src_dir)/controls/scrollable/item-view/default-item-layout.cpp \ $(public_api_src_dir)/controls/scrollable/item-view/item-layout.cpp \ @@ -52,6 +53,9 @@ public_api_default_controls_header_files = \ public_api_gaussian_blur_view_header_files = \ $(public_api_src_dir)/controls/gaussian-blur-view/gaussian-blur-view.h +public_api_image_view_header_files = \ + $(public_api_src_dir)/controls/image-view/image-view.h + public_api_item_view_header_files = \ $(public_api_src_dir)/controls/scrollable/item-view/default-item-layout.h \ $(public_api_src_dir)/controls/scrollable/item-view/item-factory.h \