text-message-field-example.cpp
5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* 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.
*
*/
/**
* @file message-field-example.cpp
* @brief Basic usage of TextField control
*/
// EXTERNAL INCLUDES
#include <dali-toolkit/dali-toolkit.h>
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
const char* DESKTOP_IMAGE( DALI_IMAGE_DIR "woodEffect.jpg" );
const Vector2 DESKTOP_SIZE( Vector2( 1440, 1600 ) );
const Vector2 PHOTOBOX_SIZE( Vector2(330.0f, 80.0f ) );
const float MAX_OFFSCREEN_RENDERING_SIZE = 2048.f;
const float SCREEN_BORDER = 5.0f; // Border around screen that Popups and handles will not exceed
}
/**
* @brief The main class of the demo.
*/
class TextMessageFieldExample : public ConnectionTracker
{
public:
TextMessageFieldExample( Application& application )
: mApplication( application ),
mTargetActorPosition(),
mTargetActorSize()
{
// Connect to the Application's Init signal
mApplication.InitSignal().Connect( this, &TextMessageFieldExample::Create );
}
~TextMessageFieldExample()
{
// Nothing to do here.
}
/**
* One-time setup in response to Application InitSignal.
*/
void Create( Application& application )
{
Stage stage = Stage::GetCurrent();
mStageSize = stage.GetSize();
stage.KeyEventSignal().Connect(this, &TextMessageFieldExample::OnKeyEvent);
// Create Root actor
Actor rootActor = Actor::New();
rootActor.SetName("rootActor");
rootActor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
rootActor.SetSize( mStageSize );
rootActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
stage.Add( rootActor );
const Size mTargetActorSize( mStageSize.width, DESKTOP_SIZE.height );
// Create Desktop
ResourceImage backgroundImage = ResourceImage::New( DESKTOP_IMAGE );
ImageActor desktop = ImageActor::New( backgroundImage );
desktop.SetName("desktopActor");
desktop.SetAnchorPoint( AnchorPoint::TOP_LEFT );
desktop.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
desktop.SetSize( mTargetActorSize );
rootActor.Add( desktop ); // Add desktop (content) to offscreen actor
// Create Photo Box A
ImageActor photoBoxA = CreateSolidColorActor( Vector4(0,0,0,0), true, Color::WHITE, 1 );
photoBoxA.SetName("photoBoxA");
photoBoxA.SetAnchorPoint( AnchorPoint::CENTER );
photoBoxA.SetParentOrigin( ParentOrigin::CENTER );
photoBoxA.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
photoBoxA.SetSize( PHOTOBOX_SIZE );
photoBoxA.SetPosition( 0.0f, -500.0f, 1.0f );
desktop.Add( photoBoxA );
// Create TextField
TextField field = TextField::New();
field.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
field.SetPadding( Padding( 1.0f, 1.0f, 1.0f, 1.0f ) );
field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
field.SetZ( 1.0f );
field.SetProperty( TextField::Property::TEXT, "Enter Title name" );
field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( SCREEN_BORDER, SCREEN_BORDER, mStageSize.width - SCREEN_BORDER*2, mStageSize.height - SCREEN_BORDER*2 ) );
photoBoxA.Add( field );
mPanGestureDetector = PanGestureDetector::New();
mPanGestureDetector.DetectedSignal().Connect(this, &TextMessageFieldExample::OnPanGesture );
mPanGestureDetector.Attach( desktop );
}
/**
* 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();
}
}
}
void OnPanGesture( Actor actor, const PanGesture& gesture )
{
if( gesture.state == Gesture::Continuing )
{
Vector2 position = Vector2( gesture.displacement );
mTargetActorPosition.y = mTargetActorPosition.y + position.y;
mTargetActorPosition.y = std::min( mTargetActorPosition.y, -mTargetActorSize.height );
mTargetActorPosition.y = std::max( mTargetActorPosition.y, ( mTargetActorSize.height - mStageSize.height*0.25f ) );
actor.SetPosition( 0.0f, mTargetActorPosition.y );
}
}
private:
Application& mApplication;
PanGestureDetector mPanGestureDetector;
Vector2 mTargetActorPosition;
Vector2 mTargetActorSize;
Vector2 mStageSize;
};
void RunTest( Application& application )
{
TextMessageFieldExample test( application );
application.MainLoop();
}
/** Entry point for Linux & Tizen applications */
int main( int argc, char **argv )
{
Application application = Application::New( &argc, &argv );
RunTest( application );
return 0;
}