From 9ece25b3a03c7f83d922c46a9004bd4fa8fb9443 Mon Sep 17 00:00:00 2001 From: Richard Underhill Date: Wed, 11 Mar 2015 11:24:16 +0000 Subject: [PATCH] Emojis Example Change-Id: I1d3e62c1ad548c1c81b4c8dab2246c22a68249aa Signed-off-by: Richard Underhill --- com.samsung.dali-demo.xml | 4 +- demo/dali-demo.cpp | 1 + examples/text-label-emojis/emoji-strings.h | 103 ++++++++++++++ examples/text-label-emojis/text-label-emojis.cpp | 155 +++++++++++++++++++++ .../text-label-emojis/vertical-layout-impl.cpp | 144 +++++++++++++++++++ examples/text-label-emojis/vertical-layout-impl.h | 91 ++++++++++++ examples/text-label-emojis/vertical-layout.cpp | 88 ++++++++++++ examples/text-label-emojis/vertical-layout.h | 65 +++++++++ 8 files changed, 650 insertions(+), 1 deletion(-) create mode 100644 examples/text-label-emojis/emoji-strings.h create mode 100644 examples/text-label-emojis/text-label-emojis.cpp create mode 100644 examples/text-label-emojis/vertical-layout-impl.cpp create mode 100644 examples/text-label-emojis/vertical-layout-impl.h create mode 100644 examples/text-label-emojis/vertical-layout.cpp create mode 100644 examples/text-label-emojis/vertical-layout.h diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index a278803..cf4763d 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -76,7 +76,9 @@ - + + + diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index e703cac..76273bb 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -49,6 +49,7 @@ int main(int argc, char **argv) demo.AddExample(Example("image-scaling-irregular-grid.example", DALI_DEMO_STR_TITLE_IMAGE_SCALING)); demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)/*TODO - new string*/); + demo.AddExample(Example("text-label-emojis.example", "Emoji Text")/*TODO - new string*/); demo.AddExample(Example("animated-shapes.example", "Animated Shapes")); demo.AddExample(Example("path-animation.example", "Path Animation")); app.MainLoop(); diff --git a/examples/text-label-emojis/emoji-strings.h b/examples/text-label-emojis/emoji-strings.h new file mode 100644 index 0000000..81c8a6f --- /dev/null +++ b/examples/text-label-emojis/emoji-strings.h @@ -0,0 +1,103 @@ +#ifndef __DALI_DEMO_EMOJI_STRINGS_H__ +#define __DALI_DEMO_EMOJI_STRINGS_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. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace EmojiStrings +{ + struct Emoji + { + uint32_t mUnicode; + std::string mUTF8; + std::string mDescription; + }; + + const Emoji EMOJIS[] = { + + { 0x1F601,"\xF0\x9F\x98\x81","grinning face with smiling eyes" }, + { 0x1F602,"\xF0\x9F\x98\x82","face with tears of joy" }, + //{ 0x1F603,"\xF0\x9F\x98\x83","smiling face with open mouth" }, + //{ 0x1F604,"\xF0\x9F\x98\x84","smiling face with open mouth and smiling eyes" }, + { 0x1F605,"\xF0\x9F\x98\x85","smiling face with open mouth and cold sweat" }, + //{ 0x1F606,"\xF0\x9F\x98\x86","smiling face with open mouth and tightly-closed eyes" }, + { 0x1F609,"\xF0\x9F\x98\x89","winking face" }, + { 0x1F60A,"\xF0\x9F\x98\x8A","smiling face with smiling eyes" }, + { 0x1F60B,"\xF0\x9F\x98\x8B","face savouring delicious food" }, + { 0x1F60C,"\xF0\x9F\x98\x8C","relieved face" }, + { 0x1F60D,"\xF0\x9F\x98\x8D","smiling face with heart-shaped eyes" }, + { 0x1F60F,"\xF0\x9F\x98\x8F","smirking face" }, + //{ 0x1F612,"\xF0\x9F\x98\x92","unamused face" }, + //{ 0x1F613,"\xF0\x9F\x98\x93","face with cold sweat" }, + //{ 0x1F614,"\xF0\x9F\x98\x94","pensive face" }, + //{ 0x1F616,"\xF0\x9F\x98\x96","confounded face" }, + { 0x1F618,"\xF0\x9F\x98\x98","face throwing a kiss" }, + { 0x1F61A,"\xF0\x9F\x98\x9A","kissing face with closed eyes" }, + //{ 0x1F61C,"\xF0\x9F\x98\x9C","face with stuck-out tongue and winking eye" }, + //{ 0x1F61D,"\xF0\x9F\x98\x9D","face with stuck-out tongue and tightly-closed eyes" }, + //{ 0x1F61E,"\xF0\x9F\x98\x9E","disappointed face" }, + { 0x1F620,"\xF0\x9F\x98\xA0","angry face" }, + + /* + { "POUTING FACE", + { "CRYING FACE", + { "PERSEVERING FACE", + { "FACE WITH LOOK OF TRIUMPH", + { "DISAPPOINTED BUT RELIEVED FACE", + { "FEARFUL FACE", + { "WEARY FACE", + { "SLEEPY FACE", + { "TIRED FACE", + { "LOUDLY CRYING FACE", + { "FACE WITH OPEN MOUTH AND COLD SWEAT", + { "FACE SCREAMING IN FEAR", + { "ASTONISHED FACE", + { "FLUSHED FACE", + { "DIZZY FACE", + { "FACE WITH MEDICAL MASK", + { "GRINNING CAT FACE WITH SMILING EYES", + { "CAT FACE WITH TEARS OF JOY", + { "SMILING CAT FACE WITH OPEN MOUTH", + { "SMILING CAT FACE WITH HEART-SHAPED EYES", + { "CAT FACE WITH WRY SMILE", + { "KISSING CAT FACE WITH CLOSED EYES", + { "POUTING CAT FACE", + { "CRYING CAT FACE", + { "WEARY CAT FACE", + { "FACE WITH NO GOOD GESTURE", + { "FACE WITH OK GESTURE", + { "PERSON BOWING DEEPLY", + { "SEE-NO-EVIL MONKEY", + { "HEAR-NO-EVIL MONKEY", + { "SPEAK-NO-EVIL MONKEY", + { "HAPPY PERSON RAISING ONE HAND", + { "PERSON RAISING BOTH HANDS IN CELEBRATION", + { "PERSON FROWNING", + { "PERSON WITH POUTING FACE", + { "PERSON WITH FOLDED HANDS", + */ + + }; + + const unsigned int NUMBER_OF_EMOJIS = 12; + +} // EmojiStrings + +#endif // __DALI_DEMO_EMOJI_STRINGS_H__ diff --git a/examples/text-label-emojis/text-label-emojis.cpp b/examples/text-label-emojis/text-label-emojis.cpp new file mode 100644 index 0000000..a0ff7bd --- /dev/null +++ b/examples/text-label-emojis/text-label-emojis.cpp @@ -0,0 +1,155 @@ +/* + * 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 "vertical-layout.h" +#include "emoji-strings.h" + +// EXTERNAL INCLUDES +#include +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; +using namespace EmojiStrings; + + // TODO Need to expose Text::RENDER..... +const int ATLAS_RENDERER = 0; + +// This example shows how to create and display Hello World! using a simple TextActor +// +class EmojiExample : public ConnectionTracker +{ +public: + + typedef uint32_t SizeType; + + EmojiExample( Application& application ) + : mApplication( application ) + { + std::cout << "EmoticonController::EmoticonController" << std::endl; + + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &EmojiExample::Create ); + } + + ~EmojiExample() + { + // Nothing to do here; + } + + // The Init signal is received once (only) during the Application lifetime + void Create( Application& application ) + { + + mLayout = VerticalLayout::New(); + mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Stage stage = Stage::GetCurrent(); + stage.Add( mLayout ); + stage.KeyEventSignal().Connect(this, &EmojiExample::OnKeyEvent); + + for( unsigned int index = 0u; index < NUMBER_OF_EMOJIS; ++index ) + { + const Emoji& emoji = EMOJIS[index]; + const std::string text = emoji.mUTF8 + " " + emoji.mDescription; + TextLabel label = TextLabel::New(); + label.SetParentOrigin( ParentOrigin::TOP_CENTER ); + label.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + label.SetProperty( TextLabel::Property::MULTI_LINE, true ); + label.SetProperty( TextLabel::Property::RENDERING_BACKEND, 0 ); + label.SetProperty( TextLabel::Property::TEXT, text ); + mLayout.AddLabel( label ); + mLayout.TouchedSignal().Connect( this, &EmojiExample::OnTouchEvent ); + } + + const Vector2& size = stage.GetSize(); + const float height = mLayout.GetHeightForWidth( size.width ); + mLayout.SetSize( Size( size.width, height ) ); + mLayout.TouchedSignal().Connect( this, &EmojiExample::OnTouchEvent ); + + } + + bool OnTouchEvent( Actor actor, const TouchEvent& event ) + { + if( 1u == event.GetPointCount() ) + { + const TouchPoint::State state = event.GetPoint(0u).state; + + // Clamp to integer values; this is to reduce flicking due to pixel misalignment + const float localPoint = static_cast( static_cast( event.GetPoint( 0 ).local.y ) ); + + if( TouchPoint::Down == state ) + { + mLastPoint = localPoint; + mAnimation = Animation::New( 0.25f ); + } + else if( TouchPoint::Motion == state ) + { + if( mAnimation ) + { + mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); + mAnimation.Play(); + mLastPoint = localPoint; + } + } + } + + return true; + } + + /** + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + + +private: + Application& mApplication; + VerticalLayout mLayout; + Animation mAnimation; + float mLastPoint; +}; + +void RunTest( Application& application ) +{ + EmojiExample test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & SLP applications +// +int main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} diff --git a/examples/text-label-emojis/vertical-layout-impl.cpp b/examples/text-label-emojis/vertical-layout-impl.cpp new file mode 100644 index 0000000..b3ebbf2 --- /dev/null +++ b/examples/text-label-emojis/vertical-layout-impl.cpp @@ -0,0 +1,144 @@ +/* + * 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 "vertical-layout-impl.h" + +// INTERNAL INCLUDES +#include "vertical-layout.h" + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +Toolkit::VerticalLayout VerticalLayout::New() +{ + // Create the implementation, temporarily owned by this handle on stack + IntrusivePtr< VerticalLayout > impl = new VerticalLayout(); + + // Pass ownership to CustomActor handle + Toolkit::VerticalLayout handle( *impl ); + + // Second-phase init of the implementation + // This can only be done after the CustomActor connection has been made... + impl->Initialize(); + + return handle; +} + +VerticalLayout::VerticalLayout() +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) +{ +} + +VerticalLayout::~VerticalLayout() +{ +} + +void VerticalLayout::OnInitialize() +{ +} + +Vector3 VerticalLayout::GetNaturalSize() +{ + Vector3 size = Vector3::ZERO; + + CustomActor self = Self(); + for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index ) + { + Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) ); + + if( label ) + { + Vector3 labelSize = label.GetNaturalSize(); + + size.width = ( labelSize.width > size.width ) ? labelSize.width : size.width; + size.height += labelSize.height; + } + } + + return size; +} + +float VerticalLayout::GetHeightForWidth( float width ) +{ + float height = 0.f; + + CustomActor self = Self(); + for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index ) + { + Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) ); + + if( label ) + { + height += label.GetHeightForWidth( width ); + } + } + + return height; +} + +float VerticalLayout::GetWidthForHeight( float height ) +{ + return 0.f; +} + +void VerticalLayout::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ) +{ +} + +void VerticalLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container ) +{ + CustomActor self = Self(); + + Vector3 position; + for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index ) + { + Size childSize = size; + Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) ); + + if( label ) + { + label.SetPosition( position ); + + childSize.height = label.GetHeightForWidth( size.width ); + position.height += childSize.height; + + label.SetSize( childSize ); + } + + container.push_back( ActorSizePair( label, childSize ) ); + } +} + +void VerticalLayout::AddLabel( Toolkit::TextLabel label ) +{ + Self().Add( label ); + + RelayoutRequest(); +} + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali diff --git a/examples/text-label-emojis/vertical-layout-impl.h b/examples/text-label-emojis/vertical-layout-impl.h new file mode 100644 index 0000000..ecdfdd8 --- /dev/null +++ b/examples/text-label-emojis/vertical-layout-impl.h @@ -0,0 +1,91 @@ +#ifndef __DALI_DEMO_VERTICAL_LAYOUT_IMPL_H__ +#define __DALI_DEMO_VERTICAL_LAYOUT_IMPL_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 "vertical-layout.h" + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +class VerticalLayout : public Control +{ +public: + /** + * @copydoc Dali::Toollkit::TextLabel::New() + */ + static Toolkit::VerticalLayout New(); + + VerticalLayout(); + + virtual ~VerticalLayout(); + + /** + * @copydoc Control::OnInitialize() + */ + virtual void OnInitialize(); + + // Size negotiation methods inherited from Internal::Control + + /** + * @copydoc Control::GetNaturalSize() + */ + virtual Vector3 GetNaturalSize(); + + /** + * @copydoc Control::GetHeightForWidth() + */ + virtual float GetHeightForWidth( float width ); + + /** + * @copydoc Control::GetWidthForHeight() + */ + virtual float GetWidthForHeight( float height ); + + /** + * @copydoc Control::OnFontChange() + */ + virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ); + + /** + * @copydoc Control::OnRelayout() + */ + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); + + void AddLabel( Toolkit::TextLabel label ); + +private: + // Undefined copy constructor and assignment operators + VerticalLayout(const VerticalLayout&); + VerticalLayout& operator=(const VerticalLayout& rhs); +}; + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_DEMO_VERTICAL_LAYOUT_IMPL_H__ diff --git a/examples/text-label-emojis/vertical-layout.cpp b/examples/text-label-emojis/vertical-layout.cpp new file mode 100644 index 0000000..8046632 --- /dev/null +++ b/examples/text-label-emojis/vertical-layout.cpp @@ -0,0 +1,88 @@ +/* + * 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 "vertical-layout.h" + +// INTERNAL INCLUDES +#include "vertical-layout-impl.h" + +namespace Dali +{ + +namespace Toolkit +{ + +VerticalLayout VerticalLayout::New() +{ + return Internal::VerticalLayout::New(); +} + +VerticalLayout::VerticalLayout() +{ +} + +VerticalLayout::VerticalLayout( const VerticalLayout& handle ) +: Control( handle ) +{ +} + +VerticalLayout& VerticalLayout::operator=( const VerticalLayout& handle ) +{ + if( &handle != this ) + { + Control::operator=( handle ); + } + return *this; +} + +VerticalLayout VerticalLayout::DownCast( BaseHandle handle ) +{ + return Control::DownCast( handle ); +} + +VerticalLayout::~VerticalLayout() +{ +} + +VerticalLayout::VerticalLayout( Internal::VerticalLayout& internal ) +: Control( internal ) +{ +} + +VerticalLayout::VerticalLayout( Dali::Internal::CustomActor* internal ) +: Control( internal ) +{ +} + +void VerticalLayout::AddLabel( TextLabel label ) +{ + GetImpl( *this ).AddLabel( label ); +} + +Internal::VerticalLayout& VerticalLayout::GetImpl( VerticalLayout& verticalLayout ) +{ + DALI_ASSERT_ALWAYS( verticalLayout ); + + Dali::RefObject& handle = verticalLayout.GetImplementation(); + + return static_cast(handle); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/examples/text-label-emojis/vertical-layout.h b/examples/text-label-emojis/vertical-layout.h new file mode 100644 index 0000000..1f8b176 --- /dev/null +++ b/examples/text-label-emojis/vertical-layout.h @@ -0,0 +1,65 @@ +#ifndef __DALI_DEMO_VERTICAL_LAYOUT_H__ +#define __DALI_DEMO_VERTICAL_LAYOUT_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. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ +class VerticalLayout; +} // namespace Internal + +class VerticalLayout : public Toolkit::Control +{ +public: + static VerticalLayout New(); + + VerticalLayout(); + + VerticalLayout( const VerticalLayout& handle ); + + VerticalLayout& operator=( const VerticalLayout& handle ); + + ~VerticalLayout(); + + VerticalLayout( Internal::VerticalLayout& internal ); + + explicit VerticalLayout( Dali::Internal::CustomActor* internal ); + + VerticalLayout DownCast( BaseHandle handle ); + + void AddLabel( TextLabel label ); + + Internal::VerticalLayout& GetImpl( VerticalLayout& verticalLayout ); + +private: +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_DEMO_VERTICAL_LAYOUT_H__ -- 2.7.4