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.
19 #include <dali-toolkit/dali-toolkit.h>
23 #include "emoji-strings.h"
26 using namespace Dali::Toolkit;
27 using namespace EmojiStrings;
29 // TODO Need to expose Text::RENDER.....
30 const int ATLAS_RENDERER = 0;
32 // This example shows how to create and display Hello World! using a simple TextActor
34 class EmojiExample : public ConnectionTracker
38 typedef uint32_t SizeType;
40 EmojiExample( Application& application )
41 : mApplication( application )
43 std::cout << "EmoticonController::EmoticonController" << std::endl;
45 // Connect to the Application's Init signal
46 mApplication.InitSignal().Connect( this, &EmojiExample::Create );
51 // Nothing to do here;
54 // The Init signal is received once (only) during the Application lifetime
55 void Create( Application& application )
57 Stage stage = Stage::GetCurrent();
58 stage.SetBackgroundColor( Color::WHITE );
59 stage.KeyEventSignal().Connect(this, &EmojiExample::OnKeyEvent);
61 mTableView = Toolkit::TableView::New( NUMBER_OF_EMOJIS, 1 );
62 mTableView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
63 mTableView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
64 mTableView.SetParentOrigin( ParentOrigin::TOP_LEFT );
65 mTableView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
66 mTableView.TouchedSignal().Connect( this, &EmojiExample::OnTouchEvent );
67 stage.Add( mTableView );
69 for( unsigned int index = 0u; index < NUMBER_OF_EMOJIS; ++index )
71 const Emoji& emoji = EMOJIS[index];
72 const std::string text = emoji.mUTF8 + " " + emoji.mDescription;
74 TextLabel label = TextLabel::New( text );
75 label.SetParentOrigin( ParentOrigin::TOP_CENTER );
76 label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
77 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
79 mTableView.SetFitHeight( index );
80 mTableView.AddChild( label, Toolkit::TableView::CellPosition( index, 0 ) );
84 bool OnTouchEvent( Actor actor, const TouchEvent& event )
86 if( 1u == event.GetPointCount() )
88 const TouchPoint::State state = event.GetPoint(0u).state;
90 // Clamp to integer values; this is to reduce flicking due to pixel misalignment
91 const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
93 if( TouchPoint::Down == state )
95 mLastPoint = localPoint;
96 mAnimation = Animation::New( 0.25f );
98 else if( TouchPoint::Motion == state )
102 mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR );
104 mLastPoint = localPoint;
113 * Main key event handler
115 void OnKeyEvent(const KeyEvent& event)
117 if(event.state == KeyEvent::Down)
119 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
128 Application& mApplication;
129 TableView mTableView;
130 Animation mAnimation;
134 void RunTest( Application& application )
136 EmojiExample test( application );
138 application.MainLoop();
141 // Entry point for Linux & SLP applications
143 int DALI_EXPORT_API main( int argc, char **argv )
145 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
147 RunTest( application );