2013-09-20 22:23:13 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 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 __UITEXTFIELD_H__
|
|
|
|
#define __UITEXTFIELD_H__
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
#include "base-classes/UIWidget.h"
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace gui {
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
class UICCTextField: public cocos2d::TextFieldTTF, public cocos2d::TextFieldDelegate
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
UICCTextField();
|
|
|
|
~UICCTextField();
|
|
|
|
|
|
|
|
virtual void onEnter();
|
|
|
|
|
|
|
|
// static
|
|
|
|
static UICCTextField* create(const char *placeholder, const char *fontName, float fontSize);
|
|
|
|
|
|
|
|
// CCTextFieldDelegate
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual bool onTextFieldAttachWithIME(cocos2d::TextFieldTTF *pSender);
|
|
|
|
virtual bool onTextFieldDetachWithIME(cocos2d::TextFieldTTF * pSender);
|
|
|
|
virtual bool onTextFieldInsertText(cocos2d::TextFieldTTF * pSender, const char * text, int nLen);
|
|
|
|
virtual bool onTextFieldDeleteBackward(cocos2d::TextFieldTTF * pSender, const char * delText, int nLen);
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
void insertText(const char* text, int len);
|
|
|
|
void deleteBackward();
|
|
|
|
|
|
|
|
void openIME();
|
|
|
|
void closeIME();
|
|
|
|
|
|
|
|
void setMaxLengthEnabled(bool enable);
|
|
|
|
bool isMaxLengthEnabled();
|
|
|
|
void setMaxLength(int length);
|
|
|
|
int getMaxLength();
|
|
|
|
int getCharCount();
|
|
|
|
void setPasswordEnabled(bool enable);
|
|
|
|
bool isPasswordEnabled();
|
|
|
|
void setPasswordStyleText(const char* styleText);
|
|
|
|
void setPasswordText(const char* text);
|
|
|
|
void setAttachWithIME(bool attach);
|
|
|
|
bool getAttachWithIME();
|
|
|
|
void setDetachWithIME(bool detach);
|
|
|
|
bool getDetachWithIME();
|
|
|
|
void setInsertText(bool insert);
|
|
|
|
bool getInsertText();
|
|
|
|
void setDeleteBackward(bool deleteBackward);
|
|
|
|
bool getDeleteBackward();
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_bMaxLengthEnabled;
|
|
|
|
int m_nMaxLength;
|
|
|
|
bool m_bPasswordEnabled;
|
|
|
|
std::string m_strPasswordStyleText;
|
|
|
|
bool m_bAttachWithIME;
|
|
|
|
bool m_bDetachWithIME;
|
|
|
|
bool m_bInsertText;
|
|
|
|
bool m_bDeleteBackward;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TEXTFIELD_EVENT_ATTACH_WITH_IME,
|
|
|
|
TEXTFIELD_EVENT_DETACH_WITH_IME,
|
|
|
|
TEXTFIELD_EVENT_INDERT_TEXT,
|
|
|
|
TEXTFIELD_EVENT_DELETE_BACKWARD,
|
|
|
|
}TextFiledEventType;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
typedef void (cocos2d::Object::*SEL_TextFieldEvent)(cocos2d::Object*, TextFiledEventType);
|
2013-09-20 22:23:13 +08:00
|
|
|
#define textfieldeventselector(_SELECTOR) (SEL_TextFieldEvent)(&_SELECTOR)
|
|
|
|
|
|
|
|
//class UITextField : public UIWidget
|
|
|
|
class UITextField : public UIWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UITextField();
|
|
|
|
virtual ~UITextField();
|
|
|
|
static UITextField* create();
|
|
|
|
virtual bool init();
|
|
|
|
virtual void initRenderer();
|
2013-10-15 18:00:03 +08:00
|
|
|
void setTouchSize(const cocos2d::Size &size);
|
2013-09-20 22:23:13 +08:00
|
|
|
void setText(const char* text);
|
|
|
|
void setPlaceHolder(const char* value);
|
|
|
|
void setFontSize(int size);
|
|
|
|
void setFontName(const char* name);
|
|
|
|
virtual void didNotSelectSelf();
|
|
|
|
const char* getStringValue();
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual bool onTouchBegan(const cocos2d::Point &touchPoint);
|
2013-09-20 22:23:13 +08:00
|
|
|
void setMaxLengthEnabled(bool enable);
|
|
|
|
bool isMaxLengthEnabled();
|
|
|
|
void setMaxLength(int length);
|
|
|
|
int getMaxLength();
|
|
|
|
void setPasswordEnabled(bool enable);
|
|
|
|
bool isPasswordEnabled();
|
|
|
|
void setPasswordStyleText(const char* styleText);
|
|
|
|
virtual void update(float dt);
|
|
|
|
bool getAttachWithIME();
|
|
|
|
void setAttachWithIME(bool attach);
|
|
|
|
bool getDetachWithIME();
|
|
|
|
void setDetachWithIME(bool detach);
|
|
|
|
bool getInsertText();
|
|
|
|
void setInsertText(bool insertText);
|
|
|
|
bool getDeleteBackward();
|
|
|
|
void setDeleteBackward(bool deleteBackward);
|
2013-10-15 18:00:03 +08:00
|
|
|
void addEventListener(cocos2d::Object* target, SEL_TextFieldEvent selecor);
|
|
|
|
virtual void setAnchorPoint(const cocos2d::Point &pt);
|
|
|
|
virtual void setColor(const cocos2d::Color3B &color);
|
2013-09-20 22:23:13 +08:00
|
|
|
virtual void setOpacity(int opacity);
|
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
|
|
|
virtual const char* getDescription() const;
|
|
|
|
/*compatibel*/
|
|
|
|
/**
|
|
|
|
* These methods will be removed
|
|
|
|
*/
|
|
|
|
void setMaxLengthEnable(bool is){setMaxLengthEnabled(is);};
|
|
|
|
void setPasswordEnable(bool is){setPasswordEnabled(is);};
|
|
|
|
/************/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual const cocos2d::Size& getContentSize() const;
|
|
|
|
virtual cocos2d::Node* getVirtualRenderer();
|
2013-09-20 22:23:13 +08:00
|
|
|
protected:
|
|
|
|
// event
|
|
|
|
void attachWithIMEEvent();
|
|
|
|
void detachWithIMEEvent();
|
|
|
|
void insertTextEvent();
|
|
|
|
void deleteBackwardEvent();
|
|
|
|
virtual void onSizeChanged();
|
|
|
|
void textfieldRendererScaleChangedWithSize();
|
|
|
|
protected:
|
|
|
|
UICCTextField* _textFieldRenderer;
|
|
|
|
|
|
|
|
float _touchWidth;
|
|
|
|
float _touchHeight;
|
|
|
|
bool _useTouchArea;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Object* _eventListener;
|
2013-09-20 22:23:13 +08:00
|
|
|
SEL_TextFieldEvent _eventSelector;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
#endif /* defined(__CocoGUI__UITextField__) */
|