Refactoring Button: remove painter
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.h
index f0884e1..2c4c115 100644 (file)
@@ -24,7 +24,6 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/buttons/button.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/buttons/button.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
-#include "button-painter-impl.h"
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -118,7 +117,7 @@ public:
   /**
    * @copydoc Dali::Toolkit::Button::SetSelected( bool selected )
    */
   /**
    * @copydoc Dali::Toolkit::Button::SetSelected( bool selected )
    */
-  virtual void SetSelected( bool selected );
+  void SetSelected( bool selected );
 
   /**
    * @copydoc Dali::Toolkit::Button::IsSelected() const
 
   /**
    * @copydoc Dali::Toolkit::Button::IsSelected() const
@@ -143,7 +142,7 @@ public:
   /**
    * @copydoc Dali::Toolkit::Button::SetLabel( Actor label )
    */
   /**
    * @copydoc Dali::Toolkit::Button::SetLabel( Actor label )
    */
-  virtual void SetLabel( Actor label );   // TODO: After refactoring painter, virtual will be removed
+  void SetLabel( Actor label );
 
   /**
    * @copydoc Dali::Toolkit::Button::GetLabel()
 
   /**
    * @copydoc Dali::Toolkit::Button::GetLabel()
@@ -151,165 +150,120 @@ public:
   Actor GetLabel() const;
 
   /**
   Actor GetLabel() const;
 
   /**
-   * Used by the painter only.
-   * @return A reference to the label actor.
-   */
-  Actor& GetLabel();
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image )
-   */
-  void SetButtonImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
-   */
-  void SetButtonImage( Actor image );
-
-  /**
    * @copydoc Dali::Toolkit::PushButton::GetButtonImage()
    */
   Actor GetButtonImage() const;
 
   /**
    * @copydoc Dali::Toolkit::PushButton::GetButtonImage()
    */
   Actor GetButtonImage() const;
 
   /**
-   * Used by the painter only.
+   * Internal use only.
    * @return A reference to the button image.
    */
   Actor& GetButtonImage();
 
   /**
    * @return A reference to the button image.
    */
   Actor& GetButtonImage();
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( const Image image )
-   */
-  void SetSelectedImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
-   */
-  void SetSelectedImage( Actor image );
-
-  /**
    * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
    */
   Actor GetSelectedImage() const;
 
   /**
    * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
    */
   Actor GetSelectedImage() const;
 
   /**
-   * Used by the painter only.
+   * Internal use only.
    * @return A reference to the selected image.
    */
   Actor& GetSelectedImage();
 
   /**
    * @return A reference to the selected image.
    */
   Actor& GetSelectedImage();
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image )
-   */
-  void SetBackgroundImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
-   */
-  void SetBackgroundImage( Actor image );
-
-  /**
    * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
    */
   Actor GetBackgroundImage() const;
 
   /**
    * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
    */
   Actor GetBackgroundImage() const;
 
   /**
-   * Used by the painter only.
+   * Internal use only.
    * @return A reference to the background image.
    */
   Actor& GetBackgroundImage();
 
   /**
    * @return A reference to the background image.
    */
   Actor& GetBackgroundImage();
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Image image )
-   */
-  void SetDisabledImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
-   */
-  void SetDisabledImage( Actor image );
-
-  /**
    * @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
    */
   Actor GetDisabledImage() const;
 
   /**
    * @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
    */
   Actor GetDisabledImage() const;
 
   /**
-   * Used by the painter only.
+   * Internal use only.
    * @return A reference to the disabled button image.
    */
   Actor& GetDisabledImage();
 
   /**
    * @return A reference to the disabled button image.
    */
   Actor& GetDisabledImage();
 
   /**
-   * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Image image )
+   * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage()
    */
    */
-  void SetDisabledSelectedImage( Image image );
+  Actor GetDisabledSelectedImage() const;
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
+   * Internal use only.
+   * @return A reference to the disabled selected image.
    */
    */
-  void SetDisabledSelectedImage( Actor image );
+  Actor& GetDisabledSelectedImage();
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage()
+   * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
    */
    */
-  Actor GetDisabledSelectedImage() const;
+  Actor GetDisabledBackgroundImage() const;
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the disabled selected image.
+   * Internal use only.
+   * @return A reference to the disabled background image.
    */
    */
-  Actor& GetDisabledSelectedImage();
+  Actor& GetDisabledBackgroundImage();
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Image image )
+   * Performs actions as requested using the action name.
+   * @param[in] object The object on which to perform the action.
+   * @param[in] actionName The action to perform.
+   * @param[in] attributes The attributes with which to perfrom this action.
+   * @return true if action has been accepted by this control
    */
    */
