static void DoApply( ImageActor actor, const std::string& maskImage, const Vector2& maskSize, Vector4 maskBorder ) { const char* ALPHA_MASK_VERTEX_SHADER_SOURCE = "uniform vec2 uImageSize; \n" "uniform vec2 uMaskSize; \n" "varying vec2 vMaskTexCoord; \n" " \n" "void main() \n" "{ \n" " gl_Position = uMvpMatrix * vec4(aPosition, 1.0); \n" " \n" " // Ignore mask UVs for image \n" " \n" " highp vec2 halfImageSize = uImageSize * 0.5; \n" " vTexCoord = (aPosition.xy + halfImageSize) / uImageSize; \n" " \n" " // UVs were calculated for image size, so convert for mask size \n" " \n" " highp vec2 halfMaskSize = uMaskSize * 0.5; \n" " highp vec2 halfSizeDelta = halfImageSize - halfMaskSize; \n" " \n" " highp vec2 maskPosition = aPosition.xy; \n" " maskPosition.x -= halfSizeDelta.x * sign(aPosition.x); \n" " maskPosition.y -= halfSizeDelta.y * sign(aPosition.y); \n" " \n" " vMaskTexCoord = (maskPosition + halfMaskSize) / uMaskSize; \n" "} \n"; const char* ALPHA_MASK_FRAGMENT_SHADER_SOURCE = "varying vec2 vMaskTexCoord; \n" " \n" "void main() \n" "{ \n" " highp vec4 mask = texture2D(sEffect, vMaskTexCoord); \n" " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(1,1,1,mask.a); \n" "} \n"; ShaderEffect maskEffect = ShaderEffect::New( ALPHA_MASK_VERTEX_SHADER_SOURCE, ALPHA_MASK_FRAGMENT_SHADER_SOURCE, GeometryType( GEOMETRY_TYPE_IMAGE ), ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) ); maskEffect.SetEffectImage( Image::New( maskImage ) ); maskEffect.SetUniform( "uImageSize", Vector2(0,0) /*Constrained to actor size*/ ); maskEffect.ApplyConstraint( Constraint::New<Vector2>( maskEffect.GetPropertyIndex("uImageSize"), Source(actor, Actor::SIZE), NinePatchMaskEffectSizeConstraint() ) ); maskEffect.SetUniform( "uMaskSize", maskSize ); // Actor must provide nine-patch style geometry for this effect to work actor.SetStyle( ImageActor::STYLE_NINE_PATCH ); actor.SetNinePatchBorder( maskBorder ); actor.SetShaderEffect( maskEffect ); }
void KeyboardFocusManager::CreateDefaultFocusIndicatorActor() { // Create a focus indicator actor shared by all the keyboard focusable actors Image borderImage = ResourceImage::New(FOCUS_BORDER_IMAGE_PATH); ImageActor focusIndicator = ImageActor::New(borderImage); focusIndicator.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION ); focusIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH ); focusIndicator.SetNinePatchBorder(FOCUS_BORDER_IMAGE_BORDER); focusIndicator.SetPosition(Vector3(0.0f, 0.0f, 1.0f)); // Apply size constraint to the focus indicator focusIndicator.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); SetFocusIndicatorActor(focusIndicator); }
int UtcDaliImageSetNinePatchBorder(void) { TestApplication application; Image image = Image::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f)); DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION ); DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION ); DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION ); DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION ); END_TEST; }
int UtcDaliImageGetStyle(void) { TestApplication application; Image image = Image::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); // flush the queue and render once application.SendNotification(); application.Render(); DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION ); END_TEST; }
int UtcDaliImageActor9Patch(void) { TestApplication application; tet_infoline("Positive test for Dali::ImageActor:: 9 patch api"); Image image = Image::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); Vector4 border(0.1,0.2,0.3,0.4); actor.SetNinePatchBorder(border); DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION ); DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION ); DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION ); DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION ); END_TEST; }
void Magnifier::SetFrameVisibility(bool visible) { if(visible && !mFrameLayer) { Actor self(Self()); Layer mFrameLayer = Layer::New(); mFrameLayer.SetParentOrigin( ParentOrigin::CENTER ); Stage::GetCurrent().Add(mFrameLayer); Image image = Image::New( DEFAULT_FRAME_IMAGE_PATH ); ImageActor frame = ImageActor::New( image ); frame.SetDrawMode(DrawMode::OVERLAY); frame.SetStyle( ImageActor::STYLE_NINE_PATCH ); frame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT ); mFrameLayer.Add(frame); // Apply position constraint to the frame Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, Source( self, Actor::WORLD_POSITION ), EqualToConstraint() ); frame.ApplyConstraint(constraint); // Apply scale constraint to the frame constraint = Constraint::New<Vector3>( Actor::SCALE, Source( self, Actor::SCALE ), EqualToConstraint() ); frame.ApplyConstraint(constraint); Source(self, Actor::SCALE), // Apply size constraint to the the frame constraint = Constraint::New<Vector3>(Actor::SIZE, Source(self, Actor::SIZE), ImageBorderSizeConstraint()); frame.ApplyConstraint(constraint); } else if(!visible && mFrameLayer) { Stage::GetCurrent().Remove(mFrameLayer); mFrameLayer.Reset(); } }
ImageActor CreateSolidColorActor( const Vector4& color, bool border, const Vector4& borderColor, const unsigned int borderSize ) { ImageActor image; if( borderSize > MAX_BORDER_SIZE ) { return image; } const unsigned int bitmapWidth = borderSize * 2 + 2; bool needAlphaChannel = (color.a < 1.0f) || ( border && borderColor.a < 1.0f ); BufferImage imageData; if( needAlphaChannel ) { imageData = BufferImage::New( bitmapWidth, bitmapWidth, Pixel::RGBA8888 ); } else { imageData = BufferImage::New( bitmapWidth, bitmapWidth, Pixel::RGB888 ); } // Create the image PixelBuffer* pixbuf = imageData.GetBuffer(); if( !pixbuf ) { return image; } Vector4 outerColor = color; if ( border ) { outerColor = borderColor; } // Using a (2 + border) x (2 + border) image gives a better blend with the GL implementation // than a (1 + border) x (1 + border) image const unsigned int bitmapSize = bitmapWidth * bitmapWidth; const unsigned int topLeft = bitmapWidth * borderSize + borderSize; const unsigned int topRight = topLeft + 1; const unsigned int bottomLeft = bitmapWidth * (borderSize + 1) + borderSize; const unsigned int bottomRight = bottomLeft + 1; if( needAlphaChannel ) { for( size_t i = 0; i < bitmapSize; ++i ) { if( i == topLeft || i == topRight || i == bottomLeft || i == bottomRight ) { pixbuf[i*4+0] = 0xFF * color.r; pixbuf[i*4+1] = 0xFF * color.g; pixbuf[i*4+2] = 0xFF * color.b; pixbuf[i*4+3] = 0xFF * color.a; } else { pixbuf[i*4+0] = 0xFF * outerColor.r; pixbuf[i*4+1] = 0xFF * outerColor.g; pixbuf[i*4+2] = 0xFF * outerColor.b; pixbuf[i*4+3] = 0xFF * outerColor.a; } } } else { for( size_t i = 0; i < bitmapSize; ++i ) { if( i == topLeft || i == topRight || i == bottomLeft || i == bottomRight ) { pixbuf[i*3+0] = 0xFF * color.r; pixbuf[i*3+1] = 0xFF * color.g; pixbuf[i*3+2] = 0xFF * color.b; } else { pixbuf[i*3+0] = 0xFF * outerColor.r; pixbuf[i*3+1] = 0xFF * outerColor.g; pixbuf[i*3+2] = 0xFF * outerColor.b; } } } imageData.Update(); image = ImageActor::New( imageData ); image.SetParentOrigin( ParentOrigin::CENTER ); if( border ) { image.SetStyle( ImageActor::STYLE_NINE_PATCH ); image.SetNinePatchBorder( Vector4::ONE * (float)borderSize * 2.0f ); } return image; }