CCTextFieldTTF


#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__


转载于:https://www.cnblogs.com/sssssnian/p/3748627.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值