-  void SetDisabledBackgroundImage( Image image );
+  static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes );
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
+   * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
    */
    */
-  void SetDisabledBackgroundImage( Actor image );
+  virtual void SetButtonImage( Actor image ) {}
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
+   * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
    */
    */
-  Actor GetDisabledBackgroundImage() const;
+  virtual void SetSelectedImage( Actor image ) {}
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the disabled background image.
+   * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
    */
    */
-  Actor& GetDisabledBackgroundImage();
+  virtual void SetBackgroundImage( Actor image ) {}
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the button image that is fading out.
+   * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
    */
    */
-  Actor& GetFadeOutButtonImage();
+  virtual void SetDisabledImage( Actor image ) {}
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the selected image that is fading out.
+   * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
    */
    */
-  Actor& GetFadeOutSelectedImage();
+  virtual void SetDisabledSelectedImage( Actor image ) {}
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the background image that is fading out.
+   * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
    */
    */
-  Actor& GetFadeOutBackgroundImage();
+  virtual void SetDisabledBackgroundImage( Actor image ) {}
+
+protected:
 
   /**
 
   /**
-   * Performs actions as requested using the action name.
-   * @param[in] object The object on which to perform the action.
-   * @param[in] actionName The action to perform.
-   * @param[in] attributes The attributes with which to perfrom this action.
-   * @return true if action has been accepted by this control
+   * Internal use only.
+   * @return A reference to the label actor.
    */
    */
-  static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes );
+  Actor& GetLabel();
 
 private:
 
 private:
+
   /**
    * Perform the click action to click the button.
    * @param[in] attributes The attributes to perfrom this action.
   /**
    * Perform the click action to click the button.
    * @param[in] attributes The attributes to perfrom this action.
@@ -348,24 +302,40 @@ private:
   virtual void OnTouchPointInterrupted();
 
   /**
   virtual void OnTouchPointInterrupted();
 
   /**
-   * This method is called when the animation time is set.
-   * Needs to be reimplemented in subclasses to set the animation time in different buttons.
-   * @param animationTime The animation time in seconds.
+   * This method is called when the button is removed from the stage.
+   * Could be reimplemented in subclasses to provide specific behaviour.
    */
    */
-  virtual void OnAnimationTimeSet( float animationTime );
+  virtual void OnButtonStageDisconnection();
 
   /**
 
   /**
-   * This method is called when the animation time is requested.
-   * Needs to be reimplemented in subclases to return the animation time.
-   * @return The animation time in seconds.
+   * This method is called when the label is set.
    */
    */
-  virtual float OnAnimationTimeRequested() const;
+  virtual void OnLabelSet() {}
 
   /**
 
   /**
-   * This method is called when the button is removed from the stage.
-   * Could be reimplemented in subclasses to provide specific behaviour.
+   * This method is called when the \e selected property is changed.
    */
    */
-  virtual void OnButtonStageDisconnection();
+  virtual void OnSelected( bool selected ) {}
+
+  /**
+   * This method is called when the \e disabled property is changed.
+   */
+  virtual void OnDisabled( bool disabled ) {}
+
+  /**
+   * This method is called when the button is pressed.
+   */
+  virtual void OnPressed() {}
+
+  /**
+   * This method is called when the button is released.
+   */
+  virtual void OnReleased() {}
+
+  /**
+   * This method is called when the button is clicked
+   */
+  virtual void OnClicked() {}
 
 public:
 
 
 public:
 
@@ -438,11 +408,6 @@ private: // From Control
   virtual void OnActivated();
 
   /**
   virtual void OnActivated();
 
   /**
-   * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
-   */
-  virtual void OnControlSizeSet( const Vector3& targetSize );
-
-  /**
    * Callback received when the button is disconnected from the stage.
    * It resets the button status.
    */
    * Callback received when the button is disconnected from the stage.
    * It resets the button status.
    */
@@ -479,14 +444,25 @@ protected:
     ButtonDown,                                ///< The button is down.
   };
 
     ButtonDown,                                ///< The button is down.
   };
 
