From: Paul Wisbey Date: Wed, 4 Mar 2015 18:08:51 +0000 (+0000) Subject: Merge remote-tracking branch 'origin/tizen' into new_text X-Git-Tag: new_text_0.1~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F36309%2F4;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Merge remote-tracking branch 'origin/tizen' into new_text Conflicts: build/tizen/dali-toolkit/Makefile.am dali-toolkit/dali-toolkit.h dali-toolkit/internal/controls/buttons/button-impl.cpp dali-toolkit/internal/controls/buttons/push-button-impl.cpp dali-toolkit/internal/controls/text-input/text-input-decorator-impl.cpp dali-toolkit/internal/controls/text-input/text-input-impl.cpp dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp dali-toolkit/public-api/controls/text-input/text-input.h dali-toolkit/public-api/controls/text-view/text-view.h Change-Id: I47246662ec5ea38428d62f11f9dd5e5bc0c50dd1 --- 928136dbb9e23970f3894eabc7c8b224003b77be diff --cc dali-toolkit/dali-toolkit.h index ddadae0,2acf635..844fe87 --- a/dali-toolkit/dali-toolkit.h +++ b/dali-toolkit/dali-toolkit.h @@@ -83,6 -84,11 +84,9 @@@ #include #include -#include - + #include + #include + #include #include #include diff --cc dali-toolkit/internal/controls/buttons/button-impl.cpp index 4e98d75,4f7dd86..b847925 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@@ -233,7 -229,9 +228,6 @@@ float Button::GetAnimationTime() cons void Button::SetLabel( const std::string& label ) { - RelayoutRequest(); - Toolkit::TextView textView = Toolkit::TextView::New( label ); - textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button - SetLabel( textView ); } void Button::SetLabel( Actor label ) diff --cc dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 628fe67,4aae15b..bd26b23 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@@ -24,8 -23,7 +23,6 @@@ #include // INTERNAL INCLUDES - #include "push-button-default-painter-impl.h" - -#include #include namespace Dali diff --cc dali-toolkit/public-api/controls/text-controls/text-field.h index 4d97b03,0000000..0f1b4fd mode 100644,000000..100644 --- a/dali-toolkit/public-api/controls/text-controls/text-field.h +++ b/dali-toolkit/public-api/controls/text-controls/text-field.h @@@ -1,134 -1,0 +1,134 @@@ +#ifndef __DALI_TOOLKIT_TEXT_FIELD_H__ +#define __DALI_TOOLKIT_TEXT_FIELD_H__ + +/* + * Copyright (c) 2015 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 +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal DALI_INTERNAL +{ +class TextField; +} + +/** + * @brief A control which provides a single-line editable text field. + */ +class DALI_IMPORT_API TextField : public Control +{ +public: + + // Property indices - static const Property::Index PROPERTY_RENDERING_BACKEND; ///< name "rendering-backend", type INT - static const Property::Index PROPERTY_PLACEHOLDER_TEXT; ///< name "placeholder-text", type STRING - static const Property::Index PROPERTY_TEXT; ///< name "text", type STRING - static const Property::Index PROPERTY_CURSOR_IMAGE; ///< name "cursor-image", type STRING - static const Property::Index PROPERTY_PRIMARY_CURSOR_COLOR; ///< name "primary-cursor-color", type VECTOR4 - static const Property::Index PROPERTY_SECONDARY_CURSOR_COLOR; ///< name "secondary-cursor-color", type VECTOR4 - static const Property::Index PROPERTY_ENABLE_CURSOR_BLINK; ///< name "enable-cursor-blink", type BOOLEAN - static const Property::Index PROPERTY_CURSOR_BLINK_INTERVAL; ///< name "cursor-blink-interval", type FLOAT - static const Property::Index PROPERTY_CURSOR_BLINK_DURATION; ///< name "cursor-blink-duration", type FLOAT - static const Property::Index PROPERTY_GRAB_HANDLE_IMAGE; ///< name "grab-handle-image", type STRING - static const Property::Index PROPERTY_DECORATION_BOUNDING_BOX; ///< name "decoration-bounding-box", type RECTANGLE ++ static const Dali::Property::Index PROPERTY_RENDERING_BACKEND; ///< name "rendering-backend", type INT ++ static const Dali::Property::Index PROPERTY_PLACEHOLDER_TEXT; ///< name "placeholder-text", type STRING ++ static const Dali::Property::Index PROPERTY_TEXT; ///< name "text", type STRING ++ static const Dali::Property::Index PROPERTY_CURSOR_IMAGE; ///< name "cursor-image", type STRING ++ static const Dali::Property::Index PROPERTY_PRIMARY_CURSOR_COLOR; ///< name "primary-cursor-color", type VECTOR4 ++ static const Dali::Property::Index PROPERTY_SECONDARY_CURSOR_COLOR; ///< name "secondary-cursor-color", type VECTOR4 ++ static const Dali::Property::Index PROPERTY_ENABLE_CURSOR_BLINK; ///< name "enable-cursor-blink", type BOOLEAN ++ static const Dali::Property::Index PROPERTY_CURSOR_BLINK_INTERVAL; ///< name "cursor-blink-interval", type FLOAT ++ static const Dali::Property::Index PROPERTY_CURSOR_BLINK_DURATION; ///< name "cursor-blink-duration", type FLOAT ++ static const Dali::Property::Index PROPERTY_GRAB_HANDLE_IMAGE; ///< name "grab-handle-image", type STRING ++ static const Dali::Property::Index PROPERTY_DECORATION_BOUNDING_BOX; ///< name "decoration-bounding-box", type RECTANGLE + + // Property names + static const std::string RENDERING_BACKEND_PROPERTY_NAME; ///< Property, name "rendering-backend", type INT + static const std::string PLACEHOLDER_TEXT_PROPERTY_NAME; ///< Property, name "placeholder-text", type STRING + static const std::string TEXT_PROPERTY_NAME; ///< Property, name "text", type STRING + static const std::string CURSOR_IMAGE_PROPERTY_NAME; ///< Property, name "cursor-image", type STRING + static const std::string PRIMARY_CURSOR_COLOR_PROPERTY_NAME; ///< Property, name "primary-cursor-color", type VECTOR4 + static const std::string SECONDARY_CURSOR_COLOR_PROPERTY_NAME; ///< Property, name "secondary-cursor-color", type VECTOR4 + static const std::string ENABLE_CURSOR_BLINK_PROPERTY_NAME; ///< Property, name "enable-cursor-blink", type BOOLEAN + static const std::string CURSOR_BLINK_INTERVAL_PROPERTY_NAME; ///< Property, name "cursor-blink-interval", type FLOAT + static const std::string CURSOR_BLINK_DURATION_PROPERTY_NAME; ///< Property, name "cursor-blink-duration", type FLOAT + static const std::string GRAB_HANDLE_IMAGE_PROPERTY_NAME; ///< Property, name "grab-handle-image", type STRING + static const std::string DECORATION_BOUNDING_BOX; ///< Property, name "decoration-bounding-box", type RECTANGLE + + /** + * Create the TextField control. + * @return A handle to the TextField control. + */ + static TextField New(); + + /** + * @brief Creates an empty handle. + */ + TextField(); + + /** + * @brief Copy constructor. + * + * @param[in] handle The handle to copy from. + */ + TextField( const TextField& handle ); + + /** + * @brief Assignment operator. + * + * @param[in] handle The handle to copy from. + * @return A reference to this. + */ + TextField& operator=( const TextField& handle ); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~TextField(); + + /** + * @brief Downcast a handle to TextField. + * + * If the BaseHandle points is a TextField the downcast returns a valid handle. + * If not the returned handle is left empty. + * + * @param[in] handle Handle to an object + * @return handle to a TextField or an empty handle + */ + static TextField DownCast( BaseHandle handle ); + +public: // Not intended for application developers + + /** + * @brief Creates a handle using the Toolkit::Internal implementation. + * + * @param[in] implementation The Control implementation. + */ + DALI_INTERNAL TextField( Internal::TextField& implementation ); + + /** + * @brief Allows the creation of this Control from an Internal::CustomActor pointer. + * + * @param[in] internal A pointer to the internal CustomActor. + */ + explicit DALI_INTERNAL TextField( Dali::Internal::CustomActor* internal ); +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_FIELD_H__ diff --cc dali-toolkit/public-api/controls/text-controls/text-label.h index 00398b3,0000000..e1f69c0 mode 100644,000000..100644 --- a/dali-toolkit/public-api/controls/text-controls/text-label.h +++ b/dali-toolkit/public-api/controls/text-controls/text-label.h @@@ -1,120 -1,0 +1,120 @@@ +#ifndef __DALI_TOOLKIT_TEXT_LABEL_H__ +#define __DALI_TOOLKIT_TEXT_LABEL_H__ + +/* + * Copyright (c) 2015 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 +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal DALI_INTERNAL +{ +class TextLabel; +} + +/** + * @brief A control which renders a short text string. + * + * Text labels are lightweight, non-editable and do not respond to user input. + */ +class DALI_IMPORT_API TextLabel : public Control +{ +public: + + // Property indices - static const Property::Index PROPERTY_RENDERING_BACKEND; ///< name "rendering-backend", type INT - static const Property::Index PROPERTY_TEXT; ///< name "text", type STRING - static const Property::Index PROPERTY_MULTI_LINE; ///< name "multi-line", type BOOLEAN ++ static const Dali::Property::Index PROPERTY_RENDERING_BACKEND; ///< name "rendering-backend", type INT ++ static const Dali::Property::Index PROPERTY_TEXT; ///< name "text", type STRING ++ static const Dali::Property::Index PROPERTY_MULTI_LINE; ///< name "multi-line", type BOOLEAN + + // Property names + static const std::string RENDERING_BACKEND_PROPERTY_NAME; ///< Property, name "rendering-backend", type INT + static const std::string TEXT_PROPERTY_NAME; ///< Property, name "text", type STRING + static const std::string MULTI_LINE_PROPERTY_NAME; ///< Property, name "multi-line", type BOOLEAN + + /** + * Create the TextLabel control. + * @return A handle to the TextLabel control. + */ + static TextLabel New(); + + /** + * @brief Creates an empty handle. + */ + TextLabel(); + + /** + * @brief Copy constructor. + * + * @param[in] handle The handle to copy from. + */ + TextLabel( const TextLabel& handle ); + + /** + * @brief Assignment operator. + * + * @param[in] handle The handle to copy from. + * @return A reference to this. + */ + TextLabel& operator=( const TextLabel& handle ); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~TextLabel(); + + /** + * @brief Downcast a handle to TextLabel. + * + * If the BaseHandle points is a TextLabel the downcast returns a valid handle. + * If not the returned handle is left empty. + * + * @param[in] handle Handle to an object + * @return handle to a TextLabel or an empty handle + */ + static TextLabel DownCast( BaseHandle handle ); + +public: // Not intended for application developers + + /** + * @brief Creates a handle using the Toolkit::Internal implementation. + * + * @param[in] implementation The Control implementation. + */ + DALI_INTERNAL TextLabel( Internal::TextLabel& implementation ); + + /** + * @brief Allows the creation of this Control from an Internal::CustomActor pointer. + * + * @param[in] internal A pointer to the internal CustomActor. + */ + explicit DALI_INTERNAL TextLabel( Dali::Internal::CustomActor* internal ); +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_TEXT_LABEL_H__ diff --cc dali-toolkit/public-api/file.list index a354b63,cbe5e77..483fb87 --- a/dali-toolkit/public-api/file.list +++ b/dali-toolkit/public-api/file.list @@@ -94,24 -95,6 +94,24 @@@ public_api_src_files = $(public_api_src_dir)/shader-effects/swirl-effect.cpp \ $(public_api_src_dir)/shader-effects/water-effect.cpp \ $(public_api_src_dir)/styling/style-manager.cpp \ + $(public_api_src_dir)/text/bidirectional-support.cpp \ + $(public_api_src_dir)/text/character-set-conversion.cpp \ + $(public_api_src_dir)/text/logical-model.cpp \ + $(public_api_src_dir)/text/multi-language-support.cpp \ - $(public_api_src_dir)/text/script.cpp \ ++ $(public_api_src_dir)/text/text-script.cpp \ + $(public_api_src_dir)/text/segmentation.cpp \ + $(public_api_src_dir)/text/shaper.cpp \ + $(public_api_src_dir)/text/text-control-interface.cpp \ + $(public_api_src_dir)/text/text-controller.cpp \ + $(public_api_src_dir)/text/text-view.cpp \ + $(public_api_src_dir)/text/text-view-interface.cpp \ + $(public_api_src_dir)/text/visual-model.cpp \ + $(public_api_src_dir)/text/decorator/text-decorator.cpp \ + $(public_api_src_dir)/text/layouts/layout-engine.cpp \ + $(public_api_src_dir)/text/rendering/text-backend.cpp \ + $(public_api_src_dir)/text/rendering/text-renderer.cpp \ + $(public_api_src_dir)/text/rendering/basic/text-basic-renderer.cpp \ + $(public_api_src_dir)/text/rendering/shaders/text-basic-shader.cpp \ $(public_api_src_dir)/transition-effects/cube-transition-cross-effect.cpp \ $(public_api_src_dir)/transition-effects/cube-transition-effect.cpp \ $(public_api_src_dir)/transition-effects/cube-transition-fold-effect.cpp \ diff --cc dali-toolkit/public-api/text/rendering/basic/text-basic-renderer.cpp index 5cd608f,0000000..b4b8515 mode 100644,000000..100644 --- a/dali-toolkit/public-api/text/rendering/basic/text-basic-renderer.cpp +++ b/dali-toolkit/public-api/text/rendering/basic/text-basic-renderer.cpp @@@ -1,321 -1,0 +1,320 @@@ +/* + * Copyright (c) 2015 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. + * + */ + +// CLASS HEADER +#include + +// INTERNAL INCLUDES +#include +#include +#include +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; +using namespace Dali::Toolkit::Text; + +namespace +{ + +const std::size_t PADDING = 2; //< To avoid GL filtering artefacts + +struct TextureCoordinates +{ + TextureCoordinates() + : topLeft( 0.0f, 0.0f ), + topRight( 1.0f, 0.0f ), + bottomLeft( 0.0f, 1.0f ), + bottomRight( 1.0f, 1.0f ) + { + } + + Vector2 topLeft; + Vector2 topRight; + Vector2 bottomLeft; + Vector2 bottomRight; +}; + +struct AtlasHelperGlyph +{ + AtlasHelperGlyph() + : fontId( 0 ), + index( 0 ), + xOffset( 0 ), + width( 0 ), + height( 0 ) + { + } + + AtlasHelperGlyph( FontId id, + GlyphIndex glyphIndex, + std::size_t offset, + std::size_t widthPixels, + std::size_t heightPixels ) + : fontId( id ), + index( glyphIndex ), + xOffset( offset ), + width( widthPixels ), + height( heightPixels ) + { + } + + FontId fontId; + GlyphIndex index; + std::size_t xOffset; + std::size_t width; + std::size_t height; + TextureCoordinates coords; +}; + +struct AtlasHelper +{ + AtlasHelper() + : mWidth( 0.0f ), + mHeight( 0.0f ) + { + mFontClient = TextAbstraction::FontClient::Get(); + } + + void Reset() + { + mWidth = 0.0f; + mHeight = 0.0f; + mGlyphs.clear(); + } + + void Reserve( std::size_t size ) + { + mGlyphs.reserve( size ); + } + + bool GlyphFound( FontId fontId, GlyphIndex index ) const + { + for( unsigned int i=0; i(glyph.xOffset) / static_cast(mWidth); + coords.topLeft.y = 0.0f; + coords.topRight.x = static_cast(glyph.xOffset + glyph.width) / static_cast(mWidth); + coords.topRight.y = 0.0f; + coords.bottomLeft.x = static_cast(glyph.xOffset) / static_cast(mWidth); + coords.bottomLeft.y = static_cast(glyph.height) / static_cast(mHeight); + coords.bottomRight.x = static_cast(glyph.xOffset + glyph.width) / static_cast(mWidth); + coords.bottomRight.y = static_cast(glyph.height) / static_cast(mHeight); + } + + return atlas; + } + + void GetTextureCoordinates( FontId fontId, GlyphIndex index, TextureCoordinates& coords ) + { + for( unsigned int i=0; i mGlyphs; + + TextAbstraction::FontClient mFontClient; +}; + +} // unnamed namespace + +struct BasicRenderer::Impl +{ + /** + * @brief Ccreate an Atlas, uploading the necessary glyph bitmaps + * + * @param[in] glyphs The glyphs to upload. + */ + Atlas CreateAtlas( const Vector& glyphs ) + { + AtlasHelper& helper = mAtlasHelper; + + // Clear previous atlas + helper.Reset(); + helper.Reserve( glyphs.Count() ); + + for( unsigned int i=0; i 0 && + height > 0 ) // skip whitespace + { + if( !helper.GlyphFound( glyphs[i].fontId, glyphs[i].index ) ) + { + helper.AddGlyph( glyphs[i] ); + } + } + } + + // Uploads the bitmaps to Dali + return helper.CreateAtlas(); + } + + /** + * @brief Helper method to create a mesh with one quad per glyph. + * + * @param[in] glyphs The glyphs to display. + * @param[in] positions The 2D positions of the glyphs. + * @param[in] image The material uses this as a diffuse texture. + */ + Mesh CreateMesh( const Vector& glyphs, const std::vector& positions, Image image ) + { + MeshData::VertexContainer vertices( 4 * glyphs.Count() ); // 1 quad per glyph + + MeshData::FaceIndices faces; + faces.reserve( 6 * glyphs.Count() ); // 2 triangles per quad + + for( unsigned int i=0; i 0 && + height > 0 ) // skip whitespace + { + const Vector2& position = positions[i]; + + TextureCoordinates coords; + mAtlasHelper.GetTextureCoordinates( glyphs[i].fontId, glyphs[i].index, coords ); + + vertices[ i*4 + 0 ] = MeshData::Vertex( Vector3( position.x + 0.0f*width, position.y + 0.0f*height, 0.0f ), coords.topLeft, Vector3( 1.0f, 0.0f, 0.0f ) ); + vertices[ i*4 + 1 ] = MeshData::Vertex( Vector3( position.x + 1.0f*width, position.y + 0.0f*height, 0.0f ), coords.topRight, Vector3( 1.0f, 1.0f, 0.0f ) ); + vertices[ i*4 + 2 ] = MeshData::Vertex( Vector3( position.x + 0.0f*width, position.y + 1.0f*height, 0.0f ), coords.bottomLeft, Vector3( 0.0f, 1.0f, 0.0f ) ); + vertices[ i*4 + 3 ] = MeshData::Vertex( Vector3( position.x + 1.0f*width, position.y + 1.0f*height, 0.0f ), coords.bottomRight, Vector3( 0.0f, 0.0f, 1.0f ) ); + + faces.push_back( i*4 + 0 ); faces.push_back( i*4 + 3 ); faces.push_back( i*4 + 1 ); + faces.push_back( i*4 + 0 ); faces.push_back( i*4 + 2 ); faces.push_back( i*4 + 3 ); + } + } + + Material material = Material::New( "Material" ); + material.SetDiffuseTexture( image ); + + // Create the mesh data from the vertices and faces + MeshData meshData; + meshData.SetHasColor( false ); + meshData.SetMaterial( material ); + meshData.SetVertices( vertices ); + meshData.SetFaceIndices( faces ); + + // Create a mesh from the data + Dali::Mesh mesh = Mesh::New( meshData ); + return mesh; + } + + RenderableActor mActor; ///< The actor which renders the text + + AtlasHelper mAtlasHelper; ///< A helper class for storing atlas positions etc. +}; + +Text::RendererPtr BasicRenderer::New() +{ + return Text::RendererPtr( new BasicRenderer() ); +} + +RenderableActor BasicRenderer::Render( Text::ViewInterface& view ) +{ + UnparentAndReset( mImpl->mActor ); + + Text::Length numberOfGlyphs = view.GetNumberOfGlyphs(); + + if( numberOfGlyphs > 0 ) + { + Vector glyphs; + glyphs.Resize( numberOfGlyphs ); + + view.GetGlyphs( &glyphs[0], 0, numberOfGlyphs ); + + std::vector positions; + positions.resize( numberOfGlyphs ); + view.GetGlyphPositions( &positions[0], 0, numberOfGlyphs ); + + Atlas atlas = mImpl->CreateAtlas( glyphs ); + + MeshActor actor = MeshActor::New( mImpl->CreateMesh( glyphs, positions, atlas ) ); + actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); + actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); - actor.SetAffectedByLighting( false ); + + ShaderEffect shader = BasicShader::New(); + actor.SetShaderEffect( shader ); + + mImpl->mActor = actor; + } + + return mImpl->mActor; +} + +BasicRenderer::BasicRenderer() +{ + mImpl = new Impl(); +} + +BasicRenderer::~BasicRenderer() +{ + delete mImpl; +} diff --cc dali-toolkit/public-api/text/text-script.cpp index c320a7e,0000000..c320a7e mode 100644,000000..100644 --- a/dali-toolkit/public-api/text/text-script.cpp +++ b/dali-toolkit/public-api/text/text-script.cpp