X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-input%2Ftext-input-popup-impl.cpp;h=6484bfaccab522780d4531c9f6a34b7f69f07c26;hp=7d9bf42648c21aa7bb4f07cdcd325bc300079100;hb=8fef10ea440a32a1536b485dc7a035f9defa537c;hpb=e2eda444afbe82e9591fe198eef339227f90a616 diff --git a/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp b/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp index 7d9bf42..6484bfa 100644 --- a/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp @@ -1,171 +1,94 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +/* + * Copyright (c) 2014 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 +#include +#include +#include +// INTERNAL INCLUDES #include #include +#include -using namespace std; using namespace Dali; -namespace { - -// Popup: Background -const char* DEFAULT_PANEL_BACKGROUND = DALI_IMAGE_DIR "cutCopyPastePopup_bg.png"; - -// Popup: Divider -const char* DEFAULT_PANEL_BUTTON_DIVIDER = DALI_IMAGE_DIR "copypanelLine.png"; - -/* Functionality in place to have the end buttons using different images to inner button. - * Supply a centre image and then a left and right image, the centre image can have straight ends while - * the left image can be rounded on the left and straight on the right, the right image can be straight on the left and rounded on the right. - */ - -// Popup: Left Pressed Highlight -const char* DEFAULT_BUTTON_HIGHLIGHT_LEFT( DALI_IMAGE_DIR "00_popup_button_pressed.png" ); -const Vector4 DEFAULT_BUTTON_HIGHLIGHT_LEFT_BORDER( 6.0f, 9.0f, 6.0f, 9.0f ); - -// Popup: Center Pressed Highlight -const char* DEFAULT_BUTTON_HIGHLIGHT_CENTER( DALI_IMAGE_DIR "00_popup_button_pressed.png" ); -const Vector4 DEFAULT_BUTTON_HIGHLIGHT_CENTER_BORDER( 6.0f, 9.0f, 6.0f, 9.0f ); +#define GET_LOCALE_TEXT(string) dgettext("sys_string", string) -// Popup: Right Pressed Highlight -const char* DEFAULT_BUTTON_HIGHLIGHT_RIGHT( DALI_IMAGE_DIR "00_popup_button_pressed.png" ); -const Vector4 DEFAULT_BUTTON_HIGHLIGHT_RIGHT_BORDER( 6.0f, 9.0f, 6.0f, 9.0f ); - -// Popup: Tails -const char* DEFAULT_POPUP_TAIL_BOTTOM( DALI_IMAGE_DIR "00_popup_bubble_tail_bottom.png" ); - -// Popup: Vertical Constraint -// TODO: Remove - this should come from application - it is not possible to get the -// height of the indicator actor from Dali-Toolkit. +namespace +{ const Vector2 DEFAULT_POPUP_INDICATOR_OFFSET(0.0f, 60.0f); -const Vector4 BACKGROUND_IMAGE_BORDER( 22.0f, 20.0f, 29.0f, 27.0f ); -const Vector2 BACKGROUND_IMAGE_SIZE( 50.0f, 54.0f ); -const Vector3 POPUP_TEXT_OFFSET( 12.0f, 10.0f, 0.0f ); -const Vector3 POPUP_TEXT_ENLARGE( 12.0f, 28.0f, 0.0f ); -const Vector3 POPUP_MINIMUM_SIZE( 128.0f, 124.0f, 0.0f ); - -const Vector3 BUTTON_TEXT_ENLARGE( 32.0f, 0.0f, 0.0f ); -const Vector3 BUTTON_TEXT_MINIMUM_SIZE( 128.0f, 126.0f, 0.0f ); -const Vector3 BUTTON_TEXT_MAXIMUM_SIZE( 196.0f, 126.0f, 0.0f ); -const Vector3 TEXT_LABEL_MAX_SIZE( 160.0f, 30.0f, 0.0f ); - -const float DIVIDER_WIDTH(2.0f); ///< Width of each button divider -const float DIVIDER_MARGIN(10.0f); ///< Top/Bottom Margin between divider and edge of popup. - -const float DEFAULT_UI_FONT_SIZE(7.0f); ///< Standard font size for Text-Input's UI - -const float HIDE_POPUP_ANIMATION_DURATION(0.2f); ///< Duration of popup hide animation in seconds. -const float SHOW_POPUP_ANIMATION_DURATION(0.2f); ///< Duration of popup show animation in seconds. - -const Vector2 DEFAULT_ICON_SIZE( 45.0f, 45.0f ); ///< Default icon size for image in options -const float TEXT_POSITION_OFFSET( -19.0f ); ///< Default offset for text label -const float ICON_POSITION_OFFSET( 19.0f ); ///< Default offset for icon - -// TODO: This should be based on the content for example: // 1. For selection: should be above top of highlighted selection, or below bottom of highlighted selection + end handle. // 2. For cursor: should be above top of cursor, or below bottom of cursor + grab handle. -const std::string POPUP_ALTERNATIVE_OFFSET("popup-alternative-offset"); ///< Alternative offset property for confinenment constraint. - /** - * Confine Actor to boundaries of reference actor (e.g. Parent) - * Actor bounds (top-left position + size) are confined to reference Actor's - * bounds. + * Image resource paths */ -struct ConfinementConstraint -{ - /** - * Confinement constraint constructor. - * @param[in] topLeftMargin (optional) Top-Left margins (defaults to 0.0f, 0.0f) - * @param[in] bottomRightMargin (optional) Bottom-Right margins (defaults to 0.0f, 0.0f) - * @param[in] flipVertical (optional) whether to flip Actor to the other side if near edge, and by - * how much (defaults to 0.0f i.e. no flip) - */ - ConfinementConstraint(Vector2 topLeftMargin = Vector2::ZERO, Vector2 bottomRightMargin = Vector2::ZERO, bool flipHorizontal = false, bool flipVertical = false) - : mMinIndent(topLeftMargin), - mMaxIndent(bottomRightMargin), - mFlipHorizontal(flipHorizontal), - mFlipVertical(flipVertical) - { - } - - Vector3 operator()(const Vector3& constPosition, - const PropertyInput& sizeProperty, - const PropertyInput& parentOriginProperty, - const PropertyInput& anchorPointProperty, - const PropertyInput& referenceSizeProperty, - const PropertyInput& alternativeOffsetProperty) - { - const Vector3& size = sizeProperty.GetVector3(); - const Vector3& origin = parentOriginProperty.GetVector3(); - const Vector3& anchor = anchorPointProperty.GetVector3(); - const Vector3& referenceSize = referenceSizeProperty.GetVector3(); - const Vector2& alternativeOffset = alternativeOffsetProperty.GetVector2(); - - Vector3 newPosition(constPosition); - - // Get actual position of Actor relative to parent's Top-Left. - Vector3 position(constPosition + origin * referenceSize); - - // if top-left corner is outside of Top-Left bounds, then push back in screen. - Vector3 corner(position - size * anchor - mMinIndent); - - if(mFlipHorizontal && corner.x < 0.0f) - { - corner.x = 0.0f; - newPosition.x += size.width + alternativeOffset.width; - } - - if(mFlipVertical && corner.y < 0.0f) - { - corner.y = 0.0f; - newPosition.y += size.height + alternativeOffset.height; - } - - newPosition.x -= std::min(corner.x, 0.0f); - newPosition.y -= std::min(corner.y, 0.0f); +const std::string POPUP_BACKGROUND( DALI_IMAGE_DIR "popup_bubble_bg.#.png" ); +const std::string POPUP_BACKGROUND_EFFECT( DALI_IMAGE_DIR "popup_bubble_bg_ef.#.png" ); +const std::string POPUP_BACKGROUND_LINE( DALI_IMAGE_DIR "popup_bubble_bg_line.#.png" ); + +const std::string POPUP_TAIL_BOTTOM( DALI_IMAGE_DIR "popup_bubble_tail_bottom.png" ); +const std::string POPUP_TAIL_BOTTOM_EFFECT( DALI_IMAGE_DIR "popup_bubble_tail_bottom_ef.png" ); +const std::string POPUP_TAIL_BOTTOM_LINE( DALI_IMAGE_DIR "popup_bubble_tail_bottom_line.png" ); +const std::string POPUP_TAIL_TOP( DALI_IMAGE_DIR "popup_bubble_tail_top.png" ); +const std::string POPUP_TAIL_TOP_EFFECT( DALI_IMAGE_DIR "popup_bubble_tail_top_ef.png" ); +const std::string POPUP_TAIL_TOP_LINE( DALI_IMAGE_DIR "popup_bubble_tail_top_line.png" ); + +const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" ); +const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" ); +const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" ); +const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" ); +const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" ); +const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" ); - // if bottom-right corner is outside of Bottom-Right bounds, then push back in screen. - corner += size - referenceSize + mMinIndent + mMaxIndent; - - if(mFlipHorizontal && corner.x > 0.0f) - { - corner.x = 0.0f; - newPosition.x -= size.width + alternativeOffset.width; - } - - if(mFlipVertical && corner.y > 0.0f) - { - corner.y = 0.0f; - newPosition.y -= size.height + alternativeOffset.height; - } - - newPosition.x -= std::max(corner.x, 0.0f); - newPosition.y -= std::max(corner.y, 0.0f); - - return newPosition; - } +/** + * Constant values for building the GUI + */ +const Vector4 POPUP_MARGIN( 14.0f, 14.0f, 14.0f, 14.0f ); ///< Margin around the popup visible background Image. +const Vector4 POPUP_BORDER( 2.0f, 2.0f, 2.0f, 2.0f ); ///< The Border of the popup. +const Vector2 POPUP_MIN_SIZE( 0.0f, 126.0f ); ///< The minimum size of the popup. +const Vector2 POPUP_MAX_SIZE( 720.0f, 126.0f ); ///< The maximum size of the popup. +const float POPUP_TAIL_Y_OFFSET( -2.25f ); ///< The y offset of the tail. +const Vector2 POPUP_TAIL_SIZE( 36.0f, 36.0f ); ///< The size of the tail. +const Vector2 POPUP_DIVIDER_SIZE( 1.0f, 126.0f ); ///< The size of the divider. + +const Vector4 OPTION_PADDING( 16.0f, 16.0f, 24.0f, 19.0f ); ///< The padding within the option to position icon and text away from the border. The order is left, right, top and bottom +const Vector2 OPTION_MAX_SIZE( 220.0f, 126.0f ); ///< The maximum size of the option. +const Vector2 OPTION_MIN_SIZE( 128.0f, 126.0f ); ///< The minimum size of the option. +const Vector2 OPTION_ICON_SIZE( 45.0f, 45.0f ); ///< The size of the icon. +const Vector2 OPTION_TEXT_MIN_SIZE( 128.0f, 30.0f ); ///< The minimum size of the text. +const float OPTION_GAP_ICON_TEXT( 8.0f ); ///< The gap between the icon and the text + +const float HIDE_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup hide animation in seconds. +const float SHOW_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup show animation in seconds. - Vector3 mMinIndent; ///< Top-Left Margin - Vector3 mMaxIndent; ///< Bottom-Right Margin. - bool mFlipHorizontal; ///< Whether to flip actor's position if exceeds horizontal screen bounds - bool mFlipVertical; ///< Whether to flip actor's position if exceeds vertical screen bounds -}; +/** + * Default Colors + */ +const Vector4 DEFAULT_POPUP_BACKGROUND( Vector4( .20f, 0.29f, 0.44f, 1.0f ) ); +const Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) ); +const Vector4 DEFAULT_POPUP_LINE_COLOR( Vector4( 0.36f, 0.45f, 0.59f, 1.0f ) ); +const Vector4 DEFAULT_OPTION_ICON( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); +const Vector4 DEFAULT_OPTION_ICON_PRESSED( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); +const Vector4 DEFAULT_OPTION_TEXT( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); +const Vector4 DEFAULT_OPTION_TEXT_PRESSED( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); } // unnamed namespace @@ -178,275 +101,444 @@ namespace Toolkit namespace Internal { -const char* const TextInputPopup::SIGNAL_PRESSED = "pressed"; -const char* const TextInputPopup::SIGNAL_HIDE_FINISHED = "hide-finished"; -const char* const TextInputPopup::SIGNAL_SHOW_FINISHED = "show-finished"; +namespace +{ + +// Signals + +const char* const SIGNAL_PRESSED = "pressed"; +const char* const SIGNAL_HIDE_FINISHED = "hide-finished"; +const char* const SIGNAL_SHOW_FINISHED = "show-finished"; + +} + +const char* const TextInputPopup::OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option. +const char* const TextInputPopup::OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option. +const char* const TextInputPopup::OPTION_CUT("option-cut"); // "Cut" popup option. +const char* const TextInputPopup::OPTION_COPY("option-copy"); // "Copy" popup option. +const char* const TextInputPopup::OPTION_PASTE("option-paste"); // "Paste" popup option. +const char* const TextInputPopup::OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option. TextInputPopup::TextInputPopup() : mState(StateHidden), - mRootActor(Layer::New()), + mRoot( Layer::New() ), + mButtons(), + mVisiblePopUpSize(), + mPopupTailXPosition( 0.0f ), + mContentSize(), + mBackgroundColor( DEFAULT_POPUP_BACKGROUND ), + mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ), + mLineColor( DEFAULT_POPUP_LINE_COLOR ), + mIconColor( DEFAULT_OPTION_ICON ), + mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ), + mTextColor( DEFAULT_OPTION_TEXT ), + mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED ), + mSelectOptionPriority(1), + mSelectAllOptionPriority(2), + mCutOptionPriority(3), + mCopyOptionPriority(4), + mPasteOptionPriority(5), + mClipboardOptionPriority(6), mPressedSignal(), mHideFinishedSignal(), mShowFinishedSignal() { - mAlternativeOffsetProperty = mRootActor.RegisterProperty( POPUP_ALTERNATIVE_OFFSET, Vector2::ZERO ); - mRootActor.SetParentOrigin( ParentOrigin::CENTER ); - mRootActor.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - // constrain popup to size of parent. + mRoot.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mRoot.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); +} + +void TextInputPopup::AddToParent( Actor parent ) +{ + Actor existingParent = mRoot.GetParent(); + + if ( !existingParent ) + { + parent.Add( mRoot ); + } +} + +void TextInputPopup::RemoveFromParent() +{ + Actor parent = mRoot.GetParent(); + + if ( parent ) + { + parent.Remove( mRoot ); + } +} + +void TextInputPopup::CreateLayer( const Vector2& size ) +{ + mLayer = Layer::New(); + mLayer.SetParentOrigin(ParentOrigin::CENTER); + mLayer.SetAnchorPoint(AnchorPoint::CENTER); + mLayer.SetSize( size ); // matches stencil size + mLayer.SetName("popup-mLayer"); } -Actor TextInputPopup::Self() +void TextInputPopup::CreateStencil( const Vector2& size ) { - return mRootActor; + mStencil = CreateSolidColorActor( Color::BLUE ); + mStencil.SetParentOrigin( ParentOrigin::CENTER ); + mStencil.SetAnchorPoint( AnchorPoint::CENTER ); + mStencil.SetDrawMode( DrawMode::STENCIL ); + mStencil.SetVisible( true ); + mStencil.SetName( "popup-stencil" ); + mStencil.SetSize( size ); } -void TextInputPopup::AddToStage() +void TextInputPopup::OnScrollStarted( const Vector3& position ) { - // TODO: Confinement constraint borders should be defined by the application. - // It should also not use the stage directly, instead it should add to parent container. - Stage::GetCurrent().Add(mRootActor); + mButtons.SetSensitive( false ); +} - ApplyConfinementConstraint(); +void TextInputPopup::OnScrollCompleted( const Vector3& position ) +{ + mButtons.SetSensitive( true ); } -void TextInputPopup::ApplyConfinementConstraint() +void TextInputPopup::CreateScrollView() { - mRootActor.RemoveConstraints(); - Constraint constraint = Constraint::New( Actor::POSITION, - LocalSource( Actor::SIZE ), - LocalSource( Actor::PARENT_ORIGIN ), - LocalSource( Actor::ANCHOR_POINT ), - ParentSource( Actor::SIZE ), - LocalSource( mAlternativeOffsetProperty ), - ConfinementConstraint( DEFAULT_POPUP_INDICATOR_OFFSET, - Vector2::ZERO, - false, - true) ); - mRootActor.ApplyConstraint(constraint); + mScrollView = Toolkit::ScrollView::New(); + mScrollView.SetName("popup-scroll-view"); + mScrollView.SetAnchorPoint( AnchorPoint::CENTER ); + mScrollView.SetParentOrigin( ParentOrigin::CENTER ); + mScrollView.SetScrollingDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 40.0f ) ); + mScrollView.SetAxisAutoLock( true ); + mScrollView.ScrollStartedSignal().Connect( this, &TextInputPopup::OnScrollStarted ); + mScrollView.ScrollCompletedSignal().Connect( this, &TextInputPopup::OnScrollCompleted ); } -void TextInputPopup::RemoveFromStage() +void TextInputPopup::UpdateScrollViewRulerAndSize( const Vector2& visibleSize ) { - Actor rootActor = Self(); - Stage::GetCurrent().Remove( rootActor ); + mScrollView.SetSize( visibleSize.x, visibleSize.y ); + + RulerPtr rulerX = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed. + RulerPtr rulerY = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed. + rulerY->Disable(); + rulerX->SetDomain( RulerDomain( 0, mContentSize.width, true ) ); + mScrollView.SetRulerX(rulerX); + mScrollView.SetRulerY(rulerY); } + void TextInputPopup::Clear() { if ( mBackground ) { - mRootActor.Remove( mBackground ); - mBackground.Reset(); - mButtonContainer.clear(); + UnparentAndReset( mTail ); + UnparentAndReset( mStencil ); + UnparentAndReset( mBackground ); + UnparentAndReset( mButtons ); + UnparentAndReset( mScrollView ); mDividerContainer.clear(); - - RemoveFromStage(); - mRootActor.RemoveConstraints(); - + RemoveFromParent(); mState = StateHidden; } } -Toolkit::TextView TextInputPopup::CreateOptionText( const MarkupProcessor::StyledTextArray& styledCaption ) +ImageActor TextInputPopup::CreateOptionIcon( Image iconImage, const Vector4& color ) { - Toolkit::TextView label = Toolkit::TextView::New( styledCaption ); - label.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed ); - label.SetWidthExceedPolicy( Toolkit::TextView::Fade ); - label.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - label.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - label.SetPosition( 0.0f, TEXT_POSITION_OFFSET ); - - return label; + ImageActor icon = ImageActor::New( iconImage ); + icon.SetSize( OPTION_ICON_SIZE ); + icon.SetParentOrigin( ParentOrigin::TOP_CENTER ); + icon.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + icon.SetColor( color ); + icon.SetY( OPTION_PADDING.z - POPUP_BORDER.y ); + return icon; } -ImageActor TextInputPopup::CreateOptionIcon( Image iconImage ) +Toolkit::TextView TextInputPopup::CreateOptionCaption( const std::string& caption, const Vector4& color ) { - ImageActor icon = ImageActor::New( iconImage ); + TextStyle style; + style.SetTextColor( color ); - icon.SetSize( DEFAULT_ICON_SIZE ); - icon.SetParentOrigin( ParentOrigin::TOP_CENTER ); - icon.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - icon.SetPosition( 0.0f, ICON_POSITION_OFFSET ); + PointSize pointSize( Font::PixelsToPoints( OPTION_TEXT_MIN_SIZE.y ) ); + style.SetFontPointSize( pointSize ); - return icon; + MarkupProcessor::StyledTextArray styledCaption; + styledCaption.push_back( MarkupProcessor::StyledText( Text( caption ), style ) ); + + Toolkit::TextView textView = Toolkit::TextView::New( styledCaption ); + textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed ); + textView.SetWidthExceedPolicy( Toolkit::TextView::EllipsizeEnd ); + textView.SetHeightExceedPolicy( Toolkit::TextView::EllipsizeEnd ); + textView.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + textView.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + textView.SetY( -OPTION_PADDING.w + POPUP_BORDER.w ); + + MarkupProcessor::StyledTextArray styledCaptionEllipsize; + MarkupProcessor::SetTextStyle( Text("..."), styledCaptionEllipsize, style ); + textView.SetEllipsizeText( styledCaptionEllipsize ); + + const float textWidth = textView.GetWidthForHeight( OPTION_TEXT_MIN_SIZE.y ); + textView.SetSize( textWidth, OPTION_TEXT_MIN_SIZE.y ); + + return textView; } -void TextInputPopup::CreatePopUpBackground() +void TextInputPopup::CreateBackground() { // Create background-panel if not already created (required if we have at least one option) if ( !mBackground ) { - Image backgroundImage = Image::New( DEFAULT_PANEL_BACKGROUND ); - - mBackground = ImageActor::New( backgroundImage ); - // Expand background from bottom-center of root actor. - mBackground.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - mBackground.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - mBackground.SetStyle( ImageActor::STYLE_NINE_PATCH ); - - mBackground.SetNinePatchBorder( Vector4(13.0f, 13.0f, 13.0f, 13.0f) ); - - Self().Add( mBackground ); - mContentSize = POPUP_TEXT_OFFSET; + Image bgImg = ResourceImage::New( POPUP_BACKGROUND ); + mBackground = ImageActor::New( bgImg ); + mBackground.SetAnchorPoint( AnchorPoint::CENTER ); + mBackground.SetParentOrigin( ParentOrigin::CENTER ); + mBackground.SetName( "text-input-popup-background" ); + mBackground.SetColor( mBackgroundColor ); + + Image bgEffectImg = ResourceImage::New( POPUP_BACKGROUND_EFFECT ); + mBackgroundEffect = ImageActor::New( bgEffectImg ); + mBackgroundEffect.SetAnchorPoint( AnchorPoint::CENTER ); + mBackgroundEffect.SetParentOrigin( ParentOrigin::CENTER ); + mBackgroundEffect.SetName( "text-input-popup-background-effect" ); + mBackgroundEffect.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mBackgroundEffect.SetZ( 1.0f ); + mBackground.Add( mBackgroundEffect ); + + Image bgLine = ResourceImage::New( POPUP_BACKGROUND_LINE ); + mBackgroundLine = ImageActor::New( bgLine ); + mBackgroundLine.SetAnchorPoint( AnchorPoint::CENTER); + mBackgroundLine.SetParentOrigin( ParentOrigin::CENTER ); + mBackgroundLine.SetName( "text-input-popup-background-effect" ); + mBackgroundLine.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mBackgroundLine.SetColor( mLineColor ); + mBackgroundLine.SetZ( 0.1f ); + mBackgroundEffect.Add( mBackgroundLine ); Hide(false); - AddToStage(); - - // Add Tail too. - Image tailImage = Image::New( DEFAULT_POPUP_TAIL_BOTTOM ); + } +} - mTail = ImageActor::New( tailImage ); +void TextInputPopup::CreateTail() +{ + if ( !mTail ) + { + Image tail = ResourceImage::New( POPUP_TAIL_BOTTOM ); + mTail = ImageActor::New( tail ); mTail.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); mTail.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - mBackground.Add( mTail ); - // TODO: Make tail visible, and positioned in relation to original intended position of popup (i.e. before constrained effects) - mTail.SetVisible(false); + mTail.SetName( "text-input-popup-tail" ); + mTail.SetPosition( 0.0f, POPUP_TAIL_Y_OFFSET - POPUP_BORDER.w, 1.2f ); + mTail.SetColor( mBackgroundColor ); + + Image tailEffect = ResourceImage::New( POPUP_TAIL_BOTTOM_EFFECT ); + mTailEffect = ImageActor::New( tailEffect ); + mTailEffect.SetParentOrigin( ParentOrigin::CENTER ); + mTailEffect.SetAnchorPoint( AnchorPoint::CENTER ); + mTailEffect.SetName( "text-input-popup-tail-effect" ); + mTailEffect.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mTailEffect.SetZ( 0.1f ); + mTail.Add( mTailEffect ); + + Image tailLine = ResourceImage::New( POPUP_TAIL_BOTTOM_LINE ); + mTailLine = ImageActor::New( tailLine ); + mTailLine.SetParentOrigin( ParentOrigin::CENTER ); + mTailLine.SetAnchorPoint( AnchorPoint::CENTER ); + mTailLine.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mTailLine.SetName( "text-input-popup-tail-line" ); + mTailLine.SetColor( mLineColor ); + mTailLine.SetZ( 0.1f ); + mTailEffect.Add( mTailLine ); } } -void TextInputPopup::CreateDivider() +ImageActor TextInputPopup::CreateDivider() { - if(mButtonContainer.size() > 0) - { - Image dividerImage = Image::New( DEFAULT_PANEL_BUTTON_DIVIDER ); - ImageActor divider = ImageActor::New( dividerImage ); - divider.SetParentOrigin( ParentOrigin::TOP_LEFT ); - divider.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - divider.SetPosition( Vector3( mContentSize.width, POPUP_TEXT_OFFSET.y + 5.0f, 0.0f ) ); - // Keep track of all the dividers. As their height's need to be updated to the max. of all - // buttons currently added. - mDividerContainer.push_back(divider); - - mBackground.Add( divider ); - mContentSize.width += DIVIDER_WIDTH; - } + ImageActor divider = Toolkit::CreateSolidColorActor( mLineColor ); + divider.SetParentOrigin( ParentOrigin::TOP_LEFT ); + divider.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + divider.SetSize( POPUP_DIVIDER_SIZE.width , mContentSize.height ); + divider.SetPosition( mContentSize.width - POPUP_DIVIDER_SIZE.width, 0.0f ); + + // Keep track of all the dividers. As their height's need to be updated to the max of all + // buttons currently added. + mDividerContainer.push_back( divider ); + + return divider; } -ImageActor TextInputPopup::CreatePressedBackground( const Vector3 requiredSize, const bool finalFlag ) +ImageActor TextInputPopup::CreatePressedBackground( const Vector2& requiredSize ) { - std::string pressedImageFilename; - Vector4 pressedImageBorder; - Vector2 pressedImageSize; + ImageActor pressedBg = Toolkit::CreateSolidColorActor( mBackgroundPressedColor ); + pressedBg.SetDrawMode( DrawMode::OVERLAY ); + pressedBg.SetParentOrigin( ParentOrigin::CENTER ); + pressedBg.SetAnchorPoint( AnchorPoint::CENTER ); + pressedBg.SetSize( requiredSize ); + return pressedBg; +} - if(mButtonContainer.size() == 0) // LEFT - { - pressedImageFilename = DEFAULT_BUTTON_HIGHLIGHT_LEFT; - pressedImageBorder = DEFAULT_BUTTON_HIGHLIGHT_LEFT_BORDER; - } - else if(!finalFlag) // CENTER - { - pressedImageFilename = DEFAULT_BUTTON_HIGHLIGHT_CENTER; - pressedImageBorder = DEFAULT_BUTTON_HIGHLIGHT_CENTER_BORDER; - } - else // RIGHT +TextInputPopup::ButtonRequirement TextInputPopup::CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority, + const std::string& name, const std::string& caption, Image iconImage, bool enabled ) +{ + TextInputPopup::ButtonRequirement currentButton; + currentButton.buttonId = buttonId; + currentButton.orderOfPriority = orderOfPriority; + currentButton.name = name; + currentButton.caption = caption; + currentButton.iconImage = iconImage; + currentButton.enabled = enabled; + + return currentButton; +} + +void TextInputPopup::CreateOrderedListOfOptions() +{ + mOrderListOfButtons.clear(); + + for ( std::size_t index= 0; index < ButtonsEnumEnd; index++ ) { - pressedImageFilename = DEFAULT_BUTTON_HIGHLIGHT_RIGHT; - pressedImageBorder = DEFAULT_BUTTON_HIGHLIGHT_RIGHT_BORDER; - } + TextInputPopup::ButtonRequirement currentButton; + + // Create button for each possible option using Option priority + switch ( index ) + { + case ButtonsCut: + { + Image cutIcon = ResourceImage::New( OPTION_ICON_CUT ); + currentButton = CreateRequiredButton( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), cutIcon, false ); + break; + } + case ButtonsCopy: + { + Image copyIcon = ResourceImage::New( OPTION_ICON_COPY ); + currentButton = CreateRequiredButton( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), copyIcon, false ); + break; + } + case ButtonsPaste: + { + Image pasteIcon = ResourceImage::New( OPTION_ICON_PASTE ); + currentButton = CreateRequiredButton( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon, false ); + break; + } + case ButtonsSelect: + { + Image selectIcon = ResourceImage::New( OPTION_ICON_SELECT ); + currentButton = CreateRequiredButton( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), selectIcon, false ); + break; + } + case ButtonsSelectAll: + { + Image selectAllIcon = ResourceImage::New( OPTION_ICON_SELECT_ALL ); + currentButton = CreateRequiredButton( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon, false ); + break; + } + case ButtonsClipboard: + { + Image clipboardIcon = ResourceImage::New( OPTION_ICON_CLIPBOARD ); + currentButton = CreateRequiredButton( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, false ); + break; + } + } + + bool match = false; - Image pressedImage = Image::New( pressedImageFilename ); - ImageActor pressedImageBg = ImageActor::New( pressedImage ); - pressedImageBg.SetStyle( ImageActor::STYLE_NINE_PATCH ); - pressedImageBg.SetNinePatchBorder( pressedImageBorder ); - pressedImageBg.SetSize ( requiredSize ); - pressedImageBg.SetParentOrigin( ParentOrigin::CENTER ); - pressedImageBg.SetAnchorPoint( AnchorPoint::CENTER ); + // Insert button in list of buttons in order of priority setting. + for( std::vector::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it ) + { + const ButtonRequirement& button( *it ); + if ( currentButton.orderOfPriority < button.orderOfPriority ) + { + if ( currentButton.orderOfPriority != 0 ) // If order priority 0 then do not add button as not required. + { + mOrderListOfButtons.insert( it, currentButton ); + } + match = true; + } + } - return pressedImageBg; + if ( !match ) + { + mOrderListOfButtons.push_back( currentButton ); + } + } } -void TextInputPopup::AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption) +Vector2 TextInputPopup::GetConstrainedTextSize( const Vector2& textSize ) { - CreatePopUpBackground(); + return Vector2( std::min( textSize.width, OPTION_MAX_SIZE.width - OPTION_PADDING.x - OPTION_PADDING.y ), textSize.height ); +} - CreateDivider(); +void TextInputPopup::AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption) +{ + // 1. Create container for text and icon when not pressed. + Actor optionContainer = Actor::New(); + optionContainer.SetParentOrigin( ParentOrigin::TOP_LEFT ); + optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - // Create a Button with Text, Icon and highlight when pressed + // 2. Add text. + Toolkit::TextView captionTextView = CreateOptionCaption( caption, mTextColor ); + optionContainer.Add( captionTextView ); - Toolkit::PushButton button = Toolkit::PushButton::New(); - button.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed ); - button.SetName( name ); + // 3. Add icon. + ImageActor icon = CreateOptionIcon( iconImage, mIconColor ); + optionContainer.Add( icon ); - // Create container for text and icon when not pressed - Actor iconTextContainer = Actor::New(); - iconTextContainer.SetParentOrigin( ParentOrigin::TOP_LEFT ); - iconTextContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + // 4. Calculate the size of option. + const Vector2 textSize = Vector2( captionTextView.GetNaturalSize() ); + captionTextView.SetSize( GetConstrainedTextSize( textSize ) ); - // 1. Add text. - TextStyle style; - style.SetFontPointSize( PointSize( DEFAULT_UI_FONT_SIZE ) ); - MarkupProcessor::StyledTextArray styledCaption; - styledCaption.push_back( MarkupProcessor::StyledText( Text( caption ), style ) ); - Toolkit::TextView label = CreateOptionText( styledCaption ); - label.SetName( name ); - iconTextContainer.Add( label ); + const Vector2 optionSize( std::max( textSize.x, OPTION_ICON_SIZE.x ) + OPTION_PADDING.x + OPTION_PADDING.z, + OPTION_PADDING.z + OPTION_ICON_SIZE.y + OPTION_GAP_ICON_TEXT + textSize.y + OPTION_MAX_SIZE.y ); - // Get natural size of text and then constrain it to bounds. - const Vector3 textSize = label.GetNaturalSize(); - const Vector3 constrainedTextSize = Min( textSize, TEXT_LABEL_MAX_SIZE ); - Vector3 buttonSize( Max(constrainedTextSize + BUTTON_TEXT_ENLARGE, BUTTON_TEXT_MINIMUM_SIZE) ); - buttonSize = ( Min(buttonSize, BUTTON_TEXT_MAXIMUM_SIZE) ); - label.SetSize( Min( buttonSize + BUTTON_TEXT_ENLARGE, constrainedTextSize ) ); - button.SetParentOrigin( ParentOrigin::TOP_LEFT ); - button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - button.SetSize( buttonSize ); - button.SetPosition( Vector3( mContentSize.width, POPUP_TEXT_OFFSET.y, 0.0f ) ); + Vector2 constrainedOptionSize = Min( Max( optionSize, OPTION_MIN_SIZE ), OPTION_MAX_SIZE ); - // 2. Add icon - ImageActor icon = CreateOptionIcon( iconImage ); + constrainedOptionSize.height = constrainedOptionSize.height - POPUP_BORDER.y - POPUP_BORDER.z; - iconTextContainer.Add( icon ); + // 5. Create a option. + Toolkit::PushButton option = Toolkit::PushButton::New(); + option.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed ); + option.SetParentOrigin( ParentOrigin::TOP_LEFT ); + option.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + option.SetSize( constrainedOptionSize ); + option.SetX( mContentSize.x ); + option.SetName( name ); + option.SetAnimationTime( 0.0f ); + option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed ); + mButtons.Add( option ); - // 3. Add highlight - Pressed state in Pushbutton needs a new image which means creating the text and icon again but including a highlight this time. - ImageActor pressedImageBg = CreatePressedBackground( buttonSize, finalOption ); + // 6. Set the normal option image. + option.SetButtonImage( optionContainer ); - Actor iconPressedTextContainer = Actor::New(); - iconPressedTextContainer.SetDrawMode( DrawMode::OVERLAY ); + // 7. Update the content size. + mContentSize.x += constrainedOptionSize.x; + mContentSize.y = std::max ( constrainedOptionSize.y, mContentSize.y ); - Toolkit::TextView pressedLabel = CreateOptionText( styledCaption ); - pressedLabel.SetSize( Min( buttonSize, TEXT_LABEL_MAX_SIZE ) ); - ImageActor pressedIcon = CreateOptionIcon( iconImage ); + // 8. Create the pressed container. + Actor optionPressedContainer = Actor::New(); - iconPressedTextContainer.Add( pressedImageBg ); - iconPressedTextContainer.Add( pressedLabel ); - iconPressedTextContainer.Add( pressedIcon ); + // 9. Add option pressed background. + Vector2 optionPressedBackgroundSize( constrainedOptionSize.x - POPUP_BORDER.x, mContentSize.y - POPUP_BORDER.y - POPUP_BORDER.w ); + ImageActor optionPressedBackground = CreatePressedBackground( optionPressedBackgroundSize ); + optionPressedContainer.Add( optionPressedBackground ); - // Set Pressed button Image - iconPressedTextContainer.SetSize( buttonSize ); - button.SetPressedImage( iconPressedTextContainer ); + // 10. Add pressed text + Toolkit::TextView pressedCaptionTextView = CreateOptionCaption( caption, mTextPressedColor ); + pressedCaptionTextView.SetSize( GetConstrainedTextSize( Vector2( pressedCaptionTextView.GetNaturalSize() ) ) ); + optionPressedBackground.Add( pressedCaptionTextView ); - // Set Normal button Image - iconTextContainer.SetSize( buttonSize ); - button.SetButtonImage( iconTextContainer ); - mBackground.Add( button ); + // 11. Add pressed icon + ImageActor pressedIcon = CreateOptionIcon( iconImage, mIconPressedColor ); + optionPressedBackground.Add( pressedIcon ); - // Update content size (represents size of all content i.e. from top-left of first button, to bottom-right of last button) - mContentSize.width += buttonSize.width; - mContentSize.height = std::max(mContentSize.height, buttonSize.height); - mButtonContainer.push_back(button); + // 12. Set the pressed option image + option.SetSelectedImage( optionPressedContainer ); - // resize all dividers based on the height content (i.e. max of all button heights) - const float dividerHeight = mContentSize.height - DIVIDER_MARGIN; - for(ActorIter i = mDividerContainer.begin(); i != mDividerContainer.end(); ++i) + // 13. Add the divider + if ( !finalOption ) { - i->SetSize( DIVIDER_WIDTH, dividerHeight ); + ImageActor divider = CreateDivider(); + mButtons.Add( divider ); } - - Vector3 popupSize( Max(mContentSize + POPUP_TEXT_ENLARGE, POPUP_MINIMUM_SIZE) ); - - mBackground.SetSize( popupSize ); - // Make Root Actor reflect the size of its content - mRootActor.SetSize( popupSize ); - mTail.SetPosition(Vector3(0.0f, -20.0f, 0.0f)); - - button.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed ); } void TextInputPopup::Hide(bool animate) { - if(mBackground) + if( mRoot ) { if(mAnimation) { @@ -457,8 +549,8 @@ void TextInputPopup::Hide(bool animate) if(animate) { mAnimation = Animation::New( HIDE_POPUP_ANIMATION_DURATION ); - mAnimation.AnimateTo( Property(mBackground, Actor::SCALE), Vector3::ZERO, AlphaFunctions::EaseOut ); - mAnimation.AnimateTo( Property(mBackground, Actor::COLOR_ALPHA), 0.0f, AlphaFunctions::EaseOut ); + mAnimation.AnimateTo( Property(mRoot, Actor::Property::SCALE), Vector3::ZERO, AlphaFunctions::EaseOut ); + mAnimation.AnimateTo( Property(mRoot, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunctions::EaseOut ); mAnimation.Play(); mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnHideFinished ); @@ -466,28 +558,35 @@ void TextInputPopup::Hide(bool animate) } else { - mBackground.SetProperty(Actor::SCALE, Vector3::ZERO); - mBackground.SetProperty(Actor::COLOR_ALPHA, 0.0f); + mRoot.SetProperty(Actor::Property::SCALE, Vector3::ZERO); + mRoot.SetProperty(Actor::Property::COLOR_ALPHA, 0.0f); mState = StateHidden; } } } -void TextInputPopup::Show(bool animate) +void TextInputPopup::Show( Actor target, bool animate ) { - if(mBackground) + if( mRoot ) { + mRoot.SetSensitive( true ); + if(mAnimation) { mAnimation.Clear(); mAnimation.Reset(); } + if ( target ) + { + AddToParent( target ); + } + if(animate) { mAnimation = Animation::New( SHOW_POPUP_ANIMATION_DURATION ); - mAnimation.AnimateTo( Property(mBackground, Actor::SCALE), Vector3::ONE, AlphaFunctions::EaseOut ); - mAnimation.AnimateTo( Property(mBackground, Actor::COLOR_ALPHA), 1.0f, AlphaFunctions::EaseOut ); + mAnimation.AnimateTo( Property(mRoot, Actor::Property::SCALE), Vector3::ONE, AlphaFunctions::EaseOut ); + mAnimation.AnimateTo( Property(mRoot, Actor::Property::COLOR_ALPHA), 1.0f, AlphaFunctions::EaseOut ); mAnimation.Play(); mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnShowFinished ); @@ -495,19 +594,13 @@ void TextInputPopup::Show(bool animate) } else { - mBackground.SetProperty(Actor::SCALE, Vector3::ONE); - mBackground.SetProperty(Actor::COLOR_ALPHA, 1.0f); + mRoot.SetProperty(Actor::Property::SCALE, Vector3::ONE); + mRoot.SetProperty(Actor::Property::COLOR_ALPHA, 1.0f); mState = StateShown; } } } -void TextInputPopup::SetAlternativeOffset(Vector2 offset) -{ - mRootActor.SetProperty( mAlternativeOffsetProperty, offset ); - ApplyConfinementConstraint(); -} - TextInputPopup::State TextInputPopup::GetState(void) const { return mState; @@ -515,7 +608,272 @@ TextInputPopup::State TextInputPopup::GetState(void) const Actor TextInputPopup::GetRootActor() const { - return mRootActor; + return mRoot; +} + +// Styling + +void TextInputPopup::SetCutPastePopupColor( const Vector4& color ) +{ + mBackgroundColor = color; +} + +const Vector4& TextInputPopup::GetCutPastePopupColor() const +{ + return mBackgroundColor; +} + +void TextInputPopup::SetCutPastePopupPressedColor( const Vector4& color ) +{ + mBackgroundPressedColor = color; +} + +const Vector4& TextInputPopup::GetCutPastePopupPressedColor() const +{ + return mBackgroundPressedColor; +} + +void TextInputPopup::SetCutPastePopupBorderColor( const Vector4& color ) +{ + mLineColor = color; +} + +const Vector4& TextInputPopup::GetCutPastePopupBorderColor() const +{ + return mLineColor; +} + +void TextInputPopup::SetCutPastePopupIconColor( const Vector4& color ) +{ + mIconColor = color; +} + +const Vector4& TextInputPopup::GetCutPastePopupIconColor() const +{ + return mIconColor; +} + +void TextInputPopup::SetCutPastePopupIconPressedColor( const Vector4& color ) +{ + mIconPressedColor = color; +} + +const Vector4& TextInputPopup::GetCutPastePopupIconPressedColor() +{ + return mIconPressedColor; +} + +void TextInputPopup::SetCutPastePopupTextColor( const Vector4& color ) +{ + mTextColor = color; +} + +const Vector4& TextInputPopup::GetCutPastePopupTextColor() +{ + return mTextColor; +} + +void TextInputPopup::SetCutPastePopupTextPressedColor( const Vector4& color ) +{ + mTextPressedColor = color; +} + +const Vector4& TextInputPopup::GetCutPastePopupTextPressedColor() +{ + return mTextPressedColor; +} + +void TextInputPopup::TogglePopupButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable ) +{ + bool match ( false ); + for( std::vector::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it ) + { + ButtonRequirement& button( *it ); + if ( requiredButton == button.buttonId ) + { + button.enabled = enable; + match = true; + } + } +} + +void TextInputPopup::SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority ) +{ + switch ( button ) + { + case ButtonsCut: + { + mCutOptionPriority = priority; + break; + } + case ButtonsCopy: + { + mCopyOptionPriority = priority; + break; + } + case ButtonsPaste: + { + mPasteOptionPriority = priority; + break; + } + case ButtonsSelect: + { + mSelectOptionPriority = priority; + break; + } + case ButtonsSelectAll: + { + mSelectAllOptionPriority = priority; + break; + } + case ButtonsClipboard: + { + mClipboardOptionPriority = priority; + break; + } + case ButtonsEnumEnd: + { + DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice"); + break; + } + } + CreateOrderedListOfOptions(); // Update list of options as priority changed. +} + +unsigned int TextInputPopup::GetButtonPriorityPosition( TextInputPopup::Buttons button ) const +{ + unsigned int priority = 0; + + switch ( button ) + { + case ButtonsCut: + { + priority = mCutOptionPriority; + break; + } + case ButtonsCopy: + { + priority = mCopyOptionPriority; + break; + } + case ButtonsPaste: + { + priority = mPasteOptionPriority; + break; + } + case ButtonsSelect: + { + priority = mSelectOptionPriority; + break; + } + case ButtonsSelectAll: + { + priority = mSelectAllOptionPriority; + break; + } + case ButtonsClipboard: + { + priority = mClipboardOptionPriority; + break; + } + case ButtonsEnumEnd: + { + DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice"); + break; + } + } + + return priority; +} + +void TextInputPopup::AddPopupOptions() +{ + mContentSize = Vector2( POPUP_MIN_SIZE.width, ( POPUP_BORDER.y + POPUP_BORDER.z ) ); + + // 1. Create the background. + CreateBackground(); + + // 2. Create the tail. + CreateTail(); + + // 3. Create the scroll view and Actor to hold buttons. + CreateScrollView(); + + // Clear previous buttons + if ( mButtons ) + { + UnparentAndReset( mButtons ); + } + + mButtons = Actor::New(); + mButtons.SetParentOrigin( ParentOrigin::CENTER ); + mButtons.SetAnchorPoint( AnchorPoint::CENTER ); + + // 4. Create the options and add into the scroll view. + for( std::vector::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it ) + { + const ButtonRequirement& button( *it ); + if ( button.enabled ) + { + AddOption( button.name, button.caption, button.iconImage, it != ( endIt - 1 ) ? false : true ); + } + } + + // 5. Calculate size of content and of popup including borders + const Vector2 popupSize = Vector2( std::min ( ( POPUP_BORDER.x + mContentSize.width + POPUP_BORDER.z ), POPUP_MAX_SIZE.width ) , POPUP_BORDER.y + mContentSize.height + POPUP_BORDER.w ); + + mVisiblePopUpSize = Vector3( popupSize.width - POPUP_BORDER.x - POPUP_BORDER.z , mContentSize.height, 1.0f); + + mBackground.SetSize( popupSize.x + 28 - POPUP_BORDER.x - POPUP_BORDER.z, popupSize.y + 28 - POPUP_BORDER.y - POPUP_BORDER.w ); + mButtons.SetSize( mVisiblePopUpSize.GetVectorXY() ); + + // 6. Set the scroll view ruler. + UpdateScrollViewRulerAndSize( mVisiblePopUpSize.GetVectorXY() ); + + // 7. Create stencil + const Vector2 stencilSize = Vector2( mVisiblePopUpSize.GetVectorXY() ); + + CreateLayer( stencilSize ); + CreateStencil( stencilSize ); + + mScrollView.Add ( mButtons ); + mLayer.Add( mScrollView); + mLayer.Add( mStencil); + mRoot.Add( mTail ); + mRoot.Add( mBackground ); + mRoot.Add( mLayer ); + + // 8. Set the root size. + mRoot.SetSize( popupSize ); // Make Root Actor reflect the size of its content +} + +const Vector3& TextInputPopup::GetVisibileSize() const +{ + return mVisiblePopUpSize; +} + +void TextInputPopup::SetTailPosition( const Vector3& position, bool yAxisFlip ) +{ + mPopupTailXPosition = std::max( position.x, POPUP_TAIL_SIZE.width*0.5f - mVisiblePopUpSize.width*0.5f + POPUP_BORDER.x ); + + std::min( mPopupTailXPosition, mVisiblePopUpSize.width*0.5f - POPUP_BORDER.x - POPUP_TAIL_SIZE.width*0.5f ); + + mTail.SetX( mPopupTailXPosition ); + + if ( yAxisFlip ) + { + Image tail = ResourceImage::New( POPUP_TAIL_TOP ); + Image tailEffect = ResourceImage::New( POPUP_TAIL_TOP_EFFECT ); + Image tailLine = ResourceImage::New( POPUP_TAIL_TOP_LINE ); + + mTail.SetImage( tail ); + mTailEffect.SetImage( tailEffect ); + mTailLine.SetImage( tailLine ); + + mTail.SetParentOrigin( ParentOrigin::TOP_CENTER ); + mTail.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + mTail.SetY( POPUP_BORDER.y - POPUP_TAIL_Y_OFFSET ); + } } bool TextInputPopup::OnButtonPressed( Toolkit::Button button ) @@ -539,17 +897,17 @@ void TextInputPopup::OnShowFinished(Animation& source) mShowFinishedSignal.Emit( *this ); } -TextInputPopup::PressedSignalV2& TextInputPopup::PressedSignal() +TextInputPopup::PressedSignalType& TextInputPopup::PressedSignal() { return mPressedSignal; } -TextInputPopup::HideFinishedSignalV2& TextInputPopup::HideFinishedSignal() +TextInputPopup::VisibilityChangeFinishedSignalType& TextInputPopup::HideFinishedSignal() { return mHideFinishedSignal; } -TextInputPopup::ShowFinishedSignalV2& TextInputPopup::ShowFinishedSignal() +TextInputPopup::VisibilityChangeFinishedSignalType& TextInputPopup::ShowFinishedSignal() { return mShowFinishedSignal; }