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 * @file message-field-example.cpp
20 * @brief Basic usage of TextField control
24 #include <dali-toolkit/dali-toolkit.h>
27 using namespace Dali::Toolkit;
31 const char* DESKTOP_IMAGE( DALI_IMAGE_DIR "woodEffect.jpg" );
32 const Vector2 DESKTOP_SIZE( Vector2( 1440, 1600 ) );
33 const Vector2 PHOTOBOX_SIZE( Vector2(330.0f, 80.0f ) );
34 const float MAX_OFFSCREEN_RENDERING_SIZE = 2048.f;
35 const float SCREEN_BORDER = 5.0f; // Border around screen that Popups and handles will not exceed
38 * @brief The main class of the demo.
40 class TextMessageFieldExample : public ConnectionTracker
44 TextMessageFieldExample( Application& application )
45 : mApplication( application ),
46 mTargetActorPosition(),
49 // Connect to the Application's Init signal
50 mApplication.InitSignal().Connect( this, &TextMessageFieldExample::Create );
53 ~TextMessageFieldExample()
55 // Nothing to do here.
59 * One-time setup in response to Application InitSignal.
61 void Create( Application& application )
63 Stage stage = Stage::GetCurrent();
64 mStageSize = stage.GetSize();
66 stage.KeyEventSignal().Connect(this, &TextMessageFieldExample::OnKeyEvent);
69 Actor rootActor = Actor::New();
70 rootActor.SetName("rootActor");
71 rootActor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
72 rootActor.SetSize( mStageSize );
73 rootActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
75 stage.Add( rootActor );
77 const Size mTargetActorSize( mStageSize.width, DESKTOP_SIZE.height );
80 ResourceImage backgroundImage = ResourceImage::New( DESKTOP_IMAGE );
81 ImageActor desktop = ImageActor::New( backgroundImage );
82 desktop.SetName("desktopActor");
83 desktop.SetAnchorPoint( AnchorPoint::TOP_LEFT );
84 desktop.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
85 desktop.SetSize( mTargetActorSize );
87 rootActor.Add( desktop ); // Add desktop (content) to offscreen actor
90 ImageActor photoBoxA = CreateSolidColorActor( Vector4(0,0,0,0), true, Color::WHITE, 1 );
91 photoBoxA.SetName("photoBoxA");
92 photoBoxA.SetAnchorPoint( AnchorPoint::CENTER );
93 photoBoxA.SetParentOrigin( ParentOrigin::CENTER );
94 photoBoxA.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
95 photoBoxA.SetSize( PHOTOBOX_SIZE );
96 photoBoxA.SetPosition( 0.0f, -500.0f, 1.0f );
97 desktop.Add( photoBoxA );
100 TextField field = TextField::New();
101 field.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
102 field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
103 field.SetPadding( Padding( 1.0f, 1.0f, 1.0f, 1.0f ) );
104 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
106 field.SetProperty( TextField::Property::TEXT, "Enter Title name" );
107 field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( SCREEN_BORDER, SCREEN_BORDER, mStageSize.width - SCREEN_BORDER*2, mStageSize.height - SCREEN_BORDER*2 ) );
108 photoBoxA.Add( field );
110 mPanGestureDetector = PanGestureDetector::New();
111 mPanGestureDetector.DetectedSignal().Connect(this, &TextMessageFieldExample::OnPanGesture );
112 mPanGestureDetector.Attach( desktop );
116 * Main key event handler
118 void OnKeyEvent(const KeyEvent& event)
120 if(event.state == KeyEvent::Down)
122 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
129 void OnPanGesture( Actor actor, const PanGesture& gesture )
131 if( gesture.state == Gesture::Continuing )
133 Vector2 position = Vector2( gesture.displacement );
134 mTargetActorPosition.y = mTargetActorPosition.y + position.y;
135 mTargetActorPosition.y = std::min( mTargetActorPosition.y, -mTargetActorSize.height );
136 mTargetActorPosition.y = std::max( mTargetActorPosition.y, ( mTargetActorSize.height - mStageSize.height*0.25f ) );
137 actor.SetPosition( 0.0f, mTargetActorPosition.y );
143 Application& mApplication;
144 PanGestureDetector mPanGestureDetector;
146 Vector2 mTargetActorPosition;
147 Vector2 mTargetActorSize;
151 void RunTest( Application& application )
153 TextMessageFieldExample test( application );
155 application.MainLoop();
158 /** Entry point for Linux & Tizen applications */
159 int main( int argc, char **argv )
161 Application application = Application::New( &argc, &argv );
163 RunTest( application );