Pass stage from actor to attachment to avoid unnecessary calls to Stage::GetCurrent()
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / text-attachment-impl.h
index 03e154c..eec38ae 100644 (file)
@@ -1,21 +1,22 @@
 #ifndef __DALI_INTERNAL_TEXT_ATTACHMENT_H__
 #define __DALI_INTERNAL_TEXT_ATTACHMENT_H__
 
-//
-// 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.
+ *
+ */
 
 // INTERNAL INCLUDES
 #include <dali/public-api/math/radian.h>
 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
 #include <dali/internal/event/text/font-declarations.h>
-#include <dali/internal/common/text-array.h>
 #include <dali/internal/event/text/text-request-helper.h>
 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
 #include <dali/internal/common/owner-pointer.h>
+#include <dali/integration-api/text-array.h>
 
 namespace Dali
 {
@@ -53,25 +54,25 @@ public:
 
   /**
    * Create a new TextAttachment.
+   * @param[in] stage The stage to use for messaging
    * @param[in] parentNode The node to attach a scene-object to.
    * @param [in] text The text which will be displayed.
    * @param [in] font The font which will be used for the text.
-   * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
    * @return A smart-pointer to the newly allocated TextAttachment.
    */
-  static TextAttachmentPtr New( const SceneGraph::Node& parentNode, const TextArray& text, FontPointer font, bool isLeftToRight );
+  static TextAttachmentPtr New( Stage& stage, const SceneGraph::Node& parentNode, const Integration::TextArray& text, FontPointer font );
 
   /**
    * Set the text label displayed by the attachment
    * @param [in] text The new text label
    */
-  void SetText(const TextArray& text);
+  void SetText(const Integration::TextArray& text);
 
   /**
    * Get the text label displayed by the attachment
    * @return The text label
    */
-  const TextArray& GetText() const
+  const Integration::TextArray& GetText() const
   {
     // This is not animatable; the cached value is up-to-date.
     return mText;
@@ -103,39 +104,41 @@ public:
   }
 
   /**
-   * @copydoc Dali::TextActor::SetGradientColor()
+   * Set the text color
+   * @param[in] color The text color
    */
-  void SetGradientColor( const Vector4& color );
+  void SetTextColor(const Vector4& color);
 
   /**
-   * @copydoc Dali::TextActor::GetGradientColor()
+   * Get the text color
+   * @return The text color
    */
-  const Vector4& GetGradientColor() const;
+  Vector4 GetTextColor() const;
 
   /**
-   * @copydoc Dali::TextActor::SetGradientStartPoint()
+   * Resets to default the text color.
    */
-  void SetGradientStartPoint( const Vector2& position );
+  void ResetTextColor();
 
   /**
-   * @copydoc Dali::TextActor::GetGradientStartPoint()
+   * @copydoc Dali::TextActor::SetWeight()
    */
-  const Vector2& GetGradientStartPoint() const;
+  void SetWeight( TextStyle::Weight weight );
 
   /**
-   * @copydoc Dali::TextActor::SetGradientEndPoint()
+   * @copydoc Dali::TextActor::GetWeight()
    */
-  void SetGradientEndPoint( const Vector2& position );
+  TextStyle::Weight GetWeight() const;
 
   /**
-   * @copydoc Dali::TextActor::GetGradientEndPoint()
+   * Resets to default the text weight.
    */
-  const Vector2& GetGradientEndPoint() const;
+  void ResetWeight();
 
   /**
    * @copydoc Dali::TextActor::SetSmoothEdge(const float)
    */
-  void SetSmoothEdge(const float smoothEdge);
+  void SetSmoothEdge( float smoothEdge );
 
   /**
    * Retrieve the smooth edge value.
@@ -144,6 +147,57 @@ public:
   float GetSmoothEdge() const;
 
   /**
+   * Resets to default the smooth edge.
+   */
+  void ResetSmoothEdge();
+
+  /**
+   * Enable italics on the text actor, the text will be sheared by the given angle.
+   * @param[in] angle Italics angle in radians.
+   */
+  void SetItalics( Radian angle );
+
+  /**
+   * @copydoc Dali::TextActor::GetItalics()
+   */
+  bool GetItalics() const;
+
+  /**
+   * @copydoc Dali::TextActor::GetItalicsAngle()
+   */
+  Radian GetItalicsAngle() const;
+
+  /**
+   * Resets to default the italics.
+   */
+  void ResetItalics();
+
+  /**
+   * @copydoc Dali::TextActor::SetUnderline()
+   */
+  void SetUnderline( bool enable, float thickness, float position );
+
+  /**
+   * @copydoc Dali::TextActor::GetUnderline()
+   */
+  bool GetUnderline() const;
+
+  /**
+   * @copydoc Internal::TextActor::GetUnderlineThickness()
+   */
+  float GetUnderlineThickness() const;
+
+  /**
+   * @copydoc Internal::TextActor::GetUnderlinePosition()
+   */
+  float GetUnderlinePosition() const;
+
+  /**
+   * Resets to default the text underline.
+   */
+  void ResetUnderline();
+
+  /**
    * @copydoc Dali::TextActor::SetOutline(const bool,const Vector4&,const Vector2&)
    */
   void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
@@ -162,9 +216,14 @@ public:
   void GetOutlineParams( Vector4& color, Vector2& thickness ) const;
 
   /**
+   * Resets to default the text outline.
+   */
+  void ResetOutline();
+
+  /**
    * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
    */
-  void SetGlow( bool enable, const Vector4& color, const float intensity);
+  void SetGlow( bool enable, const Vector4& color, float intensity );
 
   /**
    * Get glow state.
@@ -180,9 +239,14 @@ public:
   void GetGlowParams( Vector4& color, float& intensity ) const;
 
   /**
+   * Resets to default the text glow.
+   */
+  void ResetGlow();
+
+  /**
    * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
    */
-  void SetShadow( bool enable, const Vector4& color, const Vector2& offset, const float size);
+  void SetShadow( bool enable, const Vector4& color, const Vector2& offset, float size );
 
   /**
    * Retrieve the shadow state.
@@ -199,57 +263,43 @@ public:
   void GetShadowParams( Vector4& color, Vector2& offset, float& size ) const;
 
   /**
-   * Set the text color
-   * @param[in] color The text color
+   * Resets to default the text shadow.
    */
-  void SetTextColor(const Vector4& color);
+  void ResetShadow();
 
   /**
-   * Get the text color
-   * @return The text color
+   * @see Dali::TextActor::SetGradientColor()
+   * @see Dali::TextActor::SetGradientStartPoint()
+   * @see Dali::TextActor::SetGradientEndPoint()
    */
-  Vector4 GetTextColor() const;
+  void SetGradient( const Vector4& color, const Vector2& startPoint, const Vector2& endPoint );
 
   /**
-   * Enable italics on the text actor, the text will be sheared by the given angle.
-   * @param[in] angle Italics angle in radians.
-   */
-  void SetItalics( const Radian& angle );
-
-  /**
-   * @copydoc Dali::TextActor::GetItalics()
-   */
-  const Radian& GetItalics() const;
-
-  /**
-   * @copydoc Dali::TextActor::SetUnderline()
-   */
-  void SetUnderline( bool enable, float thickness, float position );
-
-  /**
-   * @copydoc Dali::TextActor::GetUnderline()
+   * @copydoc Dali::TextActor::GetGradientColor()
    */
-  bool GetUnderline() const;
+  const Vector4& GetGradientColor() const;
 
   /**
-   * @copydoc Internal::TextActor::GetUnderlineThickness()
+   * @copydoc Dali::TextActor::GetGradientStartPoint()
    */
-  float GetUnderlineThickness() const;
+  const Vector2& GetGradientStartPoint() const;
 
   /**
-   * @copydoc Internal::TextActor::GetUnderlinePosition()
+   * @copydoc Dali::TextActor::GetGradientEndPoint()
    */
-  float GetUnderlinePosition() const;
+  const Vector2& GetGradientEndPoint() const;
 
   /**
-   * @copydoc Dali::TextActor::SetWeight()
+   * Resets to default the text gradient.
    */
-  void SetWeight( TextStyle::Weight weight );
+  void ResetGradient();
 
   /**
-   * @copydoc Dali::TextActor::GetWeight()
+   * Retrieves the text style.
+   *
+   * @param[out] style The text style.
    */
-  TextStyle::Weight GetWeight() const;
+  void GetTextStyle( TextStyle& style ) const;
 
   /**
    * Measure the natural size of a text string, as displayed in this font.
@@ -271,6 +321,11 @@ public:
    */
   bool IsTextLoaded();
 
+  /**
+   * Calculates the weighted smoothing value.
+   */
+  void CalculateWeightedSmoothing( TextStyle::Weight weight, float smoothEdge );
+
 public: // glyph texture observer
 
   /**
@@ -292,11 +347,6 @@ private:
    bool IsTextModified();
 
   /**
-   * Allocate a TextParameters object on this TextAttachment if one does not exist
-   */
-  void AllocateTextParameters();
-
-  /**
    * First stage construction of a TextAttachment.
    * @param[in] stage Used to send messages to scene-graph.
    */
@@ -322,17 +372,6 @@ private:
    */
   void SetTextChanges();
 
-  /**
-   * Send new texture-id message
-   */
-  void SendTextureIdMessage();
-
-  /**
-   * Make a request to load the current text
-   * @param uniqueText the text to request to be loaded
-   */
-  void RequestText( const TextArray& uniqueText );
-
 protected:
 
   /**
@@ -344,31 +383,24 @@ private:
 
   const SceneGraph::TextAttachment* mSceneObject; ///< Not owned
 
-  TextRequestHelper mTextRequestHelper;  ///< Text request helper
-  FontPointer mFont; ///< The font resource
-
+  TextRequestHelper mTextRequestHelper;           ///< Text request helper
+  FontPointer mFont;                              ///< The font resource
+  Vector4* mTextColor;                            ///< on demand storage for text color
+  TextStyle mStyle;                               ///< on demand storage for text effects parameters ( do not store font parameters and color )
+                                                  ///< Font parameters are stored in the FontPointer member. Inside the TextStyle, font parameters and color are allocated in the same struct,
+                                                  ///< so store the text color in the style will allocate space for the font parameters as well, wasting space.
   // Cached values for public getters
-  TextArray mText;
+  Integration::TextArray mText;
 
-  bool    mUnderlineEnabled:1;  ///< whether the text is underlined
-  bool    mIsLeftToRight:1;     ///< whether the text is left to right
   bool    mTextChanged:1;       ///< whether the text has changed
   bool    mFontChanged:1;       ///< whether the font has changed
   bool    mUnderlineChanged:1;  ///< whether the underline has changed
   bool    mItalicsChanged:1;    ///< whether the italics has changed
-  bool    mItalicsEnabled:1;    ///< whether italics are enabled
   bool    mTextureIdSet:1;      ///< flag to signify if the texture id has been set on the scene-graph text-attachment
   unsigned int mTextureId;      ///< the texture id of the glyph atlas being used
-  float   mSmoothing;           ///< edge smoothing for the font
-  Radian  mItalicsAngle;        ///< font italics angle
-  float mUnderlineThickness;    ///< The underline's thickness.
-  float mUnderlinePosition;     ///< The underline's position.
   Vector2 mTextSize;            ///< text natural size
-  TextStyle::Weight mWeight;    ///< font weight
 
   OwnerPointer< TextVertexBuffer > mVertexBuffer; ///< vertex data to display the text
-  OwnerPointer< TextParameters > mTextParameters; ///< on demand storage for text effect parameters
-  Vector4* mTextColor;                            ///< on demand storage for text color
 };
 
 } // namespace Internal