-  void SetPainter(ButtonPainterPtr painter);
+  /**
+   * Button paint states.
+   */
+  enum PaintState
+  {
+    UnselectedState,              ///< The button is unselected.
+    SelectedState,                ///< The button is selected.
+    DisabledUnselectedState,      ///< The button is disabled and unselected.
+    DisabledSelectedState,        ///< The button is disabled and selected.
+    UnselectedSelectedTransition, ///< The button is in transition from unselected to selected.
+    SelectedUnselectedTransition, ///< The push button is in transition from selected to unselected.
+    UnselectedDisabledTransition, ///< The button is in transition from unselected to disabled.
+    DisabledUnselectedTransition, ///< The button is in transition from disabled to unselected.
+    SelectedDisabledTransition,   ///< The button is in transition from selected to disabled.
+    DisabledSelectedTransition    ///< The button is in transition from disabled to selected.
+  };
 
   ButtonState GetState();
 
 
   ButtonState GetState();
 
-  Actor mLabel;                                //TODO: After refactoring painter, this will be private
-  bool  mTogglableButton;                      //TODO: After refactoring painter, this will be private
-  bool  mSelected;                             //TODO: After refactoring painter, this will be private
-
 private:
 
   // Undefined
 private:
 
   // Undefined
@@ -497,37 +473,32 @@ private:
 
 private:
 
 
 private:
 
-  ButtonPainterPtr mPainter;                   ///< Pointer to a ButtonPainter base class.
-
   // Signals
   Toolkit::Button::ButtonSignalType mPressedSignal;           ///< Signal emitted when the button is pressed.
   // Signals
   Toolkit::Button::ButtonSignalType mPressedSignal;           ///< Signal emitted when the button is pressed.
-  Toolkit::Button::ButtonSignalType mReleasedSignal;         ///< Signal emitted when the button is released.
+  Toolkit::Button::ButtonSignalType mReleasedSignal;          ///< Signal emitted when the button is released.
   Toolkit::Button::ButtonSignalType mClickedSignal;           ///< Signal emitted when the button is clicked.
   Toolkit::Button::ButtonSignalType mClickedSignal;           ///< Signal emitted when the button is clicked.
-  Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed.
+  Toolkit::Button::ButtonSignalType mStateChangedSignal;      ///< Signal emitted when the button's state is changed.
 
   Timer mAutoRepeatingTimer;                   ///< Timer used to implement the autorepeating property.
 
 
   Timer mAutoRepeatingTimer;                   ///< Timer used to implement the autorepeating property.
 
-//  Actor mLabel;                                ///< Stores the button label.
-
-  Actor mButtonImage;                          ///< Stores the unselected image.
-  Actor mSelectedImage;                        ///< Stores the selected image.
-  Actor mBackgroundImage;                      ///< Stores the background image.
-  Actor mDisabledImage;                        ///< Stores the disabled image.
-  Actor mDisabledSelectedImage;                ///< Stores the disabled selected image.
-  Actor mDisabledBackgroundImage;              ///< Stores the disabled background image.
+  Actor mLabel;                                ///< Stores the button label.
 
 
-  Actor mFadeOutButtonImage;                   ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
-  Actor mFadeOutSelectedImage;                 ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
-  Actor mFadeOutBackgroundImage;               ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
+  Actor mButtonContent;                        ///< Stores the unselected content.
+  Actor mSelectedContent;                      ///< Stores the selected content.
+  Actor mBackgroundContent;                    ///< Stores the background content.
+  Actor mDisabledContent;                      ///< Stores the disabled content.
+  Actor mDisabledSelectedContent;              ///< Stores the disabled selected content.
+  Actor mDisabledBackgroundContent;            ///< Stores the disabled background content.
 
   TapGestureDetector mTapDetector;
 
   bool             mDisabled;                  ///< Stores the disabled property.
   bool             mAutoRepeating;             ///< Stores the autorepeating property.
 
   TapGestureDetector mTapDetector;
 
   bool             mDisabled;                  ///< Stores the disabled property.
   bool             mAutoRepeating;             ///< Stores the autorepeating property.
-//  bool             mTogglableButton;           ///< Stores the togglable property.
-//  bool             mSelected;                  ///< Stores the selected state.
+  bool             mTogglableButton;           ///< Stores the togglable property.
+  bool             mSelected;                  ///< Stores the selected state.
   float            mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
   float            mNextAutoRepeatingDelay;    ///< Stores the next autorepeating delay in seconds.
   float            mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
   float            mNextAutoRepeatingDelay;    ///< Stores the next autorepeating delay in seconds.
+  float            mAnimationTime;             ///< The animation time.
 
   // Actions
   bool             mClickActionPerforming;
 
   // Actions
   bool             mClickActionPerforming;
@@ -537,7 +508,6 @@ private:
 
 } // namespace Internal
 
 
 } // namespace Internal
 
-
 // Helpers for public-api forwarding methods
 
 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
 // Helpers for public-api forwarding methods
 
 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )