- /**
- * Popup
- */
-
- void CreateOrderedListOfPopupOptions()
- {
- mCopyPastePopup.mOrderListOfButtons.clear();
-
- // Create button for each possible option using Option priority
- ResourceImage cutIcon = ResourceImage::New( OPTION_ICON_CUT );
- mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCut, mCopyPastePopup.mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), cutIcon, true ) );
-
- ResourceImage copyIcon = ResourceImage::New( OPTION_ICON_COPY );
- mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCopy, mCopyPastePopup.mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), copyIcon, true ) );
-
- ResourceImage pasteIcon = ResourceImage::New( OPTION_ICON_PASTE );
- mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsPaste, mCopyPastePopup.mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon, true ) );
-
- ResourceImage selectIcon = ResourceImage::New( OPTION_ICON_SELECT );
- mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelect, mCopyPastePopup.mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), selectIcon, true ) );
-
- ResourceImage selectAllIcon = ResourceImage::New( OPTION_ICON_SELECT_ALL );
- mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelectAll, mCopyPastePopup.mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon, true ) );
-
- ResourceImage clipboardIcon = ResourceImage::New( OPTION_ICON_CLIPBOARD );
- mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsClipboard, mCopyPastePopup.mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, true ) );
-
- // Sort the buttons according their priorities.
- std::sort( mCopyPastePopup.mOrderListOfButtons.begin(), mCopyPastePopup.mOrderListOfButtons.end(), PriorityCompare );
- }
-
- void CreateBackground( PopupImpl& popup )
- {
- // Create background-panel if not already created (required if we have at least one option)
- if ( !popup.mBackground )
- {
- ResourceImage bgImg = ResourceImage::New( POPUP_BACKGROUND );
- popup.mBackground = ImageActor::New( bgImg );
- popup.mBackground.SetColor( popup.mBackgroundColor );
- popup.mBackground.SetParentOrigin( ParentOrigin::CENTER );
-
- NinePatchImage backgroundImageNinePatch = NinePatchImage::DownCast( bgImg );
- if( backgroundImageNinePatch )
- {
- const Size ninePatchImageSize = Size( static_cast<float>( bgImg.GetWidth() ), static_cast<float>( bgImg.GetHeight() ) );
- Rect<int> childRect = backgroundImageNinePatch.GetChildRectangle();
-
- // -1u because of the cropping.
- popup.mNinePatchMargins.x = childRect.x - 1u;
- popup.mNinePatchMargins.y = ninePatchImageSize.width - ( childRect.x + childRect.width ) - 1u;
- popup.mNinePatchMargins.z = childRect.y - 1u;
- popup.mNinePatchMargins.w = ninePatchImageSize.height - ( childRect.y + childRect.height ) - 1u;
- }
-
- ResourceImage::Image bgEffectImg = ResourceImage::New( POPUP_BACKGROUND_EFFECT );
- ImageActor backgroundEffect = ImageActor::New( bgEffectImg );
- backgroundEffect.SetParentOrigin( ParentOrigin::CENTER );
-
- ResourceImage::Image bgLine = ResourceImage::New( POPUP_BACKGROUND_LINE );
- ImageActor backgroundLine = ImageActor::New( bgLine );
- backgroundLine.SetParentOrigin( ParentOrigin::CENTER );
- backgroundLine.SetColor( popup.mLineColor );
-
- popup.mBackground.Add( backgroundEffect );
- popup.mBackground.Add( backgroundLine );
- }
- }
-
- void AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons )
- {
- // 1. Create the backgrounds for the popup option both normal and pressed.
- // Both containers will be added to a button.
- Actor optionContainer = Actor::New();
- optionContainer.SetDrawMode( DrawMode::OVERLAY );
- //optionContainer.SetParentOrigin( ParentOrigin::CENTER );
- optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
- ImageActor optionPressedContainer = Toolkit::CreateSolidColorActor( mCopyPastePopup.mBackgroundPressedColor );
- optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
- //optionPressedContainer.SetParentOrigin( ParentOrigin::CENTER );
- optionPressedContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
- // 2. Add text.
- Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
- captionTextLabel.SetProperty( TextLabel::Property::TEXT, caption );
- optionContainer.Add( captionTextLabel );
-
- Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
- pressedCaptionTextLabel.SetProperty( TextLabel::Property::TEXT, caption );
- optionPressedContainer.Add( pressedCaptionTextLabel );
-
- // Calculates the icon/text position.
- float iconTextOffsetY = 0.0f;
-
- if ( showIcons )
- {
- // 3. Create the icons
- ImageActor pressedIcon = ImageActor::New( iconImage );
- ImageActor icon = ImageActor::New( iconImage );
-
- optionContainer.Add( icon );
- optionPressedContainer.Add( pressedIcon );
-
- iconTextOffsetY = 0.5f * ( ( DEFAULT_POPUP_MAX_SIZE.height - mCopyPastePopup.mNinePatchMargins.z - mCopyPastePopup.mNinePatchMargins.w ) - ( OPTION_ICON_SIZE.height + OPTION_GAP_ICON_TEXT + OPTION_TEXT_LINE_HEIGHT ) );
-
- icon.SetParentOrigin( ParentOrigin::TOP_CENTER );
- icon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- icon.SetY( iconTextOffsetY );
-
- pressedIcon.SetParentOrigin( ParentOrigin::TOP_CENTER );
- pressedIcon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- pressedIcon.SetY( iconTextOffsetY );
-
- // Layout icon + gap + text
- captionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
- pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
- pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
- captionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
- pressedCaptionTextLabel.SetY( -iconTextOffsetY );
- captionTextLabel.SetY( -iconTextOffsetY );
- }
- else
- {
- // Centre option text
- captionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
- captionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
- pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
- pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
- }
-
- // Calculate the size of the text.
- Vector3 textSize = captionTextLabel.GetNaturalSize();
- textSize.width = std::min( textSize.width, OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH );
-
- // Set the size to the text. Text will be ellipsized if exceeds the max width.
- captionTextLabel.SetSize( textSize );
- pressedCaptionTextLabel.SetSize( textSize );
-
- // 4. Calculate the size of option.
-
- // The width is the max size of the text or the icon plus the margins clamped between the option min and max size.
- // The height is the whole popup height minus the ninepatch margins.
- const Vector2 optionSize( std::min( OPTION_MAX_WIDTH, std::max( OPTION_MIN_WIDTH, std::max( textSize.width, OPTION_ICON_SIZE.width ) + 2.f * OPTION_MARGIN_WIDTH ) ),
- DEFAULT_POPUP_MAX_SIZE.height - mCopyPastePopup.mNinePatchMargins.z - mCopyPastePopup.mNinePatchMargins.w );
-
- optionContainer.SetSize( optionSize );
- optionPressedContainer.SetSize( optionSize );
-
- // 5. Create a option.
- Toolkit::PushButton option = Toolkit::PushButton::New();
- option.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
- option.SetSize( optionSize );
- option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- option.SetX( mCopyPastePopup.mContentSize.width );
- option.SetName( name );
- option.SetAnimationTime( 0.0f );
- //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
-
- parent.Add( option );
-
- // 6. Set the normal option image.
- option.SetButtonImage( optionContainer );
-
- // 7. Set the pressed option image
- option.SetSelectedImage( optionPressedContainer );
-
- // 8. Update the content size.
- mCopyPastePopup.mContentSize.width += optionSize.width;
- mCopyPastePopup.mContentSize.height = std::max ( optionSize.height, mCopyPastePopup.mContentSize.height );
-
- // 9. Add the divider
- if( !finalOption )
- {
- const Size size( POPUP_DIVIDER_WIDTH, mCopyPastePopup.mContentSize.height );
-
- ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
- divider.SetSize (size);
- divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
- divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- divider.SetPosition( mCopyPastePopup.mContentSize.width - POPUP_DIVIDER_WIDTH, 0.0f );
- parent.Add( divider );
- }
- }
-
- void SetUpPopup( Actor& parent, Size& size )
- {
- // Create Layer and Stencil.
- parent = Layer::New();
- Layer layer = Layer::New();
- ImageActor stencil = CreateSolidColorActor( Color::RED );
- stencil.SetDrawMode( DrawMode::STENCIL );
- stencil.SetVisible( true );
- Actor scrollview = Actor::New();
-
- //todo Use Size negotiation
- layer.SetSize( size ); // matches stencil size
- parent.SetSize( size ); // matches stencil size
- stencil.SetSize( size );
- scrollview.SetSize( size );
- mCopyPastePopup.mButtons.SetSize( size );
-
- layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
- scrollview.SetAnchorPoint(AnchorPoint::TOP_LEFT);
- //mCopyPastePopup.mBackground.SetAnchorPoint(AnchorPoint::TOP_LEFT);
- mCopyPastePopup.mButtons.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
- parent.Add( mCopyPastePopup.mBackground );
- parent.Add( layer );
- layer.Add( stencil );
- layer.Add( scrollview );
- scrollview.Add( mCopyPastePopup.mButtons );
- }
-
- void AddPopupOptions( bool createTail, bool showIcons )
- {
- mCopyPastePopup.mShowIcons = showIcons;
-
- mCopyPastePopup.mContentSize = Vector2::ZERO;
-
- mCopyPastePopup.mButtons = Actor::New();
-
- // Add the options into the buttons container.
-
- // 1. Determine how many buttons are active and should be added to container.
- std::size_t numberOfOptions = 0u;
- for( std::vector<ButtonRequirement>::const_iterator it = mCopyPastePopup.mOrderListOfButtons.begin(), endIt = mCopyPastePopup.mOrderListOfButtons.end(); ( it != endIt ); ++it )
- {
- const ButtonRequirement& button( *it );
- if( button.enabled )
- {
- ++numberOfOptions;
- }
- }
-
- // 2. Iterate list of buttons and add active ones.
- std::size_t optionsAdded = 0u;
- for( std::vector<ButtonRequirement>::const_iterator it = mCopyPastePopup.mOrderListOfButtons.begin(), endIt = mCopyPastePopup.mOrderListOfButtons.end(); ( it != endIt ); ++it )
- {
- const ButtonRequirement& button( *it );
- if ( button.enabled )
- {
- ++optionsAdded;
- AddOption( mCopyPastePopup.mButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions, mCopyPastePopup.mShowIcons );
- }
- }
-
- // Calculate the size of the whole popup which may not be all visible.
- mCopyPastePopup.mRequiredPopUpSize = Size( std::min( mCopyPastePopup.mMaxWidth, mCopyPastePopup.mContentSize.width + mCopyPastePopup.mNinePatchMargins.x + mCopyPastePopup.mNinePatchMargins.y ), DEFAULT_POPUP_MAX_SIZE. height );
-
- // Set the size of the background, background line and background effect.
- mCopyPastePopup.mBackground.SetSize( mCopyPastePopup.mRequiredPopUpSize);
- for( std::size_t index = 0u, childCount = mCopyPastePopup.mBackground.GetChildCount(); index < childCount; ++index )
- {
- mCopyPastePopup.mBackground.GetChildAt( index ).SetSize( mCopyPastePopup.mRequiredPopUpSize );
- }
-
- // Size of the contents within the popup
- mCopyPastePopup.mVisiblePopUpSize = Size( mCopyPastePopup.mRequiredPopUpSize.width - mCopyPastePopup.mNinePatchMargins.x - mCopyPastePopup.mNinePatchMargins.y, mCopyPastePopup.mRequiredPopUpSize.height - mCopyPastePopup.mNinePatchMargins.z - mCopyPastePopup.mNinePatchMargins.w );
-
- }
-
- void CreatePopup()
- {
- if ( !mCopyPastePopup.mRoot )
- {
- mActiveCopyPastePopup = true;
- CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
- CreateBackground( mCopyPastePopup );
- AddPopupOptions( true, true );
- SetUpPopup( mCopyPastePopup.mRoot, mCopyPastePopup.mVisiblePopUpSize );
- Actor textControl = mTextControlParent.Self();
- textControl.Add( mCopyPastePopup.mRoot );
- }
- }
-
- void DestroyPopup()
- {
- if ( mCopyPastePopup.mRoot )
- {
- mActiveCopyPastePopup = false;
- UnparentAndReset( mCopyPastePopup.mButtons );
- UnparentAndReset( mCopyPastePopup.mRoot );
- }
- }