cocos2d-X 节点(CCTextFieldTTF.h)API

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-X 节点(CCTextFieldTTF.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
///cocos2d-x-3.0alpha0/cocos2dx/text_input_node


#ifndef __CC_TEXT_FIELD_H__
#define __CC_TEXT_FIELD_H__

#include "label_nodes/CCLabelTTF.h"
#include "text_input_node/CCIMEDelegate.h"

NS_CC_BEGIN

class TextFieldTTF;

/**
 * @addtogroup input
 * @{
 */

class CC_DLL TextFieldDelegate
{
public:
    /**
    @brief    如果 sender(发送者)不希望 attach(附加到) IME, return true;
    */
    virtual bool onTextFieldAttachWithIME(TextFieldTTF * sender)
    {
        CC_UNUSED_PARAM(sender);
        return false;
    }

    /**
    @brief     如果 sender(发送者)不希望和 detach(分离) IME, return true;
    */
    virtual bool onTextFieldDetachWithIME(TextFieldTTF * sender)
    {
        CC_UNUSED_PARAM(sender);
        return false;
    }

    /**
    @brief    如果 sender(发送者)不希望插入 text , return true; 
    */
    virtual bool onTextFieldInsertText(TextFieldTTF * sender, const char * text, int nLen)
    {
        CC_UNUSED_PARAM(sender);
        CC_UNUSED_PARAM(text);
        CC_UNUSED_PARAM(nLen);
        return false;
    }

    /**
    @brief    如果 sender(发送者)不希望删除 delText , return true;
    */
    virtual bool onTextFieldDeleteBackward(TextFieldTTF * sender, const char * delText, int nLen)
    {
        CC_UNUSED_PARAM(sender);
        CC_UNUSED_PARAM(delText);
        CC_UNUSED_PARAM(nLen);
        return false;
    }

    /**
    @brief    如果 sender(发送者)不希望被绘制 , return true.
    */
    virtual bool onDraw(TextFieldTTF * sender)
    {
        CC_UNUSED_PARAM(sender);
        return false;
    }
};

/**
@brief   一个简单的使用 TTF 字体的输入 field(文本).
*/
class CC_DLL TextFieldTTF : public LabelTTF, public IMEDelegate
{
public:
    /**
     * @js ctor
     */
    TextFieldTTF();
    /**
     * @js NA
     * @lua NA
     */
    virtual ~TextFieldTTF();

    //char * description();     //描述

    /**  使用 fontname, alignment, dimension 、 font size  创建一个 TextFieldTTF*/
    static TextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, const Size& dimensions, TextHAlignment alignment, const char *fontName, float fontSize);
    /**  使用 fontname、 font size  创建一个 TextFieldTTF */
    static TextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize);
    /**  使用 fontname, alignment, dimension 、 font size  初始化一个 TextFieldTTF */
    bool initWithPlaceHolder(const char *placeholder, const Size& dimensions, TextHAlignment alignment, const char *fontName, float fontSize);
    /**  使用 fontname、 font size  初始化一个 TextFieldTTF */
    bool initWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize);

    /**
    @brief   打开键盘和接收输入文本.
    */
    virtual bool attachWithIME();

    /**
    @brief   最终文本输入和关闭键盘.
    */
    virtual bool detachWithIME();

    //
    // properties
    //
    /**
     * @js NA
     * @lua NA
     */
    inline TextFieldDelegate* getDelegate() const { return _delegate; };
    /**
     * @js NA
     * @lua NA
     */
    inline void setDelegate(TextFieldDelegate* delegate) { _delegate = delegate; };

    inline int getCharCount() const { return _charCount; };
    virtual const Color3B& getColorSpaceHolder();
    virtual void setColorSpaceHolder(const Color3B& color);

    //输入文本属性
public:
    virtual void setString(const char *text);
    virtual const char* getString(void) const;
protected:
    TextFieldDelegate * _delegate;
    int _charCount;
    
    std::string * _inputText;

    //文本属性的占位符
    //如果文本字段为 nil 占位符将显示.
public:
    virtual void setPlaceHolder(const char * text);
    virtual const char * getPlaceHolder(void);
protected:
    std::string * _placeHolder;
    Color3B _colorSpaceHolder;
public:
    virtual void setSecureTextEntry(bool value);
    virtual bool isSecureTextEntry();
protected:
    bool _secureTextEntry;
protected:

    virtual void draw();

    //
    // IMEDelegate 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 * _lens;
};

// end of input group
/// @}

NS_CC_END

#endif    // __CC_TEXT_FIELD_H__





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值