2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/event/actor-attachments/image-attachment-impl.h>
21 #include <dali/internal/update/node-attachments/scene-graph-image-attachment.h>
22 #include <dali/internal/event/common/stage-impl.h>
23 #include <dali/public-api/common/dali-common.h>
29 static Dali::Internal::SceneGraph::ImageAttachment::PixelArea EMPTY_PIXEL_AREA(0,0,0,0);
38 ImageAttachmentPtr ImageAttachment::New( const SceneGraph::Node& parentNode, Image* image )
40 StagePtr stage = Stage::GetCurrent();
42 ImageAttachmentPtr attachment( new ImageAttachment( *stage, image ) );
44 // Transfer object ownership of scene-object to message
45 SceneGraph::ImageAttachment* sceneObject = CreateSceneObject( image );
46 AttachToNodeMessage( stage->GetUpdateManager(), parentNode, sceneObject );
48 // Keep raw pointer for message passing
49 attachment->mSceneObject = sceneObject;
54 ImageAttachment::ImageAttachment(Stage& stage, Image* image)
55 : RenderableAttachment(stage),
57 mPixelArea(EMPTY_PIXEL_AREA),
58 mStyle(Dali::ImageActor::STYLE_QUAD),
59 mBorder(0.45,0.45,0.1,0.1),
60 mIsPixelAreaSet(false),
61 mBorderInPixels(false)
63 mImageConnectable.Set( image, false );
66 ImageAttachment::~ImageAttachment()
70 void ImageAttachment::SetImage(Image* image)
72 bool onStage = OnStage();
73 // keep a reference to Image object
74 mImageConnectable.Set( image, onStage );
76 // Wait until the scene-graph attachment is connected, before providing resource ID
79 unsigned int resourceId = (NULL != image) ? image->GetResourceId() : 0u;
81 // sceneObject is being used in a separate thread; queue a message to set
82 SetTextureIdMessage( mStage->GetUpdateInterface(), *mSceneObject, resourceId );
86 Dali::Image ImageAttachment::GetImage()
89 Image* current = mImageConnectable.Get();
92 image = Dali::Image( current );
96 // returning uninitialized image (empty image)
101 void ImageAttachment::SetPixelArea(const PixelArea& pixelArea)
103 // check to see if pixel area is actually different, using rect::operator==
104 if( pixelArea != mPixelArea )
106 // Cache for public getters
107 mPixelArea = pixelArea;
108 mIsPixelAreaSet = true;
110 // sceneObject is being used in a separate thread; queue a message to set
111 SetPixelAreaMessage( mStage->GetUpdateInterface(), *mSceneObject, mPixelArea );
115 void ImageAttachment::ClearPixelArea()
117 // Cache for public getters
118 mIsPixelAreaSet = false;
120 // sceneObject is being used in a separate thread; queue a message to set
121 ClearPixelAreaMessage( mStage->GetUpdateInterface(), *mSceneObject );
124 void ImageAttachment::SetStyle(Style style)
126 // Cache for public getters
129 // sceneObject is being used in a separate thread; queue a message to set
130 SetStyleMessage( mStage->GetUpdateInterface(), *mSceneObject, style );
133 void ImageAttachment::SetNinePatchBorder(const Vector4& border, bool inPixels)
135 // Cache for public getters
137 mBorderInPixels = inPixels;
139 // sceneObject is being used in a separate thread; queue a message to set
140 SetNinePatchBorderMessage( mStage->GetUpdateInterface(), *mSceneObject, border, inPixels );
143 SceneGraph::ImageAttachment* ImageAttachment::CreateSceneObject( const Image* current )
147 return SceneGraph::ImageAttachment::New( current->GetResourceId() );
150 return SceneGraph::ImageAttachment::New( 0u );
153 void ImageAttachment::OnStageConnection2()
155 mImageConnectable.OnStageConnect();
157 // Provide resource ID when scene-graph attachment is connected
158 Image* image = mImageConnectable.Get();
159 unsigned int resourceId = (NULL != image) ? image->GetResourceId() : 0u;
160 if ( 0u != resourceId )
162 SetTextureIdMessage( mStage->GetUpdateInterface(), *mSceneObject, resourceId );
166 void ImageAttachment::OnStageDisconnection2()
168 // Remove resource ID when scene-graph attachment is disconnected
169 SetTextureIdMessage( mStage->GetUpdateInterface(), *mSceneObject, 0u );
171 mImageConnectable.OnStageDisconnect();
174 const SceneGraph::RenderableAttachment& ImageAttachment::GetSceneObject() const
176 DALI_ASSERT_DEBUG( mSceneObject != NULL );
177 return *mSceneObject;
180 } // namespace Internal