forked from cocos2d/cocos2d-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCTextFieldTTF.h
176 lines (147 loc) · 5.55 KB
/
CCTextFieldTTF.h
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
167
168
169
170
171
172
173
174
175
176
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CC_TEXT_FIELD_H__
#define __CC_TEXT_FIELD_H__
#include "label_nodes/CCLabelTTF.h"
#include "text_input_node/CCIMEDelegate.h"
#include "touch_dispatcher/CCTouchDelegateProtocol.h"
NS_CC_BEGIN
class CCTextFieldTTF;
/**
* @addtogroup input
* @{
*/
class CC_DLL CCTextFieldDelegate
{
public:
/**
@brief If the sender doesn't want to attach to the IME, return true;
*/
virtual bool onTextFieldAttachWithIME(CCTextFieldTTF * sender)
{
CC_UNUSED_PARAM(sender);
return false;
}
/**
@brief If the sender doesn't want to detach from the IME, return true;
*/
virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * sender)
{
CC_UNUSED_PARAM(sender);
return false;
}
/**
@brief If the sender doesn't want to insert the text, return true;
*/
virtual bool onTextFieldInsertText(CCTextFieldTTF * sender, const char * text, int nLen)
{
CC_UNUSED_PARAM(sender);
CC_UNUSED_PARAM(text);
CC_UNUSED_PARAM(nLen);
return false;
}
/**
@brief If the sender doesn't want to delete the delText, return true;
*/
virtual bool onTextFieldDeleteBackward(CCTextFieldTTF * sender, const char * delText, int nLen)
{
CC_UNUSED_PARAM(sender);
CC_UNUSED_PARAM(delText);
CC_UNUSED_PARAM(nLen);
return false;
}
/**
@brief If the sender doesn't want to draw, return true.
*/
virtual bool onDraw(CCTextFieldTTF * sender)
{
CC_UNUSED_PARAM(sender);
return false;
}
};
/**
@brief A simple text input field with TTF font.
*/
class CC_DLL CCTextFieldTTF : public CCLabelTTF, public CCIMEDelegate
{
public:
CCTextFieldTTF();
virtual ~CCTextFieldTTF();
//char * description();
/** creates a CCTextFieldTTF from a fontname, alignment, dimension and font size */
static CCTextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, const CCSize& dimensions, CCTextAlignment alignment, const char *fontName, float fontSize);
/** creates a CCLabelTTF from a fontname and font size */
static CCTextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize);
/** initializes the CCTextFieldTTF with a font name, alignment, dimension and font size */
bool initWithPlaceHolder(const char *placeholder, const CCSize& dimensions, CCTextAlignment alignment, const char *fontName, float fontSize);
/** initializes the CCTextFieldTTF with a font name and font size */
bool initWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize);
/**
@brief Open keyboard and receive input text.
*/
virtual bool attachWithIME();
/**
@brief End text input and close keyboard.
*/
virtual bool detachWithIME();
//////////////////////////////////////////////////////////////////////////
// properties
//////////////////////////////////////////////////////////////////////////
CC_SYNTHESIZE(CCTextFieldDelegate *, m_pDelegate, Delegate);
CC_SYNTHESIZE_READONLY(int, m_nCharCount, CharCount);
virtual const ccColor3B& getColorSpaceHolder();
virtual void setColorSpaceHolder(const ccColor3B& color);
// input text property
public:
virtual void setString(const char *text);
virtual const char* getString(void);
protected:
std::string * m_pInputText;
// place holder text property
// place holder text displayed when there is no text in the text field.
public:
virtual void setPlaceHolder(const char * text);
virtual const char * getPlaceHolder(void);
protected:
std::string * m_pPlaceHolder;
ccColor3B m_ColorSpaceHolder;
public:
virtual void setSecureTextEntry(bool value);
virtual bool isSecureTextEntry();
protected:
bool m_bSecureTextEntry;
protected:
virtual void draw();
//////////////////////////////////////////////////////////////////////////
// CCIMEDelegate interface
//////////////////////////////////////////////////////////////////////////
virtual bool canAttachWithIME();
virtual bool canDetachWithIME();
virtual void insertText(const char * text, int len);
virtual void deleteBackward();
virtual const char * getContentText();
private:
class LengthStack;
LengthStack * m_pLens;
};
// end of input group
/// @}
NS_CC_END
#endif // __CC_TEXT_FIELD_H__