utc-Dali-TableView.cpp
utc-Dali-TextField.cpp
utc-Dali-TextLabel.cpp
+ utc-Dali-TextSelectionPopup.cpp
utc-Dali-ToolBar.cpp
- utc-Dali-WaterEffect.cpp
utc-Dali-Button.cpp
utc-Dali-Control.cpp
utc-Dali-ControlImpl.cpp
utc-Dali-DefaultControls.cpp
- utc-Dali-FocusManager.cpp
- utc-Dali-DissolveEffect.cpp
+ utc-Dali-AccessibilityFocusManager.cpp
- utc-Dali-IrisEffect.cpp
utc-Dali-ItemLayout.cpp
utc-Dali-ItemView.cpp
utc-Dali-KeyboardFocusManager.cpp
#include <dali.h>
#include <dali-toolkit/dali-toolkit.h>
-#include <dali/devel-api/actors/mesh-actor.h>
-#include <dali/devel-api/modeling/material.h>
+ #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
using namespace Dali;
using namespace Dali::Toolkit;
topleveldir = $(devincludepath)/dali-toolkit
toplevel_HEADERS = ../../../dali-toolkit/dali-toolkit.h
- publicapidir = $(topleveldir)/public-api
-
- publicapicontrolsdir = $(publicapidir)/controls
- publicapialignmentdir = $(publicapicontrolsdir)/alignment
- publicapibloomviewdir = $(publicapicontrolsdir)/bloom-view
- publicapibubbleemitterdir = $(publicapicontrolsdir)/bubble-effect
- publicapibuttonsdir = $(publicapicontrolsdir)/buttons
- publicapiclusterdir = $(publicapicontrolsdir)/cluster
- publicapidefaultcontrolsdir = $(publicapicontrolsdir)/default-controls
- publicapieffectsviewdir = $(publicapicontrolsdir)/effects-view
- publicapigaussianblurviewdir = $(publicapicontrolsdir)/gaussian-blur-view
- publicapiimageviewdir = $(publicapicontrolsdir)/image-view
- publicapiitemviewdir = $(publicapicontrolsdir)/scrollable/item-view
- publicapimagnifierdir = $(publicapicontrolsdir)/magnifier
- publicapinavigationframedir = $(publicapicontrolsdir)/navigation-frame
- publicapipageturnviewdir = $(publicapicontrolsdir)/page-turn-view
- publicapipopupdir = $(publicapicontrolsdir)/popup
- publicapiscrollbardir = $(publicapicontrolsdir)/scroll-bar
- publicapiscrollcomponentdir = $(publicapicontrolsdir)/scroll-component
- publicapiscrollabledir = $(publicapicontrolsdir)/scrollable
- publicapiscrollviewdir = $(publicapicontrolsdir)/scrollable/scroll-view
- publicapiselectorsdir = $(publicapicontrolsdir)/selectors
- publicapishadowviewdir = $(publicapicontrolsdir)/shadow-view
- publicapisliderdir = $(publicapicontrolsdir)/slider
- publicapisuperblurviewdir = $(publicapicontrolsdir)/super-blur-view
- publicapitableviewdir = $(publicapicontrolsdir)/table-view
- publicapitextcontrolsdir = $(publicapidir)/controls/text-controls
- publicapitoolbardir = $(publicapicontrolsdir)/tool-bar
- publicapiviewdir = $(publicapicontrolsdir)/view
- publicapibuilderdir = $(publicapidir)/builder
- publicapifocusmanagerdir = $(publicapidir)/focus-manager
- publicapishadereffectsdir = $(publicapidir)/shader-effects
- publicapibubbleeffectdir = $(publicapidir)/shader-effects/bubble-effect
- publicapistylingdir = $(publicapidir)/styling
- publicapitransitioneffectsdir = $(publicapidir)/transition-effects
- publicapiscriptingdir = $(publicapidir)/scripting
- publicapirenderingbackenddir = $(publicapidir)/text
-
- publicapi_HEADERS = $(public_api_header_files)
- publicapicontrols_HEADERS = $(public_api_controls_header_files)
- publicapialignment_HEADERS = $(public_api_alignment_header_files)
- publicapibloomview_HEADERS = $(public_api_bloom_view_header_files)
- publicapibubbleemitter_HEADERS = $(public_api_bubble_emitter_header_files)
- publicapibuttons_HEADERS = $(public_api_buttons_header_files)
- publicapicluster_HEADERS = $(public_api_cluster_header_files)
- publicapidefaultcontrols_HEADERS = $(public_api_default_controls_header_files)
- publicapieffectsview_HEADERS = $(public_api_effects_view_header_files)
+ # devel api
+ develapidir = $(topleveldir)/devel-api
+ develapibuilderdir = $(develapidir)/builder
+ develapicontrolsdir = $(develapidir)/controls
+ develapibloomviewdir = $(develapicontrolsdir)/bloom-view
+ develapibubbleemitterdir = $(develapicontrolsdir)/bubble-effect
+ develapieffectsviewdir = $(develapicontrolsdir)/effects-view
+ develapimagnifierdir = $(develapicontrolsdir)/magnifier
+ develapipopupdir = $(develapicontrolsdir)/popup
+ develapipageturnviewdir = $(develapicontrolsdir)/page-turn-view
+ develapisliderdir = $(develapicontrolsdir)/slider
+ develapishadowviewdir = $(develapicontrolsdir)/shadow-view
+ develapisuperblurviewdir = $(develapicontrolsdir)/super-blur-view
+ develapifocusmanagerdir = $(develapidir)/focus-manager
+ develapiscriptingdir = $(develapidir)/scripting
-develapibubbleeffectdir = $(develapidir)/shader-effects/bubble-effect
+ develapishadereffectsdir = $(develapidir)/shader-effects
+ develapitransitioneffectsdir = $(develapidir)/transition-effects
+ develapistylingdir = $(develapidir)/styling
+ develapitoolbardir = $(develapicontrolsdir)/tool-bar
+
+ # devel headers
+ develapibloomview_HEADERS = $(devel_api_bloom_view_header_files)
+ develapibubbleemitter_HEADERS = $(devel_api_bubble_emitter_header_files)
-develapibubbleeffect_HEADERS = $(devel_api_bubble_effect_header_files)
+ develapibuilder_HEADERS = $(devel_api_builder_header_files)
+ develapieffectsview_HEADERS = $(devel_api_effects_view_header_files)
+ develapifocusmanager_HEADERS = $(devel_api_focus_manager_header_files)
+ develapimagnifier_HEADERS = $(devel_api_magnifier_header_files)
+ develapipageturnview_HEADERS = $(devel_api_page_turn_view_header_files)
+ develapipopup_HEADERS = $(devel_api_popup_header_files)
+ develapiscripting_HEADERS = $(devel_api_scripting_header_files)
+ develapishadowview_HEADERS = $(devel_api_shadow_view_header_files)
+ develapishadereffects_HEADERS = $(devel_api_shader_effects_header_files)
+ develapislider_HEADERS = $(devel_api_slider_header_files)
+ develapistyling_HEADERS = $(devel_api_styling_header_files)
+ develapisuperblurview_HEADERS = $(devel_api_super_blur_view_header_files)
+ develapitoolbar_HEADERS = $(devel_api_tool_bar_header_files)
+ develapitransitioneffects_HEADERS = $(devel_api_transition_effects_header_files)
+
+ # public api source
+ publicapidir = $(topleveldir)/public-api
+ publicapicontrolsdir = $(publicapidir)/controls
+ publicapialignmentdir = $(publicapicontrolsdir)/alignment
+ publicapibuttonsdir = $(publicapicontrolsdir)/buttons
+ publicapidefaultcontrolsdir = $(publicapicontrolsdir)/default-controls
+ publicapigaussianblurviewdir = $(publicapicontrolsdir)/gaussian-blur-view
+ publicapiscrollbardir = $(publicapicontrolsdir)/scroll-bar
+ publicapiscrollabledir = $(publicapicontrolsdir)/scrollable
+ publicapiscrollviewdir = $(publicapicontrolsdir)/scrollable/scroll-view
+ publicapiitemviewdir = $(publicapicontrolsdir)/scrollable/item-view
+ publicapitableviewdir = $(publicapicontrolsdir)/table-view
+ publicapitextcontrolsdir = $(publicapicontrolsdir)/text-controls
+ publicapifocusmanagerdir = $(publicapidir)/focus-manager
+ publicapirenderingbackenddir = $(publicapidir)/text
+
+ # public api headers
+ publicapi_HEADERS = $(public_api_header_files)
+ publicapicontrols_HEADERS = $(public_api_controls_header_files)
+ publicapialignment_HEADERS = $(public_api_alignment_header_files)
+ publicapibuttons_HEADERS = $(public_api_buttons_header_files)
+ publicapidefaultcontrols_HEADERS = $(public_api_default_controls_header_files)
publicapigaussianblurview_HEADERS = $(public_api_gaussian_blur_view_header_files)
- publicapiimageview_HEADERS = $(public_api_image_view_header_files)
- publicapiitemview_HEADERS = $(public_api_item_view_header_files)
- publicapimagnifier_HEADERS = $(public_api_magnifier_header_files)
- publicapinavigationframe_HEADERS = $(public_api_navigation_frame_header_files)
- publicapipageturnview_HEADERS = $(public_api_page_turn_view_header_files)
- publicapipopup_HEADERS = $(public_api_popup_header_files)
- publicapiscrollbar_HEADERS = $(public_api_scroll_bar_header_files)
-
- publicapiscrollcomponent_HEADERS = $(public_api_scroll_component_header_files)
- publicapiscrollable_HEADERS = $(public_api_scrollable_header_files)
- publicapiscrollview_HEADERS = $(public_api_scroll_view_header_files)
- publicapiselectors_HEADERS = $(public_api_selectors_header_files)
- publicapishadowview_HEADERS = $(public_api_shadow_view_header_files)
- publicapislider_HEADERS = $(public_api_slider_header_files)
- publicapisuperblurview_HEADERS = $(public_api_super_blur_view_header_files)
- publicapitableview_HEADERS = $(public_api_table_view_header_files)
- publicapitextcontrols_HEADERS = $(public_api_text_controls_header_files)
- publicapitoolbar_HEADERS = $(public_api_tool_bar_header_files)
- publicapiview_HEADERS = $(public_api_view_header_files)
- publicapibuilder_HEADERS = $(public_api_builder_header_files)
- publicapifocusmanager_HEADERS = $(public_api_focus_manager_header_files)
- publicapishadereffects_HEADERS = $(public_api_shader_effects_header_files)
- publicapistyling_HEADERS = $(public_api_styling_header_files)
- publicapitransitioneffects_HEADERS = $(public_api_transition_effects_header_files)
- publicapiscripting_HEADERS = $(public_api_scripting_header_files)
+ publicapiitemview_HEADERS = $(public_api_item_view_header_files)
+ publicapiscrollbar_HEADERS = $(public_api_scroll_bar_header_files)
+ publicapiscrollable_HEADERS = $(public_api_scrollable_header_files)
+ publicapiscrollview_HEADERS = $(public_api_scroll_view_header_files)
+ publicapitableview_HEADERS = $(public_api_table_view_header_files)
+ publicapitextcontrols_HEADERS = $(public_api_text_controls_header_files)
+ publicapifocusmanager_HEADERS = $(public_api_focus_manager_header_files)
publicapirenderingbackend_HEADERS = $(public_api_rendering_backend_header_files)
--- /dev/null
-void BubbleEmitter::StartExplosion( float duration, float multiple )
-{
- GetImpl(*this).StartExplosion( duration, multiple );
-}
-
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // CLASS HEADER
+ #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
+
+ // INTERNAL INCLUDES
+ #include <dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h>
+
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ BubbleEmitter::BubbleEmitter()
+ {
+ }
+
+ BubbleEmitter::~BubbleEmitter()
+ {
+ }
+
+ BubbleEmitter::BubbleEmitter( Internal::BubbleEmitter& implementation )
+ : Control( implementation )
+ {
+ }
+
+ BubbleEmitter::BubbleEmitter(Dali::Internal::CustomActor* internal)
+ : Control( internal )
+ {
+ VerifyCustomActorPointer<Internal::BubbleEmitter>( internal );
+ }
+
+ BubbleEmitter BubbleEmitter::New( const Vector2& winSize,
+ Image shapeImage,
+ unsigned int maximumNumberOfBubble,
+ const Vector2& bubbleSizeRange )
+ {
+ return Internal::BubbleEmitter::New( winSize, shapeImage, maximumNumberOfBubble, bubbleSizeRange );
+ }
+
+ BubbleEmitter::BubbleEmitter( const BubbleEmitter& handle )
+ : Control( handle )
+ {
+ }
+
+ BubbleEmitter& BubbleEmitter::operator=( const BubbleEmitter& rhs )
+ {
+ if( &rhs != this )
+ {
+ Control::operator=(rhs);
+ }
+ return *this;
+ }
+
+ BubbleEmitter BubbleEmitter::DownCast( BaseHandle handle )
+ {
+ return Control::DownCast<BubbleEmitter, Internal::BubbleEmitter>( handle );
+ }
+
+ Actor BubbleEmitter::GetRootActor()
+ {
+ return GetImpl(*this).GetRootActor();
+ }
+
+ void BubbleEmitter::SetBackground( Image bgImage, const Vector3& hsvDelta )
+ {
+ GetImpl(*this).SetBackground( bgImage, hsvDelta );
+ }
+
+ void BubbleEmitter::SetShapeImage( Image shapeImage )
+ {
+ GetImpl(*this).SetShapeImage( shapeImage );
+ }
+
+ void BubbleEmitter::SetBubbleScale( float scale )
+ {
+ GetImpl(*this).SetBubbleScale( scale );
+ }
+
+ void BubbleEmitter::SetBubbleDensity( unsigned int density )
+ {
+ GetImpl(*this).SetBubbleDensity( density );
+ }
+
+ void BubbleEmitter::SetBlendMode( bool enable )
+ {
+ GetImpl(*this).SetBlendMode( enable );
+ }
+
+ void BubbleEmitter::EmitBubble( Animation& animation, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement )
+ {
+ GetImpl(*this).EmitBubble( animation, emitPosition, direction, displacement );
+ }
+
+ void BubbleEmitter::Restore()
+ {
+ GetImpl(*this).Restore();
+ }
+
+ } // namespace Toolkit
+
+ } // namespace Dali
--- /dev/null
- * Ideally every bubble's moving track is controlled by different uniforms in BubbleEffect shaders.
+ #ifndef __DALI_TOOLKIT_BUBBLE_EMMITER_H__
+ #define __DALI_TOOLKIT_BUBBLE_EMMITER_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // INTERNAL INCLUDES
+ #include <dali-toolkit/public-api/controls/control.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ namespace Internal DALI_INTERNAL
+ {
+ /**
+ * @brief BubbleEmitter implementation class.
+ */
+ class BubbleEmitter;
+ }
+
+ /**
+ * @brief BubbleEmitter is used to display lots of moving bubbles on the stage.
+ *
+ * This is done by applying BubbleEffect to multiple specifically created meshActors.
+ */
+ class DALI_IMPORT_API BubbleEmitter : public Control
+ {
+ public:
+
+ /**
+ * @brief Create an empty BubbleEmitter handle.
+ */
+ BubbleEmitter();
+
+ /**
+ * @brief Virtual destructor.
+ */
+ ~BubbleEmitter();
+
+ /**
+ * @brief Create an initialized BubbleEmitter.
+ *
+ * @param[in] winSize The size of the bubble moving area, usually the same size as the background image actor.
+ * @param[in] shapeImage The alpha channnel of this texture defines the bubble shape.
+ * @param[in] maximumNumberOfBubble The maximum number of bubble needed.
+ * @param[in] bubbleSizeRange The size range of the bubbles; x component is the low bound, and y component is the up bound.
+ * @return The initialized BubbleEmitter object.
+ */
+ static BubbleEmitter New( const Vector2& winSize,
+ Image shapeImage,
+ unsigned int maximumNumberOfBubble,
+ const Vector2& bubbleSizeRange );
+
+
+ /**
+ * @brief Copy constructor.
+ *
+ * Creates another handle that points to the same real object
+ * @param[in] handle The handle to copy
+ */
+ BubbleEmitter( const BubbleEmitter& handle );
+
+ /**
+ * @brief Assignment operator.
+ *
+ * Changes this handle to point to another real object
+ * @param[in] rhs The object to point at
+ * @return A reference to this
+ */
+ BubbleEmitter& operator=( const BubbleEmitter& rhs );
+
+ /**
+ * @brief Downcast an Object handle to SuperBlurView.
+ *
+ * If handle points to a BubbleEmitter, the downcast produces valid handle.
+ * If not, the returned handle is left uninitialized.
+ * @param[in] handle Handle to an object
+ * @return handle to a BubbleEmitter or an uninitialized handle
+ */
+ static BubbleEmitter DownCast( BaseHandle handle );
+
+ /**
+ * @brief Return the root actor of all bubbles, should then be added to stage.
+ *
+ * @return The bubble root actor.
+ */
+ Actor GetRootActor();
+
+ /**
+ * @brief Set Background image.
+ *
+ * The bubbles pick color from this image with HSV values adjusted.
+ * @param[in] bgImage The background image which provide color to bubbles.
+ * @param[in] hsvDelta The hsv channel difference used to adjust the background image color.
+ * If set these vector as Vector3::Zero, original colors are used.
+ */
+ void SetBackground( Image bgImage, const Vector3& hsvDelta );
+
+ /**
+ * @brief Set bubble shape.
+ *
+ * The bubble mesh is a rectangular patch, but its displayed shape is decided by the alpha channel of the shape image.
+ * @param[in] shapeImage The image whose alpha channel defines the bubble shape.
+ */
+ void SetShapeImage( Image shapeImage );
+
+ /**
+ * @brief Set the scale factor applied to all the bubbles.
+ *
+ * @param [in] scale The scale factor applied on bubbles.
+ */
+ void SetBubbleScale( float scale );
+
+ /**
+ * @brief Set the density of the bubble.
+ *
- * The available density is one to nine. The default density is five.
++ * Ideally every bubble's moving track is controlled by different uniforms in shader.
+ * To increase the density, 'density' number of bubbles are sharing one group of uniforms, but with random offsets between these bubbles.
- /**
- * @brief Start an animation to enlarge every activated bubble's size and moving speed.
- *
- * @param[in] duration The duration of the animation
- * @param[in] multiple The bubble size and moving speed will be increased gradually to multiple speed during the animation.
- */
- void StartExplosion( float duration, float multiple );
-
++ * The available densities are one to nine only. The default value is five.
+ * By set the density bigger than one, instead of emit one bubble each time, a 'density' number of bubbles are emitted.
+ * @param[in] density The density of the bubble.
+ */
+ void SetBubbleDensity( unsigned int density );
+
+ /**
+ * @brief Enable different blending mode for rendering.
+ *
+ * @param[in] enable If false, the default blending function for RenderableActor is used.
+ */
+ void SetBlendMode( bool enable );
+
+ /**
+ * @brief Add a bubble movement to the animation.
+ *
+ * @param[in] animation The animation reference.
+ * By passing the animation into BubbleEmitter, the animation's duration and how many bubbles contained within this animation are freely decided in App.
+ * @param[in] emitPosition The start position of the bubble movement.
+ * @param[in] direction The direction used to constrain the bubble to move in an adjacent direction around it.
+ * @param[in] displacement The displacement used to bound the moving distance of the bubble.
+ */
+ void EmitBubble( Animation& animation, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement );
+
+ /**
+ * @brief Reset all the parameters controlling the bubbles after animation.
+ */
+ void Restore();
+
+ public: // Not intended for developer use
+
+ /**
+ * @brief Creates a handle using the Toolkit::Internal implementation.
+ *
+ * @param[in] implementation The Control implementation.
+ */
+ DALI_INTERNAL BubbleEmitter(Internal::BubbleEmitter& implementation);
+
+ /**
+ * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
+ *
+ * @param[in] internal A pointer to the internal CustomActor.
+ */
+ explicit DALI_INTERNAL BubbleEmitter(Dali::Internal::CustomActor* internal);
+ };
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif /* __DALI_TOOLKIT_BUBBLE_EMMITER_H__ */
--- /dev/null
- $(devel_api_src_dir)/shader-effects/bubble-effect/bubble-effect.cpp \
- $(devel_api_src_dir)/shader-effects/bubble-effect/color-adjuster.cpp \
- $(devel_api_src_dir)/shader-effects/alpha-discard-effect.cpp \
- $(devel_api_src_dir)/shader-effects/bendy-effect.cpp \
- $(devel_api_src_dir)/shader-effects/blind-effect.cpp \
- $(devel_api_src_dir)/shader-effects/bouncing-effect.cpp \
- $(devel_api_src_dir)/shader-effects/carousel-effect.cpp \
- $(devel_api_src_dir)/shader-effects/displacement-effect.cpp \
- $(devel_api_src_dir)/shader-effects/dissolve-effect.cpp \
- $(devel_api_src_dir)/shader-effects/dissolve-local-effect.cpp \
- $(devel_api_src_dir)/shader-effects/distance-field-effect.cpp \
- $(devel_api_src_dir)/shader-effects/image-region-effect.cpp \
- $(devel_api_src_dir)/shader-effects/iris-effect.cpp \
- $(devel_api_src_dir)/shader-effects/mask-effect.cpp \
- $(devel_api_src_dir)/shader-effects/mirror-effect.cpp \
- $(devel_api_src_dir)/shader-effects/motion-blur-effect.cpp \
- $(devel_api_src_dir)/shader-effects/motion-stretch-effect.cpp \
- $(devel_api_src_dir)/shader-effects/nine-patch-mask-effect.cpp \
- $(devel_api_src_dir)/shader-effects/overlay-effect.cpp \
- $(devel_api_src_dir)/shader-effects/page-turn-book-spine-effect.cpp \
- $(devel_api_src_dir)/shader-effects/page-turn-effect.cpp \
- $(devel_api_src_dir)/shader-effects/quadratic-bezier.cpp \
- $(devel_api_src_dir)/shader-effects/ripple-effect.cpp \
- $(devel_api_src_dir)/shader-effects/ripple2d-effect.cpp \
- $(devel_api_src_dir)/shader-effects/shear-effect.cpp \
- $(devel_api_src_dir)/shader-effects/soft-button-effect.cpp \
- $(devel_api_src_dir)/shader-effects/spot-effect.cpp \
- $(devel_api_src_dir)/shader-effects/square-dissolve-effect.cpp \
- $(devel_api_src_dir)/shader-effects/swirl-effect.cpp \
- $(devel_api_src_dir)/shader-effects/water-effect.cpp \
+ # Add local source files here
+
+ devel_api_src_files = \
+ $(devel_api_src_dir)/builder/builder.cpp \
+ $(devel_api_src_dir)/builder/json-parser.cpp \
+ $(devel_api_src_dir)/builder/tree-node.cpp \
+ $(devel_api_src_dir)/controls/bloom-view/bloom-view.cpp \
+ $(devel_api_src_dir)/controls/bubble-effect/bubble-emitter.cpp \
+ $(devel_api_src_dir)/controls/effects-view/effects-view.cpp \
+ $(devel_api_src_dir)/controls/magnifier/magnifier.cpp \
+ $(devel_api_src_dir)/controls/page-turn-view/page-factory.cpp \
+ $(devel_api_src_dir)/controls/page-turn-view/page-turn-landscape-view.cpp \
+ $(devel_api_src_dir)/controls/page-turn-view/page-turn-portrait-view.cpp \
+ $(devel_api_src_dir)/controls/page-turn-view/page-turn-view.cpp \
+ $(devel_api_src_dir)/controls/popup/popup.cpp \
+ $(devel_api_src_dir)/controls/shadow-view/shadow-view.cpp \
+ $(devel_api_src_dir)/controls/slider/slider.cpp \
+ $(devel_api_src_dir)/controls/super-blur-view/super-blur-view.cpp \
+ $(devel_api_src_dir)/controls/text-controls/text-selection-popup.cpp \
+ $(devel_api_src_dir)/controls/tool-bar/tool-bar.cpp \
+ $(devel_api_src_dir)/focus-manager/keyinput-focus-manager.cpp \
+ $(devel_api_src_dir)/styling/style-manager.cpp \
+ $(devel_api_src_dir)/scripting/script.cpp \
-devel_api_bubble_effect_header_files = \
- $(devel_api_src_dir)/shader-effects/bubble-effect/bubble-effect.h \
- $(devel_api_src_dir)/shader-effects/bubble-effect/color-adjuster.h
-
+ $(devel_api_src_dir)/transition-effects/cube-transition-cross-effect.cpp \
+ $(devel_api_src_dir)/transition-effects/cube-transition-effect.cpp \
+ $(devel_api_src_dir)/transition-effects/cube-transition-fold-effect.cpp \
+ $(devel_api_src_dir)/transition-effects/cube-transition-wave-effect.cpp
+
+ # Add devel header files here
+
+ devel_api_bloom_view_header_files = \
+ $(devel_api_src_dir)/controls/bloom-view/bloom-view.h
+
- $(devel_api_src_dir)/shader-effects/page-turn-book-spine-effect.h \
- $(devel_api_src_dir)/shader-effects/page-turn-effect.h \
+ devel_api_bubble_emitter_header_files = \
+ $(devel_api_src_dir)/controls/bubble-effect/bubble-emitter.h
+
+ devel_api_builder_header_files = \
+ $(devel_api_src_dir)/builder/builder.h \
+ $(devel_api_src_dir)/builder/json-parser.h \
+ $(devel_api_src_dir)/builder/tree-node.h
+
+ devel_api_effects_view_header_files = \
+ $(devel_api_src_dir)/controls/effects-view/effects-view.h
+
+ devel_api_magnifier_header_files = \
+ $(devel_api_src_dir)/controls/magnifier/magnifier.h
+
+ devel_api_page_turn_view_header_files = \
+ $(devel_api_src_dir)/controls/page-turn-view/page-factory.h \
+ $(devel_api_src_dir)/controls/page-turn-view/page-turn-landscape-view.h \
+ $(devel_api_src_dir)/controls/page-turn-view/page-turn-portrait-view.h \
+ $(devel_api_src_dir)/controls/page-turn-view/page-turn-view.h
+
+ devel_api_popup_header_files = \
+ $(devel_api_src_dir)/controls/popup/popup.h
+
+ devel_api_shadow_view_header_files = \
+ $(devel_api_src_dir)/controls/shadow-view/shadow-view.h
+
+ devel_api_slider_header_files = \
+ $(devel_api_src_dir)/controls/slider/slider.h
+
+ devel_api_focus_manager_header_files = \
+ $(devel_api_src_dir)/focus-manager/keyinput-focus-manager.h
+
+ devel_api_styling_header_files = \
+ $(devel_api_src_dir)/styling/style-manager.h
+
+ devel_api_scripting_header_files = \
+ $(devel_api_src_dir)/scripting/script.h \
+ $(devel_api_src_dir)/scripting/script-plugin.h
+
+ devel_api_shader_effects_header_files = \
+ $(devel_api_src_dir)/shader-effects/alpha-discard-effect.h \
+ $(devel_api_src_dir)/shader-effects/bendy-effect.h \
+ $(devel_api_src_dir)/shader-effects/blind-effect.h \
+ $(devel_api_src_dir)/shader-effects/bouncing-effect.h \
+ $(devel_api_src_dir)/shader-effects/carousel-effect.h \
+ $(devel_api_src_dir)/shader-effects/displacement-effect.h \
+ $(devel_api_src_dir)/shader-effects/dissolve-effect.h \
+ $(devel_api_src_dir)/shader-effects/dissolve-local-effect.h \
+ $(devel_api_src_dir)/shader-effects/distance-field-effect.h \
+ $(devel_api_src_dir)/shader-effects/image-region-effect.h \
+ $(devel_api_src_dir)/shader-effects/iris-effect.h \
+ $(devel_api_src_dir)/shader-effects/mask-effect.h \
+ $(devel_api_src_dir)/shader-effects/mirror-effect.h \
+ $(devel_api_src_dir)/shader-effects/motion-blur-effect.h \
+ $(devel_api_src_dir)/shader-effects/motion-stretch-effect.h \
+ $(devel_api_src_dir)/shader-effects/nine-patch-mask-effect.h \
+ $(devel_api_src_dir)/shader-effects/overlay-effect.h \
- $(devel_api_src_dir)/shader-effects/swirl-effect.h \
- $(devel_api_src_dir)/shader-effects/water-effect.h
+ $(devel_api_src_dir)/shader-effects/quadratic-bezier.h \
+ $(devel_api_src_dir)/shader-effects/ripple-effect.h \
+ $(devel_api_src_dir)/shader-effects/ripple2d-effect.h \
+ $(devel_api_src_dir)/shader-effects/shear-effect.h \
+ $(devel_api_src_dir)/shader-effects/soft-button-effect.h \
+ $(devel_api_src_dir)/shader-effects/spot-effect.h \
+ $(devel_api_src_dir)/shader-effects/square-dissolve-effect.h \
++ $(devel_api_src_dir)/shader-effects/swirl-effect.h
+
+ devel_api_super_blur_view_header_files = \
+ $(devel_api_src_dir)/controls/super-blur-view/super-blur-view.h
+
+ devel_api_text_selection_popup_header_files = \
+ $(devel_api_src_dir)/controls/text-controls/text-selection-popup.h
+
+ devel_api_tool_bar_header_files = \
+ $(devel_api_src_dir)/controls/tool-bar/tool-bar.h
+
+ devel_api_transition_effects_header_files = \
+ $(devel_api_src_dir)/transition-effects/cube-transition-effect.h \
+ $(devel_api_src_dir)/transition-effects/cube-transition-cross-effect.h \
+ $(devel_api_src_dir)/transition-effects/cube-transition-fold-effect.h \
+ $(devel_api_src_dir)/transition-effects/cube-transition-wave-effect.h
+
--- /dev/null
- * AlphaDiscardEffect alphaDiscardEffect = AlphaDiscardEffect::New();
+ #ifndef __DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H__
+ #define __DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new Alpha discard effect
++ *
+ * Alpha discard effect is used to discard fragments when the alpha colour value is below a threshold.
+ * This is useful for stenciling.
+ *
+ * Usage example:
+ *
+ * ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
-class DALI_IMPORT_API AlphaDiscardEffect : public ShaderEffect
++ * ShaderEffect alphaDiscardEffect = CreateAlphaDiscardEffect();
+ * actor.SetShaderEffect( alphaDiscardEffect );
++ *
++ * @return A handle to a newly allocated ShaderEffect.
+ */
-public:
-
- /**
- * Create an empty AlphaDiscardEffect handle.
- */
- AlphaDiscardEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~AlphaDiscardEffect();
-
- /**
- * Create a AlphaDiscardEffect.
- * @return A handle to a newly allocated AlphaDiscardEffect.
- */
- static AlphaDiscardEffect New();
-
-private: // Not intended for application developers
++inline ShaderEffect CreateAlphaDiscardEffect()
+ {
- DALI_INTERNAL AlphaDiscardEffect( ShaderEffect handle );
-};
++ const char* ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE =
++ "void main() \n"
++ "{ \n"
++ " mediump vec4 color = texture2D( sTexture, vTexCoord ); \n"
++ " if(color.a <= 0.0001) \n"
++ " { \n"
++ " discard; \n"
++ " } \n"
++ " gl_FragColor = color * uColor; \n"
++ "} \n";
+
++ return ShaderEffect::New( "", // Use default
++ ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE );
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H__
--- /dev/null
-class DALI_IMPORT_API BendyEffect : public ShaderEffect
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * Creates a new Bendy effect
++ *
+ * BendyEffect is a custom shader effect to achieve bendy effects in Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ * "uCenter" - The center point of the bendy effect
++ * "uDirection" - The direction of the bendy effect
++ * "uRadius" - The radius of the bendy effect
++ *
++ * @return A handle to a newly allocated ShaderEffect.
+ */
-public:
-
- /**
- * Create an uninitialized BendyEffect; this can be initialized with BendyEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- BendyEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~BendyEffect();
-
- /**
- * Create an initialized BendyEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static BendyEffect New();
-
- /**
- * Set the center point of the bendy effect.
- * @param [in] center The new center point.
- */
- void SetCenter(const Vector2& center);
-
- /**
- * Set the direction of the bendy effect.
- * @param [in] direction The new direction.
- */
- void SetDirection(const Vector2& direction);
-
- /**
- * Set the radius of the bendy effect.
- * @param [in] radius The new radius.
- */
- void SetRadius(float radius);
-
- /**
- * Get the name for the center property
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
- /**
- * Get the name for the direction property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetDirectionPropertyName() const;
-
- /**
- * Get the name for the radius property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetRadiusPropertyName() const;
-
-
-private: // Not intended for application developers
- DALI_INTERNAL BendyEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateBendyEffect()
+ {
++ // append the default version
++ std::string vertextShader(
++ "uniform mediump vec2 uCenter;\n"
++ "uniform mediump vec2 uDirection;\n"
++ "uniform mediump float uRadius;\n"
++ "\n"
++ "varying mediump float vShade;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ " mediump float lighting = 0.25;\n"
++ " mediump vec4 position = uModelView * vec4(aPosition,1.0);\n"
++ "\n"
++ " mediump vec2 d = position.xy - uCenter;\n"
++ " mediump float dist = max( 0.0, dot(d,uDirection) );\n"
++ " mediump float radius = max(0.0, uRadius - dist * 0.01);\n"
++ "\n"
++ " mediump float cs = cos(dist / radius / 2.0);\n"
++ " mediump float sn = sin(dist / radius / 2.0);\n"
++ "\n"
++ "position.xy = position.xy - uDirection * dist;\n"
++ "\n"
++ "position.xy += uDirection * sn * radius;\n"
++ "position.z += (1.0 - cs) * radius;\n"
++ "\n"
++ "gl_Position = uProjection * position;\n"
++ "\n"
++ "vShade = 1.0 - abs(sn) * lighting;\n"
++ "\n"
++ "vTexCoord = aTexCoord;\n"
++ "}" );
++
++ std::string fragmentShader(
++ "varying mediump float vShade;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(vShade,vShade,vShade,1.0);\n"
++ "}" );
++
++ // Create the implementation, temporarily owned on stack,
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ vertextShader,
++ fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
++
++ shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
++ shaderEffect.SetUniform( "uDirection", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION );
++ shaderEffect.SetUniform( "uRadius", 0.0f );
++
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__
--- /dev/null
- * BlindEffect is a custom shader effect to achieve blind effects in Image actors
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API BlindEffect : public ShaderEffect
-{
-public:
-
- /**
- * Create an uninitialized BlindEffect; this can be initialized with BlindEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- BlindEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~BlindEffect();
-
- /**
- * Create an initialized ~BlindEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static BlindEffect New();
++ * @brief BlindEffect is a custom shader effect to achieve blind effects in Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ * "uStep" - The step of the blind effect.
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
- /**
- * Set the step of the blind effect.
- * @param [in] step The step
- */
- void SetStep(float step);
+
++inline ShaderEffect CreateBlindEffect()
++{
++ std::string fragmentShader(
++ "uniform mediump float uStep; \n"
++ "void main() \n"
++ "{ \n"
++ " mediump vec4 alphaColor; \n"
++ " mediump vec4 baseColor; \n"
++ " baseColor = texture2D( sTexture, vTexCoord); \n"
++ " alphaColor = vec4(0.1,0.1,0.1,1.0); \n"
++ " lowp float index = 0.0; \n"
++ " index = floor(vTexCoord.y/0.1); \n"
++ " if((vTexCoord.y < (index * 0.1 + uStep * 0.005)) && (vTexCoord.y > index * 0.1))\n"
++ " { \n"
++ " gl_FragColor = alphaColor; \n"
++ " } \n"
++ " else \n"
++ " { \n"
++ " gl_FragColor = baseColor; \n"
++ " } \n"
++ " gl_FragColor*=uColor; \n"
++ "} \n"
++ );
+
- /**
- * Get the name for the step property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetStepPropertyName() const;
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ "",
++ fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
+
-private: // Not intended for application developers
- DALI_INTERNAL BlindEffect(ShaderEffect handle);
-};
++ shaderEffect.SetUniform( "uStep", 0.0f );
+
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
--- /dev/null
- * @brief BouncingEffect is a custom overscroll effect with two waves appearing at two sides then moving towards center and overlapping.
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_BOUNCING_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_BOUNCING_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
- * Toolkit::BouncingEffect bouncingEffect = Toolkit::BouncingEffect::New( Vector4(0.f,1.f,1.f,0.5f) );
++ * @brief Creates a new bouncing effect
++ *
++ * BouncingEffect is a custom overscroll effect with two waves appearing at two sides then moving towards center and overlapping.
+ *
+ * Usage Example:
+ *
+ * // Create the an imageActor, set shader effect, and add it to the stage
+ * ImageActor imageActor = ImageActor::New( BufferImage::New( 1, 1 ) );
+ * imageActor.SetSize(720.f,58.f);
- * animation.AnimateTo( Property( bouncingEffect, bouncingEffect.GetProgressRatePropertyName() ),
++ * Toolkit::ShaderEffect bouncingEffect = CreateBouncingEffect( Vector4(0.f,1.f,1.f,0.5f) );
+ * imageActor.SetShaderEffect( bouncingEffect );
+ * imageActor.SetParentOrigin( ParentOrigin::CENTER );
+ * Stage::GetCurrent().Add( imageActor );
+ *
+ * // Start the animation
+ * Animation animation = Animation::New(1.f);
-class DALI_IMPORT_API BouncingEffect : public ShaderEffect
-{
-public:
-
- /**
- * @brief Creates an empty BouncingEffect handle
- */
- BouncingEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~BouncingEffect();
++ * animation.AnimateTo( Property( bouncingEffect,"uProgressRate" ),
+ * 1.f, AlphaFunction::BOUNCE );
+ * animation.Play();
++ *
++ * Animatable/Constrainable uniforms:
++ * "uProgressRate" - The progress rate to the effect
++ *
++ * @param[in] color The color used on the bouncing stripe
++ * @return A handle to a newly allocated ShaderEffect
+ */
- /**
- * @brief Create a BouncingEffect object
- *
- * @param[in] color The color used on the bouncing stripe
- * @return A handle to a newly allocated Dali resource.
- */
- static BouncingEffect New( const Vector4& color );
-
- /**
- * @brief Set the progress rate to the effect.
- *
- * The whole progress ( with progress rate from 0.0 to 1.0 ):
- * two waves appear at two sides; move towards center and overlap.
- * @param[in] progressRate The progress rate value.
- */
- void SetProgressRate( float progressRate );
-
- /**
- * @brief Get the name for the progress rate property.
- *
- * @return A std::string containing the property name.
- */
- const std::string& GetProgressRatePropertyName() const;
-
-
-private: // Not intended for application developers
- DALI_INTERNAL BouncingEffect( ShaderEffect handle );
+
-};
++inline ShaderEffect CreateBouncingEffect(const Vector4& color)
++{
++ std::string fragmentShader = DALI_COMPOSE_SHADER(
++ precision mediump float;\n
++ uniform float uProgressRate;\n
++ uniform vec4 uAssignedColor;\n
++ void main()\n
++ {\n
++ float progressRate = abs(uProgressRate)*0.5;\n
++ float amplitude = 0.15 - progressRate*0.15 ;\n
++ float x1 = 7.5 * (vTexCoord.x - progressRate);\n
++ float x2 = 7.5 * (vTexCoord.x - 1.0 + progressRate);\n
++ float height1 = max(0.00001, 0.3 - amplitude * ( exp(x1) + exp(-x1) ) );\n
++ float height2 = max(0.00001, 0.3 - amplitude * ( exp(x2) + exp(-x2) ) );\n
++ float height3 = max(0.00001, 1.0 - 3.0 * amplitude * ( exp(x1*0.5) + exp(-x1*0.5) ) );\n
++ float height4 = max(0.00001, 1.0 - 3.0 * amplitude * ( exp(x2*0.5) + exp(-x2*0.5) ) );\n
++ vec4 fragColor = vec4(0.0);\n
++ float y = vTexCoord.y/(height1+height2);\n
++ float y2 = vTexCoord.y/max(height3,height4);\n
++ float coef = max(height1,height2)*5.0/( 1.0+exp(y*12.0-6.0) );\n
++ float alpha = pow( max(0.0,(1.0-y2))*(1.0-min(abs(x1),abs(x2))/5.0), 2.0);\n
++ if( vTexCoord.y < 0.075 )\n
++ {\n
++ fragColor= mix(uAssignedColor, vec4(1.0), coef);\n
++ fragColor += (vec4(1.0)-fragColor) * alpha;\n
++ }\n
++ else if (y2<1.0)\n
++ {\n
++ fragColor =vec4(1.0,1.0,1.0, alpha + (1.0-alpha)*coef);\n
++ fragColor.rgb -= ( vec3(1.0)-uAssignedColor.rgb )*min(clamp(y*1.2-0.3, 0.0, 0.3),clamp(0.9-y*1.2,0.0,0.3));\n
++ }\n
++ fragColor.a *= 10.0*min(min(vTexCoord.x, 1.0-vTexCoord.x),0.1)*min(1.0, progressRate/0.2);\n
++ gl_FragColor = fragColor;\n
++ }
++ );
++
++ ShaderEffect shaderEffect;
++ shaderEffect = ShaderEffect::New( "", fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
++
++ shaderEffect.SetUniform( "uAssignedColor", color );
++ shaderEffect.SetUniform( "uProgressRate", 0.0f );
++
++ return shaderEffect;
++}
+
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_BOUNCING_H__
--- /dev/null
-class DALI_IMPORT_API CarouselEffect : public ShaderEffect
+ #ifndef __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
+ #define __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new Carousel effect
++ *
+ * CarouselEffect is a custom shader effect to achieve Carousel effects in actors
+ *
+ * A Carousel has a Radius property which can be +ve (appear as if viewing from the outside of
+ * a cylinder/sphere)
+ * or -ve (appear as if viewing from the inside of a cylinder/sphere).
+ *
+ * It can be a horizontal or vertical (cylindrical) or both (spherical). The AnglePerUnit
+ * property provides this functionality as a Vector2.
+ *
+ * Finally, the carousel's center position can be specified as a Screen coordinate (top-left being
+ * the origin).
++ *
++ * Animatable/Constrainable uniforms:
++ * "uRadius" - The radius of the Carousel effect. A positive Radius will bend toward the camera,
++ * while a negative Radius will bend away from the camera.
++ * "uAnglePerUnit" - The angle deviation of Carousel in degrees per geometric unit for each axis
++ For example if you wish for the horizontal angle deviation to vary from +/- 10
++ degrees, then a Value of 20.0f / stageWidth for the X component should be specified.
++ * "uCenter" - The center point of the carousel (in screen coordinates) this is where the peek of the carousel should appear.
++ * Defaults value is top-left corner (0.0f, 0.0f).
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an uninitialized CarouselEffect; this can be initialized with CarouselEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- CarouselEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~CarouselEffect();
-
- /**
- * Create an initialized CarouselEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static CarouselEffect New();
-
- /**
- * Set the radius of the Carousel effect.
- * A positive Radius will bend toward the camera,
- * while a negative Radius will bend away from the camera.
- * @param[in] radius The new radius.
- */
- void SetRadius( float radius);
-
- /**
- * Sets the center point of the carousel (in screen coordinates)
- * this is where the peek of the carousel should appear.
- * this defaults to top-left corner (0.0f, 0.0f).
- *
- * @param[in] center The center point.
- */
- void SetCenter( const Vector2& center );
-
- /**
- * Set the angle deviation of Carousel in degrees per
- * geometric unit for each axis. For example if you
- * wish for the horizontal angle deviation to vary from +/- 10
- * degrees, then a Value of 20.0f / stageWidth for the X
- * component should be specified.
- *
- * @param[in] angle the Angle Spread in X and Y axes.
- */
- void SetAnglePerUnit( const Vector2& angle );
-
- /**
- * Get the name for the radius property
- * @return A std::string containing the property name
- */
- const std::string& GetRadiusPropertyName() const;
-
- /**
- * Get the name for the center property
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
- /**
- * Get the name for the angle spread property
- * @return A std::string containing the property name
- */
- const std::string& GetAnglePerUnitPropertyName() const;
-
-
-private: // Not intended for application developers
- DALI_INTERNAL CarouselEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateCarouselEffect()
+ {
++ // append the default version
++ std::string vertexShader(
++ "uniform float uRadius;\n"
++ "uniform mediump vec2 uCenter;\n"
++ "uniform mediump vec2 uAnglePerUnit;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ " mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
++ " mediump vec2 d = (world.xy - uCenter) * uAnglePerUnit;\n"
++ " mediump float a = length(d);\n"
++ " mediump float cs = cos(radians(a));\n"
++ " world.z -= cs * uRadius;\n"
++ " gl_Position = uProjection * world;\n"
++ " \n"
++ " vTexCoord = aTexCoord;\n"
++ "}\n");
++
++ ShaderEffect shaderEffect = ShaderEffect::New(
++ vertexShader,
++ "",
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
++
++
++ shaderEffect.SetUniform( "uRadius", 0.0f );
++ shaderEffect.SetUniform( "uCenter", Vector2( 0.0f, 0.0f ) );
++ shaderEffect.SetUniform( "uAnglePerUnit", Vector2( 0.0f, 0.0f ) );
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
--- /dev/null
- * Class for two state displacement effect shader that works on a per object basis. By passing a height-normal map as an effect image, the user can create
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_DISPLACEMENT_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_DISPLACEMENT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new displacement effect
+ *
- * DisplacementEffect buttonEffect = DisplacementEffect::New();
++ * Two state displacement effect shader that works on a per object basis. By passing a height-normal map as an effect image, the user can create
+ * various styles of buttons on an image actor. The shader requires two height-normal maps in one image, one for each state.
+ *
+ * The normals and height information for the two states of the button should be strictly specified in this format:
+ * ______________
+ * | State 0 |
+ * | |
+ * | | --> Unpressed button normals in rgb and height in a
+ * | Map |
+ * |______________|
+ * | State 1 |
+ * | |
+ * | | --> Pressed button normals in rgb and height in a
+ * | Map |
+ * |______________|
+ *
+ * The RGB values should contain the surface normals and the alpha should contian the height map. For a better effect keep the highest point (alpha value) in
+ * the combined map as 1.0 and the lowest posint as 0.0 and 0.5 for any region which doesn't need displacement.
+ *
+ * For the supplied Normal map the Y-Axis should be down, Meaning (0,0) is in the top left. As the shader inverts the Y axis for lighting calculation.
+ *
+ * Limitations: Can be applied to ImageActor only, And doesn't provide support for specular color.
+ *
+ * Usage example:-
+ *
+ * // Create shader used for doing soft button\n
- * animation.AnimateTo( Property(buttonEffect, buttonEffect.GetStatePropertyName()), 1.0f, AlphaFunction::BOUNCE, ... );\n
++ * ShaderEffect buttonEffect = CreateDisplacementEffect();
+ * buttonEffect.SetEffectImage(Image::New( FANCY_BUTTON_HEIGHT_MAP_IMAGE_PATH ););
+ *
+ * // set shader to the soft button\n
+ * ImageActor fancyButton = ImageActor::New( ... );\n
+ * fancyButton.SetShaderEffect( buttonEffect );
+ *
+ * // animate a button push, using e.g. AlphaFunction::BOUNCE. With these values the button pushes in and out (animates to and fro between the two states)
+ *
+ *
+ * Animation animation = Animation::New( ... );\n
-class DALI_IMPORT_API DisplacementEffect : public ShaderEffect
-{
++ * animation.AnimateTo( Property(buttonEffect, "uState"), 1.0f, AlphaFunction::BOUNCE, ... );\n
+ * animation.Play();\n
+ *
++ * Animatable/Constrainable uniforms:
++ * "uLightDirection" - The light direction is used in the lighting calculation. The angle of incidence directly affects the amount of light reflected.
++ * Default (0.0f, 0.7070168f, 0.7071068f), i.e angled at the surface from in front and above.
++ * "uAmbientLightColor" - The ambient light is used in the lighting calculation. Care must be taken to not saturate the image by setting this value too high,
++ * or the indentation will not look correct. Default 0.15.
++ * "uDiffuseLightColor" - The diffuse light is used in the lighting calculation. Default is (1.0f, 1.0f, 1.0f).
++ * "uLightMultiplier" - The ambient and diffuse lighting is multiplied by this factor. Since a diffuse light at an angle will cause the whole image to darken,
++ * this property can be used to scale the image back up closer to the pixel values of the original diffuse texture. Care must be taken
++ * to not saturate the image,or the indentation will not look correct. Default 1.0
++ * "uState" - The shader can have a maximum of two end states 0 or 1, Animate between these two values to do the transitions
++ * between states. Default 0.0
++ * "uHightScale" - The height displacement is multiplied by this factor. Tweak this to get the required level of depth. Default 0.1
++ * "uFixedNormal" - The Fixed normal will be used for the light calculation. Tweak this to get the required level of light.
++ * Only applicable for the FIXED type shader and not for DISPLACED type
++ *
++ * @param type The type of the effect, can be either DISPLACED, or FIXED.
++ * @return A handle to a newly allocated ShaderEffect
++ *
+ */
-public:
+
- typedef enum
++typedef enum
++{
++ DISPLACEMENT_EFFECT_DISPLACED = 0, /// Image gets displaced
++ DISPLACEMENT_EFFECT_FIXED /// Image does not displace. Useful for matching lighting between areas that do not displace and those that do, e.g for backgrounds which are visible between buttons.
++}DisplacementEffectType;
+
- DISPLACED = 0, /// Image gets displaced
- FIXED /// Image does not displace. Useful for matching lighting between areas that do not displace and those that do, e.g for backgrounds which are visible between buttons.
- }Type;
-
- /**
- * Create an uninitialized DisplacementEffect; this can be initialized with DisplacementEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- DisplacementEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~DisplacementEffect();
-
- /**
- * Create an initialized DisplacementEffect
- * @param type The type of the effect, can be either DISPLACED, or FIXED.
- * @return A handle to a newly allocated Dali resource.
- */
- static DisplacementEffect New(Type type);
-
- /**
- * Get the name for the light direction property (Vector3)
- * The light direction is used in the lighting calculation. The angle of incidence directly affects the amount of light reflected.
- * Default (0.0f, 0.7070168f, 0.7071068f), i.e angled at the surface from in front and above.
- * @return A std::string containing the property name
- */
- const std::string& GetLightDirectionPropertyName() const;
-
- /**
- * Get the name for the ambient lighting color property (Vector3)
- * The ambient light is used in the lighting calculation. Care must be taken to not saturate the image by setting this value too high,
- * or the indentation will not look correct. Default 0.15.
- * @return A std::string containing the property name
- */
- const std::string& GetAmbientLightColorPropertyName() const;
-
- /**
- * Get the name for the diffuse light color property (Vector3).
- * The diffuse light is used in the lighting calculation. Default is (1.0f, 1.0f, 1.0f).
- * @return A std::string containing the property name
- */
- const std::string& GetDiffuseLightColorPropertyName() const;
-
- /**
- * Get the name for the lighting multiplier property (float).
- * The ambient and diffuse lighting is multiplied by this factor. Since a diffuse light at an angle will cause the whole image to darken,
- * this property can be used to scale the image back up closer to the pixel values of the original diffuse texture. Care must be taken to not saturate the image,
- * or the indentation will not look correct. Default 1.0
- * @return A std::string containing the property name
- */
- const std::string& GetLightingMultiplierPropertyName() const;
-
- /**
- * Get the name for the state property (float).
- * The shader can have a maximum of two end states 0 or 1, Animate between these two values to do the transitions between states.
- * Default 0.0
- * @return A std::string containing the property name.
- */
- const std::string& GetStatePropertyName() const;
-
- /**
- * Get the name for the height scale property (float).
- * The height displacement is multiplied by this factor. Tweak this to get the required level of depth.
- * Default 0.1
- * @return A std::string containing the property name.
- */
- const std::string& GetHeightScalePropertyName() const;
-
- /**
- * Get the name for the fixed normal property (Vector3).
- * Only applicable for the FIXED type shader and not for DISPLACEMENT type.
- * The Fixed normal will be used for the light calculation. Tweak this to get the required level of light.
- * Default (0.0f, 0.0f, 1.0f)
- * @return A std::string containing the property name.
- */
- const std::string& GetFixedNormalPropertyName() const;
-
- /**
- * Set the light direction property
- * The light direction is used in the lighting calculation. The angle of incidence directly affects the amount of light reflected.
- * Default (0.0f, 0.7070168f, 0.7071068f), i.e angled at the surface from in front and above.
- * @param [in] lightDirection The new light direction.
- */
- void SetLightDirection(Vector3 lightDirection);
-
- /**
- * Set the ambient light color property
- * The ambient light is used in the lighting calculation. Care must be taken to not saturate the image by setting this value too high,
- * or the indentation will not look correct. Default (0.15f, 0.15f, 0.15f).
- * @param [in] ambientLight The new ambient light value.
- */
- void SetAmbientLightColorProperty(Vector3 ambientLight);
-
- /**
- * Set the diffuse light color property.
- * The diffuse light is used in the lighting calculation. Default is (1.0f, 1.0f, 1.0f), i.e. a white light so the natural image color is shown.
- * @param [in] diffuseLight The new diffuse light value.
- */
- void SetDiffuseLightColorProperty(Vector3 diffuseLight);
-
- /**
- * Get the name for the lighting multiplier property.
- * The ambient and diffuse lighting is multiplied by this factor. Since a diffuse light at an angle will cause the whole image to darken,
- * this property can be used to scale the image back up closer to the pixel values of the original diffuse texture. Care must be taken to not saturate the image,
- * or the indentation will not look correct. Default 1.0
- * @param [in] lightMultiplier The new light multiplier value.
- */
- void SetLightingMultiplierProperty(float lightMultiplier);
-
- /**
- * Get the name for the state property.
- * The shader can only be in or in between two states 0 or 1, Animate between these two values to do the transitions between states.
- * @param [in] state The new state value.
- */
- void SetStateProperty(float state);
-
- /**
- * Set the name for the height scale property.
- * The height displacement is multiplied by this factor. Tweak this to get the required level of depth. Default 0.1
- * @param [in] heightScale The new height scale.
- */
- void SetHeightScaleProperty(float heightScale);
-
- /**
- * Set the name for fixed normal property, Only applicable for the FIXED type shader and not for DISPLACEMENT type.
- * The Fixed normal will be used for the light calculation. Tweak this to get the required level of light.
- * @param [in] fixedNormal The new normal for the fixed type shader effect.
- */
- void SetFixedNormalProperty(Vector3 fixedNormal);
-
-private:
- // Not intended for application developers
- DALI_INTERNAL DisplacementEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateDisplacementEffect(DisplacementEffectType type)
++{
++ std::string fragmentSourceFixed;
++ fragmentSourceFixed = "precision mediump float;\n"
++ "uniform vec3 uLightDirection;\n"
++ "uniform vec3 uAmbientLightColor;\n"
++ "uniform vec3 uDiffuseLightColor;\n"
++ "uniform float uLightMultiplier;\n"
++ "uniform float uState;\n"
++ "uniform float uHightScale;\n"
++ "uniform vec3 uFixedNormal;\n"
++
++ "void main()\n"
++ "{\n"
++ " vec4 col = texture2D(sTexture, vTexCoord);\n"
++ // calc lighting
++ " float intensity = dot(uLightDirection, uFixedNormal);"
++ " vec3 lighting = (intensity * uDiffuseLightColor) + uAmbientLightColor;\n"
++ " lighting *= uLightMultiplier;\n"
++ // output col = image * light
++ " gl_FragColor = vec4(col.rgb * lighting * uColor.rgb, col.a * uColor.a);\n"
++ "}\n";
++
++
++
++ std::string fragmentSourceDisplaced(
++ "precision mediump float;\n"
++ "uniform vec3 uLightDirection;\n"
++ "uniform vec3 uAmbientLightColor;\n"
++ "uniform vec3 uDiffuseLightColor;\n"
++ "uniform float uLightMultiplier;\n"
++ "uniform float uState;\n"
++ "uniform float uHightScale;\n"
++ "void main()\n"
++ "{\n"
++ " highp vec4 displacementMap1 = texture2D(sEffect, vec2(vTexCoord.s, vTexCoord.t/2.0));\n"
++ " highp vec4 displacementMap2 = texture2D(sEffect, vec2(vTexCoord.s, 0.5+vTexCoord.t/2.0));\n"
++ " highp vec4 displacementMap = mix(displacementMap1, displacementMap2, uState);\n"
++
++ " vec3 normalAdjusted = normalize(displacementMap.rgb*2.0-1.0);\n"
++ " float height = uHightScale * (displacementMap.a*2.0 - 1.0);\n"
++ " vec2 displacement = vec2(0.0);\n"
++ " displacement += (vec2(0.5)-vTexCoord.st)*height;\n"
++ " vec2 newCoord = vTexCoord.st + displacement.xy;\n"
++
++ " vec4 col = texture2D(sTexture, newCoord);\n"
++ // Y-Axis for the normal map is taken as in Y-Down format, So inverting it for GL
++ " float intensity = dot(uLightDirection, vec3(1.0,-1.0, 1.0) * normalAdjusted);"
++ " vec3 lighting = (intensity * uDiffuseLightColor) + uAmbientLightColor;\n"
++ " lighting *= uLightMultiplier;\n"
++ " vec3 color = col.rgb * lighting * uColor.rgb;\n"
++ " gl_FragColor = vec4(color, col.a * uColor.a);\n"
++ "}\n");
++
++ //////////////////////////////////////
++ // Create shader effect
++ //
++ //
++
++ ShaderEffect shaderEffect;
++ switch(type)
+ {
++ case DISPLACEMENT_EFFECT_DISPLACED:
++ shaderEffect = ShaderEffect::New( "", fragmentSourceDisplaced);
++ break;
++
++ case DISPLACEMENT_EFFECT_FIXED:
++ default:
++ shaderEffect = ShaderEffect::New( "", fragmentSourceFixed);
++ break;
++ }
++
++
++ //////////////////////////////////////
++ // Register uniform properties
++ //
++ //
++ // factors that scale the look, defaults
++ shaderEffect.SetUniform("uLightDirection",Vector3(0.0, 0.7070168f, 0.7071068f));
++ shaderEffect.SetUniform("uAmbientLightColor",Vector3(0.15f, 0.15f, 0.15f));
++ shaderEffect.SetUniform("uDiffuseLightColor",Vector3(1.0f, 1.0f, 1.0f));
++ shaderEffect.SetUniform("uLightMultiplier",1.0f);
++ shaderEffect.SetUniform("uState",0.0f);
++ shaderEffect.SetUniform("uHightScale",0.1f);
++
++ if(type == DISPLACEMENT_EFFECT_FIXED)
++ {
++ shaderEffect.SetUniform("uFixedNormal",Vector3(0.0f, 0.0f, 1.0f) );
++ }
++
++ return shaderEffect;
++}
+
+ }
+
+ }
+
+ #endif //#ifndef __DALI_TOOLKIT_SHADER_EFFECT_DISPLACEMENT_H__
--- /dev/null
- * @brief DissolveEffect is a custom shader effect to achieve Dissolve effects in Image actors.
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_DISSOLVE_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_DISSOLVE_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API DissolveEffect : public ShaderEffect
++ * @brief Set the dissolve central line.
++ *
++ * Use one point (position) and one direction ( displacement ) vector to define this line
++ * As we use the texture coordinate as pixel position to calculate random offset,
++ * the line should passing through rectangle {(0,0),(0,1),(1,0),(1,1)},
++ * so make the position parameter with two component values between 0.0 to 1.0
++ * @param[in] dissolveEffect The shader effect
++ * @param[in] position The point ( locates within rectangle {(0,0),(0,1),(1,0),(1,1)} ) passed through by the central line
++ * @param[in] displacement The direction of the central line
++ */
++inline void DissolveEffectSetCentralLine( ShaderEffect& dissolveEffect, const Vector2& position, const Vector2& displacement )
++{
++ // the line passes through 'position' and has the direction of 'displacement'
++ float coefA, coefB, coefC; //line equation: Ax+By+C=0;
++ coefA = displacement.y;
++ coefB = -displacement.x;
++ coefC = -displacement.y*position.x + displacement.x*position.y;
++
++ float inversedAABB = 1.f / (coefA*coefA+coefB*coefB);
++ float inversedSqrtAABB = sqrtf(inversedAABB);
++ float saddleA;
++
++ //saddle surface(Hyperbolic paraboloid)function, used to calculate the dissolve starting time
++ //z = y*y/a/a - x*x/b/b
++ //with our selection of parameters(a and b), this value for any texture coordinate is between -1.0 and 1.0
++
++ Vector3 saddleParam; // [0]: a*a, [1]: b*b, [2] b
++ Vector2 translation;
++ Vector2 rotation;
++ float toNext = -1.f;
++ if( displacement.x > 0.f || (EqualsZero(displacement.x) && displacement.y > 0.f) )
++ {
++ toNext = 1.f;
++ }
++
++ if( (displacement.y * displacement.x < 0.0f) )
++ {
++ //distance from (0,0) to the line
++ float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB;
++ //distance from (1, 1 ) to the line
++ float distanceBottomRight = fabsf(coefA+coefB+coefC) * inversedSqrtAABB;
++ saddleA = std::max( distanceTopLeft, distanceBottomRight );
++
++ //foot of a perpendicular: (1,0) to the line
++ float footX1 = ( coefB*coefB - coefA*coefC) * inversedAABB;
++ float footY1 = (-coefA*coefB - coefB*coefC) * inversedAABB;
++ //foot of a perpendicular: (0,1) to the line
++ float footX2 = (-coefA*coefB - coefA*coefC) * inversedAABB;
++ float footY2 = ( coefA*coefA - coefB*coefC) * inversedAABB;
++ saddleParam[1] = (footX1-footX2)*(footX1-footX2) + (footY1-footY2)*(footY1-footY2);
++ translation = Vector2(-footX2,-footY2);
++ }
++ else
++ {
++ //distance from(1,0) to the line
++ float distanceTopRight = fabsf(coefA+coefC) * inversedSqrtAABB;
++ //distance from(0,1) to the line
++ float distanceBottomLeft = fabsf(coefB+coefC) * inversedSqrtAABB;
++ saddleA = std::max( distanceTopRight, distanceBottomLeft );
++ //foot of a perpendicular: (0,0) to the line
++ float footX3 = (-coefA*coefC) * inversedAABB;
++ float footY3 = (-coefB*coefC) * inversedAABB;
++ //foot of a perpendicular: (1.0,1.0) to the line
++ float footX4 = ( coefB*coefB - coefA*coefB - coefA*coefC) * inversedAABB;
++ float footY4 = (-coefA*coefB + coefA*coefA- coefB*coefC) * inversedAABB;
++ saddleParam[1] = (footX3-footX4)*(footX3-footX4) + (footY3-footY4)*(footY3-footY4);
++ translation = Vector2(-footX3, -footY3);
++ }
++
++ saddleParam[2] = sqrtf(saddleParam[1]);
++ saddleParam[0] = saddleA*saddleA;
++ rotation = Vector2(-displacement.x, displacement.y);
++ rotation.Normalize();
++
++ dissolveEffect.SetUniform( "uSaddleParam", saddleParam );
++ dissolveEffect.SetUniform( "uTranslation", translation );
++ dissolveEffect.SetUniform( "uRotation", rotation );
++ dissolveEffect.SetUniform( "uToNext", toNext );
++}
++/**
++ * @brief Create a new Dissolve effect
++ *
++ * DissolveEffect is a custom shader effect to achieve Dissolve effects in Image actors.
++ *
++ * Animatable/Constrainable uniforms:
++ * "uPercentage" - This value is proportional to the distortion applied; a value of zero means no distortion.
++ *
++ * @param[in] useHighPrecision True if using high precision in fragment shader for fully random noise, false otherwise
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * @brief Create an uninitialized DissolveEffect; this can be initialized with DissolveEffect::New().
- *
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- DissolveEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~DissolveEffect();
-
- /**
- * @brief Create an initialized DissolveEffect.
- *
- * @param[in] useHighPrecision True if using high precision in fragment shader for fully random noise, false otherwise
- * @return A handle to a newly allocated Dali resource.
- */
- static DissolveEffect New( bool useHighPrecision = true);
-
- /**
- * @brief Set the dissolve central line.
- *
- * Use one point (position) and one direction ( displacement ) vector to define this line
- * As we use the texture coordinate as pixel position to calculate random offset,
- * the line should passing through rectangle {(0,0),(0,1),(1,0),(1,1)},
- * so make the position parameter with two component values between 0.0 to 1.0
- * @param[in] position The point ( locates within rectangle {(0,0),(0,1),(1,0),(1,1)} ) passed through by the central line
- * @param[in] displacement The direction of the central line
- */
- void SetCentralLine( const Vector2& position, const Vector2& displacement );
-
- /**
- * @brief Sets the distortion applied to the effect texture.
- *
- * This value is proportional to the distortion applied; a value of zero means no distortion.
- * @param [in] distortion The distortion value.
- */
- void SetDistortion( float distortion );
-
- /**
- * @brief Get the name for the distortion property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetDistortionPropertyName() const;
-
-private: // Not intended for application developers
- DALI_INTERNAL DissolveEffect(ShaderEffect handle);
-};
++
++inline ShaderEffect CreateDissolveEffect(bool useHighPrecision = true)
+ {
++ std::string prefixHighPrecision( "precision highp float;\n");
++ std::string prefixMediumPrecision( "precision mediump float;\n" );
++ std::string vertexShader(
++ "uniform float uPercentage;\n"
++ "uniform vec3 uSaddleParam;\n"
++ "uniform vec2 uTranslation;\n"
++ "uniform vec2 uRotation; \n"
++ "uniform float uToNext;\n"
++ "varying float vPercentage;\n"
++ "void main()\n"
++ "{\n"
++ "gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
++ "vTexCoord = aTexCoord;\n"
++ //Calculate the distortion value given the dissolve central line
++ "vec2 texCoor = vec2( (aTexCoord.s - sTextureRect.s ) / (sTextureRect.p - sTextureRect.s), (aTexCoord.t- sTextureRect.t)/(sTextureRect.q - sTextureRect.t) ); \n"
++ "vec2 value = texCoor + uTranslation; \n"
++ "mat2 rotateMatrix = mat2( uRotation.s, uRotation.t, -uRotation.t, uRotation.s ); \n"
++ "value = rotateMatrix * value; \n"
++ "if(uToNext == 1.0) \n"
++ " value.s = uSaddleParam[2] + value.s; \n"
++ "float delay = value.t*value.t / uSaddleParam[0] - value.s*value.s/uSaddleParam[1];\n"
++ "vPercentage = clamp( uPercentage*2.0 - 0.5*sin(delay*1.571) - 0.5, 0.0, 1.0 ); \n"
++ "}\n");
++ std::string fragmentShader(
++ "varying float vPercentage;\n"
++ "float rand(vec2 co) \n"
++ "{\n"
++ " return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n"
++ "}\n"
++ "void main()\n"
++ "{\n"
++ //Calculate the randomness
++ "float offsetS = rand( vTexCoord * vPercentage ) * (sTextureRect.p - sTextureRect.s) - vTexCoord.s + sTextureRect.s; \n"
++ "float offsetT = rand( vec2(vTexCoord.t*vPercentage, vTexCoord.s * vPercentage) ) * (sTextureRect.q - sTextureRect.t) - vTexCoord.t + sTextureRect.t; \n"
++ "vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage; \n"
++ "gl_FragColor = texture2D( sTexture, lookupCoord ) * uColor; \n"
++ "gl_FragColor.a *= 1.0 - vPercentage; \n"
++ "}" );
++
++ // Create the implementation, temporarily owned on stack,
++ Dali::ShaderEffect shaderEffect;
++ if( useHighPrecision )
++ {
++ shaderEffect = Dali::ShaderEffect::New(
++ prefixHighPrecision+vertexShader, prefixHighPrecision + fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_BLENDING ) );
++ }
++ else
++ {
++ shaderEffect = Dali::ShaderEffect::New(
++ prefixMediumPrecision+vertexShader, prefixMediumPrecision + fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_BLENDING ) );
++ }
++
++ shaderEffect.SetUniform( "uPercentage", 0.0f );
++ shaderEffect.SetProperty( ShaderEffect::Property::GRID_DENSITY, Dali::Property::Value(50.0f) );
++
++ DissolveEffectSetCentralLine( shaderEffect, Vector2(1.0f,0.5f), Vector2(-1.0f, 0.0f) );
++
++ return shaderEffect;
++
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_DISSOLVE_H__
--- /dev/null
-class DALI_IMPORT_API DissolveLocalEffect : public ShaderEffect
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_LOCAL_DISSOLVE_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_LOCAL_DISSOLVE_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
++#include <sstream>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Create a new DissolveLocalEffect
++ *
+ * DissolveLocalEffect is a custom shader effect to achieve Dissolve effects in multiple small areas of Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ * "uTransparency"
++ * "uCenter" - The center positions of each dimples
++ * "uRadius" - The propagation radius of each dimple
++ * "uPercentage" - The distortion applied to the effect texture. A value of zero means no distortion
++ *
++ * @param[in] numberOfDimples The number of dimples
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an uninitialized DissolveLocalEffect; this can be initialized with DissolveLocalEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- DissolveLocalEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~DissolveLocalEffect();
-
- /**
- * Create an initialized DissolveLocalEffect.
- * @param[in] numberOfDimples The number of dimples
- * @return A handle to a newly allocated Dali resource.
- */
- static DissolveLocalEffect New( unsigned int numberOfDimples );
-
- /**
- * Get the number of dimples the shader supports.
- * @return The number of dimples in the shader.
- */
- unsigned int GetNumberOfDimples() const;
-
- /**
- * Set the transparency of the drifted pixels.
- * @param[in] transparency The transparency of the drifted pixels.
- */
- void SetTransparency( float transparency);
-
- /**
- * Set the certer position of a dimple.
- * @param[in] index The index of the dimple to change.
- * @param[in] center The center position of the dimple.
- * @pre index has to be between 0 and GetNumberOfDimples() - 1
- */
- void SetCenter( unsigned int index, const Vector2& center );
-
- /**
- * Set the propogation radius of a dimple.
- * @param[in] index The index of the dimple to change.
- * @param[in] radius The propagation radius of the dimple.
- * @pre index has to be between 0 and GetNumberOfDimples() - 1
- */
- void SetRadius( unsigned int index, float radius );
-
- /**
- * Sets the distortion applied to the effect texture.
- * This value is proportional to the distortion applied; a value of zero means no distortion.
- * @param[in] index The index of the dimple to change.
- * @param[in] distortion The distortion value.
- * @pre index has to be between 0 and GetNumberOfDimples() - 1
- */
- void SetDistortion( unsigned int index, float distortion );
-
- /**
- * Get the name of the center property of a dimple.
- * @param[in] index The index of the dimple.
- * @return A std::string containing the property name.
- * @pre index has to be between 0 and GetNumberOfDimples() - 1
- */
- std::string GetCenterPropertyName( unsigned int index ) const;
-
- /**
- * Get the name of the radius property of a dimple.
- * @param[in] index The index of the dimple.
- * @return A std::string containing the property name
- * @pre index has to be between 0 and GetNumberOfDimples() - 1
- */
- std::string GetRadiusPropertyName( unsigned int index ) const;
-
- /**
- * Get the name for the distortion property of a dimple
- * @param[in] index the index of a dimple.
- * @return A std::string containing the property name
- * @pre index has to be between 0 and GetNumberOfDimples() - 1
- */
- std::string GetDistortionPropertyName( unsigned int index ) const;
-
-private: // Not intended for application developers
-
- DALI_INTERNAL DissolveLocalEffect( ShaderEffect handle );
-
-private:
-
- unsigned int mNumberOfDimples; ///< The number of dimples the shader supports
-
-};
++inline ShaderEffect CreateDissolveLocalEffect( unsigned int numberOfDimples )
+ {
++ std::ostringstream vertexShaderStringStream;
++ vertexShaderStringStream << "#define NUMBER_OF_DIMPLE "<< numberOfDimples << "\n";
++ std::string vertexShader(
++ "precision highp float;\n"
++ "uniform vec2 uCenter[ NUMBER_OF_DIMPLE ];\n"
++ "uniform float uRadius[ NUMBER_OF_DIMPLE ]; \n"
++ "uniform float uPercentage[ NUMBER_OF_DIMPLE ]; \n"
++ "varying float vPercentage;\n"
++ "void main()\n"
++ "{\n"
++ " vec4 position = uModelView * vec4( aPosition, 1.0 );\n"
++ " float percentage = 0.0;\n"
++ " for( int i=0; i<NUMBER_OF_DIMPLE; ++i )\n"
++ " {\n"
++ " float distance = distance(uCenter[i], position.xy);\n"
++ " percentage = max(percentage, uPercentage[i] * cos(clamp( distance/uRadius[i], 0.0, 1.0 )*1.57) );"
++ " }\n"
++ " vPercentage = clamp( percentage, 0.0, 1.0 );\n"
++ " gl_Position = uProjection * position;\n"
++ " vTexCoord = aTexCoord;\n"
++ "}\n");
++ vertexShaderStringStream << vertexShader;
++
++ std::string fragmentShader(
++ "precision highp float;\n"
++ "uniform float uTransparency;\n"
++ "varying float vPercentage;\n"
++ "float rand(vec2 co) \n"
++ "{\n"
++ " return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n"
++ "}\n"
++ "void main()\n"
++ "{\n"
++ //Calculate the randomness
++ " float offsetS = rand( vTexCoord * vPercentage ); \n"
++ " float offsetT = rand( vec2(vTexCoord.t*vPercentage, vTexCoord.s * vPercentage) ); \n"
++ " vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage; \n"
++ " gl_FragColor = texture2D( sTexture, lookupCoord ) * uColor; \n"
++ " gl_FragColor.a *= 1.0 - uTransparency*vPercentage; \n"
++ "}\n");
++
++ ShaderEffect shaderEffect = ShaderEffect::New(
++ vertexShaderStringStream.str(), fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_BLENDING ) );
++
++ //Register uniform properties
++ std::ostringstream oss;
++ for( unsigned int i = 0; i < numberOfDimples; i++ )
++ {
++ oss.str("");
++ oss<< "uCenter["<< i << "]";
++ shaderEffect.SetUniform(oss.str(), Vector2(0.f,0.f));
++
++ oss.str("");
++ oss<< "uRadius["<< i << "]";
++ shaderEffect.SetUniform(oss.str(), 0.f);
++
++ oss.str("");
++ oss<< "uPercentage["<< i << "]";
++ shaderEffect.SetUniform( oss.str(), 0.f );
++ }
++
++ shaderEffect.SetProperty( ShaderEffect::Property::GRID_DENSITY, Dali::Property::Value(5.f) );
++ shaderEffect.SetUniform( "uTransparency", 0.5f );
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_LOCAL_DISSOLVE_H__
--- /dev/null
-class DALI_IMPORT_API DistanceFieldEffect : public ShaderEffect
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * Creates a new DistanceFieldEffect
++ *
+ * DistanceFieldEffect is a custom shader effect to achieve distance field on Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ *
++ * "uSmoothing" - Soft edge smoothing. Specify the distance field value for the center of the edge.
++
++ * "uDoGlow" - The glow state. If true, glow is enabled
++ * "uGlowBoundary" - The glow boundary factor
++ * "uGlowColor" - The glow color multiplier
++
++ * "uDoShadow" - The shadow state. If true, shadows is enabled. Cannot be used with glow/and or outline
++ * "uShadowColor" - The shadow color multiplier
++ * "uShadowOffset" - The shadow offset
++
++ * "uDoOutline" - The outline state. If true, outline is enabled
++ * "uOutlineColor" - The outline color multiplier
++ * "uOutlineParams"- Thickness of outline. The outline thickness is determined by two values.
++ * First value [0-1] Specifies the distance field value for the center of the outline.
++ * Second value [0-1] Specifies the softness/width/anti-aliasing of the outlines inner edge.
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an uninitialized DistanceFieldEffect; this can be initialized with DistanceFieldEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- DistanceFieldEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~DistanceFieldEffect();
-
- /**
- * Create an initialized DistanceFieldEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static DistanceFieldEffect New();
-
- /**
- * Set the shadow state
- * @param[in] shadowEnable value - true, enable shadow.
- * @note Shadow cannot be used with glow/and or outline.
- */
- void SetShadow(bool shadowEnable);
-
- /**
- * Set the shadow color multiplier (e.g. output RGB)
- * @param[in] color Shadow color value
- */
- void SetShadowColor(const Vector4& color);
-
- /**
- * Set the shadow offset
- * @param[in] color shadow offset value
- */
- void SetShadowOffset(const Vector2& color);
-
- /**
- * Set the glow state
- * @param[in] glowEnable value - true, enable glow.
- */
-
- void SetGlow(bool glowEnable);
-
- /**
- * Set the glow color multiplier (e.g. output RGB)
- * @param[in] color Glow color value
- */
- void SetGlowColor(const Vector4& color);
-
- /**
- * Set the glow boundary factor
- * @param[in] glowBoundary glow boundary
- */
- void SetGlowBoundary(float glowBoundary);
-
- /**
- * Set the outline state
- * @param[in] outlineEnable value - true, enable outline.
- */
-
- void SetOutline(bool outlineEnable);
-
- /**
- * Set the outline color multiplier (e.g. output RGB)
- * @param[in] color Outline color value
- */
- void SetOutlineColor(const Vector4& color);
-
- /**
- * Sets the outline parameters.
- * @param[in] outlineParams Thickness of outline. The outline thickness is determined by two parameters.
- * params[0] (0-1) Specifies the distance field value for the center of the outline.
- * 0 <= params[0] <= 1
- * params[1] (0-1) Specifies the softness/width/anti-aliasing of the outlines inner edge.
- * 0 <= params[0] <= 1
- */
- void SetOutlineParams(const Vector2& outlineParams);
-
- /**
- * Set soft edge smoothing
- * @param[in] smoothing Specify the distance field value for the center of the edge.
- * 0 <= params <= 1
- */
- void SetSmoothingEdge(float smoothing);
-
- /**
- * Get the name for the outline-enable property
- * @return A std::string containing the property name
- */
- const std::string& GetOutlineEnablePropertyName() const;
-
- /**
- * Get the name for the glow-enable property
- * @return A std::string containing the property name
- */
- const std::string& GetGlowEnablePropertyName() const;
-
- /**
- * Get the name for the shadow-enable property
- * @return A std::string containing the property name
- */
- const std::string& GetShadowEnablePropertyName() const;
-
- /**
- * Get the name for the radius property
- * @return A std::string containing the property name
- */
- const std::string& GetColorPropertyName() const;
-
- /**
- * Get the name for the smoothing property
- * @return A std::string containing the property name
- */
- const std::string& GetSmoothingPropertyName() const;
-
- /**
- * Get the name for the outline color property
- * @return A std::string containing the property name
- */
- const std::string& GetOutlineColorPropertyName() const;
-
- /**
- * Get the name for the outline size property
- * @return A std::string containing the property name
- */
- const std::string& GetOutlineSizePropertyName() const;
-
- /**
- * Get the name for the shadow color property
- * @return A std::string containing the property name
- */
- const std::string& GetShadowColorPropertyName() const;
-
- /**
- * Get the name for the shadow offset property
- * @return A std::string containing the property name
- */
- const std::string& GetShadowOffsetPropertyName() const;
-
- /**
- * Get the name for the glow color property
- * @return A std::string containing the property name
- */
- const std::string& GetGlowColorPropertyName() const;
-
- /**
- * Get the name for the glow boundary property
- * @return A std::string containing the property name
- */
- const std::string& GetGlowBoundaryPropertyName() const;
-
-private:
- DALI_INTERNAL DistanceFieldEffect(ShaderEffect handle);
-
-};
++inline ShaderEffect CreateDistanceFieldEffect()
+ {
++ std::string fragmentShaderPrefix(
++ "#extension GL_OES_standard_derivatives : enable\n"
++ "\n"
++ );
++
++ std::string fragmentShader(
++ "uniform mediump float uSmoothing;\n"
++ "uniform mediump float uGlowBoundary;\n"
++ "uniform mediump vec2 uOutlineParams;\n"
++ "uniform lowp vec4 uOutlineColor;\n"
++ "uniform lowp vec4 uShadowColor;\n"
++ "uniform mediump vec2 uShadowOffset;\n"
++ "uniform lowp vec4 uGlowColor;\n"
++ "uniform lowp float uDoOutline;\n"
++ "uniform lowp float uDoShadow;\n"
++ "uniform lowp float uDoGlow;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ " // sample distance field\n"
++ " mediump float distance = texture2D(sTexture, vTexCoord).a;\n"
++ " mediump float smoothWidth = fwidth(distance);\n"
++ " mediump float alphaFactor = smoothstep(uSmoothing - smoothWidth, uSmoothing + smoothWidth, distance);\n"
++ " lowp vec4 color;\n"
++ " if (uDoShadow == 0.0)\n"
++ " {\n"
++ " mediump float alpha = uColor.a * alphaFactor;\n"
++ " lowp vec4 rgb = uColor;\n"
++ "\n"
++ " if (uDoOutline > 0.0)\n"
++ " {\n"
++ " mediump float outlineWidth = uOutlineParams[1] + smoothWidth;\n"
++ " mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);\n"
++ " alpha = smoothstep(uSmoothing - smoothWidth, uSmoothing + smoothWidth, distance);\n"
++ " rgb = mix(uOutlineColor, uColor, outlineBlend);\n"
++ " }\n"
++ "\n"
++ " if (uDoGlow > 0.0)\n"
++ " {\n"
++ " rgb = mix(uGlowColor, rgb, alphaFactor);\n"
++ " alpha = smoothstep(uGlowBoundary, uSmoothing, distance);\n"
++ " }\n"
++ "\n"
++ " // set fragment color\n"
++ " color = vec4(rgb.rgb, alpha);\n"
++ " }\n"
++ "\n"
++ " else // (uDoShadow > 0.0)\n"
++ " {\n"
++ " mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;\n"
++ " mediump float inText = alphaFactor;\n"
++ " mediump float inShadow = smoothstep(uSmoothing - smoothWidth, uSmoothing + smoothWidth, shadowDistance);\n"
++ "\n"
++ " // inside object, outside shadow\n"
++ " if (inText == 1.0)\n"
++ " {\n"
++ " color = uColor;\n"
++ " }\n"
++ " // inside object, outside shadow\n"
++ " else if ((inText != 0.0) && (inShadow == 0.0))\n"
++ " {\n"
++ " color = uColor;\n"
++ " color.a *= inText;\n"
++ " }\n"
++ " // outside object, completely inside shadow\n"
++ " else if ((inText == 0.0) && (inShadow == 1.0))\n"
++ " {\n"
++ " color = uShadowColor;\n"
++ " }\n"
++ " // inside object, completely inside shadow\n"
++ " else if ((inText != 0.0) && (inShadow == 1.0))\n"
++ " {\n"
++ " color = mix(uShadowColor, uColor, inText);\n"
++ " color.a = uShadowColor.a;\n"
++ " }\n"
++ " // inside object, inside shadow's border\n"
++ " else if ((inText != 0.0) && (inShadow != 0.0))\n"
++ " {\n"
++ " color = mix(uShadowColor, uColor, inText);\n"
++ " color.a *= max(inText, inShadow);\n"
++ " }\n"
++ " // inside shadow's border\n"
++ " else if (inShadow != 0.0)\n"
++ " {\n"
++ " color = uShadowColor;\n"
++ " color.a *= inShadow;\n"
++ " }\n"
++ " // outside shadow and object\n"
++ " else \n"
++ " {\n"
++ " color.a = 0.0;\n"
++ " }\n"
++ "\n"
++ " }\n"
++ "\n"
++ " gl_FragColor = color;\n"
++ "\n"
++ "}\n"
++ );
++
++ // Create the implementation, temporarily owned on stack
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::NewWithPrefix(
++ "", "",
++ fragmentShaderPrefix, fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING));
++
++ shaderEffect.SetUniform("uSmoothing",0.5f);
++ shaderEffect.SetUniform("uOutlineColor",Color::BLACK);
++ shaderEffect.SetUniform("uOutlineParams",Vector2(0.51f, 0.0f));
++ shaderEffect.SetUniform("uGlowBoundary",0.4f);
++ shaderEffect.SetUniform("uGlowColor",Color::GREEN);
++ shaderEffect.SetUniform("uShadowColor",Vector4(0.0f, 0.0f, 0.0f, 0.4f));
++
++ // TODO: find a way to set the shadow offset in texel coordinates instead of UVs.
++ shaderEffect.SetUniform("uShadowOffset",Vector2(0.05f, 0.05f));
++
++ // Default:
++ shaderEffect.SetUniform("uDoOutline",false);
++ shaderEffect.SetUniform("uDoGlow",false);
++ shaderEffect.SetUniform("uDoShadow",false);
++
++ return shaderEffect;
++}
++
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
--- /dev/null
- * @brief ImageRegionEffect is a custom shader effect to show only a region of an Image actor.
+ #ifndef __DALI_TOOLKIT_IMAGE_REGION_EFFECT_H__
+ #define __DALI_TOOLKIT_IMAGE_REGION_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API ImageRegionEffect : public ShaderEffect
++ * @brief Creates a new ImageRegionEffect
++ *
++ * ImageRegionEffect is a custom shader effect to show only a region of an Image actor.
++ *
++ * Animatable/Constrainable uniforms:
++ * "uTopLeft" - The top-left corner of the image region. The coordinates are in percentage,
++ * (0,0) being the top-left and (1,1) the bottom right of the original image
++ * "uBottomRight" - The bottom-right corner of the image region. The coordinates are in percentage,
++ * (0,0) being the top-left and (1,1) the bottom right of the original image
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * @brief Create an uninitialized ImageRegionEffect; this can be initialized with ImageRegionEffect::New().
- *
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- ImageRegionEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~ImageRegionEffect();
-
- /**
- * @brief Create an initialized ImageRegionEffect.
- *
- * @return A handle to a newly allocated Dali resource.
- */
- static ImageRegionEffect New();
-
- /**
- * @brief Set the top-left corner of the image region.
- *
- * The coordinates are in percentage, (0,0) being the top-left and (1,1) the bottom right of the original image.
- * @param [in] point The top-left corner of the region.
- */
- void SetTopLeft(const Vector2& point);
-
- /**
- * @brief Set the bottom-right corner of the image region.
- *
- * The coordinates are in percentage, (0,0) being the top-left and (1,1) the bottom right of the original image.
- * @param [in] point The bottom-right corner of the region.
- */
- void SetBottomRight(const Vector2& point);
-
- /**
- * @brief Get the name for the top-left point property.
- *
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetTopLeftPropertyName() const;
-
- /**
- * @brief Get the name for the bottom-right point property which can be used in Animation APIs.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetBottomRightPropertyName() const;
-
-private: // Not intended for application developers
- DALI_INTERNAL ImageRegionEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateImageRegionEffect()
+ {
++ std::string vertexShader(
++ "uniform mediump vec2 uTopLeft;\n"
++ "uniform mediump vec2 uBottomRight;\n"
++ "void main()\n"
++ "{\n"
++ " mediump vec4 position = vec4(aPosition,1.0);\n"
++ " gl_Position = uMvpMatrix * position;\n"
++ // The line below is doing the same as the following commented lines:
++ //" vec2 imageSize = sTextureRect.zw - sTextureRect.xy;\n"
++ //" vec2 topLeft = sTextureRect.xy + uTopLeft * imageSize;\n"
++ //" vec2 bottomRight = sTextureRect.xy + uBottomRight * imageSize;\n"
++ //" vec2 texCoord = (aTexCoord - sTextureRect.xy) / imageSize;\n"
++ //" vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );\n"
++ " vTexCoord = sTextureRect.xy + uTopLeft * ( sTextureRect.zw - sTextureRect.xy ) + ( aTexCoord - sTextureRect.xy ) * ( uBottomRight - uTopLeft );\n"
++ "}\n"
++ );
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New( vertexShader, "" );
++ shaderEffect.SetUniform( "uTopLeft", Vector2( 0.f, 0.f ) );
++ shaderEffect.SetUniform( "uBottomRight", Vector2( 1.f, 1.f ) );
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_IMAGE_REGION_EFFECT_H__
--- /dev/null
- * @brief IrisEffect is a custom shader effect to achieve iris effects in Image actors
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_IRIS_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_IRIS_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API IrisEffect : public ShaderEffect
++ * @brief Creates a new IrisEffect
++ *
++ * IrisEffect is a custom shader effect to achieve iris effects in Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ *
++ * "uRadius" - The radius of the iris effect in texture coordinate distance,
++ * i.e. 0.0 (no circle) to 1.0 (complete circle), to > 1.0 (extending outside of texture).
++ * @note For Atlas Textures results may be unpredictable.
++ *
++ * "uBlendFactor" - The blend factor of the iris effect. The lower the value, the larger the blending portion
++ * (between Opaque & Transparent). Blending will account for 1 / blendFactor of the radius
++ * of the texture.
++ *
++ * "uCenter" - The center point of the iris (in texture coordinates)
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-
-public:
-
- /**
- * @brief Create an uninitialized IrisEffect; this can be initialized with IrisEffect::New().
- *
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- IrisEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~IrisEffect();
-
- /**
- * @brief Create an initialized IrisEffect.
- *
- * @return A handle to a newly allocated Dali resource.
- */
- static IrisEffect New();
-
- /**
- * @brief Set the radius of the iris effect in texture coordinate distance,
- * i.e. 0.0 (no circle) to 1.0 (complete circle), to > 1.0 (extending
- * outside of texture).
- *
- * @note For Atlas Textures results may be unpredictable.
- *
- * @param [in] radius The new radius.
- */
- void SetRadius(float radius);
-
- /**
- * @brief Set the blend factor of the iris effect.
- *
- * The lower the value, the larger the blending portion
- * (between Opaque & Transparent)
- *
- * Blending will account for 1 / blendFactor of the radius
- * of the texture.
- *
- * @param [in] value The new blend Factor.
- */
- void SetBlendFactor(float value);
-
- /**
- * @brief Sets the center point of the iris (in texture coordinates).
- *
- * @param[in] center The center point.
- */
- void SetCenter( const Vector2& center );
-
- /**
- * @brief Get the name for the radius property which can be used in Animation APIs.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetRadiusPropertyName() const;
-
- /**
- * @brief Get the name for the blend factor property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetBlendFactorPropertyName() const;
-
- /**
- * @brief Get the name for the center property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
-
-private: // Not intended for application developers
- DALI_INTERNAL IrisEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateIrisEffect()
+ {
++ // append the default version
++ std::string vertexShader(
++ "uniform mediump vec2 uCenter;\n"
++ "varying mediump vec2 vRelativePosition;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ " mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
++ " gl_Position = uProjection * world;\n"
++ " \n"
++ " vTexCoord = aTexCoord;\n"
++ " vRelativePosition = aTexCoord - uCenter;\n"
++ "}\n");
++
++ std::string fragmentShader(
++ "uniform mediump float uRadius; \n"
++ "uniform mediump float uBlendFactor; \n"
++ "varying mediump vec2 vRelativePosition; \n"
++ "void main() \n"
++ "{ \n"
++ " mediump float delta = (length(vRelativePosition) - uRadius); \n"
++ " delta = clamp(0.0 - delta * uBlendFactor, 0.0, 1.0); \n"
++ " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor; \n"
++ " gl_FragColor.a *= delta; \n"
++ "} \n"
++ );
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ vertexShader,
++ fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
++
++ shaderEffect.SetUniform( "uRadius", 0.0f );
++ shaderEffect.SetUniform( "uBlendFactor", 100.0f );
++ shaderEffect.SetUniform( "uCenter", Vector2(0.5f, 0.5f) );
++
++ return shaderEffect;
++}
+
+ }
+ }
+
+ #endif
--- /dev/null
- * @brief MaskEffect is used to control which parts of an image are visible, using the alpha channel of a separate mask image.
+ #ifndef __DALI_TOOLKIT_MASK_EFFECT_H__
+ #define __DALI_TOOLKIT_MASK_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/images/image.h>
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
- * MaskEffect maskEffect = MaskEffect::New( Image::New( MASK_IMAGE_PATH ) );
++ * @brief Creates a new MaskEffect
++ *
++ * MaskEffect is used to control which parts of an image are visible, using the alpha channel of a separate mask image.
+ *
+ * Typically mask images should be the same size as the main image being viewed, but this isn't essential.
+ *
+ * Usage example:
+ *
+ * ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
-class DALI_IMPORT_API MaskEffect : public ShaderEffect
++ * ShaderEffect maskEffect = CreateMaskEffect( Image::New( MASK_IMAGE_PATH ) );
+ * actor.SetShaderEffect( maskEffect );
++ *
++ * @param[in] maskImage The image to use as a mask
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * @brief Create an empty MaskEffect handle.
- */
- MaskEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~MaskEffect();
++inline ShaderEffect CreateMaskEffect(Image maskImage)
+ {
- /**
- * @brief Create a MaskEffect.
- *
- * @param[in] maskImage The image to use as a mask
- * @return A handle to a newly allocated MaskEffect.
- */
- static MaskEffect New( Image maskImage );
++ const char* ALPHA_MASK_FRAGMENT_SHADER_SOURCE =
++ "void main() \n"
++ "{ \n"
++ " highp vec4 mask = texture2D(sEffect, vTexCoord); \n"
++ " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(1,1,1,mask.a); \n"
++ "} \n";
+
-private: // Not intended for application developers
++ ShaderEffect shaderEffect = ShaderEffect::New(
++ "", // Use default
++ ALPHA_MASK_FRAGMENT_SHADER_SOURCE,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
+
- DALI_INTERNAL MaskEffect( ShaderEffect handle );
-};
++ shaderEffect.SetEffectImage( maskImage );
+
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_MASK_EFFECT_H__
--- /dev/null
-class DALI_IMPORT_API MirrorEffect : public ShaderEffect
+ #ifndef __DALI_TOOLKIT_MIRROR_EFFECT_H__
+ #define __DALI_TOOLKIT_MIRROR_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new MirrorEffect
++ *
+ * MirrorEffect is a custom shader effect to achieve square effects in Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ * "uDepth" - The depth of the mirror effect. Default value 0.5
++ * "uAlpha" - The alpha of the mirror effect. Default value 1.0
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an uninitialized MirrorEffect; this can be initialized with MirrorEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- MirrorEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~MirrorEffect();
-
- /**
- * Create an initialized MirrorEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static MirrorEffect New();
-
- /**
- * Set the depth of the mirror effect.
- * @param [in] depth The new mirror depth value.
- */
- void SetDepth(float depth);
-
- /**
- * Set the alpha of the mirror effect.
- * @param [in] alpha The new mirror alpha value.
- */
- void SetAlpha(float alpha);
-
- /**
- * Get the name for the depth property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetDepthPropertyName() const;
-
- /**
- * Get the name for the alpha property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetAlphaPropertyName() const;
++inline ShaderEffect CreateMirrorEffect()
+ {
-private: // Not intended for application developers
- DALI_INTERNAL MirrorEffect(ShaderEffect handle);
-};
++ std::string vertexShader(
++ "void main() \n"
++ "{ \n"
++ " mediump vec3 pos = aPosition; \n"
++ " pos.y = pos.y * 3.0; \n"
++ " mediump vec4 world = uModelView * vec4(pos,1.0); \n"
++ " gl_Position = uProjection * world; \n"
++ " vTexCoord = aTexCoord; \n"
++ "} \n" );
++
++ std::string fragmentShader(
++ "uniform mediump float uDepth; \n"
++ "uniform mediump float uAlpha; \n"
++ "void main() \n"
++ "{ \n"
++ " if(vTexCoord.y < 1.0 / 3.0) \n"
++ " { \n"
++ " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
++ " } \n"
++ " else if(vTexCoord.y < 2.0 / 3.0) \n"
++ " { \n"
++ " gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y * 3.0 - 1.0)) * uColor; \n"
++ " gl_FragColor.a *= uAlpha; \n"
++ " } \n"
++ " else \n"
++ " { \n"
++ " highp float darkness = 3.0 - vTexCoord.y * 3.0; \n"
++ " darkness = (1.0 - 1.0 / uDepth + darkness * 1.0/ uDepth) * 0.65; \n"
++ " highp vec4 color = texture2D(sTexture, vec2(vTexCoord.x, -vTexCoord.y *3.0 + 3.0)) * uColor; \n"
++ " color.a *= uAlpha; \n"
++ " gl_FragColor = color * vec4(darkness, darkness, darkness, darkness); \n"
++ " } \n"
++ "} \n" );
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ vertexShader,
++ fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
++
++ shaderEffect.SetUniform("uAlpha", 1.0f);
++ shaderEffect.SetUniform("uDepth", 0.5f);
++
++ return shaderEffect;
++}
+
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_MIRROR_EFFECT_H__
--- /dev/null
-#include <dali/public-api/actors/renderable-actor.h>
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
- * Class for motion blur shader that works on a per object basis. Objects will
++#include <dali/public-api/actors/image-actor.h>
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Create a new MotionBlurEffect
+ *
- * MotionBlurEffect MotionBlurEffect = MotionBlurEffect::New();
++ * Motion blur shader works on a per object basis. Objects will
+ * blur when they move, or if the camera moves. Can be applied to ImageActor or
+ * TextActor only.
+ *
+ * Usage example:-
+ *
+ * // Create shader used for doing motion blur\n
- * Actor Actor = Actor::New( ... );\n
- * Actor.SetShaderEffect( MotionBlurEffect );
++ * ShaderEffect MotionBlurEffect = CreateMotionBlurEffect();
+ *
+ * // set actor shader to the blur one\n
-class DALI_IMPORT_API MotionBlurEffect : public ShaderEffect
++ * Actor actor = Actor::New( ... );\n
++ * actor.SetShaderEffect( MotionBlurEffect );
+ *
++ * // Constrain "uModelLastFrame" to be the same as the actor's world matrix\n
++ * Dali::Property::Index uModelProperty = MotionBlurEffect.GetPropertyIndex( "uModelLastFrame" );
++ * Constraint constraint = Constraint::New<Matrix>( MotionBlurEffect, uModelProperty, EqualToConstraint() );\n
++ * constraint.AddSource( Source( actor , Actor::Property::WORLD_MATRIX ) );\n
++ * constraint.Apply();\n
++ *
++ *
++ * Animatable/Constrainable uniforms:
++ * "uBlurTexCoordScale" - This scales the offset for texture samples along the motion velocity vector.
++ * A smaller value means the samples will be spaced closer, larger value further
++ * apart. User should use this to get the blur to look contiguous, i.e. the blur
++ * texels should not be too widely spread, with gaps in between. Default 0.125.
++ * "uGeometryStretchFactor" - This scales the amount the geometry stretches backwards along the motion velocity
++ * vector. A smaller value means the geometry stretches less, larger it stretches more.
++ * User should use this to get the blur to 'bleed' into areas outside the physical
++ * bounds of the actor. We need this as the blur is only applied inside the bounds of
++ * the actor, but you would expect motion blur trails where the actor was previously
++ * but is there no longer. Default 0.05.
++ * "uSpeedScalingFactor" - This takes the magnitude of the motion velocity vector and scales it to produce a
++ * value which is used to fade the blur in / out with the speed that the actor is moving.
++ * As the blur fades in, more of the blur is visible and less of the original actor, and
++ * viceversa. This value is also used to control how much to fade the actor near the
++ * edges, based on the speed the actor is moving. When the actor is at rest this is not applied.
++ * Default 0.5.
++ * "uObjectFadeStart" - The displacement from the centre of the actor that the actor will start to fade towards its
++ * edges. This is used to prevent an unsightly hard edge between the blurred actor and the scene.
++ * Depends on the values of the vertices in the vertex stream. When the actor is at rest this is
++ * not applied. Default 0.25, which is half way towards the edge for an ImageRenderer::QUAD.
++ * "uObjectFadeEnd" - The displacement from the centre of the actor that the actor will finish fading towards its
++ * edges. This is used to prevent an unsightly hard edge between the blurred actor and the scene.
++ * Depends on the values of the vertices in the vertex stream. When the actor is at rest this is
++ * not applied.Default 0.5, which is all the way towards the edge for an ImageRenderer::QUAD.
++ * "uAlphaScale" - Global scaler applied to the alpha of the actor. Used to make the blurred actor a bit more subtle
++ * (helps to hide discontinuities due to limited number of texture samples) and reveal a bit of the
++ * background behind it as it moves. When the actor is at rest this is not applied. Default 0.75.
++ * "uNumSamples" - The number of texture samples to be taken. Increasing the number of samples provides better quality
++ * at the cost of performance.
++ * "uModelLastFrame" - The model to world space transformation matrix of the actor in the previous frame.
++ *
++ * @param numBlurSamples Number of samples used by the shader
++ * @return A handle to a newly allocated ShaderEffect
+ */
-
-public:
-
- /**
- * Create an uninitialized MotionBlurEffect; this can be initialized with MotionBlurEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- MotionBlurEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~MotionBlurEffect();
-
- /**
- * Create an initialized MotionBlurEffect
- * The number of texture samples taken along the motion velocity vector of the
- * actor, producing the blur, is set to a default of 8.
- * @return A handle to a newly allocated Dali resource.
- */
- static MotionBlurEffect New();
-
- /**
- * Create a MotionBlurEffect and attach it to the specified actor
- * The number of texture samples taken along the motion velocity vector of the
- * actor, producing the blur, is set to a default of 8.
- * @param renderable actor to apply the effect to
- * @return A handle to a newly allocated Dali resource.
- */
- static MotionBlurEffect Apply( RenderableActor renderable );
-
- /**
- * Create an initialized MotionBlurEffect
- * @param numBlurSamples The number of texture samples taken along the motion
- * velocity vector of the actor, producing the blur. A higher number gives a
- * smoother blur but costs more in terms of performance.
- * @param numBlurSamples to have
- * @return A handle to a newly allocated Dali resource.
- */
- static MotionBlurEffect New( unsigned int numBlurSamples );
-
- /**
- * Set texcoord scale property. This scales the offset for texture samples
- * along the motion velocity vector. A smaller value means the samples will
- * be spaced closer, larger value further apart. User should use this to get
- * the blur to look contiguous, i.e. the blur texels should not be too widely
- * spread, with gaps in between. Default 0.125.
- * @param texcoordScale The scaling factor that multiplies the motion velocity vector for texture lookups.
- */
- void SetTexcoordScale( float texcoordScale );
-
- /**
- * Set geometry stretch factor property. This scales the amount the
- * geometry stretches backwards along the motion velocity vector. A smaller
- * value means the geometry stretches less, larger it stretches more. User
- * should use this to get the blur to 'bleed' into areas outside the physical
- * bounds of the actor. We need this as the blur is only applied inside the
- * bounds of the actor, but you would expect motion blur trails where the
- * actor was previously but is there no longer. Default 0.05.
- * @param scalingFactor The scaling factor that extrudes the geometry backwards along the motion velocity vector.
- */
- void SetGeometryStretchFactor( float scalingFactor );
-
- /**
- * Set speed scaling factor property. This takes the magnitude of the motion
- * velocity vector and scales it to produce a value which is used to fade the
- * blur in / out with the speed that the actor is moving. As the blur fades
- * in, more of the blur is visible and less of the original actor, and vice
- * versa.
- * This value is also used to control how much to fade the actor near the
- * edges, based on the speed the actor is moving. When the actor is at rest
- * this is not applied. Default 0.5.
- * @param scalingFactor The scaling factor that controls the edge fade / blur fade of the actor.
- */
- void SetSpeedScalingFactor( float scalingFactor );
-
- /**
- * Set the displacement from the centre of the actor that the actor will start
- * to fade towards its edges. This is used to prevent an unsightly hard edge
- * between the blurred actor and the scene. Depends on the values of the
- * vertices in the vertex stream. When the actor is at rest this is not applied.
- * Default 0.25, which is half way towards the edge for an ImageRenderer::QUAD.
- * @param displacement The displacement from the centre of the actor that the actor will start to edge fade.
- */
- void SetObjectFadeStart( Vector2 displacement );
-
- /**
- * Set the displacement from the centre of the actor that the actor will
- * finish fading towards its edges. This is used to prevent an unsightly hard
- * edge between the blurred actor and the scene. Depends on the values of the
- * vertices in the vertex stream. When the actor is at rest this is not applied.
- * Default 0.5, which is all the way towards the edge for an ImageRenderer::QUAD.
- * @param displacement The displacement from the centre of the actor that the actor will finish edge fading.
- */
- void SetObjectFadeEnd( Vector2 displacement );
-
- /**
- * Set a global scaler applied to the alpha of the actor. Used to make the
- * blurred actor a bit more subtle (helps to hide discontinuities due to
- * limited number of texture samples) and reveal a bit of the background
- * behind it as it moves. When the actor is at rest this is not applied. Default 0.75.
- * @param alphaScale The scaling factor which multiplies the alpha of each pixel of the actor.
- */
- void SetAlphaScale( float alphaScale );
-
- /**
- * Set the number of texture samples to be taken. Increasing the number of
- * samples provides better quality at the cost of performance.
- * @param numSamples The number of texture samples to be taken. Default is 8.
- */
- void SetNumSamples( int numSamples );
-
- /**
- * Get the name for the texcoord scale property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetTexcoordScalePropertyName() const;
-
- /**
- * Get the name for the geometry stretching property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetGeometryStretchFactorPropertyName() const;
-
- /**
- * Get the name for the speed scaling property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetSpeedScalingFactorPropertyName() const;
-
- /**
- * Get the name for the fade start property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetObjectFadeStartPropertyName() const;
-
- /**
- * Get the name for the fade end property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetObjectFadeEndPropertyName() const;
-
- /**
- * Get the name for the alpha scale property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetAlphaScalePropertyName() const;
-
- /**
- * Downcast an ShaderEffect handle to MotionBlurEffect handle. If handle points to a MotionBlurEffect object the
- * downcast produces valid handle. If not the returned handle is left uninitialized.
- * @param[in] handle to a ShaderEffect
- * @return handle to a MotionBlurEffect object or an uninitialized handle
- */
- static MotionBlurEffect DownCast( ShaderEffect handle );
-
-private:
- // Not intended for application developers
- DALI_INTERNAL MotionBlurEffect( ShaderEffect handle );
-};
++inline ShaderEffect CreateMotionBlurEffect( unsigned int numBlurSamples = 8 )
+ {
++ // Dali vertexSource prefix for reference:
++ // precision highp float;
++ // attribute vec3 aPosition;
++ // attribute vec2 aTexCoord;
++ // uniform mat4 uMvpMatrix;
++ // uniform mat4 uModelView;
++ // uniform mat3 uNormalMatrix;
++ // uniform mat4 uProjection;
++ // uniform vec4 uColor;
++ // varying vec2 vTexCoord;
++ std::string vertexSource;
++ vertexSource =
++ "precision mediump float;\n"
++ "uniform mat4 uModelLastFrame;\n"
++ "uniform float uTimeDelta;\n"
++
++ "uniform float uGeometryStretchFactor;\n"
++ "uniform float uSpeedScalingFactor;\n"
++
++ // outputs
++ "varying vec2 vModelSpaceCenterToPos;\n"
++ "varying vec2 vScreenSpaceVelocityVector;\n"
++ "varying float vSpeed;\n"
++
++ "void main()\n"
++ "{\n"
++ // get view space position of vertex this frame and last frame
++ " vec4 vertex = vec4(aPosition, 1.0);\n"
++ " vec4 viewSpaceVertex = uModelView * vertex;\n"
++ " vec4 viewSpaceVertexLastFrame = (uViewMatrix * uModelLastFrame) * vertex;\n"
++ " float reciprocalTimeDelta = 1.0 / ((uTimeDelta > 0.0) ? uTimeDelta : 0.01);\n"
++
++ // work out vertex's last movement in view space
++ " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
++
++ // get clip space position of vertex this frame and last frame
++ " vec4 clipSpaceVertex = uMvpMatrix * vertex;\n"
++ " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
++
++ // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
++ // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
++ " float t = 0.0;\n"
++ " float posDeltaLength = length(viewSpacePosDelta);\n"
++ " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
++ " {\n"
++ " vec4 viewSpaceCenterToPos = uModelView * vec4(aPosition, 0.0);\n"
++ " float centerToVertexDist = length(viewSpaceCenterToPos);\n"
++ " if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
++ " {\n"
++ " vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
++ " vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
++ " t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
++ " }\n"
++ " }\n"
++ // output vertex position lerped with its last position, based on how much it is trailing,
++ // this stretches the geom back along where it has just been, giving a warping effect
++ // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
++ " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
++
++ // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
++ " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
++ " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
++ // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
++ " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
++ " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
++ // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
++ " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
++ " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
++
++ // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
++ " vModelSpaceCenterToPos = aPosition.xy;\n"
++
++ " vTexCoord = aTexCoord;\n"
++ "}\n";
++
++
++ // Dali fragmentSource prefix for reference:
++ // precision highp float;
++ // uniform sampler2D sTexture;
++ // uniform sampler2D sEffect;
++ // uniform vec4 uColor;
++ // varying vec2 vTexCoord;
++ std::string fragmentSource;
++ fragmentSource =
++ "precision mediump float;\n"
++ "uniform vec2 uObjectFadeStart;\n"
++ "uniform vec2 uObjectFadeEnd;\n"
++ "uniform float uAlphaScale;\n"
++ "uniform float uBlurTexCoordScale;\n"
++ "uniform float uNumSamples;\n"
++ "uniform float uRecipNumSamples;\n"
++ "uniform float uRecipNumSamplesMinusOne;\n"
++ // inputs
++ "varying vec2 vModelSpaceCenterToPos;\n"
++ "varying vec2 vScreenSpaceVelocityVector;\n"
++ "varying float vSpeed;\n"
++
++ "void main()\n"
++ "{\n"
++ // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
++ // the blurred object and the unblurred background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
++ " vec2 centerToPixel = abs(vModelSpaceCenterToPos);\n"
++ " vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));\n"
++ " float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale;\n" // apply global scaler
++ " fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);\n" // fade proportional to speed, so opaque when at rest
++
++ // scale velocity vector by user requirements
++ " vec2 velocity = vScreenSpaceVelocityVector * uBlurTexCoordScale;\n"
++
++ // standard actor texel
++ " vec4 colActor = texture2D(sTexture, vTexCoord);\n"
++
++ // blurred actor - gather texture samples from the actor texture in the direction of motion
++ " vec4 col = colActor * uRecipNumSamples;\n"
++ " for(float i = 1.0; i < uNumSamples; i += 1.0)\n"
++ " {\n"
++ " float t = i * uRecipNumSamplesMinusOne;\n"
++ " col += texture2D(sTexture, vTexCoord + (velocity * t)) * uRecipNumSamples;\n"
++ " }\n"
++ " gl_FragColor = mix(colActor, col, vSpeed);\n" // lerp blurred and non-blurred actor based on speed of motion
++ " gl_FragColor.a = colActor.a * fadeToEdgesScale;\n" // fade blurred actor to its edges based on speed of motion
++ " gl_FragColor *= uColor;\n"
++ "}\n";
++
++ // NOTE: we must turn on alpha blending for the actor (HINT_BLENDING)
++ ShaderEffect shader = ShaderEffect::New( vertexSource, fragmentSource,
++ GeometryType(GEOMETRY_TYPE_IMAGE),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID) );
++
++ //////////////////////////////////////
++ // Register uniform properties
++ //
++ //
++ shader.SetUniform( "uBlurTexCoordScale", 0.125f );
++ shader.SetUniform( "uGeometryStretchFactor", 0.05f );
++ shader.SetUniform( "uSpeedScalingFactor", 0.5f );
++ shader.SetUniform( "uObjectFadeStart", Vector2( 0.25f, 0.25f ) );
++ shader.SetUniform( "uObjectFadeEnd", Vector2( 0.5f, 0.5f ) );
++ shader.SetUniform( "uAlphaScale", 0.75f );
++ shader.SetUniform( "uNumSamples", static_cast<float>( numBlurSamples ) );
++ shader.SetUniform( "uRecipNumSamples", 1.0f / static_cast<float>( numBlurSamples ) );
++ shader.SetUniform( "uRecipNumSamplesMinusOne", 1.0f / static_cast<float>( numBlurSamples - 1.0f ) );
++ shader.SetUniform( "uModelLastFrame", Matrix::IDENTITY );
++
++ return shader;
++}
+
+ }
+
+ }
+
+ #endif //#ifndef __DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H__
--- /dev/null
-#include <dali/public-api/actors/renderable-actor.h>
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_MOTION_STRETCH_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_MOTION_STRETCH_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
- * Class for motion stretch shader that works on a per object basis. Objects will stretch in the direction of motion when they move, or if the camera moves. Can be applied
++#include <dali/public-api/actors/image-actor.h>
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new MotionStretchEffect
+ *
- * MotionStretchEffect MotionStretchEffect = MotionStretchEffect::New();
++ * Motion stretch shader works on a per object basis. Objects will stretch in the direction of motion when they move, or if the camera moves. Can be applied
+ * to ImageActor or TextActor only.
+ *
+ * Usage example:-
+ *
+ * // Create shader used for doing motion stretch\n
- * Actor Actor = Actor::New( ... );\n
- * Actor.SetShaderEffect( MotionStretchEffect );
++ * ShaderEffect MotionStretchEffect = CreateMotionStretchEffect();
+ *
+ * // set actor shader to the stretch one\n
-class DALI_IMPORT_API MotionStretchEffect : public ShaderEffect
++ * Actor actor = Actor::New( ... );\n
++ * actor.SetShaderEffect( MotionStretchEffect );
+ *
++ * // Constrain "uModelLastFrame" to be the same as the actor's world matrix\n
++ * Dali::Property::Index uModelProperty = MotionBlurEffect.GetPropertyIndex( "uModelLastFrame" );
++ * Constraint constraint = Constraint::New<Matrix>( MotionBlurEffect, uModelProperty, EqualToConstraint() );\n
++ * constraint.AddSource( Source( actor , Actor::Property::WORLD_MATRIX ) );\n
++ * constraint.Apply();\n
++ *
++ * Animatable/Constrainable uniforms:
++ * "uGeometryStretchFactor" - This scales the amount the geometry stretches along the motion velocity vector.
++ * A smaller value means the geometry stretches less, larger it stretches more. Default 0.5.
++ * "uSpeedScalingFactor" - This value is used to control how much to fade the actor near the edges, based on the
++ * speed the actor is moving. When the actor is at rest this is not applied. Default 0.5.
++ * "uObjectFadeStart" - The displacement from the centre of the actor that the actor will start to fade towards
++ * its edges. This is used to prevent an unsightly hard edge between the stretched actor and
++ * the scene. Depends on the values of the vertices in the vertex stream. When the actor is at
++ * rest this is not applied. Default Vector2(0.25, 0.25), which is half way towards the edge for
++ * an ImageRenderer::QUAD.
++ * "uObjectFadeEnd" - The displacement from the centre of the actor that the actor will finish fading towards its edges.
++ * This is used to prevent an unsightly hard edge between the stretched actor and the scene. Depends
++ * on the values of the vertices in the vertex stream. When the actor is at rest this is not applied.
++ * Default 0.5, which is all the way towards the edge for an ImageRenderer::QUAD.
++ * "uAlphaScale" - Global scaler applied to the alpha of the actor. Used to make the stretched actor a bit more subtle
++ * and reveal a bit of the background behind it as it moves. When the actor is at rest this is not
++ * applied. Default 0.75.
++ * "uModelLastFrame" - The model to world space transformation matrix of the actor in the previous frame.
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-
-public:
-
- /**
- * Create an uninitialized MotionStretchEffect; this can be initialized with MotionStretchEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- MotionStretchEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~MotionStretchEffect();
-
- /**
- * Create an initialized MotionStretchEffect
- * @return A handle to a newly allocated Dali resource.
- */
- static MotionStretchEffect New();
-
- /**
- * Create a MotionStretchEffect and attach it to the specified actor
- * @param renderable actor to apply the effect to
- * @return A handle to a newly allocated Dali resource.
- */
- static MotionStretchEffect Apply( RenderableActor renderable );
-
- /**
- * Set geometry stretch factor property. This scales the amount the geometry
- * stretches along the motion velocity vector. A smaller value means the geometry
- * stretches less, larger it stretches more. Default 0.5.
- * @param scalingFactor The scaling factor that extrudes the geometry forwards along the motion velocity vector.
- */
- void SetGeometryStretchFactor( float scalingFactor );
-
- /**
- * Set speed scaling factor property. This value is used to control how much
- * to fade the actor near the edges, based on the speed the actor is moving.
- * When the actor is at rest this is not applied. Default 0.5.
- * @param scalingFactor The scaling factor that controls the edge fade of the actor.
- */
- void SetSpeedScalingFactor( float scalingFactor );
-
- /**
- * Set the displacement from the centre of the actor that the actor will start to
- * fade towards its edges. This is used to prevent an unsightly hard edge
- * between the stretched actor and the scene. Depends on the values of the
- * vertices in the vertex stream. When the actor is at rest this is not applied.
- * Default Vector2(0.25, 0.25), which is half way towards the edge for an ImageRenderer::QUAD.
- * @param displacement The displacement from the centre of the actor that the actor will start to edge fade.
- */
- void SetObjectFadeStart( Vector2 displacement );
-
- /**
- * Set the displacement from the centre of the actor that the actor will
- * finish fading towards its edges. This is used to prevent an unsightly hard
- * edge between the stretched actor and the scene. Depends on the values of
- * the vertices in the vertex stream. When the actor is at rest this is not applied.
- * Default 0.5, which is all the way towards the edge for an ImageRenderer::QUAD.
- * @param displacement The displacement from the centre of the actor that the actor will finish edge fading.
- */
- void SetObjectFadeEnd( Vector2 displacement );
-
- /**
- * Set a global scaler applied to the alpha of the actor. Used to make the
- * stretched actor a bit more subtle and reveal a bit of the background behind
- * it as it moves. When the actor is at rest this is not applied. Default 0.75.
- * @param alphaScale The scaling factor which multiplies the alpha of each pixel of the actor.
- */
- void SetAlphaScale( float alphaScale );
-
-
- /**
- * Get the name for the texcoord scale property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetTexcoordScalePropertyName() const;
-
- /**
- * Get the name for the geometry stretching property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetGeometryStretchFactorPropertyName() const;
-
- /**
- * Get the name for the speed scaling property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetSpeedScalingFactorPropertyName() const;
-
- /**
- * Get the name for the fade start X property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetObjectFadeStartPropertyName() const;
-
- /**
- * Get the name for the fade end X property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetObjectFadeEndPropertyName() const;
-
- /**
- * Get the name for the alpha scale property. Useful for animation.
- * @return A std::string containing the property name
- */
- const std::string& GetAlphaScalePropertyName() const;
-
-private:
- // Not intended for application developers
- DALI_INTERNAL MotionStretchEffect( ShaderEffect handle );
-};
++inline ShaderEffect CreateMotionStretchEffect()
+ {
++ // Dali vertexSource prefix for reference:
++ // precision highp float;
++ // attribute vec3 aPosition;
++ // attribute vec2 aTexCoord;
++ // uniform mat4 uMvpMatrix;
++ // uniform mat4 uModelView;
++ // uniform mat3 uNormalMatrix;
++ // uniform mat4 uProjection;
++ // uniform vec4 uColor;
++ // varying vec2 vTexCoord;
++ std::string vertexSource;
++ vertexSource =
++ "precision mediump float;\n"
++ "uniform mat4 uModelLastFrame;\n"
++ "uniform float uTimeDelta;\n"
++
++ "uniform float uGeometryStretchFactor;\n"
++ "uniform float uSpeedScalingFactor;\n"
++
++ // outputs
++ "varying vec2 vModelSpaceCenterToPos;\n"
++ "varying vec2 vScreenSpaceVelocityVector;\n"
++ "varying float vSpeed;\n"
++
++ "void main()\n"
++ "{\n"
++ // get view space position of vertex this frame and last frame
++ " vec4 vertex = vec4(aPosition, 1.0);\n"
++ " vec4 viewSpaceVertex = uModelView * vertex;\n"
++ " vec4 viewSpaceVertexLastFrame = uViewMatrix * uModelLastFrame * vertex;\n"
++
++ // work out vertex's last movement in view space
++ " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
++ " float reciprocalTimeDelta = 1.0 / ((uTimeDelta > 0.0) ? uTimeDelta : 0.01);\n"
++
++ // get clip space position of vertex this frame and last frame
++ " vec4 clipSpaceVertex = uMvpMatrix * vertex;\n"
++ " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
++
++ // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
++ // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
++ " float t = 0.0;\n"
++ " float posDeltaLength = length(viewSpacePosDelta);\n"
++ " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
++ " {\n"
++ " vec4 viewSpaceCenterToPos = uModelView * vec4(aPosition, 0.0);\n"
++ " float centerToVertexDist = length(viewSpaceCenterToPos);\n"
++ " if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
++ " {\n"
++ " vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
++ " vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
++ " t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
++ " }\n"
++ " }\n"
++ // output vertex position lerped with its last position, based on how much it is trailing,
++ // this stretches the geom back along where it has just been, giving a warping effect
++ // We raise t to a power in order that non-trailing vertices are effected much more than trailing ones
++ // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
++ " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * t * t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
++
++ // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
++ " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
++ " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
++ // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
++ " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
++ " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
++ // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
++ " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
++ " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
++
++ // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
++ " vModelSpaceCenterToPos = aPosition.xy;\n"
++
++ " vTexCoord = aTexCoord;\n"
++ "}\n";
++
++
++ // Dali fragmentSource prefix for reference:
++ // precision highp float;
++ // uniform sampler2D sTexture;
++ // uniform sampler2D sEffect;
++ // uniform vec4 uColor;
++ // varying vec2 vTexCoord;
++ std::string fragmentSource;
++ fragmentSource =
++ "precision mediump float;\n"
++
++ "uniform vec2 uObjectFadeStart;\n"
++ "uniform vec2 uObjectFadeEnd;\n"
++ "uniform float uAlphaScale;\n"
++
++ // inputs
++ "varying vec2 vModelSpaceCenterToPos;\n"
++ "varying vec2 vScreenSpaceVelocityVector;\n"
++ "varying float vSpeed;\n"
++
++ "void main()\n"
++ "{\n"
++ // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
++ // the stretched object and the background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
++ " vec2 centerToPixel = abs( vModelSpaceCenterToPos );\n"
++ " vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));\n"
++ " float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale;\n" // apply global scaler
++ " fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);\n" // fade proportional to speed, so opaque when at rest
++
++ // standard actor texel
++ " vec4 colActor = texture2D(sTexture, vTexCoord);\n"
++ " gl_FragColor = colActor;\n"
++ " gl_FragColor.a *= fadeToEdgesScale;\n" // fade actor to its edges based on speed of motion
++ " gl_FragColor *= uColor;\n"
++ "}";
++
++ // NOTE: we must turn on alpha blending for the actor (HINT_BLENDING)
++ ShaderEffect shaderEffect = ShaderEffect::New(
++ vertexSource, fragmentSource, GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ) );
++
++
++ //////////////////////////////////////
++ // Register uniform properties
++ //
++ //
++ shaderEffect.SetUniform( "uGeometryStretchFactor", 0.5f );
++ shaderEffect.SetUniform( "uSpeedScalingFactor", 0.5f );
++ shaderEffect.SetUniform( "uObjectFadeStart", Vector2( 0.25f, 0.25f ) );
++ shaderEffect.SetUniform( "uObjectFadeEnd", Vector2( 0.5f, 0.5f ) );
++ shaderEffect.SetUniform( "uAlphaScale", 0.75f );
++ shaderEffect.SetUniform( "uModelLastFrame", Matrix::IDENTITY );
++
++ return shaderEffect;
++}
+
+ }
+
+ }
+
+ #endif //#ifndef __DALI_TOOLKIT_SHADER_EFFECT_MOTION_STRETCH_H__
--- /dev/null
-DALI_IMPORT_API void Apply( ImageActor actor, const std::string& maskImage );
+ #ifndef __DALI_TOOLKIT_NINE_PATCH_MASK_EFFECT_H__
+ #define __DALI_TOOLKIT_NINE_PATCH_MASK_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/actors/image-actor.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
+ * @brief NinePatchMaskEffect is used to control which parts of an image are visible, using the alpha channel of a separate mask image.
+ *
+ * The mask image is expected to be smaller than the main image being viewed.
+ * Conceptually the mask image is divided into a 3x3 grid (9 patches). The middle patch is stretched whilst the outer border is not.
+ *
+ * Usage example:
+ *
+ * @code
+ * ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
+ * NinePatchMaskEffect::Apply( actor, MASK_IMAGE_PATH );
+ * @endcode
+ *
+ * NinePatchMaskEffect is mutually exclusive with ImageActor::STYLE_NINE_PATCH i.e. the actor's main image should not be a nine-patch.
+ */
+ namespace NinePatchMaskEffect
+ {
+
++static void NinePatchMaskEffectSizeConstraint( Vector2& current, const PropertyInputContainer& inputs )
++{
++ const Vector3& actorSize = inputs[0]->GetVector3();
++ current.x = actorSize.x;
++ current.y = actorSize.y;
++}
++
++inline void DoApply( ImageActor actor, const std::string& maskImage, const Vector2& maskSize, Vector4 maskBorder )
++{
++ const char* ALPHA_MASK_VERTEX_SHADER_SOURCE =
++ "precision mediump float;\n"
++ "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 mediump 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( ResourceImage::New( maskImage ) );
++
++ maskEffect.SetUniform( "uImageSize", Vector2(0,0) /*Constrained to actor size*/ );
++
++ Constraint constraint = Constraint::New<Vector2>( maskEffect, maskEffect.GetPropertyIndex("uImageSize"), NinePatchMaskEffectSizeConstraint );
++ constraint.AddSource( Source(actor, Actor::Property::SIZE) );
++ constraint.Apply();
++
++ 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 );
++}
++
+ /**
+ * @brief Apply the mask effect to an ImageActor.
+ *
+ * NinePatchMaskEffect is mutually exclusive with ImageActor::STYLE_NINE_PATCH i.e. the actor's main image should not be a nine-patch.
+ * @param [in] actor The actor which needs the effect. To remove the effect call actor.RemoveShaderEffect().
+ * @param [in] maskImage The path to a file containing the mask. The center pixels of the mask will be stretched.
+ */
-DALI_IMPORT_API void Apply( ImageActor actor, const std::string& maskImage, const Vector4& maskBorder );
++inline void Apply( ImageActor actor, const std::string& maskImage )
++{
++ const Uint16Pair maskSize = ResourceImage::GetImageSize( maskImage );
++
++ const float leftRight = (maskSize.GetWidth() - 1.0f) * 0.5f;
++ const float topBottom = (maskSize.GetHeight() - 1.0f) * 0.5f;
++
++ DoApply( actor, maskImage, Vector2( maskSize.GetWidth(), maskSize.GetHeight() ), Vector4( leftRight, topBottom, leftRight, topBottom ) );
++}
+
+ /**
+ * @brief Apply the mask effect to an ImageActor.
+ *
+ * NinePatchMaskEffect is mutually exclusive with ImageActor::STYLE_NINE_PATCH i.e. the actor's main image should not be a nine-patch.
+ * @param [in] actor The actor which needs the effect. To remove the effect call actor.RemoveShaderEffect().
+ * @param [in] maskImage The path to a file containing the mask.
+ * @param [in] maskBorder Specifies the part of the mask image that will be stretched (left, top, right, bottom).
+ */
++inline void Apply( ImageActor actor, const std::string& maskImage, const Vector4& maskBorder )
++{
++ const Uint16Pair maskSize = ResourceImage::GetImageSize( maskImage );
++
++ DoApply( actor, maskImage, Vector2( maskSize.GetWidth(), maskSize.GetHeight() ), maskBorder );
++}
+
+ } // namespace NinePatchMaskEffect
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_NINE_PATCH_MASK_EFFECT_H__
--- /dev/null
- * OverlayEffect overlayEffect = OverlayEffect::New( Image::New( OVERLAY_IMAGE_PATH ) );
+ #ifndef __DALI_TOOLKIT_OVERLAY_EFFECT_H__
+ #define __DALI_TOOLKIT_OVERLAY_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/images/image.h>
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new OverlayEffect
++ *
+ * OverlayEffect is used to apply an overlay image to the actor.
+ * Typically overlay images should be the same size as the main image being viewed, but this isn't essential.
+ *
+ * Usage example:
+ *
+ * ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
-class DALI_IMPORT_API OverlayEffect : public ShaderEffect
++ * ShaderEffect overlayEffect = CreateOverlayEffect( Image::New( OVERLAY_IMAGE_PATH ) );
+ * actor.SetShaderEffect( overlayEffect );
++ *
++ * @param[in] overlayImage The image to overlay on top of the actor
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an empty OverlayEffect handle.
- */
- OverlayEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~OverlayEffect();
++inline ShaderEffect CreateOverlayEffect(Image overlayImage)
+ {
- /**
- * Create a OverlayEffect.
- * @return A handle to a newly allocated OverlayEffect.
- */
- static OverlayEffect New( Image overlayImage );
++ // (Target > 0.5) * (1 - (1-2*(Target-0.5)) * (1-Blend)) + (Target <= 0.5) * ((2*Target) * Blend)
++ const char* OVERLAY_FRAGMENT_SHADER_SOURCE =
++ "void main()\n"
++ "{\n"
++ " lowp vec4 target = texture2D(sTexture, vTexCoord);\n"
++ " lowp vec4 overlay = texture2D(sEffect, vTexCoord);\n"
++ " if ( length( target.rgb ) > 0.5 )\n"
++ " {\n"
++ " gl_FragColor = vec4( mix( target.rgb, 1.0 - ( 1.0 - 2.0 * ( target.rgb - 0.5 ) ) * ( 1.0 - overlay.rgb ), overlay.a ), min( 1.0, target.a + overlay.a ) );\n"
++ " }\n"
++ " else\n"
++ " {\n"
++ " gl_FragColor = vec4( mix( target.rgb, 2.0 * target.rgb * overlay.rgb, overlay.a ), target.a + overlay.a );\n"
++ " }\n"
++ "}\n";
+
-private: // Not intended for application developers
++ ShaderEffect shaderEffect = ShaderEffect::New(
++ "", // Use default
++ OVERLAY_FRAGMENT_SHADER_SOURCE,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
+
- DALI_INTERNAL OverlayEffect( ShaderEffect handle );
-};
++ shaderEffect.SetEffectImage( overlayImage );
+
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_OVERLAY_EFFECT_H__
--- /dev/null
- * @brief QuadraticBezier is a custom shader to render quadratic bezier curves and bounded regions.
+ #ifndef __DALI_TOOLKIT_QUADRATIC_BEZIER_H__
+ #define __DALI_TOOLKIT_QUADRATIC_BEZIER_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+ /**
-
-class DALI_IMPORT_API QuadraticBezier : public ShaderEffect
++ * @brief Creates a new QuadraticBezier shader effect
++ *
++ * QuadraticBezier is a custom shader to render quadratic bezier curves and bounded regions.
+ *
+ * Implementation based on the paper "Resolution Independent Curve Rendering using Programmable Graphics Hardware"
+ * by Charles Loop and Jim Blinn.
+ *
+ * The coordinates of the control points is passed to the shader via uniforms.
+ * aNormal attribute is used to pass the coefficients of each control point (xy coordinates) as well as the vertex ID (z coordinate).
+ * A quadratic curve should have as normal for the first control point (0.0,0.0), (0.5,0.0) for the second and (1.0,1.0) for the third.
+ * Triangles that do not contain curves should have coordinates (0.0,1.0) for each control point in order to be filled properly.
++ *
++ * Animatable/Constrainable uniforms:
++ * "uPoint" - Position coordinates for the points in the curve
++ * "uColor" - The color of the curve or bounded region
++ * "uLineWidth" - The width of the path. Only for not filled curves
++ *
++ * @param[in] pointCount The maximum number of vertices
++ * @param[in] filled Specify whether the the bounded region should be filled or not
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * @brief Create an uninitialized QuadraticBezier; this can be initialized with QuadraticBezier::New().
- *
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- QuadraticBezier();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~QuadraticBezier();
-
- /**
- * @brief Create an initialized QuadraticBezier.
- *
- * @param[in] pointCount The maximum number of vertices
- * @param[in] filled Specify whether the the bounded region should be filled or not
- * @return A handle to a newly allocated Dali resource.
- */
- static QuadraticBezier New(unsigned int pointCount, bool filled );
-
- /**
- * @brief Set position coordinates for a point in the curve
- *
- * @param[in] index The index of the vertex
- * @param[in] position The new position
- */
- void SetPoint( unsigned int index, const Vector3& position );
-
- /**
- * @brief Set the width of the pathThis is only for not filled curves
- *
- * @param[in] width Width of the line in pixels
- */
- void SetLineWidth( float width );
-
- /**
- * @brief Sets the color of the curve
- *
- * @param[in] color The new color
- */
- void SetColor( const Vector4& color );
-
- /**
- * @brief Get the name of a the point property given its index
- *
- * @param[in] index Index of the vertex
- * @return A std::string containing the property name
- */
- std::string GetPointPropertyName( unsigned int index ) const;
-
- /**
- * @brief Get the name of the line width property
- *
- * @return A std::string containing the property name
- */
- std::string GetLineWidthPropertyName( ) const;
-
- /**
- * @brief Get the name of the color property
- *
- * @return A std::string containing the property name
- */
- std::string GetColorPropertyName( ) const;
-
-private: // Not intended for application developers
-
- DALI_INTERNAL QuadraticBezier(ShaderEffect handle);
-
-};
++inline ShaderEffect CreateQuadraticBezier(unsigned int pointCount, bool filled)
+ {
++ std::string vertexShader = DALI_COMPOSE_SHADER
++ (
++ uniform mediump vec3 uPoint[MAX_POINT_COUNT];\n
++ varying highp vec2 vCoefficient;
++ void main()\n
++ {\n
++ int vertexId = int(aNormal.z);\n
++ gl_Position = uMvpMatrix * vec4(uPoint[vertexId], 1.0);\n
++ vCoefficient = aNormal.xy;\n
++ }\n
++ );
++
++ std::string fragmentShader;
++
++ if( filled )
++ {
++ fragmentShader = DALI_COMPOSE_SHADER
++ (
++ varying highp vec2 vCoefficient;\n
++
++ void main()\n
++ {\n
++ highp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y);\n
++ highp float Cdx = dFdx(C);\n
++ highp float Cdy = dFdy(C);\n
++
++ highp float distance = float(C / sqrt(Cdx*Cdx + Cdy*Cdy));\n
++
++ gl_FragColor = uColor;\n
++ highp float alpha = 0.5 - distance;\n
++ if( alpha < 0.0 )\n
++ discard;\n
++
++ gl_FragColor.w = alpha;\n
++ }\n
++ );
++ }
++ else
++ {
++ fragmentShader = DALI_COMPOSE_SHADER
++ (
++ varying highp vec2 vCoefficient;\n
++ uniform lowp float uLineWidth;\n
++
++ void main()\n
++ {\n
++ highp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y);\n
++ highp float Cdx = dFdx(C);\n
++ highp float Cdy = dFdy(C);\n
++ highp float distance = abs(float(C / sqrt(Cdx*Cdx + Cdy*Cdy)));\n
++ gl_FragColor = uColor*(uLineWidth-distance);\n
++ }\n
++ );
++ }
++
++ std::ostringstream vertexShaderPrefix;
++ vertexShaderPrefix << "#define MAX_POINT_COUNT "<< pointCount << "\n";
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::NewWithPrefix(
++ vertexShaderPrefix.str(),vertexShader,
++ "#extension GL_OES_standard_derivatives:enable\n", fragmentShader,
++ GeometryType(GEOMETRY_TYPE_UNTEXTURED_MESH) );
++
++ //Set default uniform values
++ shaderEffect.SetUniform( "uColor", Vector4(1.0f,1.0f,1.0f,1.0f) );
++ if( !filled )
++ {
++ //Set default line widht to 1 pixel
++ shaderEffect.SetUniform( "uLineWidth", 1.0f );
++ }
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_IMAGE_REGION_EFFECT_H__
--- /dev/null
- * @brief RippleEffect is a custom shader effect to achieve ripple effects on Image actors.
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API RippleEffect : public ShaderEffect
++ * @brief Creates a new RippleEffect
++ *
++ * RippleEffect is a custom shader effect to achieve ripple effects on Image actors.
++ *
++ * Animatable/Constrainable uniforms:
++ * "uAmplitude" - The amplitude of the effect
++ * "uCenter" - The center point of the effect as screen coordinates
++ * "uTime" - The time duration for the ripple
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * @brief Create an uninitialized RippleEffect; this can be initialized with RippleEffect::New().
- *
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- RippleEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~RippleEffect();
-
- /**
- * @brief Create an initialized RippleEffect.
- *
- * @return A handle to a newly allocated Dali resource.
- */
- static RippleEffect New();
-
- /**
- * @brief Set the amplitude of the effect.
- *
- * @param [in] amplitude The new amplitude.
- */
- void SetAmplitude(float amplitude);
-
- /**
- * @brief Set the center point of the effect as screen coordinates.
- *
- * @param [in] center The new center point.
- */
- void SetCenter(const Vector2& center);
-
- /**
- * @brief Set the time duration for the ripple.
- *
- * @param[in] time The time duration in float.
- */
- void SetTime(float time);
-
- /**
- * @brief Get the name for the amplitude property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetAmplitudePropertyName() const;
-
- /**
- * @brief Get the name for the center property.
- *
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
- /**
- * @brief Get the name for the time property.
- *
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetTimePropertyName() const;
-
-private:
- DALI_INTERNAL RippleEffect(ShaderEffect handle);
-
-};
++inline ShaderEffect CreateRippleEffect()
+ {
++ std::string vertexShader(
++ "precision mediump float;\n"
++ "uniform mediump vec2 uCenter;\n"
++ "uniform mediump float uTime;\n"
++ "uniform mediump float uAmplitude;\n"
++ "varying mediump float vLight;\n"
++ "varying mediump float vShade;\n"
++ "void main()\n"
++ "{\n"
++ "float lighting = uAmplitude * 0.02;\n"
++ "float waveLength = uAmplitude * 0.0016;\n"
++ "vec4 world = uModelView * vec4(aPosition,1.0);\n"
++ "vec2 d = vec2(world.x - uCenter.x, world.y - uCenter.y);\n"
++ "float dist = length(d);\n"
++ "float amplitude = cos(uTime - dist*waveLength);\n"
++ "float slope = sin(uTime - dist*waveLength);\n"
++ "world.z += amplitude * uAmplitude;\n"
++ "gl_Position = uProjection * world;\n"
++ "vec2 lightDirection = vec2(-0.707,0.707);\n"
++ "float dot = 0.0;\n"
++ "if(dist > 0.0)\n"
++ "{\n"
++ " dot = dot(normalize(d),lightDirection) * lighting;\n"
++ "}\n"
++ "vShade = 1.0 - (dot * slope);\n"
++ "vLight = max(0.0, dot * -slope);\n"
++ "vTexCoord = aTexCoord;\n"
++ "}" );
++
++ // append the default version
++ std::string imageFragmentShader(
++ "precision mediump float;\n"
++ "varying mediump float vLight;\n"
++ "varying mediump float vShade;\n"
++ "void main()\n"
++ "{\n"
++ " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(vShade,vShade,vShade,1.0) + vec4(vLight, vLight, vLight,0.0);\n"
++ "}" );
++
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ vertexShader, imageFragmentShader,
++ GeometryType(GEOMETRY_TYPE_IMAGE), ShaderEffect::GeometryHints(ShaderEffect::HINT_GRID) );
++
++
++ shaderEffect.SetUniform( "uAmplitude", 0.0f );
++ shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f));
++ shaderEffect.SetUniform( "uTime", 0.0f );
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__
--- /dev/null
- * @brief Ripple2DEffect is a custom shader effect to achieve 2d ripple effects on Image actors.
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API Ripple2DEffect : public ShaderEffect
++ * @brief Creates a new Ripple2DEffect
++ *
++ * Ripple2DEffect is a custom shader effect to achieve 2d ripple effects on Image actors.
++ *
++ * Animatable/Constrainable uniforms:
++ * "uTime" - The time duration for the 2d ripple
++ * "uAmplitude" - The amplitude of the 2d ripple
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * @brief Create an uninitialized Ripple2DEffect; this can be initialized with Ripple2DEffect::New().
- *
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- Ripple2DEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~Ripple2DEffect();
-
- /**
- * @brief Create an initialized Ripple2DEffect.
- *
- * @return A handle to a newly allocated Dali resource.
- */
- static Ripple2DEffect New();
-
- /**
- * @brief Set the amplitude of the 2d ripple.
- *
- * @param[in] amplitude The amplitude in float.
- */
- void SetAmplitude(float amplitude);
-
- /**
- * @brief Set the time duration for the 2d ripple.
- *
- * @param[in] time The time duration in float.
- */
- void SetTime(float time);
-
- /**
- * @brief Get the name for the amplitude property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetAmplitudePropertyName() const;
-
- /**
- * @brief Get the name for the time property.
- *
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetTimePropertyName() const;
-
-private:
- DALI_INTERNAL Ripple2DEffect(ShaderEffect handle);
-
-};
++inline ShaderEffect CreateRipple2DEffect()
+ {
++ // append the default version
++ std::string fragmentShader(
++ "precision mediump float;\n"
++ "uniform float uAmplitude;\n"
++ "uniform float uTime;\n"
++ "void main()\n"
++ "{\n"
++ " highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\n"
++ " highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\n"
++ " highp float len = length(pos);\n"
++ " highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\n"
++ " gl_FragColor = texture2D(sTexture, texCoord) * uColor;\n"
++ "}" );
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ "", fragmentShader,
++ Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
++
++
++
++ shaderEffect.SetUniform( "uTextureSize", Vector2(0.0f, 0.0f) ); //@note: Is this needed?
++ shaderEffect.SetUniform( "uAmplitude", 0.0f );
++ shaderEffect.SetUniform( "uTime", 0.0f );
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
--- /dev/null
-class DALI_IMPORT_API ShearEffect : public ShaderEffect
+ #ifndef __DALI_TOOLKIT_SHEAR_EFFECT_H__
+ #define __DALI_TOOLKIT_SHEAR_EFFECT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new ShearEffect
++ *
+ * ShearEffect is a custom shader effect to achieve shear effects in Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ * "uCenter" - The center point of the shear effect in screen coordinates
++ * "uAngleXAxis" - The angle of the shear effect in the X axis
++ * "uAngleYAxis" - The angle of the shear effect in the Y axis
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an uninitialized ShearEffect; this can be initialized with ShearEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- ShearEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~ShearEffect();
-
- /**
- * Create an initialized ShearEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static ShearEffect New();
-
- /**
- * Set the center point of the shear effect in screen coordinates.
- * @param [in] center The new center point.
- */
- void SetCenter(const Vector2& center);
-
- /**
- * Set the angle of the shear effect in the X axis.
- * @param [in] angle The new angle.
- */
- void SetAngleXAxis(float angle);
-
- /**
- * Set the angle of the shear effect in the Y axis.
- * @param [in] angle The new angle.
- */
- void SetAngleYAxis(float angle);
-
- /**
- * Get the name for the center property
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
- /**
- * Get the name for the X axis property
- * @return A std::string containing the property name
- */
- const std::string& GetAngleXAxisPropertyName() const;
-
- /**
- * Get the name for the Y axis property
- * @return A std::string containing the property name
- */
- const std::string& GetAngleYAxisPropertyName() const;
-
-
-private: // Not intended for application developers
- DALI_INTERNAL ShearEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateShearEffect()
+ {
++ // append the default version
++ std::string vertexShader(
++ "uniform mediump vec2 uCenter;\n"
++ "uniform mediump float uAngleXAxis;\n"
++ "uniform mediump float uAngleYAxis;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ "mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
++ "\n"
++ "world.x = world.x + tan(radians(uAngleXAxis)) * (world.y - uCenter.y * world.w);\n"
++ "world.y = world.y + tan(radians(uAngleYAxis)) * (world.x - uCenter.x * world.w);\n"
++ "\n"
++ "gl_Position = uProjection * world;\n"
++ "\n"
++ "vTexCoord = aTexCoord;\n"
++ "}" );
++
++ // Create the implementation, temporarily owned on stack,
++ ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ vertexShader,
++ "",
++ Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID ));
++
++
++ shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
++ shaderEffect.SetUniform( "uAngleXAxis", 0.0f);
++ shaderEffect.SetUniform( "uAngleYAxis", 0.0f);
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHEAR_EFFECT_H__
--- /dev/null
- * Class for soft button shader that works on a per object basis. Using animatable parameters user can create effect of button pushing in / out. Can be applied to ImageActor only.
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SOFT_BUTTON_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_SOFT_BUTTON_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new soft button shader effect
+ *
- * SoftButtonEffect softButtonEffect = SoftButtonEffect::New();
++ * Soft button shader effect works on a per object basis. Using animatable parameters user can create
++ * effect of button pushing in / out. Can be applied to ImageActor only.
+ *
+ * Usage example:-
+ *
+ * // Create shader used for doing soft button\n
- * animation.AnimateTo( Property(softButtonEffect, softButtonEffect.GetLightingIndentationAmountPropertyName()), 0.25f, AlphaFunction::BOUNCE, ... );\n
- * animation.AnimateTo( Property(softButtonEffect, softButtonEffect.GetLightingIndentationAmountPropertyName()), -0.05f, AlphaFunction::BOUNCE, ... );\n
- * animation.AnimateTo( Property(softButtonEffect, softButtonEffect.GetTextureDistortionAmountPropertyName()), 0.25f, AlphaFunction::BOUNCE, ... );\n
- * animation.AnimateTo( Property(softButtonEffect, softButtonEffect.GetTextureDistortionAmountPropertyName()), -0.05f, AlphaFunction::BOUNCE, ... );\n
++ * ShaderEffect softButtonEffect = CreateSoftButtonEffect();
+ *
+ * // set image actor shader to the soft button one\n
+ * ImageActor imageActor = ImageActor::New( ... );\n
+ * imageActor.SetShaderEffect( softButtonEffect );
+ *
+ * // animate a button push, using e.g. AlphaFunction::BOUNCE. With these values the button pushes in and pops out slightly at the end\n
+ * Animation animation = Animation::New( ... );\n
-class DALI_IMPORT_API SoftButtonEffect : public ShaderEffect
++ * animation.AnimateTo( Property(softButtonEffect, "uLightingIndentationAmount), 0.25f, AlphaFunction::BOUNCE, ... );\n
++ * animation.AnimateTo( Property(softButtonEffect, "uLightingIndentationAmount"), -0.05f, AlphaFunction::BOUNCE, ... );\n
++ * animation.AnimateTo( Property(softButtonEffect, "uTextureDistortAmount"), 0.25f, AlphaFunction::BOUNCE, ... );\n
++ * animation.AnimateTo( Property(softButtonEffect, "uTextureDistortAmount"), -0.05f, AlphaFunction::BOUNCE, ... );\n
+ * animation.Play();\n
+ *
++ * Animatable/Constrainable uniforms:
++ *
++ * "uLightingIndentationAmount" - This property changes the lighting, to make it look like the button is pushed in. User should animate
++ * this in conjunction with texture distortion. Allowable values range from [-1..1], higher values give
++ * more change in lighting. Default 0.0 (no lighting change).
++ * "uTextureDistortAmount" - This property changes the distortion, to make it look like the button is pushed in. User should animate
++ * this in conjunction with lighting indentation. Allowable values range from [-1..1) - note 1.0 is NOT
++ * allowed - higher values give more distortion. Default 0.0 (no distortion).
++ * "uAmbientLight" - The ambient light is used in the lighting calculation. Care must be taken to not saturate the image by
++ * setting this value too high, or the indentation will not look correct. Default 0.15
++ * "uDiffuseLight" - The diffuse light is used in the lighting calculation. Default is (0.0, 0.7070168, 0.7070168),
++ * i.e. a light angled at the surface from in front and above. Note that you need to Normalize()
++ * the Vector3 that you set with this property
++ * "uLightMultiplier" - The ambient and diffuse lighting is multiplied by this factor. Since a diffuse light at an angle will
++ * cause the whole image to darken, even outside the soft button indentation, this property can be used
++ * to scale the image back up closer to the pixel values of the original diffuse texture. Care must be
++ * taken to not saturate the image,or the indentation will not look correct. Default 1.2.
++ * "uInsideCircleSizeScale" - The SoftButtonEffect consists of two shapes, one inside the other. The outside shape fits exactly to
++ * the actor, touching its edges but completely contained. The inside shape size is given by a multiplier
++ * of the outside shape size. For example a value of 0.5 means that the inside shape is half the size of
++ * the outside one. Allowable values are in the range (0.0 - 1.0), note that 0.0 and 1.0 themselves are
++ * not allowed. Default 0.75.
++ * "uOutsideCircleDepth" - The SoftButtonEffect consists of two shapes, one inside the other. The depth of the indentation at the
++ * transition between the inside and outside shapes is controlled by this property. The values lies in the
++ * range [0.0 - 1.0]. A value of 0.0 means the outside shape has no depth (and is thus invisible), value of
++ * 1.0 means the outside shape has maximum depth (and the inside shape is thus invisible). Default 0.05
++ * "uEffectRegion" - The soft button effect is applied within the supplied rect region of the texture. Default values for this
++ * is (0.0, 0.0, 1.0, 1.0) which is the entire image with 0,0 being the top left and 1.0, 1.0 being the bottom
++ * right. If the image texture is split between multiple ImageActors then the developer should specify the pixel
++ * area of the texture the effect should be applied with. Example, If the Image is split among two ImageActors
++ * side by side, with the left one using left half of the texture and right one using the right half of the
++ * texture then the pixel area value for the left ImageActor will be (0.0, 0.0, 0.5, 1.0) and the pixel area for
++ * the right will be (0.5,0.0,1.0,1.0).
++ * "uRectangleSizeScale" - This property can be used to set the mix between proportion of rectangle and proportion of ellipse - the
++ * result is a rectangle with rounded corners. If the value is 0.0, the shape is an ellipse. If the value is
++ * close to 1.0, the shape is close to a rectangle. The value lies in the range [0.0 - 1.0). Note that a value
++ * of 1.0 is NOT allowed.Default 0.5.
++ *
++ * @param type The type of the soft button, can be either ELLIPTICAL, RECTANGULAR, or FIXED.
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
++typedef enum
+ {
++ SOFT_BUTTON_ELLIPTICAL = 0, /// Button is elliptical
++ SOFT_BUTTON_RECTANGULAR, /// Button is rectangular
++ SOFT_BUTTON_FIXED /// Button does not indent (move). Useful for matching lighting between areas that do not indent (which can thus use a cheaper shader) and those that do indent.
++}SoftButtonEffectType;
++
++static void InverseConstraint( float& current, const PropertyInputContainer& inputs )
++{
++ current = 1.0f / inputs[0]->GetFloat();
++}
++
++inline ShaderEffect CreateSoftButtonEffect(SoftButtonEffectType type)
++{
++ std::string vertexSource;
++ vertexSource = "precision mediump float;\n"
++ "uniform vec3 uDiffuseLight;\n"
++ "uniform float uAmbientLight;\n"
++ "uniform float uLightMultiplier;\n"
++ "uniform vec4 uEffectRegion;\n"
++ "varying vec2 vCentredCoord;\n"
++
++ "const vec3 norm = vec3(0.0, 0.0, 1.0);\n"
++
++ "void main()\n"
++ "{\n"
++ " vTexCoord = aTexCoord;\n"
++ // Get the rect coords of the effect region in -1..1 range, i.e. circle centred around the center of the rect
++ // Done in the vertex shader itself to make use of gl interpolation for varying.
++ " vCentredCoord = vec2( ( (vTexCoord.x - uEffectRegion.x)/(uEffectRegion.z - uEffectRegion.x) * 2.0 - 1.0 ), ( (vTexCoord.y - uEffectRegion.y)/(uEffectRegion.w - uEffectRegion.y) * 2.0 - 1.0 ) );\n"
++ " gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n"
++ "}\n";
++
++ std::string fragmentSourceFixed;
++ fragmentSourceFixed = "precision mediump float;\n"
++
++ "uniform vec3 uDiffuseLight;\n"
++ "uniform float uAmbientLight;\n"
++ "uniform float uLightMultiplier;\n"
++ "varying vec2 vCentredCoord;\n"
++
++ "const vec3 norm = vec3(0.0, 0.0, 1.0);\n"
++
++ "void main()\n"
++ "{\n"
++ " vec4 col = texture2D(sTexture, vTexCoord);\n"
++ // calc lighting
++ " float lighting = (dot(uDiffuseLight, norm) + uAmbientLight) * uLightMultiplier;\n"
++ // output col = image * light
++ // use the lighting value for colors only
++ " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
++ "}\n";
++
++ std::string fragmentSourceElliptical;
++ fragmentSourceElliptical = "precision mediump float;\n"
++
++ "uniform float uLightingIndentationAmount;\n"
++ "uniform float uTextureDistortAmount;\n"
++ "uniform vec3 uDiffuseLight;\n"
++ "uniform float uAmbientLight;\n"
++ "uniform float uLightMultiplier;\n"
++ "uniform float uInsideCircleSizeScale;\n"
++ "uniform float uRecipInsideCircleSizeScale;\n"
++ "uniform float uOutsideCircleDepth;\n"
++ "uniform vec4 uEffectRegion;\n"
++ "varying vec2 vCentredCoord;\n"
++
++ "const float PI = 3.1415927;\n"
++
++ "void main()\n"
++ "{\n"
++ // Apply distortion only if the pixel is within the rect specified
++ "if( (vTexCoord.x > uEffectRegion.x) && (vTexCoord.x < uEffectRegion.z) && (vTexCoord.y > uEffectRegion.y) && (vTexCoord.y < uEffectRegion.w) )\n"
++ "{\n"
++ " vec2 coord = vCentredCoord;\n"
++
++ // find a coordinate representing distance from circle centre, such that we split into inside / outside circles that can have different gradients / normals
++ " float realDistFromCentre = length(coord);\n"
++ " realDistFromCentre = min(1.0, realDistFromCentre);\n" // clamp corners of square to vertical normal
++ " float distFromCentre;\n"
++ " if(realDistFromCentre <= uInsideCircleSizeScale)\n"
++ " {\n"
++ " distFromCentre = realDistFromCentre * uRecipInsideCircleSizeScale * (1.0 - uOutsideCircleDepth);\n" // inside circle indent, up to outline depth
++ " }\n"
++ " else \n"
++ " {\n"
++ " distFromCentre = mix(1.0 - uOutsideCircleDepth, 1.0, (realDistFromCentre - ( uInsideCircleSizeScale)) / (1.0 - uInsideCircleSizeScale));\n" // outside circle
++ " }\n"
+
- /**
- * Create an uninitialized SoftButtonEffect; this can be initialized with SoftButtonEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- SoftButtonEffect();
++ // get coords in -PI..PI range, i.e. scale the circle for use by trig functions
++ " coord *= PI;\n"
+
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~SoftButtonEffect();
++ // get a z value for the distorted surface in 0..1 range, using cos for a smooth curve (note, we ignore inside / outside circles since the difference isn't noticeable visually)
++ " vec2 cosThetaCoord = (cos(coord) * 0.5) + 0.5;\n"
++ " float z = cosThetaCoord.x * cosThetaCoord.y;\n"
+
- typedef enum
++ // get the normal for the distorted surface, using the fact that the derivative of cos is -sin, finding tangent vector from slope and then normal by cross product...
++ " float sinThetaCoord = sin(distFromCentre*PI) * uLightingIndentationAmount;\n" // slope, so tangent vec is (1.0, -sin)
++ // ...2D normal vector along distFromCentre vec is (sin, 1.0), convert to components in 3D.
++ " vec3 norm = normalize(vec3(coord.x * sinThetaCoord, coord.y * sinThetaCoord, 1.0));\n"
+
- ELLIPTICAL = 0, /// Button is elliptical
- RECTANGULAR, /// Button is rectangular
- FIXED /// Button does not indent (move). Useful for matching lighting between areas that do not indent (which can thus use a cheaper shader) and those that do indent.
- }Type;
-
- /**
- * Create an initialized SoftButtonEffect
- * @param type The type of the soft button, can be either ELLIPTICAL, RECTANGULAR, or FIXED.
- * @return A handle to a newly allocated Dali resource.
- */
- static SoftButtonEffect New(Type type);
-
- /**
- * Get the name for the lighting indentation amount property (float). Useful for animation.
- * This property changes the lighting, to make it look like the button is pushed in. User should animate this in conjunction
- * with texture distortion. Allowable values range from [-1..1], higher values give more change in lighting. Default 0.0 (no lighting change).
- * See also GetTextureDistortionAmountPropertyName().
- * @return A std::string containing the property name
- */
- const std::string& GetLightingIndentationAmountPropertyName() const;
-
- /**
- * Get the name for the texture distortion amount property (float). Useful for animation.
- * This property changes the distortion, to make it look like the button is pushed in. User should animate this is conjunction
- * with lighting indentation. Allowable values range from [-1..1) - note 1.0 is NOT allowed - higher values give more distortion. Default 0.0 (no distortion).
- * See also GetLightingIndentationAmountPropertyName().
- * @return A std::string containing the property name
- */
- const std::string& GetTextureDistortionAmountPropertyName() const;
-
- /**
- * Get the name for the ambient lighting amount property (float)
- * The ambient light is used in the lighting calculation. Care must be taken to not saturate the image by setting this value too high,
- * or the indentation will not look correct. Default 0.15.
- * @return A std::string containing the property name
- */
- const std::string& GetAmbientLightAmountPropertyName() const;
-
- /**
- * Get the name for the diffuse light property (Vector3).
- * The diffuse light is used in the lighting calculation. Default is (0.0, 0.7070168, 0.7070168), i.e. a light angled at the surface from in front and above. Note that
- * you need to Normalize() the Vector3 that you set with this property.
- * @return A std::string containing the property name
- */
- const std::string& GetDiffuseLightPropertyName() const;
-
- /**
- * Get the name for the lighting multiplier property (float).
- * The ambient and diffuse lighting is multiplied by this factor. Since a diffuse light at an angle will cause the whole image to darken, even outside the soft button
- * indentation, this property can be used to scale the image back up closer to the pixel values of the original diffuse texture. Care must be taken to not saturate the image,
- * or the indentation will not look correct. Default 1.2.
- * @return A std::string containing the property name
- */
- const std::string& GetLightingMultiplierPropertyName() const;
-
- /**
- * Get the name for the inside shape size scale property (float).
- * The SoftButtonEffect consists of two shapes, one inside the other. The outside shape fits exactly to the actor, touching its edges but completely contained. The inside
- * shape size is given by a multiplier of the outside shape size. For example a value of 0.5 means that the inside shape is half the size of the outside one. Allowable
- * values are in the range (0.0 - 1.0), note that 0.0 and 1.0 themselves are not allowed. Default 0.75.
- * See also GetOutsideShapeDepthPropertyName().
- * @return A std::string containing the property name
- */
- const std::string& GetInsideShapeSizeScalePropertyName() const;
-
- /**
- * Get the name for the outside shape depth property (float).
- * The SoftButtonEffect consists of two shapes, one inside the other. The depth of the indentation at the transition between the inside and outside shapes is controlled by
- * this property. The values lies in the range [0.0 - 1.0]. A value of 0.0 means the outside shape has no depth (and is thus invisible), value of 1.0 means the outside shape
- * has maximum depth (and the inside shape is thus invisible). Default 0.05.
- * See also GetInsideShapeSizeScalePropertyName().
- * @return A std::string containing the property name
- */
- const std::string& GetOutsideShapeDepthPropertyName() const;
-
- /**
- * Get the name for the effect pixel area property (Vector4).
- * The soft button effect is applied within the supplied rect region of the texture. Default values for this is (0.0, 0.0, 1.0, 1.0) which is the entire image with
- * 0,0 being the top left and 1.0, 1.0 being the bottom right. If the image texture is split between multiple ImageActors then the developer should specify the
- * pixel area of the texture the effect should be applied with. Example, If the Image is split among two ImageActors side by side, with the left one using left half of the
- * texture and right one using the right half of the texture then the pixel area value for the left ImageActor will be (0.0, 0.0, 0.5, 1.0) and the pixel area for the right
- * will be (0.5, 0.0, 1.0, 1.0).
- * @return A std::string containing the property name
- */
- const std::string& GetEffectPixelAreaPropertyName() const;
-
- /**
- * Get the name for the rectangle size scale property (float). Only applicable having created this SoftButtonEffect via a call to New() with RECTANGULAR as the type.
- * This property can be used to set the mix between proportion of rectangle and proportion of ellipse - the result is a rectangle with rounded corners. If the value is 0.0,
- * the shape is an ellipse. If the value is close to 1.0, the shape is close to a rectangle. The value lies in the range [0.0 - 1.0). Note that a value of 1.0 is NOT allowed.
- * Default 0.5.
- * @return A std::string containing the property name
- */
- const std::string& GetRectangleSizeScalePropertyName() const;
-
-
-private:
- // Not intended for application developers
- DALI_INTERNAL SoftButtonEffect(ShaderEffect handle);
-};
++ // form surface z and project texture onto it.
++ " float indentAmount = 1.0 / (1.0 - (z * uTextureDistortAmount));\n"
++ " vec2 distortedCoord = vCentredCoord * indentAmount;\n"
++
++ // Convert the rect coordinates in -1 to 1 range back to the original coordinates
++ " vec2 texCoord = vec2( ( (distortedCoord.x + 1.0)*(0.5) * (uEffectRegion.z - uEffectRegion.x) + uEffectRegion.x ), ( (distortedCoord.y + 1.0)*(0.5) * (uEffectRegion.w - uEffectRegion.y) + uEffectRegion.y ) ); \n"
++ " vec4 col = texture2D(sTexture, texCoord);\n"
++
++ // calc lighting
++ " float lighting = (dot(uDiffuseLight, norm) + uAmbientLight) * uLightMultiplier;\n"
++ " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
++ "}\n"
++ "else\n"
++ "{\n"
++ " vec4 col = texture2D(sTexture, vTexCoord);\n"
++ " float lighting = (dot(uDiffuseLight, vec3(0.0, 0.0, 1.0)) + uAmbientLight) * uLightMultiplier;\n"
++ " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
++ "}\n"
++ "}\n";
++
++ std::string fragmentSourceRectangular;
++ fragmentSourceRectangular = "precision mediump float;\n"
++
++ "uniform float uLightingIndentationAmount;\n"
++ "uniform float uTextureDistortAmount;\n"
++ "uniform vec3 uDiffuseLight;\n"
++ "uniform float uAmbientLight;\n"
++ "uniform float uLightMultiplier;\n"
++ "uniform float uInsideCircleSizeScale;\n"
++ "uniform float uRecipInsideCircleSizeScale;\n"
++ "uniform float uOutsideCircleDepth;\n"
++ "uniform float uRectangleSizeScale;\n"
++ "uniform vec4 uEffectRegion;\n"
++ "varying vec2 vCentredCoord;\n"
++
++ "const float PI = 3.1415927;\n"
++
++ "void main()\n"
++ "{\n"
++ // Apply distortion only if the pixel is within the rect specified
++ "if( (vTexCoord.x > uEffectRegion.x) && (vTexCoord.x < uEffectRegion.z) && (vTexCoord.y > uEffectRegion.y) && (vTexCoord.y < uEffectRegion.w) )\n"
++ "{ \n"
++ // get the rect coords to -1..1 range, i.e. circle centred around the center of the rect
++ " vec2 centredCoord = vCentredCoord;\n"
++ // clamp coords such that the circle is split into 4 pieces that lie in the corners of the actor. uRectangleScale is the distance along each axis from the centre
++ // of the actor, e.g. 0.5 is half way along an axis from centre to actor edge.
++ " vec2 clampedCoord;\n"
++ " if(centredCoord.x > 0.0)\n"
++ " {\n"
++ " if(centredCoord.x < uRectangleSizeScale)\n"
++ " {\n"
++ // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
++ " clampedCoord.x = 0.0;\n"
++ " }\n"
++ " else\n"
++ " {\n"
++ // we are outside rectangular region along this axis, so we want curvature.
++ " clampedCoord.x = smoothstep(0.0, 1.0, (centredCoord.x - uRectangleSizeScale) / (1.0 - uRectangleSizeScale));\n"
++ " }\n"
++ " }\n"
++ " else\n"
++ " {\n"
++ " if(centredCoord.x > -uRectangleSizeScale)\n"
++ " {\n"
++ // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
++ " clampedCoord.x = 0.0;\n"
++ " }\n"
++ " else\n"
++ " {\n"
++ // we are outside rectangular region along this axis, so we want curvature.
++ " clampedCoord.x = -smoothstep(0.0, 1.0, (centredCoord.x + uRectangleSizeScale) / (uRectangleSizeScale - 1.0));\n"
++ " }\n"
++ " }\n"
++ " if(centredCoord.y > 0.0)\n"
++ " {\n"
++ " if(centredCoord.y < uRectangleSizeScale)\n"
++ " {\n"
++ // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
++ " clampedCoord.y = 0.0;\n"
++ " }\n"
++ " else\n"
++ " {\n"
++ // we are outside rectangular region along this axis, so we want curvature.
++ " clampedCoord.y = smoothstep(0.0, 1.0, (centredCoord.y - uRectangleSizeScale) / (1.0 - uRectangleSizeScale));\n"
++ " }\n"
++ " }\n"
++ " else\n"
++ " {\n"
++ " if(centredCoord.y > -uRectangleSizeScale)\n"
++ " {\n"
++ // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
++ " clampedCoord.y = 0.0;\n"
++ " }\n"
++ " else\n"
++ " {\n"
++ // we are outside rectangular region along this axis, so we want curvature.
++ " clampedCoord.y = -smoothstep(0.0, 1.0, (centredCoord.y + uRectangleSizeScale) / (uRectangleSizeScale - 1.0));\n"
++ " }\n"
++ " }\n"
++ // get coords in -PI..PI range, i.e. scale above circle for use by trig functions
++ " vec2 thetaCoord = clampedCoord * PI;\n"
++ // get a z value for the distorted surface in 0..1 range, using cos for a smooth curve (note, we ignore inside / outside circles since the difference isn't noticeable visually)
++ " vec2 cosThetaCoord = (cos(thetaCoord) * 0.5) + 0.5;\n"
++ " float z = cosThetaCoord.x * cosThetaCoord.y;\n"
++ // find a coordinate representing distance from circle centre, such that we split into inside / outside circles that can have different gradients / normals
++ " float realDistFromCentre = length(thetaCoord);\n"
++ " realDistFromCentre = min(PI, realDistFromCentre);\n" // clamp corners of square to vertical normal
++ " float distFromCentre;\n"
++ " if(realDistFromCentre <= PI * uInsideCircleSizeScale)\n"
++ " {\n"
++ " distFromCentre = realDistFromCentre * uRecipInsideCircleSizeScale * (PI - (uOutsideCircleDepth * PI)) / PI;\n" // inside circle indent, up to outline depth
++ " }\n"
++ " else\n"
++ " {\n"
++ " distFromCentre = mix(PI - (uOutsideCircleDepth * PI), PI, (realDistFromCentre - ( PI * uInsideCircleSizeScale)) / (PI - (PI * uInsideCircleSizeScale)));\n" // outside circle
++ " }\n"
++ // get the normal for the distorted surface, using the fact that the derivative of cos is -sin, finding tangent vector from slope and then normal by cross product...
++ " float sinThetaCoord = sin(distFromCentre) * uLightingIndentationAmount;\n" // slope, so tangent vec is (1.0, -sin)
++ // ...2D normal vector along distFromCentre vec is (sin, 1.0), convert to components in 3D.
++ " vec3 norm = normalize(vec3(thetaCoord.x * sinThetaCoord, thetaCoord.y * sinThetaCoord, 1.0));\n"
++ // form surface z and project texture onto it.
++ " float indentAmount = 1.0 / (1.0 - (z * uTextureDistortAmount));\n"
++ " vec2 distortedCoord = centredCoord * indentAmount;\n"
++ // Convert the rect coordinates in -1 to 1 range back to the original coordinates
++ " vec2 texCoord = vec2( ( (distortedCoord.x + 1.0)/(2.0) * (uEffectRegion.z - uEffectRegion.x) + uEffectRegion.x ), ( (distortedCoord.y + 1.0)/(2.0) * (uEffectRegion.w - uEffectRegion.y) + uEffectRegion.y ) );\n"
++ " vec4 col = texture2D(sTexture, texCoord);\n"
++ // calc lighting
++ " float lighting = (dot(uDiffuseLight, norm) + uAmbientLight) * uLightMultiplier;\n"
++ // output col = image * light
++ // use the lighting value for colors only
++ " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
++
++ "}\n"
++ "else\n"
++ "{\n"
++ " vec4 col = texture2D(sTexture, vTexCoord);\n"
++ " float lighting = (dot(uDiffuseLight, vec3(0.0, 0.0, 1.0)) + uAmbientLight) * uLightMultiplier;\n"
++ " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
++ "} \n"
++ "}\n";
++
++
++ //////////////////////////////////////
++ // Create shader effectCreateSoftButtonEffect
++ //
++ //
++
++ ShaderEffect shader;
++ switch(type)
+ {
++ case SOFT_BUTTON_RECTANGULAR:
++ shader = ShaderEffect::New( vertexSource, fragmentSourceRectangular, GeometryType( GEOMETRY_TYPE_IMAGE ), ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ));
++ break;
++
++ case SOFT_BUTTON_ELLIPTICAL:
++ shader = ShaderEffect::New( vertexSource, fragmentSourceElliptical, GeometryType( GEOMETRY_TYPE_IMAGE ), ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ));
++ break;
++
++ case SOFT_BUTTON_FIXED:
++ default:
++ shader = ShaderEffect::New( vertexSource, fragmentSourceFixed, GeometryType( GEOMETRY_TYPE_IMAGE ), ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ));
++ break;
++ }
++
++ //////////////////////////////////////
++ // Register uniform properties
++ //
++ //
++ static const float SOFT_BUTTON_LIGHTING_INDENTATION_AMOUNT_DEFAULT = 0.0f;
++ static const float SOFT_BUTTON_TEXTURE_DISTORTION_AMOUNT_DEFAULT = 0.0f;
++ static const float SOFT_BUTTON_AMBIENT_LIGHT_AMOUNT_DEFAULT = 0.15f;
++ static const Vector3 SOFT_BUTTON_DIFFUSE_LIGHT_DEFAULT = Vector3(0.0f, 0.7070168f, 0.7071068f);
++ static const float SOFT_BUTTON_LIGHTING_MULTIPLIER_DEFAULT = 1.2f;
++ static const float SOFT_BUTTON_INSIDE_SHAPE_SIZE_SCALE_DEFAULT = 0.75f;
++ static const float SOFT_BUTTON_OUTSIDE_SHAPE_DEPTH_DEFAULT = Math::PI * 0.05f;
++ static const Vector4 SOFT_BUTTON_EFFECT_PIXEL_AREA_DEFAULT = Vector4(0.0f, 0.0f, 1.0f, 1.0f);
++ static const float SOFT_BUTTON_RECTANGLE_SIZE_SCALE_DEFAULT = 0.5f;
++
++ // factors that scale the look, defaults
++ shader.SetUniform("uAmbientLight", SOFT_BUTTON_AMBIENT_LIGHT_AMOUNT_DEFAULT);
++ shader.SetUniform("uDiffuseLight", SOFT_BUTTON_DIFFUSE_LIGHT_DEFAULT);
++ shader.SetUniform("uLightMultiplier", SOFT_BUTTON_LIGHTING_MULTIPLIER_DEFAULT);
++ if(SOFT_BUTTON_FIXED != type)
++ {
++ shader.SetUniform("uLightingIndentationAmount", SOFT_BUTTON_LIGHTING_INDENTATION_AMOUNT_DEFAULT);
++ shader.SetUniform("uTextureDistortAmount", SOFT_BUTTON_TEXTURE_DISTORTION_AMOUNT_DEFAULT);
++ shader.SetUniform("uInsideCircleSizeScale", SOFT_BUTTON_INSIDE_SHAPE_SIZE_SCALE_DEFAULT);
++ shader.SetUniform("uRecipInsideCircleSizeScale", 1.0f / SOFT_BUTTON_INSIDE_SHAPE_SIZE_SCALE_DEFAULT);
++ shader.SetUniform("uOutsideCircleDepth", SOFT_BUTTON_OUTSIDE_SHAPE_DEPTH_DEFAULT);
++ shader.SetUniform("uEffectRegion", SOFT_BUTTON_EFFECT_PIXEL_AREA_DEFAULT);
++ if(SOFT_BUTTON_RECTANGULAR == type)
++ {
++ shader.SetUniform("uRectangleSizeScale", SOFT_BUTTON_RECTANGLE_SIZE_SCALE_DEFAULT);
++ }
++
++ // precalc 1.0 / uInsideCircleSizeScale on CPU to save shader insns, using constraint to tie to the normal property
++ Dali::Property::Index insideCircleSizeScalePropertyIndex = shader.GetPropertyIndex("uInsideCircleSizeScale");
++ Dali::Property::Index recipInsideCircleSizeScalePropertyIndex = shader.GetPropertyIndex("uRecipInsideCircleSizeScale");
++ Constraint constraint = Constraint::New<float>( shader, recipInsideCircleSizeScalePropertyIndex, InverseConstraint );
++ constraint.AddSource( LocalSource(insideCircleSizeScalePropertyIndex) );
++ constraint.Apply();
++ }
++
++ return shader;
++}
+
+ }
+
+ }
+
+ #endif //#ifndef __DALI_TOOLKIT_SHADER_EFFECT_SOFT_BUTTON_H__
--- /dev/null
- * SpotEffect2D is a custom shader effect to achieve spot effects on Image actors
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API SpotEffect : public ShaderEffect
++ * @brief Creates a new SpotEffect
++ *
++ * SpotEffect is a custom shader effect to achieve spot effects on Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ * "uCenter" - The center of the spot. Default value (0.0,0.0)
++ * "uRadius" - The radius of the spot. Default value 0.0
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an uninitialized SpotEffect; this can be initialized with SpotEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- SpotEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~SpotEffect();
-
- /**
- * Create an initialized SpotEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static SpotEffect New();
-
- /**
- * Set the center of the spot.
- * @param[in] center The center in Vector2.
- */
- void SetCenter(const Vector2& center);
-
- /**
- * Set the radius of the spot.
- * @param[in] radius The radius in float.
- */
- void SetRadius(float radius);
-
- /**
- * Get the name for the center property
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
- /**
- * Get the name for the radius property
- * @return A std::string containing the property name
- */
- const std::string& GetRadiusPropertyName() const;
-
-private:
- DALI_INTERNAL SpotEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateSpotEffect()
+ {
++ // append the default version
++ std::string vertexShader(
++ "uniform mediump vec2 uCenter;\n"
++ "uniform mediump float uRadius;\n"
++ "varying mediump float vRange;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ " mediump vec4 world = vec4(aPosition, 1.0);\n"
++ " \n"
++ " mediump vec2 d = vec2(world.xy - uCenter);\n"
++ " mediump float dist = length(d);\n"
++ " \n"
++ " mediump float range = (uRadius - dist) / (uRadius);\n"
++ " vRange = max(0.1, range);\n"
++ " \n"
++ " gl_Position = uMvpMatrix * world;\n"
++ " vTexCoord = aTexCoord;\n"
++ "}");
++
++ std::string fragmentShader(
++ "varying mediump float vRange;\n"
++ "\n"
++ "void main()\n"
++ "{\n"
++ " gl_FragColor = texture2D(sTexture, vTexCoord) * vec4(vRange, vRange, vRange, 1.0) * uColor;\n"
++ "}" );
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ vertexShader, fragmentShader,
++ Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID ));
++
++ shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f) );
++ shaderEffect.SetUniform( "uRadius", 0.0f );
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
--- /dev/null
-class DALI_IMPORT_API SquareDissolveEffect : public ShaderEffect
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
++ * @brief Creates a new SquareDissolveEffect
++ *
+ * SquareDissolveEffect is a custom shader effect to achieve square effects in Image actors
++ *
++ * Animatable/Constrainable uniforms:
++ * "uStep" - The step of the square effect
++ * "uRows" - The rows of the square dissolve effect
++ * "uColumns" - The columns of the square dissolve effect
++ * "uTextureSize"- The texture size of the square dissolve
++ *
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * Create an uninitialized SquareDissolveEffect; this can be initialized with BendyEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- SquareDissolveEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~SquareDissolveEffect();
-
- /**
- * Create an initialized SquareDissolveEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static SquareDissolveEffect New();
-
- /**
- * Set the step of the square effect.
- * @param [in] step the new step.
- */
- void SetStep(float step);
-
- /**
- * Set the rows of the square dissolve effect.
- * @param [in] rows the new rows value.
- */
- void SetRows(float rows);
-
- /**
- * Set the columns of the square dissolve effect.
- * @param [in] columns the new columns value.
- */
- void SetColumns(float columns);
-
- /**
- * Set the texture size of the square dissolve.
- * @param[in] textureSize The texture size in Vector2.
- */
- void SetTextureSize(const Vector2& textureSize);
-
- /**
- * Get the name for the step property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetStepPropertyName() const;
-
- /**
- * Get the name for the rows property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetRowsPropertyName() const;
-
- /**
- * Get the name for the columns property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetColumnsPropertyName() const;
-
- /**
- * Get the name for the texSize property
- * which can be used in Animation API's
- * @return A std::string containing the property name
- */
- const std::string& GetTexSizePropertyName() const;
-
-private: // Not intended for application developers
- DALI_INTERNAL SquareDissolveEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateSquareDissolveEffect()
+ {
++ // variable "uStep" range scope : [0.0, 1.0]
++ std::string fragmentShader(
++ "uniform mediump vec2 uTextureSize;\n"
++ "uniform mediump float uStep;\n"
++ "uniform mediump float uRows;\n"
++ "uniform mediump float uColumns;\n"
++ "void main()\n"
++ "{\n"
++ " mediump vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns); \n"
++ " mediump vec2 intXY = vec2(vTexCoord.x * uTextureSize.x, vTexCoord.y * uTextureSize.y); \n"
++ " mediump vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y); \n"
++ " mediump vec2 UVMosaic = vec2(XYMosaic.x /uTextureSize.x, XYMosaic.y / uTextureSize.y); \n"
++ " mediump vec4 noiseVec = texture2D(sEffect, UVMosaic); \n"
++ " mediump float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0; \n"
++ " if(intensity < uStep) \n"
++ " gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0); \n"
++ " else \n"
++ " gl_FragColor = texture2D(sTexture, vTexCoord); \n"
++ " gl_FragColor *= uColor; \n"
++ "} \n" );
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ "",
++ fragmentShader,
++ GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
++
++ shaderEffect.SetUniform( "uTextureSize", Vector2(1.0f, 1.0f) );//COORDINATE_TYPE_DEFAULT
++ shaderEffect.SetUniform( "uStep", 0.1f);
++ shaderEffect.SetUniform( "uRows", 25.0f);
++ shaderEffect.SetUniform( "uColumns", 25.0f);
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
--- /dev/null
- * @brief SwirlEffect is a custom shader effect to achieve swirl effects in Image actors.
+ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SWIRL_H__
+ #define __DALI_TOOLKIT_SHADER_EFFECT_SWIRL_H__
+
+ /*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+ // EXTERNAL INCLUDES
+ #include <dali/public-api/shader-effects/shader-effect.h>
+
+ namespace Dali
+ {
+
+ namespace Toolkit
+ {
+
+ /**
-class DALI_IMPORT_API SwirlEffect : public ShaderEffect
++ * @brief Creates a new SwirlEffect
++ *
++ * SwirlEffect is a custom shader effect to achieve swirl effects in Image actors.
++ *
++ * Animatable/Constrainable uniforms:
++ * "uAngle" - The angle of the swirl
++ * "uCenter" - The center of the swirl
++ * "uRadius" - The radius of the swirl
++ *
++ * @param[in] warp True if the effect should warp
++ * @return A handle to a newly allocated ShaderEffect
+ */
-public:
-
- /**
- * @brief Create an uninitialized SwirlEffect; this can be initialized with SwirlEffect::New().
- *
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- SwirlEffect();
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- */
- ~SwirlEffect();
-
- /**
- * @brief Create an initialized SwirlEffect.
- *
- * @param[in] warp True if the effect should warp.
- * @return A handle to a newly allocated Dali resource.
- */
- static SwirlEffect New(bool warp);
-
- /**
- * @brief Set the angle of the swirl.
- *
- * @param[in] angle The angle in float.
- */
- void SetAngle(float angle);
-
- /**
- * @brief Set the center of the swirl.
- *
- * @param[in] center The center in Vector2.
- */
- void SetCenter(const Vector2& center);
-
- /**
- * @brief Set the radius of the swirl.
- *
- * @param[in] radius The radius in float.
- */
- void SetRadius(float radius);
-
- /**
- * @brief Get the name for the angle property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetAnglePropertyName() const;
-
- /**
- * @brief Get the name for the center property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
- /**
- * @brief Get the name for the radius property.
- *
- * @return A std::string containing the property name
- */
- const std::string& GetRadiusPropertyName() const;
-
-private: // Not intended for application developers
- DALI_INTERNAL SwirlEffect(ShaderEffect handle);
-};
++inline ShaderEffect CreateSwirlEffect( bool warp )
+ {
++ // append the default version
++ std::string fragmentShader(
++ "uniform mediump vec2 uTextureSize;\n"
++ "uniform highp float uRadius;\n"
++ "uniform highp float uAngle;\n"
++ "uniform mediump vec2 uCenter;\n"
++ "void main()\n"
++ "{\n"
++ " highp vec2 textureCenter = (sTextureRect.xy + sTextureRect.zw) * 0.5;\n"
++ " textureCenter = vTexCoord.st - textureCenter;\n"
++ " highp float distance = length(textureCenter);\n"
++ " if (distance >= uRadius)\n"
++ " discard;\n"
++ " highp float percent = (uRadius - distance) / uRadius;\n"
++ " highp float theta = percent * percent * uAngle * 4.0;\n"
++ " highp float sinTheta = sin(theta);\n"
++ " highp float cosTheta = cos(theta);\n" );
++ // if warp, loose the sign from sin
++ if( warp )
++ {
++ fragmentShader.append(
++ " textureCenter = vec2( dot( textureCenter, vec2(cosTheta, sinTheta) ), "
++ " dot( textureCenter, vec2(sinTheta, cosTheta) ) );\n" );
++ }
++ else
++ {
++ fragmentShader.append(
++ " textureCenter = vec2( dot( textureCenter, vec2(cosTheta, -sinTheta) ), "
++ " dot( textureCenter, vec2(sinTheta, cosTheta) ) );\n" );
++ }
++ fragmentShader.append(
++ " textureCenter += uCenter;\n"
++ " gl_FragColor = texture2D( sTexture, textureCenter ) * uColor;\n"
++ "}" );
++
++ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
++ "",
++ fragmentShader,
++ Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
++ ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
++
++ shaderEffect.SetUniform( "uAngle", 0.0f );
++ shaderEffect.SetUniform( "uCenter", Vector2(0.5f, 0.5f) );
++ shaderEffect.SetUniform( "uRadius", 1.0f );
++
++ return shaderEffect;
++}
+
+ } // namespace Toolkit
+
+ } // namespace Dali
+
+ #endif // __DALI_TOOLKIT_SHADER_EFFECT_SWIRL_H__
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
- #include <dali-toolkit/public-api/controls/bubble-effect/bubble-emitter.h>
+ #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
-#include <dali-toolkit/devel-api/shader-effects/bubble-effect/bubble-effect.h>
namespace Dali
{
#include <dali/public-api/actors/image-actor.h>
#include <dali/public-api/object/type-registry.h>
- #include <dali-toolkit/public-api/shader-effects/image-region-effect.h>
+//INTERNAL INCLUDES
++#include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
+
namespace Dali
{
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
- #include <dali-toolkit/public-api/controls/page-turn-view/page-turn-view.h>
- #include <dali-toolkit/public-api/controls/page-turn-view/page-factory.h>
- #include <dali-toolkit/public-api/controls/shadow-view/shadow-view.h>
+ #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-view.h>
-#include <dali-toolkit/internal/shader-effects/page-turn-effect-impl.h>
-#include <dali-toolkit/devel-api/shader-effects/page-turn-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/page-turn-book-spine-effect.h>
+ #include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h>
+ #include <dali-toolkit/devel-api/controls/shadow-view/shadow-view.h>
namespace Dali
{
#include <dali/public-api/common/stage.h>
#include <dali/public-api/events/tap-gesture.h>
#include <dali/public-api/events/tap-gesture-detector.h>
+ #include <dali/public-api/events/touch-event.h>
#include <dali/public-api/events/pan-gesture.h>
#include <dali/public-api/events/pan-gesture-detector.h>
-#include <dali/devel-api/geometry/mesh.h>
-#include <dali/devel-api/geometry/mesh-data.h>
#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/math/rect.h>
#include <dali/public-api/math/vector2.h>
SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
- // Set the background actor before adding so that we do not inform deriving classes
background.actor = meshActor;
- Self().Add( meshActor );
+ // Set the flag to avoid notifying children
+ mImpl->mAddRemoveBackgroundChild = true;
+ // use insert to guarantee its the first child (so that OVERLAY mode works)
+ Self().Insert( 0, meshActor );
+ mImpl->mAddRemoveBackgroundChild = false;
}
+ */
background.color = color;
}
background.actor.Reset();
}
+ /*
ImageActor imageActor = ImageActor::New( image );
- SetupBackgroundActor( imageActor, Actor::Property::SIZE, background.color );
+ SetupBackgroundActor( imageActor, background.color );
// Set the background actor before adding so that we do not inform derived classes
background.actor = imageActor;
- Self().Add( imageActor );
+ mImpl->mAddRemoveBackgroundChild = true;
+ // use insert to guarantee its the first child (so that OVERLAY mode works)
+ Self().Insert( 0, imageActor );
+ mImpl->mAddRemoveBackgroundChild = false;
+ */
}
void Control::ClearBackground()