float GetHeightForWidth( Actor actor, float width ) { Vector3 size = actor.GetCurrentSize(); float height = 0.f; TextActor textActor = TextActor::DownCast( actor ); if( textActor ) { Font font = textActor.GetFont(); if( !font ) { font = Font::New(); } size = font.MeasureText( textActor.GetText() ); } ImageActor imageActor = ImageActor::DownCast( actor ); if( ( imageActor ) && ( imageActor.GetImage() ) ) { Image image = imageActor.GetImage(); size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), 0.f ); } height = size.height / ( size.width / width ); return height; }
Vector3 GetNaturalSize( Actor actor ) { Vector3 size = actor.GetCurrentSize(); const float depth = size.depth; // Get natural size for TextActor. TextActor textActor = TextActor::DownCast( actor ); if( textActor ) { Font font = textActor.GetFont(); if( !font ) { font = Font::New(); } size = font.MeasureText( textActor.GetText() ); size.depth = depth; } // Get natural size for ImageActor. // TODO: currently it doesn't work as expected. ImageActor imageActor = ImageActor::DownCast( actor ); if( ( imageActor ) && ( imageActor.GetImage() ) ) { Image image = imageActor.GetImage(); size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), depth ); } return size; }