2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "vertical-layout.h"
21 #include "emoji-strings.h"
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/public-api/text-abstraction/text-abstraction.h>
29 using namespace Dali::Toolkit;
30 using namespace EmojiStrings;
32 // TODO Need to expose Text::RENDER.....
33 const int ATLAS_RENDERER = 0;
35 // This example shows how to create and display Hello World! using a simple TextActor
37 class EmojiExample : public ConnectionTracker
41 typedef uint32_t SizeType;
43 EmojiExample( Application& application )
44 : mApplication( application )
46 std::cout << "EmoticonController::EmoticonController" << std::endl;
48 // Connect to the Application's Init signal
49 mApplication.InitSignal().Connect( this, &EmojiExample::Create );
54 // Nothing to do here;
57 // The Init signal is received once (only) during the Application lifetime
58 void Create( Application& application )
61 mLayout = VerticalLayout::New();
62 mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
63 mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
64 Stage stage = Stage::GetCurrent();
66 stage.KeyEventSignal().Connect(this, &EmojiExample::OnKeyEvent);
68 for( unsigned int index = 0u; index < NUMBER_OF_EMOJIS; ++index )
70 const Emoji& emoji = EMOJIS[index];
71 const std::string text = emoji.mUTF8 + " " + emoji.mDescription;
72 TextLabel label = TextLabel::New();
73 label.SetParentOrigin( ParentOrigin::TOP_CENTER );
74 label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
75 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
76 label.SetProperty( TextLabel::Property::TEXT, text );
77 mLayout.AddLabel( label );
78 mLayout.TouchedSignal().Connect( this, &EmojiExample::OnTouchEvent );
81 const Vector2& size = stage.GetSize();
82 const float height = mLayout.GetHeightForWidth( size.width );
83 mLayout.SetSize( Size( size.width, height ) );
84 mLayout.TouchedSignal().Connect( this, &EmojiExample::OnTouchEvent );
88 bool OnTouchEvent( Actor actor, const TouchEvent& event )
90 if( 1u == event.GetPointCount() )
92 const TouchPoint::State state = event.GetPoint(0u).state;
94 // Clamp to integer values; this is to reduce flicking due to pixel misalignment
95 const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
97 if( TouchPoint::Down == state )
99 mLastPoint = localPoint;
100 mAnimation = Animation::New( 0.25f );
102 else if( TouchPoint::Motion == state )
106 mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear );
108 mLastPoint = localPoint;
117 * Main key event handler
119 void OnKeyEvent(const KeyEvent& event)
121 if(event.state == KeyEvent::Down)
123 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
132 Application& mApplication;
133 VerticalLayout mLayout;
134 Animation mAnimation;
138 void RunTest( Application& application )
140 EmojiExample test( application );
142 application.MainLoop();
145 // Entry point for Linux & SLP applications
147 int main( int argc, char **argv )
149 Application application = Application::New( &argc, &argv );
151 RunTest( application );