//(2) mDisabledBackgroundContent (Inserted)
//(1) mBackgroundContent
- TransitionInBetween( mUnselectedContent, mLabel, mDisabledContent );
- TransitionInAbove( mBackgroundContent, mDisabledBackgroundContent );
+ AddButtonImage( mBackgroundContent );
+ TransitionButtonImage( mDisabledBackgroundContent );
+ AddButtonImage( mUnselectedContent );
+ TransitionButtonImage( mDisabledContent );
+ ReAddLabel();
TransitionOut( mUnselectedContent );
TransitionOut( mSelectedContent );
//(2) mSelectedBackgroundContent
//(1) mBackgroundContent
- TransitionInBetween( mSelectedContent, mLabel, mDisabledSelectedContent );
- TransitionInAbove( mSelectedBackgroundContent, mDisabledBackgroundContent );
+ AddButtonImage( mBackgroundContent );
+ AddButtonImage( mSelectedBackgroundContent );
+ TransitionButtonImage( mDisabledBackgroundContent );
+ AddButtonImage( mSelectedContent );
+ TransitionButtonImage( mDisabledSelectedContent );
+ ReAddLabel();
TransitionOut( mUnselectedContent );
TransitionOut( mSelectedContent );
//(2) mBackgroundContent (Inserted)
//(1) mDisabledBackgroundContent
- TransitionInBetween( mDisabledContent, mLabel, mUnselectedContent );
- TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
+ AddButtonImage( mDisabledBackgroundContent );
+ TransitionButtonImage( mBackgroundContent );
+ AddButtonImage( mDisabledContent );
+ TransitionButtonImage( mUnselectedContent );
+ ReAddLabel();
TransitionOut( mSelectedContent );
TransitionOut( mSelectedBackgroundContent );
//(2) mBackgroundContent (Inserted)
//(1) mDisabledBackgroundContent
- TransitionInBetween( mDisabledSelectedContent, mLabel, mSelectedContent );
- TransitionInAbove( mDisabledBackgroundContent, mSelectedBackgroundContent );
- TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
+ AddButtonImage( mDisabledBackgroundContent );
+ TransitionButtonImage( mBackgroundContent );
+ TransitionButtonImage( mSelectedBackgroundContent );
+ AddButtonImage( mDisabledSelectedContent );
+ TransitionButtonImage( mSelectedContent );
+ ReAddLabel();
TransitionOut( mUnselectedContent );
TransitionOut( mDisabledContent );
//(2) mSelectedBackgroundContent (Inserted)
//(1) mBackgroundContent
- TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
- TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
- TransitionInAtIndex( 0, mBackgroundContent );
+ AddButtonImage( mBackgroundContent );
+ TransitionButtonImage( mSelectedBackgroundContent );
+ AddButtonImage( mUnselectedContent );
+ TransitionButtonImage( mSelectedContent );
+ ReAddLabel();
TransitionOut( mUnselectedContent );
TransitionOut( mDisabledContent );
//(2) mSelectedContent
//(1) mBackgroundContent
- TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
- TransitionInAtIndex( 0, mBackgroundContent );
+ AddButtonImage( mBackgroundContent );
+ AddButtonImage( mSelectedContent );
+ TransitionButtonImage( mUnselectedContent );
+ ReAddLabel();
TransitionOut( mSelectedContent );
TransitionOut( mSelectedBackgroundContent );
//(2) mSelectedBackgroundContent (Inserted)
//(1) mBackgroundContent
- TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
- TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
- TransitionInAtIndex( 0, mBackgroundContent );
+ AddButtonImage( mBackgroundContent );
+ TransitionButtonImage( mSelectedBackgroundContent );
+ AddButtonImage( mUnselectedContent );
+ TransitionButtonImage( mSelectedContent );
+ ReAddLabel();
TransitionOut( mUnselectedContent );
TransitionOut( mDisabledContent );
//(2) mSelectedContent
//(1) mBackgroundContent
- TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
- TransitionInAtIndex( 0, mBackgroundContent );
+ AddButtonImage( mBackgroundContent );
+ AddButtonImage( mSelectedContent );
+ TransitionButtonImage( mUnselectedContent );
+ ReAddLabel();
TransitionOut( mSelectedContent );
TransitionOut( mSelectedBackgroundContent );
return mPaintState;
}
-bool Button::InsertButtonImage( unsigned int index, Actor& actor )
+void Button::PrepareAddButtonImage( Actor& actor )
{
if( actor )
{
- Self().Insert( index, actor );
+ actor.Unparent();
+ Self().Add( actor );
PrepareForTranstionOut( actor );
- return true;
}
+}
- return false;
+void Button::TransitionButtonImage( Actor& actor )
+{
+ if( actor )
+ {
+ if( !actor.GetParent() )
+ {
+ Self().Add( actor );
+ }
+
+ OnTransitionIn( actor );
+ }
+}
+
+void Button::AddButtonImage( Actor& actor )
+{
+ if( actor )
+ {
+ Self().Add( actor );
+ }
+}
+
+void Button::ReAddLabel()
+{
+ if( mLabel )
+ {
+ mLabel.Unparent();
+ Self().Add( mLabel );
+ }
}
void Button::RemoveButtonImage( Actor& actor )
return childrenNum;
}
-void Button::TransitionInBetween( Actor childLower, Actor childUpper, Actor actor )
-{
- unsigned int index = childLower ? FindChildIndex( childLower ) + 1 : FindChildIndex( childUpper );
- TransitionInAtIndex( index, actor );
-}
-
-void Button::TransitionInAbove( Actor child, Actor actor )
-{
- unsigned int index = child ? FindChildIndex( child ) + 1 : 0;
- TransitionInAtIndex( index, actor );
-}
-
-void Button::TransitionInAtIndex( unsigned int index, Actor actor )
-{
- if( actor )
- {
- if( !actor.GetParent() )
- {
- Self().Insert( index, actor );
- }
-
- OnTransitionIn( actor );
- }
-}
-
void Button::TransitionOut( Actor actor )
{
OnTransitionOut( actor );
void Button::ResetImageLayers()
{
- //ensure that all layers are in the correct order and state according to the paint state
+ // Ensure that all layers are in the correct order and state according to the paint state
- int index = 0;
switch( mPaintState )
{
case UnselectedState:
RemoveButtonImage( mDisabledSelectedContent );
RemoveButtonImage( mDisabledBackgroundContent );
- if( InsertButtonImage( index, mBackgroundContent ) )
- {
- ++index;
- }
- if( InsertButtonImage( index, mUnselectedContent ) )
- {
- ++index;
- }
+ PrepareAddButtonImage( mBackgroundContent );
+ PrepareAddButtonImage( mUnselectedContent );
break;
}
case SelectedState:
RemoveButtonImage( mDisabledSelectedContent );
RemoveButtonImage( mDisabledBackgroundContent );
- if( InsertButtonImage( index, mBackgroundContent ) )
- {
- ++index;
- }
- if( InsertButtonImage( index, mSelectedBackgroundContent ) )
- {
- ++index;
- }
- if( InsertButtonImage( index, mSelectedContent ) )
- {
- ++index;
- }
+ PrepareAddButtonImage( mBackgroundContent );
+ PrepareAddButtonImage( mSelectedBackgroundContent );
+ PrepareAddButtonImage( mSelectedContent );
+ ReAddLabel();
break;
}
case DisabledUnselectedState:
RemoveButtonImage( mDisabledSelectedContent );
RemoveButtonImage( mSelectedBackgroundContent );
- if( InsertButtonImage( index, mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ) )
- {
- ++index;
- }
- if( InsertButtonImage( index, mDisabledContent ? mDisabledContent : mUnselectedContent ) )
- {
- ++index;
- }
+ PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent );
+ PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent );
+ ReAddLabel();
break;
}
case DisabledSelectedState:
if( mDisabledBackgroundContent )
{
- if( InsertButtonImage( index, mDisabledBackgroundContent) )
- {
- ++index;
- }
+ PrepareAddButtonImage( mDisabledBackgroundContent );
}
else
{
- if( InsertButtonImage( index, mBackgroundContent ) )
- {
- ++index;
- }
- if( InsertButtonImage( index, mSelectedBackgroundContent ) )
- {
- ++index;
- }
+ PrepareAddButtonImage( mBackgroundContent );
+ PrepareAddButtonImage( mSelectedBackgroundContent );
}
- if( InsertButtonImage( index, mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent) )
- {
- ++index;
- }
+ PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
+ ReAddLabel();
break;
}
}
void ResetImageLayers();
/**
- * Transitions in the actor, inserting the actor above childLower below the childUpper.
- * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor)
+ * Transitions out the actor
*/
- void TransitionInBetween( Actor childLower, Actor childUpper, Actor actor );
+ void TransitionOut( Actor actor );
/**
- * Transitions in the actor, inserting the actor above the child if the child exists or at the bottom otherwise
- * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor)
+ * Removes the actor from the button and prepares it to be transitioned out
*/
- void TransitionInAbove( Actor child, Actor actor );
+ void RemoveButtonImage( Actor& actor );
/**
- * Transitions in the actor, inserting the actor at the index
- * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor)
+ * Finds the index of the actor.
+ * If the actor doesn't exist, return the last index + 1.
*/
- void TransitionInAtIndex( unsigned int index, Actor actor );
+ unsigned int FindChildIndex( Actor& actor );
/**
- * Transitions out the actor
+ * Adds an actor to the hierarchy and prepares it to be transitioned.
+ * @param[in] actor The actor to add
*/
- void TransitionOut( Actor actor );
+ void PrepareAddButtonImage( Actor& actor );
/**
- * Inserts the actor to the button and prepares it to be transitioned out
- * @return true if the child was inserted, false otherwise
+ * Adds an actor to the hierarchy and marks it to be transitioned.
+ * @param[in] actor The actor to add
*/
- bool InsertButtonImage( unsigned int index, Actor& actor );
+ void TransitionButtonImage( Actor& actor );
/**
- * Removes the actor from the button and prepares it to be transitioned out
+ * Adds an actor to the hierarchy.
+ * @param[in] actor The actor to add
*/
- void RemoveButtonImage( Actor& actor );
+ void AddButtonImage( Actor& actor );
/**
- * Finds the index of the actor.
- * If the actor doesn't exist, return the last index + 1.
+ * (Re)Adds the label (if exists) to the hierarchy (so it is always on top).
*/
- unsigned int FindChildIndex( Actor& actor );
-
+ void ReAddLabel();
// Undefined
Button( const Button& );