49d26ec4e0539df00393bb616cac496dd42a23fe
[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     Image image;
53     Vector4 color;
54   };
55
56   Impl(ControlImpl& parent)
57   : mParent(parent),
58     mActiveCursor(ACTIVE_CURSOR_NONE),
59     mCursorBlinkInterval(0.5f),
60     mCursorBlinkDuration(0.0f)
61   {
62   }
63
64   void Relayout( const Vector2& size )
65   {
66     // TODO
67   }
68
69   ControlImpl& mParent;
70
71   unsigned int mActiveCursor;
72
73   CursorImpl mCursor[CURSOR_COUNT];
74
75   float mCursorBlinkInterval;
76   float mCursorBlinkDuration;
77 };
78
79 DecoratorPtr Decorator::New(ControlImpl& parent)
80 {
81   return DecoratorPtr( new Decorator(parent) );
82 }
83
84 void Decorator::Relayout( const Vector2& size )
85 {
86   mImpl->Relayout( size );
87 }
88
89 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
90 {
91   mImpl->mActiveCursor = activeCursor;
92 }
93
94 unsigned int Decorator::GetActiveCursor() const
95 {
96   return mImpl->mActiveCursor;
97 }
98
99 void Decorator::SetPosition( Cursor cursor, float x, float y, float height )
100 {
101   mImpl->mCursor[cursor].x = x;
102   mImpl->mCursor[cursor].y = y;
103   mImpl->mCursor[cursor].height = height;
104 }
105
106 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& height ) const
107 {
108   x = mImpl->mCursor[cursor].x;
109   y = mImpl->mCursor[cursor].y;
110   height = mImpl->mCursor[cursor].height;
111 }
112
113 void Decorator::SetImage( Cursor cursor, Dali::Image image )
114 {
115   mImpl->mCursor[cursor].image = image;
116 }
117
118 Dali::Image Decorator::GetImage( Cursor cursor ) const
119 {
120   return mImpl->mCursor[cursor].image;
121 }
122
123 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
124 {
125   mImpl->mCursor[cursor].color = color;
126 }
127
128 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
129 {
130   return mImpl->mCursor[cursor].color;
131 }
132
133 void Decorator::StartCursorBlink()
134 {
135   // TODO
136 }
137
138 void Decorator::StopCursorBlink()
139 {
140   // TODO
141 }
142
143 void Decorator::SetCursorBlinkInterval( float seconds )
144 {
145   mImpl->mCursorBlinkInterval = seconds;
146 }
147
148 float Decorator::GetCursorBlinkInterval() const
149 {
150   return mImpl->mCursorBlinkInterval;
151 }
152
153 void Decorator::SetCursorBlinkDuration( float seconds )
154 {
155   mImpl->mCursorBlinkDuration = seconds;
156 }
157
158 float Decorator::GetCursorBlinkDuration() const
159 {
160   return mImpl->mCursorBlinkDuration;
161 }
162
163 Decorator::~Decorator()
164 {
165   delete mImpl;
166 }
167
168 Decorator::Decorator(ControlImpl& parent)
169 : mImpl( NULL )
170 {
171   mImpl = new Decorator::Impl(parent);
172 }
173
174 } // namespace Text
175
176 } // namespace Toolkit
177
178 } // namespace Dali