/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
DummyVisual::DummyVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
mActionCounter( 0 )
{
}
#define DALI_TOOLKIT_DEVEL_API_VISUALS_VISUAL_PROPERTIES_DEVEL_H
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
SVG = Dali::Toolkit::Visual::SVG,
ANIMATED_IMAGE = Dali::Toolkit::Visual::ANIMATED_IMAGE,
- ANIMATED_GRADIENT = ANIMATED_IMAGE + 1, ///< Renders an animated gradient.
+ ANIMATED_GRADIENT = ANIMATED_IMAGE + 1, //< Renders an animated gradient.
+};
+
+/**
+ * @brief Visual Properties
+ */
+namespace Property
+{
+enum Type
+{
+ TYPE = Dali::Toolkit::Visual::Property::TYPE,
+ SHADER = Dali::Toolkit::Visual::Property::SHADER,
+ TRANSFORM = Dali::Toolkit::Visual::Property::TRANSFORM,
+ PREMULTIPLIED_ALPHA = Dali::Toolkit::Visual::Property::PREMULTIPLIED_ALPHA,
+ MIX_COLOR = Dali::Toolkit::Visual::Property::MIX_COLOR,
+ OPACITY = Dali::Toolkit::Visual::Property::OPACITY,
+
+ /**
+ * @brief The fitting mode of the visual
+ * @details Name "fittingMode", type FittingMode (Property::INTEGER) or Property::STRING.
+ * @see DevelVisual::FittingMode
+ * @note The default is defined by the type of visual (if it's suitable to be stretched or not).
+ */
+ FITTING_MODE = OPACITY + 1,
+};
+
+} // namespace Property
+
+/**
+ * @brief The values of this enum determine how the visual should be fit to the view
+ */
+enum FittingMode
+{
+ FIT_KEEP_ASPECT_RATIO, ///< The visual should be scaled to fit, preserving aspect ratio
+ FILL, ///< The visual should be stretched to fill, not preserving aspect ratio
};
} // namespace DevelVisual
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
Extents padding;
padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
- Property::Map transformMap = Property::Map();
+ Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
+ Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
- if( ( padding.start != 0 ) || ( padding.end != 0 ) || ( padding.top != 0 ) || ( padding.bottom != 0 ) )
+ if (Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
{
- Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>() );
+ std::swap(padding.start, padding.end);
+ }
- if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
- {
- std::swap(padding.start, padding.end);
- }
+ // remove padding from the size to know how much is left for the visual
+ auto paddedSize = size - Vector2(padding.start + padding.end, padding.top + padding.bottom);
- transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) )
- .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
- .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
- .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
- }
+ Vector2 naturalSize;
+ mVisual.GetNaturalSize(naturalSize);
+
+ // scale to fit the padded area
+ auto finalSize =
+ Toolkit::GetImplementation(mVisual).GetFittingMode() == Visual::FittingMode::FILL
+ ? paddedSize
+ : naturalSize * std::min((paddedSize.width / naturalSize.width), (paddedSize.height / naturalSize.height));
+
+ // calculate final offset within the padded area
+ auto finalOffset = Vector2(padding.start, padding.top) + (paddedSize - finalSize) * .5f;
+
+ // populate the transform map
+ Property::Map transformMap = Property::Map();
+
+ transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+ .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
+ Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+ .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
+ .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN)
+ .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize)
+ .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
+ Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE));
// Should provide a transform that handles aspect ratio according to image size
mVisual.SetTransformAndSize( transformMap, size );
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
return animatedGradientVisualPtr;
}
-AnimatedGradientVisual::AnimatedGradientVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache )
+AnimatedGradientVisual::AnimatedGradientVisual( VisualFactoryCache& factoryCache )
+: Visual::Base( factoryCache, Visual::FittingMode::FILL )
{
SetupDefaultValue();
}
}
AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
mFrameDelayTimer(),
mPlacementActor(),
mPixelArea( FULL_TEXTURE_RECT ),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
BorderVisual::BorderVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
mBorderColor( Color::TRANSPARENT ),
mBorderSize( 0.f ),
mBorderColorIndex( Property::INVALID_INDEX ),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
ColorVisual::ColorVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
mRenderIfTransparent( false )
{
}
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
GradientVisual::GradientVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
mGradientType( LINEAR ),
mIsOpaque( true )
{
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
ImageDimensions size,
FittingMode::Type fittingMode,
Dali::SamplingMode::Type samplingMode )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
mImage(),
mPixelArea( FULL_TEXTURE_RECT ),
mPlacementActor(),
}
ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const Image& image )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
mImage( image ),
mPixelArea( FULL_TEXTURE_RECT ),
mPlacementActor(),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
MeshVisual::MeshVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
mShadingMode( Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING ),
mUseTexture( true ),
mUseMipmapping( true ),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
mLoader( factoryCache.GetNPatchLoader() ),
mImageUrl(),
mAuxiliaryUrl(),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
PrimitiveVisual::PrimitiveVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
mScaleDimensions( Vector3::ONE ),
mScaleTopRadius( DEFAULT_SCALE_TOP_RADIUS ),
mScaleBottomRadius( DEFAULT_SCALE_BOTTOM_RADIUS ),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
SvgVisual::SvgVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
mAtlasRect( FULL_TEXTURE_RECT ),
mImageUrl( ),
mParsedImage( NULL ),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
TextVisual::TextVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
mController( Text::Controller::New() ),
mTypesetter( Text::Typesetter::New( mController->GetTextModel() ) ),
mAnimatableTextColorPropertyIndex( Property::INVALID_INDEX ),
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
} // unnamed namespace
-Internal::Visual::Base::Impl::Impl()
+Internal::Visual::Base::Impl::Impl(FittingMode fittingMode)
: mCustomShader( NULL ),
mBlendSlotDelegate( NULL ),
mResourceObserver( NULL ),
mDepthIndex( 0.0f ),
mMixColorIndex( Property::INVALID_INDEX ),
mOpacityIndex( Property::INVALID_INDEX ),
+ mFittingMode( fittingMode ),
mFlags( 0 ),
mResourceStatus( Toolkit::Visual::ResourceStatus::PREPARING )
{
#define DALI_TOOLKIT_INTERNAL_VISUAL_BASE_DATA_IMPL_H
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
#include <dali-toolkit/internal/visuals/visual-resource-observer.h>
#include <dali-toolkit/public-api/align-enumerations.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
namespace Dali
{
{
/**
* Constructor
+ * @param [in] fittingMode that the derived class prefers
*/
- Impl();
+ Impl(FittingMode fittingMode);
/**
* Destructor
int mDepthIndex;
Property::Index mMixColorIndex;
Property::Index mOpacityIndex;
+ FittingMode mFittingMode; //< How the contents should fit the view
int mFlags;
Toolkit::Visual::ResourceStatus mResourceStatus;
};
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
// EXTERNAL HEADER
#include <dali/public-api/common/dali-common.h>
#include <dali/devel-api/object/handle-devel.h>
+#include <dali/devel-api/scripting/enum-helper.h>
#include <dali/integration-api/debug.h>
//INTERNAL HEARDER
#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
#include <dali-toolkit/public-api/visuals/primitive-visual-properties.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
+#include <dali-toolkit/internal/helpers/property-helper.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#endif
const char * const PRE_MULTIPLIED_ALPHA_PROPERTY( "preMultipliedAlpha" );
-}
+
+} // namespace
namespace Dali
{
namespace Internal
{
-Visual::Base::Base( VisualFactoryCache& factoryCache )
-: mImpl( new Impl() ),
+namespace
+{
+
+DALI_ENUM_TO_STRING_TABLE_BEGIN( FITTING_MODE )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Visual::FittingMode, FIT_KEEP_ASPECT_RATIO )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Visual::FittingMode, FILL )
+DALI_ENUM_TO_STRING_TABLE_END( FITTING_MODE )
+
+} // namespace
+
+Visual::Base::Base( VisualFactoryCache& factoryCache, FittingMode fittingMode )
+: mImpl( new Impl(fittingMode) ),
mFactoryCache( factoryCache )
{
}
{
matchKey = Property::Key( Toolkit::Visual::Property::OPACITY );
}
+ else if( matchKey == FITTING_MODE )
+ {
+ matchKey = Property::Key( Toolkit::DevelVisual::Property::FITTING_MODE );
+ }
}
switch( matchKey.indexKey )
}
break;
}
+ case Toolkit::DevelVisual::Property::FITTING_MODE:
+ {
+ Scripting::GetEnumerationProperty< Visual::FittingMode >(
+ value, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode );
+ break;
+ }
}
}
// which is ok, because they have a different key value range.
map.Insert( Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor ); // vec4
map.Insert( Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a );
+
+ auto fittingModeString = Scripting::GetLinearEnumerationName< FittingMode >(
+ mImpl->mFittingMode, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT );
+ map.Insert( Toolkit::DevelVisual::Property::FITTING_MODE, fittingModeString );
}
void Visual::Base::CreateInstancePropertyMap( Property::Map& map ) const
return mImpl->mResourceStatus;
}
+Visual::FittingMode Visual::Base::GetFittingMode() const
+{
+ return mImpl->mFittingMode;
+}
+
Renderer Visual::Base::GetRenderer()
{
return mImpl->mRenderer;
#define DALI_TOOLKIT_INTERNAL_VISUAL_H
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/devel-api/direction-enums.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
namespace Dali
{
class ResourceObserver;
+using FittingMode = DevelVisual::FittingMode;
+
/**
* Base class for all Control rendering logic. A control may have multiple visuals.
*
*/
Toolkit::Visual::ResourceStatus GetResourceStatus() const;
-protected:
+ /**
+ * @brief Get the fitting mode for the visual
+ */
+ FittingMode GetFittingMode() const;
+
+ protected:
/**
* @brief Constructor.
*
* @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
*/
- Base( VisualFactoryCache& factoryCache );
+ Base( VisualFactoryCache& factoryCache, FittingMode fittingMode );
/**
* @brief A reference counted object may only be deleted by calling Unreference().
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
const char * const MIX_COLOR( "mixColor" );
const char * const OPACITY( "opacity" );
+// Fitting mode
+const char * const FITTING_MODE( "fittingMode" );
+
// Color visual
const char * const RENDER_IF_TRANSPARENT_NAME( "renderIfTransparent" );
#define DALI_TOOLKIT_INTERNAL_VISUAL_STRING_CONSTANTS_H
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
extern const char * const MIX_COLOR;
extern const char * const OPACITY;
+// Fitting mode
+extern const char * const FITTING_MODE;
+
// Color visual
extern const char * const RENDER_IF_TRANSPARENT_NAME;
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
}
WireframeVisual::WireframeVisual( VisualFactoryCache& factoryCache, Visual::BasePtr actualVisual )
-: Visual::Base( factoryCache ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
mActualVisual( actualVisual )
{
}