#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
+#include <dali-toolkit/devel-api/align-enums.h>
namespace Dali
{
void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
{
Control::RegisterVisual( index, visual );
+
+ VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
+ if( iter == mRegisteredVisualIndices.end() )
+ {
+ mRegisteredVisualIndices.push_back(index);
+ }
}
void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
{
Control::RegisterVisual( index, visual, enabled );
+
+ VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
+ if( iter == mRegisteredVisualIndices.end() )
+ {
+ mRegisteredVisualIndices.push_back(index);
+ }
}
void DummyControlImpl::UnregisterVisual( Property::Index index )
return Control::IsVisualEnabled( index );
}
+
Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
{
return Control::CreateTransition( transition );
void DummyControlImplOverride::OnKeyInputFocusGained() { keyInputFocusGained = true; }
void DummyControlImplOverride::OnKeyInputFocusLost() { keyInputFocusLost = true; }
+void DummyControlImplOverride::OnRelayout( const Vector2& size, RelayoutContainer& container )
+{
+ Property::Map transformMap;
+ transformMap
+ .Add( Toolkit::VisualProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
+ .Add( Toolkit::VisualProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
+ .Add( Toolkit::VisualProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
+ .Add( Toolkit::VisualProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
+ .Add( Toolkit::VisualProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
+
+ for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
+ {
+ Visual::Base visual = GetVisual(*iter);
+ visual.SetTransformAndSize( transformMap, size );
+ }
+}
+
+
DummyControl DummyControl::New( bool override )
{
DummyControl control;
void CustomSlot1( Actor actor );
bool mCustomSlot1Called;
+ typedef std::vector<Property::Index> VisualIndices;
+ VisualIndices mRegisteredVisualIndices;
protected:
virtual bool OnKeyEvent(const KeyEvent& event);
virtual void OnKeyInputFocusGained();
virtual void OnKeyInputFocusLost();
+ virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
public:
printf("Usage: \n"
" %s <testcase name>\t\t Execute a test case\n"
" %s \t\t Execute all test cases in parallel\n"
- " %s -r\t\t Execute all test cases in parallel, rerunning failed test cases\n",
- program, program, program);
+ " %s -r\t\t Execute all test cases in parallel, rerunning failed test cases\n"
+ " %s -s\t\t Execute all test cases serially\n",
+ program, program, program, program);
}
} // namespace
#include <cstddef>
#include <semaphore.h>
#include <math.h>
+#include <ctime>
#include <climits>
+#include <cstdio>
+#include <unistd.h>
namespace Dali
{
}
}
-void EventThreadCallback::WaitingForTrigger(unsigned int count)
+bool EventThreadCallback::WaitingForTrigger(unsigned int count, unsigned int seconds)
{
if( mImpl->triggeredCount >= count )
{
- return;
+ return true;
}
+ struct timespec now;
+ clock_gettime( CLOCK_REALTIME, &now );
+ now.tv_sec += seconds;
mImpl->expectedCount = count;
- sem_wait( &(mImpl->mySemaphore) );
+ int error = sem_timedwait( &(mImpl->mySemaphore), &now );
+ return error != 0;
}
CallbackBase* EventThreadCallback::GetCallback()
}
}
+
+namespace Test
+{
+
+bool WaitForEventThreadTrigger( int triggerCount )
+{
+ bool success = true;
+ const int TEST_TIMEOUT(30);
+
+ struct timespec startTime;
+ struct timespec now;
+ clock_gettime( CLOCK_REALTIME, &startTime );
+ now.tv_sec = startTime.tv_sec;
+ now.tv_nsec = startTime.tv_nsec;
+
+ Dali::EventThreadCallback* eventTrigger = NULL;
+ while( eventTrigger == NULL )
+ {
+ eventTrigger = Dali::EventThreadCallback::Get();
+ clock_gettime( CLOCK_REALTIME, &now );
+ if( now.tv_sec - startTime.tv_sec > TEST_TIMEOUT )
+ {
+ success = false;
+ break;
+ }
+ usleep(10);
+ }
+ if( eventTrigger != NULL )
+ {
+ Dali::CallbackBase* callback = eventTrigger->GetCallback();
+ eventTrigger->WaitingForTrigger( triggerCount, TEST_TIMEOUT - (now.tv_sec - startTime.tv_sec) );
+ Dali::CallbackBase::Execute( *callback );
+ }
+
+ clock_gettime( CLOCK_REALTIME, &now );
+ if( now.tv_sec > startTime.tv_sec + 1 )
+ {
+ fprintf(stderr, "WaitForEventThreadTrigger took %ld seconds\n", now.tv_sec - startTime.tv_sec );
+ }
+ return success;
+}
+
+}
void Trigger();
- void WaitingForTrigger(unsigned int count);
+ bool WaitingForTrigger(unsigned int count, unsigned int seconds );
CallbackBase* GetCallback();
}
+namespace Test
+{
+
+/**
+ * Wait for the tested code to create an event trigger, then
+ * wait for triggerCount Trigger calls to occur, and execute the trigger
+ * callback afterwards.
+ *
+ * Will wait for a maximum of 30s before failing the test and returning.
+ */
+bool WaitForEventThreadTrigger( int triggerCount );
+
+}
+
+
#endif /* __DALI_TOOLKIT_EVENT_THREAD_CALLBACK_H__ */
uint32_t id02 = loader.Load( gImage_50_RGBA, ImageDimensions( 25, 25 ) );
uint32_t id03 = loader.Load( gImage_128_RGB, ImageDimensions( 100, 100 ), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, true );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
-
- eventTrigger->WaitingForTrigger( 3 );// waiting until all three images are loaded
-
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
application.SendNotification();
application.Render();
uint32_t id02 = loader.Load( gImage_50_RGBA, ImageDimensions( 25, 25 ) );
uint32_t id03 = loader.Load( gImage_128_RGB, ImageDimensions( 100, 100 ), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, true );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
-
- eventTrigger->WaitingForTrigger( 3 ); // waiting until images are loaded
-
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
application.SendNotification();
application.Render();
END_TEST;
}
-
Vector4 textureRect3;
atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128) );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
-
- eventTrigger->WaitingForTrigger( 3 );// waiting until all three images are loaded
-
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
TestApplication application;
ImageAtlas atlas = ImageAtlas::New( 200, 200 );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
gCountOfTestFuncCall = 0;
TestUploadObserver uploadObserver;
atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128), FittingMode::DEFAULT, true, &uploadObserver );
// waiting until all three images are loaded and uploaded to atlas
- eventTrigger->WaitingForTrigger( 3 );
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
TestApplication application;
ImageAtlas atlas = ImageAtlas::New( 200, 200 );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
-
gCountOfTestFuncCall = 0;
TestUploadObserver* uploadObserver = new TestUploadObserver;
delete uploadObserver;
// waiting until all three images are loaded and uploaded to atlas
- eventTrigger->WaitingForTrigger( 3 );
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
+
application.Render(RENDER_FRAME_INTERVAL);
application.SendNotification();
ImageView imageView1 = ImageView::New( gImage_34_RGBA, ImageDimensions(34, 34) );
ImageView imageView2 = ImageView::New( gImage_50_RGBA, ImageDimensions(50, 50) );
- Stage::GetCurrent().Add( imageView1 );
- Stage::GetCurrent().Add( imageView2 );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- while( eventTrigger == NULL) // waiting uintil the ImageAtlas is created by ImageAtlasManager
- {
- usleep(10);
- eventTrigger = EventThreadCallback::Get();
- }
- CallbackBase* callback = eventTrigger->GetCallback();
+ // ImageView doesn't do size negotiation properly: it only listens to OnSizeSet:
+ imageView1.SetSize( 100, 100 );
+ imageView2.SetSize( 100, 100 );
+ imageView1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ imageView2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- eventTrigger->WaitingForTrigger( 2 );// waiting until both images are loaded
+ application.GetPlatform().SetClosestImageSize( Vector2(34, 34) );
+ Stage::GetCurrent().Add( imageView1 );
+ application.GetPlatform().SetClosestImageSize( Vector2(50, 50) );
+ Stage::GetCurrent().Add( imageView2 );
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
ImageView imageView3 = ImageView::New( gImage_128_RGB, ImageDimensions(100, 100) );
+ application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
Stage::GetCurrent().Add( imageView3 );
- eventTrigger->WaitingForTrigger( 3 ); // waiting for the third image loaded
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
callStack.Reset();
callStack.Enable(true);
+ application.GetPlatform().SetClosestImageSize(Vector2(34, 34));
BitmapLoader::ResetLatestCreated();
ImageView imageView = ImageView::New( gImage_34_RGBA, ImageDimensions( 34, 34 ) );
loader = BitmapLoader::GetLatestCreated();
DALI_TEST_CHECK( loader );
- // worker thread is created
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- DALI_TEST_CHECK( eventTrigger );
-
loader.WaitForLoading();// waiting until the image to be loaded
DALI_TEST_CHECK( loader.IsLoaded() );
- eventTrigger->WaitingForTrigger( 1 );
- CallbackBase* callback = eventTrigger->GetCallback();
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(16);
const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
+Property::Map DefaultTransform()
+{
+ Property::Map transformMap;
+ transformMap
+ .Add( Toolkit::VisualProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
+ .Add( Toolkit::VisualProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
+ .Add( Toolkit::VisualProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
+ .Add( Toolkit::VisualProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
+ .Add( Toolkit::VisualProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
+ return transformMap;
+}
+
bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
{
if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
tet_infoline( "UtcDaliVisualGetNaturalSize" );
VisualFactory factory = VisualFactory::Get();
- Vector2 visualSize( 20.f, 30.f );
+ Vector2 controlSize( 20.f, 30.f );
Vector2 naturalSize;
// color colorVisual
Dali::Property::Map map;
map[ Visual::Property::TYPE ] = Visual::COLOR;
map[ ColorVisual::Property::MIX_COLOR ] = Color::MAGENTA;
+
Visual::Base colorVisual = factory.CreateVisual( map );
- colorVisual.SetSize( visualSize );
- DALI_TEST_EQUALS( colorVisual.GetSize(), visualSize, TEST_LOCATION );
+ colorVisual.SetTransformAndSize(DefaultTransform(), controlSize );
+
colorVisual.GetNaturalSize(naturalSize);
DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION );
// image visual
Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
Visual::Base imageVisual = factory.CreateVisual( image );
- imageVisual.SetSize( visualSize );
- DALI_TEST_EQUALS( imageVisual.GetSize(), visualSize, TEST_LOCATION );
+ imageVisual.SetTransformAndSize(DefaultTransform(), controlSize );
+
imageVisual.GetNaturalSize(naturalSize);
DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 200.f), TEST_LOCATION );
map[ BorderVisual::Property::COLOR ] = Color::RED;
map[ BorderVisual::Property::SIZE ] = borderSize;
Visual::Base borderVisual = factory.CreateVisual( map );
- borderVisual.SetSize( visualSize );
- DALI_TEST_EQUALS( borderVisual.GetSize(), visualSize, TEST_LOCATION );
+ borderVisual.SetTransformAndSize(DefaultTransform(), controlSize );
borderVisual.GetNaturalSize(naturalSize);
DALI_TEST_EQUALS( naturalSize, Vector2::ZERO, TEST_LOCATION );
stopColors.PushBack( Color::GREEN );
propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
Visual::Base gradientVisual = factory.CreateVisual(propertyMap);
- gradientVisual.SetSize( visualSize );
- DALI_TEST_EQUALS( gradientVisual.GetSize(), visualSize, TEST_LOCATION );
+ gradientVisual.SetTransformAndSize(DefaultTransform(), controlSize );
gradientVisual.GetNaturalSize(naturalSize);
DALI_TEST_EQUALS( naturalSize, Vector2::ZERO,TEST_LOCATION );
// svg visual
Visual::Base svgVisual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
- svgVisual.SetSize( visualSize );
- DALI_TEST_EQUALS( svgVisual.GetSize(), visualSize, TEST_LOCATION );
+ svgVisual.SetTransformAndSize(DefaultTransform(), controlSize );
svgVisual.GetNaturalSize(naturalSize);
// TEST_SVG_FILE:
// <svg width="100" height="100">
// svg visual with a size
Visual::Base svgVisual2 = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions(200, 200) );
- DALI_TEST_EQUALS( svgVisual2.GetSize(), Vector2( 200.f, 200.f ), TEST_LOCATION );
svgVisual2.GetNaturalSize(naturalSize);
DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 100.f), TEST_LOCATION ); // Natural size should still be 100, 100
propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
Visual::Base batchImageVisual = factory.CreateVisual( propertyMap );
- batchImageVisual.SetSize( visualSize );
- DALI_TEST_EQUALS( batchImageVisual.GetSize(), visualSize, TEST_LOCATION );
+ batchImageVisual.SetTransformAndSize(DefaultTransform(), controlSize );
batchImageVisual.GetNaturalSize( naturalSize );
DALI_TEST_EQUALS( naturalSize, Vector2( 80.0f, 160.0f ), TEST_LOCATION );
END_TEST;
}
+
+
+
+int UtcDaliVisualTextVisualRender(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliVisualTextVisualRender" );
+
+ VisualFactory factory = VisualFactory::Get();
+ Property::Map propertyMap;
+ propertyMap.Insert( Visual::Property::TYPE, Visual::TEXT );
+ propertyMap.Insert( "renderingBackend", static_cast<int>( Toolkit::Text::DEFAULT_RENDERING_BACKEND ) );
+ propertyMap.Insert( "text", "Hello world" );
+ propertyMap.Insert( "fontFamily", "TizenSans" );
+
+ Property::Map fontStyleMapSet;
+ fontStyleMapSet.Insert( "weight", "bold" );
+ propertyMap.Insert( "fontStyle", fontStyleMapSet );
+
+ propertyMap.Insert( "pointSize", 12.f );
+ propertyMap.Insert( "multiLine", true );
+ propertyMap.Insert( "horizontalAlignment", "CENTER" );
+ propertyMap.Insert( "verticalAlignment", "CENTER" );
+ propertyMap.Insert( "textColor", Color::RED );
+ propertyMap.Insert( "enableMarkup", false );
+ propertyMap.Insert( "enableAutoScroll", false );
+ propertyMap.Insert( "lineSpacing", 0.f );
+ propertyMap.Insert( "batchingEnabled", false );
+ Visual::Base textVisual = factory.CreateVisual( propertyMap );
+ textVisual.SetDepthIndex( 1.f );
+
+ DummyControl dummyControl = DummyControl::New(true);
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(dummyControl.GetImplementation());
+ dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, textVisual );
+ DALI_TEST_EQUALS( dummyControl.GetRendererCount(), 0, TEST_LOCATION );
+
+ dummyControl.SetSize(200.f, 200.f);
+
+ Stage::GetCurrent().Add( dummyControl );
+ application.SendNotification();
+ application.Render();
+
+ END_TEST;
+}
#include <dali/public-api/rendering/texture-set.h>
#include <dali/public-api/rendering/shader.h>
#include <dali/devel-api/images/nine-patch-image.h>
+#include <dali-toolkit/devel-api/align-enums.h>
+#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/dali-toolkit.h>
#include "dummy-control.h"
// resolution: 600*600, pixel format: RGB888
static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
+Property::Map DefaultTransform()
+{
+ Property::Map transformMap;
+ transformMap
+ .Add( Toolkit::VisualProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
+ .Add( Toolkit::VisualProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
+ .Add( Toolkit::VisualProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
+ .Add( Toolkit::VisualProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
+ .Add( Toolkit::VisualProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
+ return transformMap;
+}
+
Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
{
Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
actor.SetSize(200.f, 200.f);
Stage::GetCurrent().Add( actor );
- visual.SetSize(Vector2(200.f, 200.f));
+ visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
actor.SetSize(200.f, 200.f);
Stage::GetCurrent().Add( actor );
- visual.SetSize(Vector2(200.f, 200.f));
+ visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
Visual::Base nPatchVisual = factory.CreateVisual( image );
- Vector2 visualSize( 20.f, 30.f ), naturalSize(0,0);
- nPatchVisual.SetSize( visualSize );
- DALI_TEST_EQUALS( nPatchVisual.GetSize(), visualSize, TEST_LOCATION );
+ Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
+ nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
nPatchVisual.GetNaturalSize( naturalSize );
DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
actor.SetSize( 200.f, 200.f );
Stage::GetCurrent().Add( actor );
- visual.SetSize( Vector2(200.f, 200.f) );
+ visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
application.SendNotification();
application.Render();
// renderer is not added to actor until the rasterization is completed.
DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
-
- eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
// renderer is added to actor
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
TraceCallStack& textureTrace = gl.GetTextureTrace();
textureTrace.Enable(true);
- DummyControl actor = DummyControl::New();
+ DummyControl actor = DummyControl::New(true);
DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+ actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
Stage::GetCurrent().Add( actor );
// renderer is not added to actor until the rasterization is completed.
DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
-
- eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
// renderer is added to actor
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
actor.SetSize( 200.f, 200.f );
Stage::GetCurrent().Add( actor );
- visual.SetSize( Vector2( 200.f, 200.f ) );
+ visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
//Ensure set on stage.
DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
actor.SetSize( 200.f, 200.f );
Stage::GetCurrent().Add( actor );
- visual.SetSize( Vector2( 200.f, 200.f ) );
+ visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
//Ensure set on stage.
DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
actor.SetSize( 200.f, 200.f );
Stage::GetCurrent().Add( actor );
- visual.SetSize( Vector2( 200.f, 200.f ) );
+ visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
//Ensure set on stage.
DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
actor.SetSize( 200.0f, 200.0f );
Stage::GetCurrent().Add( actor );
- visual.SetSize( Vector2( 200.0f, 200.0f ) );
+ visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) );
// Test SetOnStage().
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
actor.SetSize( 200.0f, 200.0f );
Stage::GetCurrent().Add( actor );
- visual.SetSize( Vector2( 200.0f, 200.0f ) );
+ visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) );
// Test SetOnStage().
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
return GetImplementation( *this ).GetName();
}
-void Visual::Base::SetSize( const Vector2& size )
+void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size controlSize )
{
- GetImplementation( *this ).SetSize( size );
-}
-
-const Vector2& Visual::Base::GetSize() const
-{
- return GetImplementation( *this ).GetSize();
+ GetImplementation( *this ).SetTransformAndSize( transform, controlSize );
}
float Visual::Base::GetHeightForWidth( float width ) const
const std::string& GetName();
/**
- * @brief Set the size of the painting area.
+ * @brief Sets the transform and the control size
*
- * @param[in] size The size of the painting area.
+ * @param[in] transform A property map describing the transform
+ * @param[in] controlSize The size of the parent control for visuals that need to scale internally.
*/
- void SetSize( const Vector2& size );
-
- /**
- * @brief Get the size of the painting area.
- *
- * @return The size of the visual's painting area.
- */
- const Vector2& GetSize() const;
+ void SetTransformAndSize( const Dali::Property::Map& transform, Size controlSize );
/**
* @brief Returns the height for a given width.
/**
* @brief Return the natural size of the visual.
*
- * Deriving classes stipulate the natural size and by default a visual has a ZERO natural size.
+ * Deriving classes stipulate the natural size and by default a
+ * visual has a ZERO natural size.
+ *
+ * @note A visual may not actually have a natural size until it has
+ * been placed on stage and acquired all it's resources.
*
* @param[out] naturalSize The visual's natural size
*/
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
namespace Dali
{
DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, ImageView, "pixelArea", Vector4(0.f, 0.f, 1.f, 1.f), PIXEL_AREA )
DALI_TYPE_REGISTRATION_END()
+
+void SetDefaultTransformMap( Property::Map& transformMap )
+{
+ transformMap.Clear();
+ transformMap
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
+
+}
+
} // anonymous namespace
using namespace Dali;
}
mVisual = Toolkit::VisualFactory::Get().CreateVisual( url, size );
- RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
+ RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
- mVisual.SetSize( mSizeSet );
+ // This transform fills the control
+ // Should provide a transform that handles aspect ratio according to image size
+ Property::Map transformMap;
+ SetDefaultTransformMap( transformMap );
+ mVisual.SetTransformAndSize( transformMap, mSizeSet );
RelayoutRequest();
}
if( mVisual )
{
Vector2 size( targetSize );
- mVisual.SetSize( size );
+
+ // This transform fills the control
+ // Should provide a transform that handles aspect ratio according to image size
+ Property::Map transformMap;
+ SetDefaultTransformMap( transformMap );
+ mVisual.SetTransformAndSize( transformMap, size );
}
}
}
}
-void ColorVisual::SetSize( const Vector2& size )
-{
- Visual::Base::SetSize( size );
-
- // ToDo: renderer responds to the size change
-}
-
void ColorVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
public: // from Visual
- /**
- * @copydoc Visual::Base::SetSize
- */
- virtual void SetSize( const Vector2& size );
-
/**
* @copydoc Visual::Base::CreatePropertyMap
*/
}
}
-void GradientVisual::SetSize( const Vector2& size )
-{
- Visual::Base::SetSize( size );
-}
-
void GradientVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
public: // from Visual
- /**
- * @copydoc Visual::Base::SetSize
- */
- virtual void SetSize( const Vector2& size );
-
/**
* @copydoc Visual::Base::CreatePropertyMap
*/
mDesiredSize = ImageDimensions( desiredWidth, desiredHeight );
}
-void BatchImageVisual::SetSize( const Vector2& size )
-{
- Visual::Base::SetSize( size );
-}
-
void BatchImageVisual::GetNaturalSize( Vector2& naturalSize )
{
if( mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0 )
}
}
+void BatchImageVisual::OnSetTransform()
+{
+ if( mImpl->mRenderer )
+ {
+ //Register transform properties
+ mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+ }
+}
} // namespace Internal
public: // from Visual
- /**
- * @copydoc Visual::Base::SetSize
- */
- virtual void SetSize( const Vector2& size );
-
/**
* @copydoc Visual::Base::GetNaturalSize
*/
*/
virtual void DoSetOffStage( Actor& actor );
+ /**
+ * @copydoc Visual::Base::OnSetTransform
+ */
+ virtual void OnSetTransform();
+
private:
/**
void main()\n
{\n
- mediump vec4 vertexPosition = uMvpMatrix *ComputeVertexPosition();\n
+ mediump vec4 vertexPosition = uMvpMatrix * ComputeVertexPosition();\n
vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n
gl_Position = vertexPosition;\n
}\n
desiredHeightValue->Get( desiredHeight );
}
+ mDesiredSize = ImageDimensions( desiredWidth, desiredHeight );
+
Property::Value* pixelAreaValue = propertyMap.Find( Toolkit::ImageVisual::Property::PIXEL_AREA, PIXEL_AREA_UNIFORM_NAME );
if( pixelAreaValue )
{
mWrapModeV = Dali::WrapMode::Type( value );
}
- mDesiredSize = ImageDimensions( desiredWidth, desiredHeight );
-
Property::Value* syncLoading = propertyMap.Find( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, SYNCHRONOUS_LOADING );
if( syncLoading )
{
}
}
-void MeshVisual::SetSize( const Vector2& size )
-{
- Visual::Base::SetSize( size );
-
- // ToDo: renderer responds to the size change
-}
-
void MeshVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
public: // from Visual
- /**
- * @copydoc Visual::Base::SetSize
- */
- virtual void SetSize( const Vector2& size );
-
/**
* @copydoc Visual::Base::CreatePropertyMap
*/
}
}
-void PrimitiveVisual::SetSize( const Vector2& size )
-{
- Visual::Base::SetSize( size );
-
- // ToDo: renderer responds to the size change
-}
-
void PrimitiveVisual::GetNaturalSize( Vector2& naturalSize )
{
naturalSize.x = mObjectDimensions.x;
public: // from Visual
- /**
- * @copydoc Visual::Base::SetSize
- */
- virtual void SetSize( const Vector2& size );
-
/**
* @copydoc Visual::Base::GetNaturalSize
*/
namespace Internal
{
-SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size )
+SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl )
{
SvgVisual* svgVisual = new SvgVisual( factoryCache );
- svgVisual->ParseFromUrl( imageUrl, size );
+ svgVisual->ParseFromUrl( imageUrl );
return svgVisual;
}
mAtlasRect( FULL_TEXTURE_RECT ),
mImageUrl(),
mParsedImage( NULL ),
- mPlacementActor()
+ mPlacementActor(),
+ mVisualSize(Vector2::ZERO)
{
// the rasterized image is with pre-multiplied alpha format
mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
// Register transform properties
mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
- if( mImpl->mSize != Vector2::ZERO && mParsedImage )
- {
- AddRasterizationTask( mImpl->mSize );
- }
+ // Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
// Hold the weak handle of the placement actor and delay the adding of renderer until the svg rasterization is finished.
mPlacementActor = actor;
}
}
-void SvgVisual::SetSize( const Vector2& size )
-{
- if(mImpl->mSize != size && mParsedImage && IsOnStage() )
- {
- AddRasterizationTask( size );
- }
- mImpl->mSize = size;
-}
-
void SvgVisual::DoCreatePropertyMap( Property::Map& map ) const
{
map.Clear();
return Dali::Property::Value();
}
-void SvgVisual::ParseFromUrl( const std::string& imageUrl, ImageDimensions size )
+void SvgVisual::ParseFromUrl( const std::string& imageUrl )
{
mImageUrl = imageUrl;
Vector2 dpi = Stage::GetCurrent().GetDpi();
float meanDpi = (dpi.height + dpi.width) * 0.5f;
mParsedImage = nsvgParseFromFile( imageUrl.c_str(), UNITS, meanDpi );
-
- if( size.GetWidth() != 0u && size.GetHeight() != 0u)
- {
- mImpl->mSize.x = size.GetWidth();
- mImpl->mSize.y = size.GetHeight();
- }
}
void SvgVisual::AddRasterizationTask( const Vector2& size )
}
}
+void SvgVisual::OnSetTransform()
+{
+ Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize );
+
+ if( mParsedImage && IsOnStage() )
+ {
+ if( visualSize != mVisualSize )
+ {
+ AddRasterizationTask( visualSize );
+ mVisualSize = visualSize;
+ }
+ }
+}
} // namespace Internal
*
* @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
* @param[in] imageUrl The URL to svg resource to use
- * @param[in] size The required size for the SVG
*/
- static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size = ImageDimensions() );
+ static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
public: // from Visual
*/
virtual void GetNaturalSize( Vector2& naturalSize );
- /**
- * @copydoc Visual::Base::SetSize
- */
- virtual void SetSize( const Vector2& size );
-
/**
* @copydoc Visual::Base::CreatePropertyMap
*/
*/
virtual void DoSetOffStage( Actor& actor );
+ /**
+ * @copydoc Visual::Base::OnSetTransform
+ */
+ virtual void OnSetTransform();
+
public:
/**
* @brief Parses the SVG Image from the set URL.
*
* @param[in] imageUrl The URL of the image to parse the SVG from.
- * @param[in] size The required size of the SVG
*/
- void ParseFromUrl( const std::string& imageUrl, ImageDimensions size = ImageDimensions() );
+ void ParseFromUrl( const std::string& imageUrl );
/**
* @bried Rasterize the svg with the given size, and add it to the visual.
std::string mImageUrl;
NSVGimage* mParsedImage;
WeakHandle<Actor> mPlacementActor;
-
+ Vector2 mVisualSize;
};
} // namespace Internal
return new TextVisual( factoryCache );
}
-void TextVisual::SetSize( const Vector2& size )
-{
- const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
-
- if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
- !mRenderer )
- {
- if( !mRenderer )
- {
- mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
- }
-
- RenderText();
- }
-}
-
float TextVisual::GetHeightForWidth( float width ) const
{
return mController->GetHeightForWidth( width );
return value;
}
+void TextVisual::OnSetTransform()
+{
+ Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize );
+
+ // Note, the direction should come from the layout of the parent control
+ mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+
+ const Text::Controller::UpdateTextType updateTextType = mController->Relayout( visualSize );
+
+ if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
+ !mRenderer )
+ {
+ if( !mRenderer )
+ {
+ mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
+ }
+ RenderText();
+ }
+}
+
void TextVisual::RenderText()
{
Actor self = mSelf.GetHandle();
/**
* @copydoc Visual::Base::GetHeightForWidth()
*/
- float GetHeightForWidth( float width ) const;
-
- /**
- * @copydoc Visual::Base::GetNaturalSize()
- */
- virtual void SetSize( const Vector2& size );
+ virtual float GetHeightForWidth( float width ) const;
/**
* @copydoc Visual::Base::GetNaturalSize()
*/
virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
+ /**
+ * @copydoc Visual::Base::OnSetTransform
+ */
+ virtual void OnSetTransform();
+
private:
/**
} // unnamed namespace
Internal::Visual::Base::Impl::Impl()
-: mCustomShader(NULL),
+: mCustomShader( NULL ),
mTransform(),
+ mControlSize( Vector2::ZERO ),
mDepthIndex( 0.0f ),
mFlags( 0 )
{
renderer.RegisterProperty( ANCHOR_POINT, Vector2(0.5,0.5) - PointToVector2( mAnchorPoint, direction ) );
}
+Vector2 Internal::Visual::Base::Impl::Transform::GetVisualSize( const Vector2& controlSize )
+{
+ return Vector2( Lerp( mOffsetSizeMode.x, mSize.x * controlSize.x, mSize.x ),
+ Lerp( mOffsetSizeMode.y, mSize.y * controlSize.y, mSize.y ) );
+}
+
+
} // namespace Internal
} // namespace Toolkit
void SetPropertyMap( const Property::Map& map );
void GetPropertyMap( Property::Map& map ) const;
void RegisterUniforms( Renderer renderer, Toolkit::Direction::Type direction );
+ Vector2 GetVisualSize( const Vector2& controlSize );
};
Renderer mRenderer;
CustomShader* mCustomShader;
std::string mName;
Transform mTransform;
- Vector2 mSize;
+ Size mControlSize;
float mDepthIndex;
int mFlags;
DoSetProperties( propertyMap );
}
+void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size controlSize )
+{
+ mImpl->mControlSize = controlSize;
+ mImpl->mTransform.SetPropertyMap( transform );
+ OnSetTransform();
+}
+
void Visual::Base::SetName( const std::string& name )
{
mImpl->mName = name;
return mImpl->mName;
}
-void Visual::Base::SetSize( const Vector2& size )
-{
- mImpl->mSize = size;
-}
-
-const Vector2& Visual::Base::GetSize() const
-{
- return mImpl->mSize;
-}
-
float Visual::Base::GetHeightForWidth( float width ) const
{
return 0.f;
{
if( index == Dali::Toolkit::Visual::DevelProperty::TRANSFORM )
{
- Property::Map* map = propertyValue.GetMap();
- if( map )
+ Property::Map* transformMap = propertyValue.GetMap();
+ if( transformMap )
{
- mImpl->mTransform.SetPropertyMap( *map );
- OnSetTransform();
+ SetTransformAndSize( *transformMap, mImpl->mControlSize );
}
}
/**
* @copydoc Toolkit::Visual::Base::SetSize
*/
- virtual void SetSize( const Vector2& size );
-
- /**
- * @copydoc Toolkit::Visual::Base::GetSize
- */
- const Vector2& GetSize() const;
+ void SetTransformAndSize( const Property::Map& transform, Size controlSize );
/**
* @copydoc Toolkit::Visual::Base::GetHeightForWidth
virtual void DoSetProperties( const Property::Map& propertyMap ) = 0;
/**
- * @brief Called when transform property changes
+ * @brief Called when transform or control size changes
+ * ( Of use to SVG and Text visuals )
*/
- virtual void OnSetTransform(){}
+ virtual void OnSetTransform() = 0;
protected:
}
else if( UrlType::SVG == type )
{
- visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url, size );
+ visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url );
}
else // Regular image
{
return geometry;
}
+void WireframeVisual::OnSetTransform()
+{
+ if( mImpl->mRenderer )
+ {
+ //Register transform properties
+ mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+ }
+}
+
} // namespace Internal
} // namespace Toolkit
*/
virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
+ /**
+ * @copydoc Visual::Base::OnSetTransform
+ */
+ virtual void OnSetTransform();
+
private:
/**
* Create the geometry which presents the quad wireframe.
#include <dali-toolkit/internal/styling/style-manager-impl.h>
#include <dali-toolkit/internal/visuals/color/color-visual.h>
#include <dali-toolkit/internal/visuals/transition-data-impl.h>
+#include <dali-toolkit/devel-api/align-enums.h>
namespace Dali
{
return HandleIndex( handle, Property::INVALID_INDEX );
}
+void SetDefaultTransform( Property::Map& propertyMap )
+{
+ propertyMap.Clear();
+ propertyMap
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
+}
/**
* Creates control through type registry
bool visualReplaced ( false );
Actor self = Self();
- if ( !mImpl->mVisuals.Empty() )
+ if( !mImpl->mVisuals.Empty() )
{
- RegisteredVisualContainer::Iterator iter;
- // Check if visual (index) is already registered. Replace if so.
- if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ RegisteredVisualContainer::Iterator iter;
+ // Check if visual (index) is already registered. Replace if so.
+ if ( FindVisual( index, mImpl->mVisuals, iter ) )
+ {
+ if( (*iter)->visual && self.OnStage() )
{
- if( (*iter)->visual && self.OnStage() )
- {
- Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
- }
- (*iter)->visual = visual;
- visualReplaced = true;
+ Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
}
+ (*iter)->visual = visual;
+ visualReplaced = true;
+ }
}
- if ( !visualReplaced ) // New registration entry
+ if( !visualReplaced ) // New registration entry
{
mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
}
if( visual )
{
Vector2 size( targetSize );
- visual.SetSize( size );
+ Property::Map transformMap;
+ SetDefaultTransform( transformMap );
+ visual.SetTransformAndSize( transformMap, size );
}
}
{
container.Add( Self().GetChildAt( i ), size );
}
+
+ Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
+ if( visual )
+ {
+ Vector2 controlSize( size );
+ Property::Map transformMap;
+ SetDefaultTransform( transformMap );
+ visual.SetTransformAndSize( transformMap, controlSize );
+ }
}
void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )