Commit ec46ed7b86ed23619756d641c21c3577d8349e62

Authored by Victor Cebollada
1 parent 9d9c2394

Text tests added

* Simple Text Label
* Simple Text Field
* Simple Text Renderer
* Simple Text Visual
* Simple Text Label Bitmap Font

Change-Id: I83204143cd0986a776dc5409d1b38d018f331339
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
com.samsung.dali-demo.xml
... ... @@ -278,6 +278,21 @@
278 278 <ui-application appid="drag-and-drop.example" exec="/usr/apps/com.samsung.dali-demo/bin/drag-and-drop.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
279 279 <label>Drag And Drop</label>
280 280 </ui-application>
  281 + <ui-application appid="simple-text-label.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-text-label.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  282 + <label>Simple Text Label</label>
  283 + </ui-application>
  284 + <ui-application appid="simple-bitmap-font-text-label.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-bitmap-font-text-label.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  285 + <label>Simple Bitmap Font Text Label</label>
  286 + </ui-application>
  287 + <ui-application appid="simple-text-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-text-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  288 + <label>Simple Text Field</label>
  289 + </ui-application>
  290 + <ui-application appid="simple-text-visual.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-text-visual.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  291 + <label>Text Visual</label>
  292 + </ui-application>
  293 + <ui-application appid="simple-text-renderer.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-text-renderer.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  294 + <label>Simple Text Renderer</label>
  295 + </ui-application>
281 296  
282 297 <privileges>
283 298 <privilege>http://tizen.org/privilege/mediastorage</privilege>
... ...
examples/simple-bitmap-font-text-label/simple-text-label-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +/**
  19 + * @file simple-text-label-example.cpp
  20 + * @brief Basic usage of SimpleTextLabel control
  21 + */
  22 +
  23 +// EXTERNAL INCLUDES
  24 +#include <dali-toolkit/dali-toolkit.h>
  25 +
  26 +#include <dali/devel-api/text-abstraction/font-client.h>
  27 +#include <dali/devel-api/text-abstraction/bitmap-font.h>
  28 +#include <dali-toolkit/devel-api/text/bitmap-font.h>
  29 +
  30 +using namespace Dali;
  31 +using namespace Dali::Toolkit;
  32 +
  33 +/**
  34 + * @brief The main class of the demo.
  35 + */
  36 +class SimpleTextLabelExample : public ConnectionTracker
  37 +{
  38 +public:
  39 +
  40 + SimpleTextLabelExample( Application& application )
  41 + : mApplication( application )
  42 + {
  43 + // Connect to the Application's Init signal
  44 + mApplication.InitSignal().Connect( this, &SimpleTextLabelExample::Create );
  45 + }
  46 +
  47 + ~SimpleTextLabelExample()
  48 + {
  49 + // Nothing to do here.
  50 + }
  51 +
  52 + /**
  53 + * One-time setup in response to Application InitSignal.
  54 + */
  55 + void Create( Application& application )
  56 + {
  57 + Stage stage = Stage::GetCurrent();
  58 +
  59 + stage.KeyEventSignal().Connect(this, &SimpleTextLabelExample::OnKeyEvent);
  60 +
  61 + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
  62 +
  63 + DevelText::BitmapFontDescription fontDescription;
  64 + fontDescription.name = "Digits";
  65 + fontDescription.underlinePosition = 0.f;
  66 + fontDescription.underlineThickness = 0.f;
  67 +
  68 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0030.png", "0", 34.f, 0.f } );
  69 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0031.png", "1", 34.f, 0.f } );
  70 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0032.png", "2", 34.f, 0.f } );
  71 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0033.png", "3", 34.f, 0.f } );
  72 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0034.png", "4", 34.f, 0.f } );
  73 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0035.png", "5", 34.f, 0.f } );
  74 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0036.png", "6", 34.f, 0.f } );
  75 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0037.png", "7", 34.f, 0.f } );
  76 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0038.png", "8", 34.f, 0.f } );
  77 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0039.png", "9", 34.f, 0.f } );
  78 + fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u003a.png", ":", 34.f, 0.f } );
  79 +
  80 +
  81 + DevelText::BitmapFontDescription colorFontDescription;
  82 + colorFontDescription.name = "DigitsColor";
  83 + colorFontDescription.underlinePosition = 0.f;
  84 + colorFontDescription.underlineThickness = 0.f;
  85 + colorFontDescription.isColorFont = true;
  86 +
  87 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0030_color.png", "0", 34.f, 0.f } );
  88 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0031_color.png", "1", 34.f, 0.f } );
  89 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0032_color.png", "2", 34.f, 0.f } );
  90 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0033_color.png", "3", 34.f, 0.f } );
  91 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0034_color.png", "4", 34.f, 0.f } );
  92 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0035_color.png", "5", 34.f, 0.f } );
  93 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0036_color.png", "6", 34.f, 0.f } );
  94 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0037_color.png", "7", 34.f, 0.f } );
  95 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0038_color.png", "8", 34.f, 0.f } );
  96 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0039_color.png", "9", 34.f, 0.f } );
  97 + colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u003a_color.png", ":", 34.f, 0.f } );
  98 +
  99 + TextAbstraction::BitmapFont bitmapFont;
  100 + TextAbstraction::BitmapFont bitmapColorFont;
  101 +
  102 + DevelText::CreateBitmapFont( fontDescription, bitmapFont );
  103 + DevelText::CreateBitmapFont( colorFontDescription, bitmapColorFont );
  104 +
  105 + fontClient.GetFontId( bitmapFont );
  106 + fontClient.GetFontId( bitmapColorFont );
  107 +
  108 + TextLabel label01 = TextLabel::New();
  109 + label01.SetAnchorPoint( AnchorPoint::CENTER );
  110 + label01.SetParentOrigin( ParentOrigin::CENTER );
  111 + label01.SetSize( 400.f, 50.f );
  112 + label01.SetPosition( 0.f, -100.f );
  113 + label01.SetProperty( TextLabel::Property::MULTI_LINE, true );
  114 +
  115 + label01.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
  116 + label01.SetProperty( TextLabel::Property::TEXT, "012<color 'value'='green'>345</color>6789:" );
  117 + label01.SetProperty( TextLabel::Property::TEXT_COLOR, Color::RED );
  118 + label01.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" );
  119 +
  120 + label01.SetBackgroundColor( Color::BLACK );
  121 +
  122 + stage.Add( label01 );
  123 +
  124 +
  125 + TextLabel label02 = TextLabel::New();
  126 + label02.SetAnchorPoint( AnchorPoint::CENTER );
  127 + label02.SetParentOrigin( ParentOrigin::CENTER );
  128 + label02.SetSize( 400.f, 50.f );
  129 + label02.SetPosition( 0.f, -50.f );
  130 + label02.SetProperty( TextLabel::Property::MULTI_LINE, true );
  131 +
  132 + label02.SetProperty( TextLabel::Property::TEXT, "0123456789:" );
  133 + label02.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
  134 + label02.SetProperty( TextLabel::Property::FONT_FAMILY, "DigitsColor" );
  135 +
  136 + label02.SetBackgroundColor( Color::BLACK );
  137 +
  138 + stage.Add( label02 );
  139 +
  140 + TextLabel label03 = TextLabel::New();
  141 + label03.SetAnchorPoint( AnchorPoint::CENTER );
  142 + label03.SetParentOrigin( ParentOrigin::CENTER );
  143 + label03.SetSize( 400.f, 50.f );
  144 + label03.SetPosition( 0.f, 0.f );
  145 + label03.SetProperty( TextLabel::Property::MULTI_LINE, true );
  146 +
  147 + label03.SetProperty( TextLabel::Property::TEXT, "0123456789:" );
  148 + label03.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" );
  149 +
  150 + label03.SetBackgroundColor( Color::WHITE );
  151 +
  152 + stage.Add( label03 );
  153 +
  154 + TextLabel label04 = TextLabel::New();
  155 + label04.SetAnchorPoint( AnchorPoint::CENTER );
  156 + label04.SetParentOrigin( ParentOrigin::CENTER );
  157 + label04.SetSize( 400.f, 50.f );
  158 + label04.SetPosition( 0.f, 50.f );
  159 + label04.SetProperty( TextLabel::Property::MULTI_LINE, true );
  160 +
  161 + label04.SetProperty( TextLabel::Property::TEXT, "0123456789:" );
  162 + label04.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" );
  163 + label04.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
  164 +
  165 + label04.SetBackgroundColor( Color::BLACK );
  166 +
  167 + stage.Add( label04 );
  168 + }
  169 +
  170 + /**
  171 + * Main key event handler
  172 + */
  173 + void OnKeyEvent(const KeyEvent& event)
  174 + {
  175 + if(event.state == KeyEvent::Down)
  176 + {
  177 + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
  178 + {
  179 + mApplication.Quit();
  180 + }
  181 + }
  182 + }
  183 +
  184 +private:
  185 +
  186 + Application& mApplication;
  187 +};
  188 +
  189 +void RunTest( Application& application )
  190 +{
  191 + SimpleTextLabelExample test( application );
  192 +
  193 + application.MainLoop();
  194 +}
  195 +
  196 +/** Entry point for Linux & Tizen applications */
  197 +int main( int argc, char **argv )
  198 +{
  199 + Application application = Application::New( &argc, &argv );
  200 +
  201 + RunTest( application );
  202 +
  203 + return 0;
  204 +}
... ...
examples/simple-text-field/simple-text-field.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +/**
  19 + * @file simple-text-field-example.cpp
  20 + * @brief Very basic usage of TextField control
  21 + */
  22 +
  23 +// EXTERNAL INCLUDES
  24 +#include <dali-toolkit/dali-toolkit.h>
  25 +#include <iostream>
  26 +
  27 +using namespace Dali;
  28 +using namespace Dali::Toolkit;
  29 +
  30 +
  31 +/**
  32 + * @brief The main class of the demo.
  33 + */
  34 +class SimpleTextFieldExample : public ConnectionTracker
  35 +{
  36 +public:
  37 +
  38 + SimpleTextFieldExample( Application& application )
  39 + : mApplication( application )
  40 + {
  41 + // Connect to the Application's Init signal
  42 + mApplication.InitSignal().Connect( this, &SimpleTextFieldExample::Create );
  43 + }
  44 +
  45 + ~SimpleTextFieldExample()
  46 + {
  47 + // Nothing to do here.
  48 + }
  49 +
  50 + /**
  51 + * One-time setup in response to Application InitSignal.
  52 + */
  53 + void Create( Application& application )
  54 + {
  55 + Stage stage = Stage::GetCurrent();
  56 + stage.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) );
  57 +
  58 + TextField field = TextField::New();
  59 + field.SetParentOrigin( ParentOrigin::CENTER );
  60 + field.SetSize( 300.f, 60.f );
  61 + field.SetBackgroundColor( Color::WHITE );
  62 + field.SetBackgroundColor( Vector4( 1.f, 1.f, 1.f, 0.15f ) );
  63 +
  64 + field.SetProperty( TextField::Property::TEXT_COLOR, Color::BLACK );
  65 + field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder" );
  66 + field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name." );
  67 +
  68 + stage.Add( field );
  69 + }
  70 +
  71 +private:
  72 +
  73 + Application& mApplication;
  74 +};
  75 +
  76 +void RunTest( Application& application )
  77 +{
  78 + SimpleTextFieldExample test( application );
  79 +
  80 + application.MainLoop();
  81 +}
  82 +
  83 +/** Entry point for Linux & Tizen applications */
  84 +int main( int argc, char **argv )
  85 +{
  86 + // DALI_DEMO_THEME_PATH not passed to Application so TextField example uses default Toolkit style sheet.
  87 + Application application = Application::New( &argc, &argv );
  88 +
  89 + RunTest( application );
  90 +
  91 + return 0;
  92 +}
... ...
examples/simple-text-label/simple-text-label-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +/**
  19 + * @file simple-text-label-example.cpp
  20 + * @brief Basic usage of SimpleTextLabel control
  21 + */
  22 +
  23 +// EXTERNAL INCLUDES
  24 +#include <dali-toolkit/dali-toolkit.h>
  25 +
  26 +using namespace Dali;
  27 +using namespace Dali::Toolkit;
  28 +
  29 +/**
  30 + * @brief The main class of the demo.
  31 + */
  32 +class SimpleTextLabelExample : public ConnectionTracker
  33 +{
  34 +public:
  35 +
  36 + SimpleTextLabelExample( Application& application )
  37 + : mApplication( application )
  38 + {
  39 + // Connect to the Application's Init signal
  40 + mApplication.InitSignal().Connect( this, &SimpleTextLabelExample::Create );
  41 + }
  42 +
  43 + ~SimpleTextLabelExample()
  44 + {
  45 + // Nothing to do here.
  46 + }
  47 +
  48 + /**
  49 + * One-time setup in response to Application InitSignal.
  50 + */
  51 + void Create( Application& application )
  52 + {
  53 + Stage stage = Stage::GetCurrent();
  54 +
  55 + stage.KeyEventSignal().Connect(this, &SimpleTextLabelExample::OnKeyEvent);
  56 +
  57 + mLabel = TextLabel::New( "A Quick Brown Fox Jumps Over The Lazy Dog" );
  58 + mLabel.SetName( "SimpleTextLabel" );
  59 + mLabel.SetAnchorPoint( AnchorPoint::CENTER );
  60 + mLabel.SetParentOrigin( ParentOrigin::CENTER );
  61 + mLabel.SetSize( 400.f, 400.f );
  62 + mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
  63 + mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK );
  64 + mLabel.SetBackgroundColor( Color::WHITE );
  65 +
  66 + stage.Add( mLabel );
  67 + }
  68 +
  69 + /**
  70 + * Main key event handler
  71 + */
  72 + void OnKeyEvent(const KeyEvent& event)
  73 + {
  74 + if(event.state == KeyEvent::Down)
  75 + {
  76 + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
  77 + {
  78 + mApplication.Quit();
  79 + }
  80 + }
  81 + }
  82 +
  83 +private:
  84 +
  85 + Application& mApplication;
  86 +
  87 + TextLabel mLabel;
  88 +};
  89 +
  90 +void RunTest( Application& application )
  91 +{
  92 + SimpleTextLabelExample test( application );
  93 +
  94 + application.MainLoop();
  95 +}
  96 +
  97 +/** Entry point for Linux & Tizen applications */
  98 +int main( int argc, char **argv )
  99 +{
  100 + Application application = Application::New( &argc, &argv );
  101 +
  102 + RunTest( application );
  103 +
  104 + return 0;
  105 +}
... ...
examples/simple-text-renderer/simple-text-renderer-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +/**
  19 + * @file simple-text-renderer-example.cpp
  20 + * @brief Basic usage of Text Renderer utility.
  21 + */
  22 +
  23 +// EXTERNAL INCLUDES
  24 +#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
  25 +#include <dali-toolkit/dali-toolkit.h>
  26 +#include <dali-toolkit/devel-api/text/text-utils-devel.h>
  27 +#include <devel-api/adaptor-framework/image-loading.h>
  28 +
  29 +#include <iostream>
  30 +#include <fstream>
  31 +
  32 +using namespace std;
  33 +using namespace Dali;
  34 +using namespace Dali::Toolkit;
  35 +
  36 +namespace
  37 +{
  38 +
  39 +const std::string IMAGE1 = DEMO_IMAGE_DIR "application-icon-1.png";
  40 +const std::string IMAGE2 = DEMO_IMAGE_DIR "application-icon-6.png";
  41 +
  42 +#define MAKE_SHADER(A)#A
  43 +
  44 +const std::string VERSION_3_ES = "#version 300 es\n";
  45 +
  46 +const char* VERTEX_SHADER = MAKE_SHADER(
  47 + precision mediump float;
  48 +
  49 + in vec2 aPosition;
  50 + in vec2 aTexCoord;
  51 +
  52 + out vec2 vUV;
  53 +
  54 + uniform vec3 uSize;
  55 + uniform mat4 uMvpMatrix;
  56 +
  57 + void main()
  58 + {
  59 + vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
  60 + vertexPosition.xyz *= uSize;
  61 + gl_Position = uMvpMatrix * vertexPosition;
  62 +
  63 + vUV = aTexCoord;
  64 + }
  65 +);
  66 +
  67 +const char* FRAGMENT_SHADER = MAKE_SHADER(
  68 + precision mediump float;
  69 +
  70 + in vec2 vUV;
  71 +
  72 + out vec4 FragColor;
  73 +
  74 + uniform sampler2D sAlbedo;
  75 + uniform vec4 uColor;
  76 +
  77 + void main()
  78 + {
  79 + vec4 color = texture( sAlbedo, vUV );
  80 + FragColor = vec4( color.rgb, uColor.a * color.a );
  81 + }
  82 +);
  83 +
  84 +Renderer CreateRenderer()
  85 +{
  86 + // Create the geometry.
  87 + struct Vertex
  88 + {
  89 + Dali::Vector2 position;
  90 + Dali::Vector2 texCoord;
  91 + };
  92 +
  93 + static const Vertex vertices[] = {{ Dali::Vector2( -0.5f, -0.5f ), Dali::Vector2( 0.0f, 0.0f ) },
  94 + { Dali::Vector2( 0.5f, -0.5f ), Dali::Vector2( 1.0f, 0.0f ) },
  95 + { Dali::Vector2( -0.5f, 0.5f ), Dali::Vector2( 0.0f, 1.0f ) },
  96 + { Dali::Vector2( 0.5f, 0.5f ), Dali::Vector2( 1.0f, 1.0f ) }};
  97 +
  98 + Property::Map property;
  99 + property.Add("aPosition", Property::VECTOR2).Add("aTexCoord", Property::VECTOR2);
  100 +
  101 + PropertyBuffer vertexBuffer = PropertyBuffer::New(property);
  102 +
  103 + vertexBuffer.SetData(vertices, sizeof(vertices) / sizeof(Vertex));
  104 +
  105 + Geometry geometry = Geometry::New();
  106 + geometry.AddVertexBuffer(vertexBuffer);
  107 +
  108 + geometry.SetType(Geometry::TRIANGLE_STRIP);
  109 +
  110 + // Create the shader
  111 + Shader shader = Shader::New( VERSION_3_ES + VERTEX_SHADER, VERSION_3_ES + FRAGMENT_SHADER );
  112 +
  113 + // Create the renderer
  114 +
  115 + Renderer renderer = Renderer::New( geometry, shader );
  116 +
  117 + return renderer;
  118 +}
  119 +
  120 +TextureSet CreateTextureSet( const Dali::Toolkit::DevelText::RendererParameters& textParameters, const std::vector<std::string>& embeddedItems )
  121 +{
  122 +
  123 + Dali::Vector<Dali::Toolkit::DevelText::EmbeddedItemInfo> embeddedItemLayout;
  124 +
  125 + Devel::PixelBuffer pixelBuffer = Toolkit::DevelText::Render( textParameters, embeddedItemLayout );
  126 +
  127 +
  128 + const int dstWidth = static_cast<int>( pixelBuffer.GetWidth() );
  129 + const int dstHeight = static_cast<int>( pixelBuffer.GetHeight() );
  130 +
  131 + unsigned int index = 0u;
  132 + for( const auto& itemLayout : embeddedItemLayout )
  133 + {
  134 + int width = static_cast<int>( itemLayout.size.width );
  135 + int height = static_cast<int>( itemLayout.size.height );
  136 + int x = static_cast<int>( itemLayout.position.x );
  137 + int y = static_cast<int>( itemLayout.position.y );
  138 +
  139 + Dali::Devel::PixelBuffer itemPixelBuffer = Dali::LoadImageFromFile( embeddedItems[index++] );
  140 + itemPixelBuffer.Resize( width, height );
  141 + itemPixelBuffer.Rotate( itemLayout.angle );
  142 +
  143 + width = static_cast<int>( itemPixelBuffer.GetWidth() );
  144 + height = static_cast<int>( itemPixelBuffer.GetHeight() );
  145 +
  146 + Dali::Pixel::Format itemPixelFormat = itemPixelBuffer.GetPixelFormat();
  147 +
  148 + // Check if the item is out of the buffer.
  149 +
  150 + if( ( x + width < 0 ) ||
  151 + ( x > dstWidth ) ||
  152 + ( y < 0 ) ||
  153 + ( y - height > dstHeight ) )
  154 + {
  155 + // The embedded item is completely out of the buffer.
  156 + continue;
  157 + }
  158 +
  159 + // Crop if it exceeds the boundaries of the destination buffer.
  160 + int layoutX = 0;
  161 + int layoutY = 0;
  162 + int cropX = 0;
  163 + int cropY = 0;
  164 + int newWidth = width;
  165 + int newHeight = height;
  166 +
  167 + bool crop = false;
  168 +
  169 + if( 0 > x )
  170 + {
  171 + newWidth += x;
  172 + cropX = std::abs( x );
  173 + crop = true;
  174 + }
  175 + else
  176 + {
  177 + layoutX = x;
  178 + }
  179 +
  180 + if( cropX + newWidth > dstWidth )
  181 + {
  182 + crop = true;
  183 + newWidth -= ( ( cropX + newWidth ) - dstWidth );
  184 + }
  185 +
  186 + layoutY = y;
  187 + if( 0.f > layoutY )
  188 + {
  189 + newHeight += layoutY;
  190 + cropY = std::abs(layoutY);
  191 + crop = true;
  192 + }
  193 +
  194 + if( cropY + newHeight > dstHeight )
  195 + {
  196 + crop = true;
  197 + newHeight -= ( ( cropY + newHeight ) - dstHeight );
  198 + }
  199 +
  200 + uint16_t uiCropX = static_cast<uint16_t>(cropX);
  201 + uint16_t uiCropY = static_cast<uint16_t>(cropY);
  202 + uint16_t uiNewWidth = static_cast<uint16_t>(newWidth);
  203 + uint16_t uiNewHeight = static_cast<uint16_t>(newHeight);
  204 +
  205 + if( crop )
  206 + {
  207 + itemPixelBuffer.Crop( uiCropX, uiCropY, uiNewWidth, uiNewHeight );
  208 + }
  209 +
  210 + // Blend the item pixel buffer with the text's color according its blending mode.
  211 + if( Dali::TextAbstraction::ColorBlendingMode::MULTIPLY == itemLayout.colorBlendingMode )
  212 + {
  213 + Dali::Devel::PixelBuffer buffer = Dali::Devel::PixelBuffer::New( uiNewWidth,
  214 + uiNewHeight,
  215 + itemPixelFormat );
  216 +
  217 + unsigned char* bufferPtr = buffer.GetBuffer();
  218 + const unsigned char* itemBufferPtr = itemPixelBuffer.GetBuffer();
  219 + const unsigned int bytesPerPixel = Dali::Pixel::GetBytesPerPixel(itemPixelFormat);
  220 + const unsigned int size = uiNewWidth * uiNewHeight * bytesPerPixel;
  221 +
  222 + for (unsigned int i = 0u; i < size; i += bytesPerPixel)
  223 + {
  224 + *(bufferPtr + 0u) = static_cast<unsigned char>( static_cast<float>( *(itemBufferPtr + 0u) ) * textParameters.textColor.r );
  225 + *(bufferPtr + 1u) = static_cast<unsigned char>( static_cast<float>( *(itemBufferPtr + 1u) ) * textParameters.textColor.g );
  226 + *(bufferPtr + 2u) = static_cast<unsigned char>( static_cast<float>( *(itemBufferPtr + 2u) ) * textParameters.textColor.b );
  227 + *(bufferPtr + 3u) = static_cast<unsigned char>( static_cast<float>( *(itemBufferPtr + 3u) ) * textParameters.textColor.a );
  228 +
  229 + itemBufferPtr += bytesPerPixel;
  230 + bufferPtr += bytesPerPixel;
  231 + }
  232 +
  233 + itemPixelBuffer = buffer;
  234 + }
  235 +
  236 + Dali::Toolkit::DevelText::UpdateBuffer(itemPixelBuffer, pixelBuffer, layoutX, layoutY, true);
  237 + }
  238 +
  239 + PixelData pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
  240 +
  241 + Texture texture = Texture::New( TextureType::TEXTURE_2D,
  242 + pixelData.GetPixelFormat(),
  243 + pixelData.GetWidth(),
  244 + pixelData.GetHeight() );
  245 + texture.Upload(pixelData);
  246 +
  247 + TextureSet textureSet = TextureSet::New();
  248 + textureSet.SetTexture( 0u, texture );
  249 +
  250 + return textureSet;
  251 +}
  252 +
  253 +} // namespace
  254 +
  255 +
  256 +/**
  257 + * @brief The main class of the demo.
  258 + */
  259 +class SimpleTextRendererExample : public ConnectionTracker
  260 +{
  261 +public:
  262 +
  263 + SimpleTextRendererExample( Application& application )
  264 + : mApplication( application )
  265 + {
  266 + // Connect to the Application's Init signal
  267 + mApplication.InitSignal().Connect( this, &SimpleTextRendererExample::Create );
  268 + }
  269 +
  270 + ~SimpleTextRendererExample()
  271 + {
  272 + // Nothing to do here.
  273 + }
  274 +
  275 + /**
  276 + * One-time setup in response to Application InitSignal.
  277 + */
  278 + void Create( Application& application )
  279 + {
  280 + Stage stage = Stage::GetCurrent();
  281 + stage.SetBackgroundColor( Color::WHITE );
  282 + stage.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) );
  283 +
  284 + stage.KeyEventSignal().Connect(this, &SimpleTextRendererExample::OnKeyEvent);
  285 +
  286 + const std::string image1 = "<item 'width'=26 'height'=26 'url'='" + IMAGE1 + "'/>";
  287 + const std::string image2 = "<item 'width'=26 'height'=26/>";
  288 +
  289 + Dali::Toolkit::DevelText::RendererParameters textParameters;
  290 + textParameters.text = "Hello " + image1 + " world " + image2 + " this " + image1 + " is " + image2 + " a " + image1 + " demo " + image2 + " of " + image1 + " circular " + image2 + " text " + image1 + " width " + image2 + " icons.";
  291 + textParameters.horizontalAlignment = "center";
  292 + textParameters.verticalAlignment = "center";
  293 + textParameters.circularAlignment = "center";
  294 + textParameters.fontFamily = "SamsungUI";
  295 + textParameters.fontWeight = "";
  296 + textParameters.fontWidth = "";
  297 + textParameters.fontSlant = "";
  298 + textParameters.layout = "circular";
  299 + textParameters.textColor = Color::BLACK;
  300 + textParameters.fontSize = 25.f;
  301 + textParameters.textWidth = 360u;
  302 + textParameters.textHeight = 360u;
  303 + textParameters.radius = 180u;
  304 + textParameters.beginAngle = 15.f;
  305 + textParameters.incrementAngle = 360.f;
  306 + textParameters.ellipsisEnabled = true;
  307 + textParameters.markupEnabled = true;
  308 +
  309 + std::vector<std::string> embeddedItems = { IMAGE2, IMAGE2, IMAGE2, IMAGE2, IMAGE2 };
  310 +
  311 + TextureSet textureSet = CreateTextureSet( textParameters, embeddedItems );
  312 +
  313 + Renderer renderer = CreateRenderer();
  314 + renderer.SetTextures( textureSet );
  315 +
  316 + Actor actor = Actor::New();
  317 + actor.SetAnchorPoint( AnchorPoint::CENTER );
  318 + actor.SetParentOrigin( ParentOrigin::CENTER );
  319 + actor.SetPosition( 0.f, 0.f);
  320 + actor.SetSize( 360.f, 360.f );
  321 + actor.SetColor( Color::WHITE );
  322 +
  323 + actor.AddRenderer( renderer );
  324 +
  325 + stage.Add( actor );
  326 + }
  327 +
  328 + /**
  329 + * Main key event handler
  330 + */
  331 + void OnKeyEvent(const KeyEvent& event)
  332 + {
  333 + if(event.state == KeyEvent::Down)
  334 + {
  335 + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
  336 + {
  337 + mApplication.Quit();
  338 + }
  339 + }
  340 + }
  341 +
  342 +private:
  343 +
  344 + Application& mApplication;
  345 +};
  346 +
  347 +/** Entry point for Linux & Tizen applications */
  348 +int main( int argc, char **argv )
  349 +{
  350 + Application application = Application::New( &argc, &argv );
  351 +
  352 + SimpleTextRendererExample test( application );
  353 +
  354 + application.MainLoop();
  355 +
  356 + return 0;
  357 +}
... ...
examples/simple-text-visual/simple-text-visual-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +/**
  19 + * @file text-visual-example.cpp
  20 + * @brief Basic usage of Text Visual.
  21 + */
  22 +
  23 +// EXTERNAL INCLUDES
  24 +#include <dali-toolkit/dali-toolkit.h>
  25 +
  26 +using namespace Dali;
  27 +using namespace Dali::Toolkit;
  28 +
  29 +/**
  30 + * @brief The main class of the demo.
  31 + */
  32 +class TextVisualExample : public ConnectionTracker
  33 +{
  34 +public:
  35 +
  36 + TextVisualExample( Application& application )
  37 + : mApplication( application )
  38 + {
  39 + // Connect to the Application's Init signal
  40 + mApplication.InitSignal().Connect( this, &TextVisualExample::Create );
  41 + }
  42 +
  43 + ~TextVisualExample()
  44 + {
  45 + // Nothing to do here.
  46 + }
  47 +
  48 + /**
  49 + * One-time setup in response to Application InitSignal.
  50 + */
  51 + void Create( Application& application )
  52 + {
  53 + Stage stage = Stage::GetCurrent();
  54 +
  55 + stage.KeyEventSignal().Connect(this, &TextVisualExample::OnKeyEvent);
  56 + stage.SetBackgroundColor( Color::WHITE );
  57 +
  58 + Dali::Toolkit::Control control = Dali::Toolkit::ImageView::New();
  59 + control.SetParentOrigin( ParentOrigin::CENTER );
  60 +
  61 + const std::string markupText( "<color value='blue'><font size='50'>H</font></color>ello <color value='blue'><font size='50'>w</font></color>orld" );
  62 +
  63 + Dali::Property::Map map;
  64 + map.Add( Dali::Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::TEXT ).
  65 + Add( Dali::Toolkit::TextVisual::Property::ENABLE_MARKUP, true ).
  66 + Add( Dali::Toolkit::TextVisual::Property::TEXT, markupText ).
  67 + Add( Dali::Toolkit::TextVisual::Property::TEXT_COLOR, Dali::Vector4( 0.25f, 0.25f, 0.5f, 1.f ) ).
  68 + Add( Dali::Toolkit::TextVisual::Property::FONT_FAMILY, "TizenSansRegular" ).
  69 + Add( Dali::Toolkit::TextVisual::Property::POINT_SIZE, 30.f ).
  70 + Add( Dali::Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "END" ).
  71 + Add( Dali::Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "CENTER" );
  72 +
  73 + control.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
  74 +
  75 + stage.Add( control );
  76 + }
  77 +
  78 + /**
  79 + * Main key event handler
  80 + */
  81 + void OnKeyEvent(const KeyEvent& event)
  82 + {
  83 + if(event.state == KeyEvent::Down)
  84 + {
  85 + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
  86 + {
  87 + mApplication.Quit();
  88 + }
  89 + }
  90 + }
  91 +
  92 +private:
  93 +
  94 + Application& mApplication;
  95 +
  96 + TextLabel mLabel;
  97 +};
  98 +
  99 +void RunTest( Application& application )
  100 +{
  101 + TextVisualExample test( application );
  102 +
  103 + application.MainLoop();
  104 +}
  105 +
  106 +/** Entry point for Linux & Tizen applications */
  107 +int main( int argc, char **argv )
  108 +{
  109 + Application application = Application::New( &argc, &argv );
  110 +
  111 + RunTest( application );
  112 +
  113 + return 0;
  114 +}
... ...
resources/images/u0030.png 0 → 100644

473 Bytes

resources/images/u0030_color.png 0 → 100644

918 Bytes

resources/images/u0031.png 0 → 100644

371 Bytes

resources/images/u0031_color.png 0 → 100644

564 Bytes

resources/images/u0032.png 0 → 100644

441 Bytes

resources/images/u0032_color.png 0 → 100644

1.01 KB

resources/images/u0033.png 0 → 100644

454 Bytes

resources/images/u0033_color.png 0 → 100644

973 Bytes

resources/images/u0034.png 0 → 100644

495 Bytes

resources/images/u0034_color.png 0 → 100644

1000 Bytes

resources/images/u0035.png 0 → 100644

420 Bytes

resources/images/u0035_color.png 0 → 100644

797 Bytes

resources/images/u0036.png 0 → 100644

477 Bytes

resources/images/u0036_color.png 0 → 100644

1.1 KB

resources/images/u0037.png 0 → 100644

454 Bytes

resources/images/u0037_color.png 0 → 100644

806 Bytes

resources/images/u0038.png 0 → 100644

505 Bytes

resources/images/u0038_color.png 0 → 100644

954 Bytes

resources/images/u0039.png 0 → 100644

467 Bytes

resources/images/u0039_color.png 0 → 100644

879 Bytes

resources/images/u003a.png 0 → 100644

271 Bytes

resources/images/u003a_color.png 0 → 100644

262 Bytes

resources/po/en_US.po
... ... @@ -261,3 +261,12 @@ msgstr &quot;Web View&quot;
261 261  
262 262 msgid "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES"
263 263 msgstr "Animated Vector Images"
  264 +
  265 +msgid "DALI_DEMO_STR_TITLE_TEXT_RENDERER"
  266 +msgstr "Text Renderer"
  267 +
  268 +msgid "DALI_DEMO_STR_TITLE_TEXT_VISUAL"
  269 +msgstr "Text Visual"
  270 +
  271 +msgid "DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT"
  272 +msgstr "Text Bitmap Font"
... ...
shared/dali-demo-strings.h
1 1 /*
2   - * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -119,6 +119,9 @@ extern &quot;C&quot;
119 119 #define DALI_DEMO_STR_TITLE_TOOLTIP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TOOLTIP")
120 120 #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS")
121 121 #define DALI_DEMO_STR_TITLE_WEB_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_WEB_VIEW")
  122 +#define DALI_DEMO_STR_TITLE_TEXT_RENDERER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_RENDERER")
  123 +#define DALI_DEMO_STR_TITLE_TEXT_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_VISUAL")
  124 +#define DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT")
122 125  
123 126 #else // !INTERNATIONALIZATION_ENABLED
124 127  
... ... @@ -209,6 +212,9 @@ extern &quot;C&quot;
209 212 #define DALI_DEMO_STR_TITLE_TOOLTIP "Tooltip"
210 213 #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS "Visual Transitions"
211 214 #define DALI_DEMO_STR_TITLE_WEB_VIEW "Web View"
  215 +#define DALI_DEMO_STR_TITLE_TEXT_RENDERER "Text Renderer"
  216 +#define DALI_DEMO_STR_TITLE_TEXT_VISUAL "Text Visual"
  217 +#define DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT "Text Bitmap Font"
212 218 #endif
213 219  
214 220 #ifdef __cplusplus
... ...
tests-reel/dali-tests-reel.cpp
1 1 /*
2   - * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -49,6 +49,11 @@ int DALI_EXPORT_API main(int argc, char **argv)
49 49 demo.AddExample(Example("text-memory-profiling.example", DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING));
50 50 demo.AddExample(Example("text-overlap.example", DALI_DEMO_STR_TITLE_TEXT_OVERLAP));
51 51 demo.AddExample(Example("visual-transitions.example", DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS));
  52 + demo.AddExample(Example("simple-text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL));
  53 + demo.AddExample(Example("simple-text-field.example", DALI_DEMO_STR_TITLE_TEXT_FIELD));
  54 + demo.AddExample(Example("simple-text-renderer.example", DALI_DEMO_STR_TITLE_TEXT_RENDERER));
  55 + demo.AddExample(Example("simple-text-visual.example", DALI_DEMO_STR_TITLE_TEXT_VISUAL));
  56 + demo.AddExample(Example("simple-bitmap-font-text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT));
52 57  
53 58 demo.SortAlphabetically( true );
54 59  
... ...