2dc5e7207b73f8613297b772fc1678db2f1eba01
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / decorator / text-decorator.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/public-api/text/decorator/text-decorator.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/constants.h>
23 #include <dali/public-api/images/image.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/math/vector4.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Text
34 {
35
36 struct Decorator::Impl
37 {
38   struct CursorImpl
39   {
40     CursorImpl()
41     : x(0.0f),
42       y(0.0f),
43       height(0.0f),
44       color(Dali::Color::WHITE)
45     {
46     }
47
48     float x;
49     float y;
50     float height;
51
52     Vector4 color;
53   };
54
55   Impl(Dali::Toolkit::Internal::Control& parent)
56   : mParent(parent),
57     mActiveCursor(ACTIVE_CURSOR_NONE),
58     mCursorBlinkInterval(0.5f),
59     mCursorBlinkDuration(0.0f)
60   {
61   }
62
63   void Relayout( const Vector2& size )
64   {
65     // TODO
66   }
67
68   Internal::Control& mParent;
69
70   unsigned int mActiveCursor;
71
72   CursorImpl mCursor[CURSOR_COUNT];
73
74   Image mCursorImage;
75
76   float mCursorBlinkInterval;
77   float mCursorBlinkDuration;
78 };
79
80 DecoratorPtr Decorator::New(Internal::Control& parent)
81 {
82   return DecoratorPtr( new Decorator(parent) );
83 }
84
85 void Decorator::Relayout( const Vector2& size )
86 {
87   mImpl->Relayout( size );
88 }
89
90 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
91 {
92   mImpl->mActiveCursor = activeCursor;
93 }
94
95 unsigned int Decorator::GetActiveCursor() const
96 {
97   return mImpl->mActiveCursor;
98 }
99
100 void Decorator::SetPosition( Cursor cursor, float x, float y, float height )
101 {
102   mImpl->mCursor[cursor].x = x;
103   mImpl->mCursor[cursor].y = y;
104   mImpl->mCursor[cursor].height = height;
105 }
106
107 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& height ) const
108 {
109   x = mImpl->mCursor[cursor].x;
110   y = mImpl->mCursor[cursor].y;
111   height = mImpl->mCursor[cursor].height;
112 }
113
114 void Decorator::SetCursorImage( Dali::Image image )
115 {
116   mImpl->mCursorImage = image;
117 }
118
119 Dali::Image Decorator::GetCursorImage() const
120 {
121   return mImpl->mCursorImage;
122 }
123
124 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
125 {
126   mImpl->mCursor[cursor].color = color;
127 }
128
129 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
130 {
131   return mImpl->mCursor[cursor].color;
132 }
133
134 void Decorator::StartCursorBlink()
135 {
136   // TODO
137 }
138
139 void Decorator::StopCursorBlink()
140 {
141   // TODO
142 }
143
144 void Decorator::SetCursorBlinkInterval( float seconds )
145 {
146   mImpl->mCursorBlinkInterval = seconds;
147 }
148
149 float Decorator::GetCursorBlinkInterval() const
150 {
151   return mImpl->mCursorBlinkInterval;
152 }
153
154 void Decorator::SetCursorBlinkDuration( float seconds )
155 {
156   mImpl->mCursorBlinkDuration = seconds;
157 }
158
159 float Decorator::GetCursorBlinkDuration() const
160 {
161   return mImpl->mCursorBlinkDuration;
162 }
163
164 Decorator::~Decorator()
165 {
166   delete mImpl;
167 }
168
169 Decorator::Decorator(Dali::Toolkit::Internal::Control& parent)
170 : mImpl( NULL )
171 {
172   mImpl = new Decorator::Impl(parent);
173 }
174
175 } // namespace Text
176
177 } // namespace Toolkit
178
179 } // namespace Dali