2014-08-19 10:28:24 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2012 James Chen
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-08-19 10:28:24 +08:00
|
|
|
|
|
|
|
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.
|
2015-03-25 18:17:58 +08:00
|
|
|
****************************************************************************/
|
2014-08-19 10:28:24 +08:00
|
|
|
|
|
|
|
#ifndef __UIEDITTEXT_H__
|
|
|
|
#define __UIEDITTEXT_H__
|
|
|
|
|
|
|
|
#include "base/CCIMEDelegate.h"
|
|
|
|
#include "ui/GUIDefine.h"
|
2018-08-07 09:29:51 +08:00
|
|
|
#include "ui/UIWidget.h"
|
2014-08-19 10:28:24 +08:00
|
|
|
#include "ui/UIScale9Sprite.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2014-08-19 10:28:24 +08:00
|
|
|
namespace ui {
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
class EditBox;
|
|
|
|
class EditBoxImpl;
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-12-21 07:21:45 +08:00
|
|
|
*@brief Editbox delegate class.
|
|
|
|
* It's useful when you want to do some customization during Editbox input event
|
2015-03-30 15:47:47 +08:00
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
|
|
|
class CC_GUI_DLL EditBoxDelegate
|
|
|
|
{
|
|
|
|
public:
|
2016-11-03 14:02:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reason for ending edit (for platforms where it is known)
|
|
|
|
*/
|
|
|
|
enum class EditBoxEndAction {
|
|
|
|
UNKNOWN,
|
|
|
|
TAB_TO_NEXT,
|
|
|
|
TAB_TO_PREVIOUS,
|
|
|
|
RETURN
|
|
|
|
};
|
|
|
|
|
2018-08-07 09:29:51 +08:00
|
|
|
virtual ~EditBoxDelegate() {}
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* This method is called when an edit box gains focus after keyboard is shown.
|
|
|
|
* @param editBox The edit box object that generated the event.
|
|
|
|
*/
|
2018-08-07 09:29:51 +08:00
|
|
|
virtual void editBoxEditingDidBegin(EditBox* /*editBox*/) {}
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* This method is called when the edit box text was changed.
|
|
|
|
* @param editBox The edit box object that generated the event.
|
|
|
|
* @param text The new text.
|
|
|
|
*/
|
2018-08-07 09:29:51 +08:00
|
|
|
virtual void editBoxTextChanged(EditBox* /*editBox*/, const std::string& /*text*/) {}
|
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* This method is called when the return button was pressed or the outside area of keyboard was touched.
|
|
|
|
* @param editBox The edit box object that generated the event.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
virtual void editBoxReturn(EditBox* editBox) = 0;
|
2016-11-03 14:02:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called when an edit box loses focus after keyboard is hidden.
|
|
|
|
* @param editBox The edit box object that generated the event.
|
|
|
|
* @param type The reason why editing ended.
|
|
|
|
*/
|
2018-08-07 09:29:51 +08:00
|
|
|
virtual void editBoxEditingDidEndWithAction(EditBox* /*editBox*/, EditBoxEndAction /*action*/) {}
|
2015-03-25 18:17:58 +08:00
|
|
|
};
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Class for edit box.
|
|
|
|
*
|
|
|
|
* You can use this widget to gather small amounts of text from the user.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class CC_GUI_DLL EditBox
|
2014-08-19 10:28:24 +08:00
|
|
|
: public Widget
|
|
|
|
, public IMEDelegate
|
2015-03-25 18:17:58 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The popup keyboard return type.
|
|
|
|
*/
|
|
|
|
enum class KeyboardReturnType
|
2014-08-19 10:28:24 +08:00
|
|
|
{
|
2015-03-25 18:17:58 +08:00
|
|
|
DEFAULT,
|
|
|
|
DONE,
|
|
|
|
SEND,
|
|
|
|
SEARCH,
|
2016-11-03 14:02:53 +08:00
|
|
|
GO,
|
|
|
|
NEXT
|
2015-03-25 18:17:58 +08:00
|
|
|
};
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief The EditBox::InputMode defines the type of text that the user is allowed
|
|
|
|
* to enter.
|
|
|
|
*/
|
|
|
|
enum class InputMode
|
|
|
|
{
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* The user is allowed to enter any text, including line breaks.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
ANY,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* The user is allowed to enter an e-mail address.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
EMAIL_ADDRESS,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-20 16:08:28 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* The user is allowed to enter an integer value.
|
2014-08-20 16:08:28 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
NUMERIC,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* The user is allowed to enter a phone number.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
PHONE_NUMBER,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* The user is allowed to enter a URL.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
URL,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* The user is allowed to enter a real number value.
|
|
|
|
* This extends kEditBoxInputModeNumeric by allowing a decimal point.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
DECIMAL,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* The user is allowed to enter any text, except for line breaks.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
SINGLE_LINE,
|
|
|
|
};
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief The EditBox::InputFlag defines how the input text is displayed/formatted.
|
|
|
|
*/
|
|
|
|
enum class InputFlag
|
|
|
|
{
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Indicates that the text entered is confidential data that should be
|
|
|
|
* obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
PASSWORD,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Indicates that the text entered is sensitive data that the
|
|
|
|
* implementation must never store into a dictionary or table for use
|
|
|
|
* in predictive, auto-completing, or other accelerated input schemes.
|
|
|
|
* A credit card number is an example of sensitive data.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
SENSITIVE,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* This flag is a hint to the implementation that during text editing,
|
|
|
|
* the initial letter of each word should be capitalized.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
INITIAL_CAPS_WORD,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* This flag is a hint to the implementation that during text editing,
|
|
|
|
* the initial letter of each sentence should be capitalized.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-03-25 18:17:58 +08:00
|
|
|
INITIAL_CAPS_SENTENCE,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Capitalize all characters automatically.
|
2014-08-19 10:28:24 +08:00
|
|
|
*/
|
2015-10-12 12:54:06 +08:00
|
|
|
INITIAL_CAPS_ALL_CHARACTERS,
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2016-06-07 10:31:16 +08:00
|
|
|
/**
|
|
|
|
* Lowercase all characters automatically.
|
|
|
|
*/
|
|
|
|
LOWERCASE_ALL_CHARACTERS
|
2015-03-25 18:17:58 +08:00
|
|
|
};
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* create a edit box with size.
|
|
|
|
* @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again.
|
|
|
|
*/
|
|
|
|
static EditBox* create(const Size& size,
|
|
|
|
Scale9Sprite* normalSprite,
|
|
|
|
Scale9Sprite* pressedSprite = nullptr,
|
|
|
|
Scale9Sprite* disabledSprite = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create a edit box with size.
|
|
|
|
* @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again.
|
|
|
|
*/
|
|
|
|
static EditBox* create(const Size& size,
|
2018-08-07 09:29:51 +08:00
|
|
|
const std::string& normalImage,
|
|
|
|
TextureResType texType);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create a edit box with size.
|
|
|
|
* @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again.
|
|
|
|
*/
|
|
|
|
static EditBox* create(const Size& size,
|
|
|
|
const std::string& normalImage,
|
|
|
|
const std::string& pressedImage = "",
|
|
|
|
const std::string& disabledImage = "",
|
2015-03-25 18:17:58 +08:00
|
|
|
TextureResType texType = TextureResType::LOCAL);
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
EditBox();
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
virtual ~EditBox();
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Init edit box with specified size. This method should be invoked right after constructor.
|
|
|
|
* @param size The size of edit box.
|
|
|
|
* @param normal9SpriteBg background image of edit box.
|
|
|
|
* @param texType the resource type, the default value is TextureResType::LOCAL
|
|
|
|
* @return Whether initialization is successfully or not.
|
|
|
|
*/
|
|
|
|
bool initWithSizeAndBackgroundSprite(const Size& size,
|
|
|
|
const std::string& normal9SpriteBg,
|
|
|
|
TextureResType texType = TextureResType::LOCAL);
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Init edit box with specified size. This method should be invoked right after constructor.
|
|
|
|
* @param size The size of edit box.
|
|
|
|
* @param normal9SpriteBg background image of edit box.
|
|
|
|
* @return Whether initialization is successfully or not.
|
|
|
|
*/
|
|
|
|
bool initWithSizeAndBackgroundSprite(const Size& size, Scale9Sprite* normal9SpriteBg);
|
|
|
|
|
2018-08-07 09:29:51 +08:00
|
|
|
/**
|
|
|
|
* Init edit box with specified size. This method should be invoked right after constructor.
|
|
|
|
* @param size The size of edit box.
|
|
|
|
* @param normalSprite normal state image of edit box.
|
|
|
|
* @param pressedSprite pressed state image of edit box.
|
|
|
|
* @param disabledSprite disabled state image of edit box.
|
|
|
|
* @return Whether initialization is successfully or not.
|
|
|
|
*/
|
|
|
|
bool initWithSizeAndBackgroundSprite(const Size& size, Scale9Sprite* normalSprite, Scale9Sprite* pressedSprite, Scale9Sprite* disabledSprite);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init edit box with specified size. This method should be invoked right after constructor.
|
|
|
|
* @param size The size of edit box.
|
|
|
|
* @param normalImage normal state texture name.
|
|
|
|
* @param pressedImage pressed state texture name.
|
|
|
|
* @param disabledImage disabled state texture name.
|
|
|
|
* @return Whether initialization is successfully or not.
|
|
|
|
*/
|
|
|
|
bool initWithSizeAndTexture(const Size& size,
|
|
|
|
const std::string& normalImage,
|
|
|
|
const std::string& pressedImage = "",
|
|
|
|
const std::string& disabledImage = "",
|
|
|
|
TextureResType texType = TextureResType::LOCAL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load textures for edit box.
|
|
|
|
*
|
|
|
|
* @param normal normal state texture name.
|
|
|
|
* @param pressed pressed state texture name.
|
|
|
|
* @param disabled disabled state texture name.
|
|
|
|
* @param texType @see `TextureResType`
|
|
|
|
*/
|
|
|
|
void loadTextures(const std::string& normal,
|
|
|
|
const std::string& pressed,
|
|
|
|
const std::string& disabled = "",
|
|
|
|
TextureResType texType = TextureResType::LOCAL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load normal state texture for edit box.
|
|
|
|
*
|
|
|
|
* @param normal normal state texture.
|
|
|
|
* @param texType @see `TextureResType`
|
|
|
|
*/
|
|
|
|
void loadTextureNormal(const std::string& normal, TextureResType texType = TextureResType::LOCAL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load pressed state texture for edit box.
|
|
|
|
*
|
|
|
|
* @param pressed pressed state texture.
|
|
|
|
* @param texType @see `TextureResType`
|
|
|
|
*/
|
|
|
|
void loadTexturePressed(const std::string& pressed, TextureResType texType = TextureResType::LOCAL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load disabled state texture for edit box.
|
|
|
|
*
|
|
|
|
* @param disabled dark state texture.
|
|
|
|
* @param texType @see `TextureResType`
|
|
|
|
*/
|
|
|
|
void loadTextureDisabled(const std::string& disabled, TextureResType texType = TextureResType::LOCAL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets capInsets for edit box.
|
|
|
|
*
|
|
|
|
* @param capInsets capInset in Rect.
|
|
|
|
*/
|
|
|
|
void setCapInsets(const Rect &capInsets);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets capInsets for edit box, only the normal state scale9 renderer will be affected.
|
|
|
|
*
|
|
|
|
* @param capInsets capInsets in Rect.
|
|
|
|
*/
|
|
|
|
void setCapInsetsNormalRenderer(const Rect &capInsets);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the capInsets of normal state scale9sprite.
|
|
|
|
* @return The normal scale9 renderer capInsets.
|
|
|
|
*/
|
|
|
|
const Rect& getCapInsetsNormalRenderer() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets capInsets for edit box, only the pressed state scale9 renderer will be affected.
|
|
|
|
*
|
|
|
|
* @param capInsets capInsets in Rect
|
|
|
|
*/
|
|
|
|
void setCapInsetsPressedRenderer(const Rect &capInsets);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the capInsets of pressed state scale9sprite.
|
|
|
|
* @return The pressed scale9 renderer capInsets.
|
|
|
|
*/
|
|
|
|
const Rect& getCapInsetsPressedRenderer() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets capInsets for edit box, only the disabled state scale9 renderer will be affected.
|
|
|
|
*
|
|
|
|
* @param capInsets capInsets in Rect.
|
|
|
|
*/
|
|
|
|
void setCapInsetsDisabledRenderer(const Rect &capInsets);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the capInsets of disabled state scale9sprite.
|
|
|
|
* @return The disabled scale9 renderer capInsets.
|
|
|
|
*/
|
|
|
|
const Rect& getCapInsetsDisabledRenderer() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Gets/Sets the delegate for edit box.
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void setDelegate(EditBoxDelegate* delegate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
EditBoxDelegate* getDelegate();
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
/**
|
|
|
|
* Registers a script function that will be called for EditBox events.
|
|
|
|
*
|
|
|
|
* This handler will be removed automatically after onExit() called.
|
|
|
|
* @code
|
|
|
|
* -- lua sample
|
|
|
|
* local function editboxEventHandler(eventType)
|
|
|
|
* if eventType == "began" then
|
|
|
|
* -- triggered when an edit box gains focus after keyboard is shown
|
|
|
|
* elseif eventType == "ended" then
|
|
|
|
* -- triggered when an edit box loses focus after keyboard is hidden.
|
|
|
|
* elseif eventType == "changed" then
|
|
|
|
* -- triggered when the edit box text was changed.
|
|
|
|
* elseif eventType == "return" then
|
|
|
|
* -- triggered when the return button was pressed or the outside area of keyboard was touched.
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* local editbox = EditBox:create(Size(...), Scale9Sprite:create(...))
|
|
|
|
* editbox = registerScriptEditBoxHandler(editboxEventHandler)
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* @param handler A number that indicates a lua function.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void registerScriptEditBoxHandler(int handler);
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Unregisters a script function that will be called for EditBox events.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
void unregisterScriptEditBoxHandler();
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* get a script Handler
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
int getScriptEditBoxHandler(){ return _scriptEditBoxHandler ;}
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2014-08-19 10:28:24 +08:00
|
|
|
#endif // #if CC_ENABLE_SCRIPT_BINDING
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the text entered in the edit box.
|
|
|
|
* @param pText The given text.
|
|
|
|
*/
|
|
|
|
void setText(const char* pText);
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Get the text entered in the edit box.
|
|
|
|
* @return The text entered in the edit box.
|
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
const char* getText() const;
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-08-07 17:27:15 +08:00
|
|
|
* Set the font. Only system font is allowed.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param pFontName The font name.
|
|
|
|
* @param fontSize The font size.
|
|
|
|
*/
|
|
|
|
void setFont(const char* pFontName, int fontSize);
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-08-07 17:27:15 +08:00
|
|
|
* Set the font name. Only system font is allowed.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param pFontName The font name.
|
|
|
|
*/
|
|
|
|
void setFontName(const char* pFontName);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the font name.
|
|
|
|
* @return The font name.
|
|
|
|
*/
|
|
|
|
const char* getFontName() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the font size.
|
|
|
|
* @param fontSize The font size.
|
|
|
|
*/
|
|
|
|
void setFontSize(int fontSize);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the font size.
|
|
|
|
* @return The font size.
|
|
|
|
*/
|
|
|
|
int getFontSize() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the font color of the widget's text.
|
|
|
|
*/
|
|
|
|
void setFontColor(const Color3B& color);
|
|
|
|
void setFontColor(const Color4B& color);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the font color of the widget's text.
|
|
|
|
*/
|
|
|
|
const Color4B& getFontColor() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-08-07 17:27:15 +08:00
|
|
|
* Set the placeholder's font. Only system font is allowed.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param pFontName The font name.
|
|
|
|
* @param fontSize The font size.
|
|
|
|
*/
|
|
|
|
void setPlaceholderFont(const char* pFontName, int fontSize);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-08-07 17:27:15 +08:00
|
|
|
* Set the placeholder's font name. only system font is allowed.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param pFontName The font name.
|
|
|
|
*/
|
|
|
|
void setPlaceholderFontName(const char* pFontName);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the placeholder's font name. only system font is allowed.
|
|
|
|
* @return The font name.
|
|
|
|
*/
|
|
|
|
const char* getPlaceholderFontName() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the placeholder's font size.
|
|
|
|
* @param fontSize The font size.
|
|
|
|
*/
|
|
|
|
void setPlaceholderFontSize(int fontSize);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the placeholder's font size.
|
|
|
|
* @return The font size.
|
|
|
|
*/
|
|
|
|
int getPlaceholderFontSize() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the font color of the placeholder text when the edit box is empty.
|
|
|
|
*/
|
|
|
|
void setPlaceholderFontColor(const Color3B& color);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the font color of the placeholder text when the edit box is empty.
|
|
|
|
*/
|
|
|
|
void setPlaceholderFontColor(const Color4B& color);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the font color of the placeholder text when the edit box is empty.
|
|
|
|
*/
|
|
|
|
const Color4B& getPlaceholderFontColor() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set a text in the edit box that acts as a placeholder when an
|
|
|
|
* edit box is empty.
|
|
|
|
* @param pText The given text.
|
|
|
|
*/
|
|
|
|
void setPlaceHolder(const char* pText);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Get a text in the edit box that acts as a placeholder when an
|
|
|
|
* edit box is empty.
|
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
const char* getPlaceHolder() const;
|
2017-02-17 15:45:19 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the input mode of the edit box.
|
|
|
|
* @param inputMode One of the EditBox::InputMode constants.
|
|
|
|
*/
|
|
|
|
void setInputMode(InputMode inputMode);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the input mode of the edit box.
|
|
|
|
* @return One of the EditBox::InputMode constants.
|
|
|
|
*/
|
|
|
|
InputMode getInputMode() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Sets the maximum input length of the edit box.
|
|
|
|
* Setting this value enables multiline input mode by default.
|
|
|
|
* Available on Android, iOS and Windows Phone.
|
|
|
|
*
|
|
|
|
* @param maxLength The maximum length.
|
|
|
|
*/
|
|
|
|
void setMaxLength(int maxLength);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Gets the maximum input length of the edit box.
|
|
|
|
*
|
|
|
|
* @return Maximum input length.
|
|
|
|
*/
|
|
|
|
int getMaxLength();
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the input flags that are to be applied to the edit box.
|
|
|
|
* @param inputFlag One of the EditBox::InputFlag constants.
|
|
|
|
*/
|
|
|
|
void setInputFlag(InputFlag inputFlag);
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the input flags that are to be applied to the edit box.
|
|
|
|
* @return One of the EditBox::InputFlag constants.
|
|
|
|
*/
|
|
|
|
InputFlag getInputFlag() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Set the return type that are to be applied to the edit box.
|
|
|
|
* @param returnType One of the EditBox::KeyboardReturnType constants.
|
|
|
|
*/
|
2017-02-17 15:45:19 +08:00
|
|
|
void setReturnType(KeyboardReturnType returnType);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the return type that are to be applied to the edit box.
|
|
|
|
* @return One of the EditBox::KeyboardReturnType constants.
|
|
|
|
*/
|
|
|
|
KeyboardReturnType getReturnType() const;
|
2016-11-09 10:38:00 +08:00
|
|
|
|
2017-02-17 15:45:19 +08:00
|
|
|
/**
|
|
|
|
* Set the text horizontal alignment.
|
|
|
|
*/
|
|
|
|
void setTextHorizontalAlignment(TextHAlignment alignment);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the text horizontal alignment.
|
|
|
|
*/
|
|
|
|
TextHAlignment getTextHorizontalAlignment() const;
|
2016-11-09 10:38:00 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/* override functions */
|
|
|
|
virtual void setPosition(const Vec2& pos) override;
|
|
|
|
virtual void setVisible(bool visible) override;
|
|
|
|
virtual void setContentSize(const Size& size) override;
|
|
|
|
virtual void setAnchorPoint(const Vec2& anchorPoint) override;
|
2015-01-27 10:10:04 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
|
|
|
virtual std::string getDescription() const override;
|
2015-01-27 10:10:04 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2015-08-07 17:27:15 +08:00
|
|
|
virtual void draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
virtual void onEnter() override;
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2017-11-02 13:57:11 +08:00
|
|
|
virtual void onExit() override;
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void keyboardWillShow(IMEKeyboardNotificationInfo& info) override;
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void keyboardDidShow(IMEKeyboardNotificationInfo& info) override;
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void keyboardWillHide(IMEKeyboardNotificationInfo& info) override;
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void keyboardDidHide(IMEKeyboardNotificationInfo& info) override;
|
2018-08-07 09:29:51 +08:00
|
|
|
|
|
|
|
void openKeyboard() const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
protected:
|
2018-08-07 09:29:51 +08:00
|
|
|
virtual void releaseUpEvent() override;
|
|
|
|
|
|
|
|
virtual void initRenderer() override;
|
|
|
|
virtual void onPressStateChangedToNormal() override;
|
|
|
|
virtual void onPressStateChangedToPressed() override;
|
|
|
|
virtual void onPressStateChangedToDisabled() override;
|
|
|
|
virtual void onSizeChanged() override;
|
|
|
|
|
|
|
|
void loadTextureNormal(SpriteFrame* normalSpriteFrame);
|
|
|
|
void setupNormalTexture(bool textureLoaded);
|
|
|
|
void loadTexturePressed(SpriteFrame* pressedSpriteFrame);
|
|
|
|
void setupPressedTexture(bool textureLoaded);
|
|
|
|
void loadTextureDisabled(SpriteFrame* disabledSpriteFrame);
|
|
|
|
void setupDisabledTexture(bool textureLoaded);
|
|
|
|
|
|
|
|
void normalTextureScaleChangedWithSize();
|
|
|
|
void pressedTextureScaleChangedWithSize();
|
|
|
|
void disabledTextureScaleChangedWithSize();
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
virtual void adaptRenderers() override;
|
2014-08-19 10:28:24 +08:00
|
|
|
|
2018-08-07 09:29:51 +08:00
|
|
|
protected:
|
2015-03-25 18:17:58 +08:00
|
|
|
void updatePosition(float dt);
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2019-08-13 18:19:32 +08:00
|
|
|
Scale9Sprite* _normalRenderer = nullptr;
|
|
|
|
Scale9Sprite* _pressedRenderer = nullptr;
|
|
|
|
Scale9Sprite* _disabledRenderer = nullptr;
|
2018-08-07 09:29:51 +08:00
|
|
|
|
|
|
|
Rect _capInsetsNormal;
|
|
|
|
Rect _capInsetsPressed;
|
|
|
|
Rect _capInsetsDisabled;
|
|
|
|
|
|
|
|
Size _normalTextureSize;
|
|
|
|
Size _pressedTextureSize;
|
|
|
|
Size _disabledTextureSize;
|
|
|
|
|
2019-08-13 18:19:32 +08:00
|
|
|
bool _normalTextureLoaded = false;
|
|
|
|
bool _pressedTextureLoaded = false;
|
|
|
|
bool _disabledTextureLoaded = false;
|
|
|
|
bool _normalTextureAdaptDirty = true;
|
|
|
|
bool _pressedTextureAdaptDirty = true;
|
|
|
|
bool _disabledTextureAdaptDirty = true;
|
2018-08-07 09:29:51 +08:00
|
|
|
|
|
|
|
std::string _normalFileName;
|
|
|
|
std::string _pressedFileName;
|
|
|
|
std::string _disabledFileName;
|
2019-08-13 18:19:32 +08:00
|
|
|
TextureResType _normalTexType = TextureResType::LOCAL;
|
|
|
|
TextureResType _pressedTexType = TextureResType::LOCAL;
|
|
|
|
TextureResType _disabledTexType = TextureResType::LOCAL;
|
2018-08-07 09:29:51 +08:00
|
|
|
|
2019-08-13 18:19:32 +08:00
|
|
|
EditBoxImpl* _editBoxImpl = nullptr;
|
|
|
|
EditBoxDelegate* _delegate = nullptr;
|
2016-11-09 10:38:00 +08:00
|
|
|
|
2019-08-13 18:19:32 +08:00
|
|
|
float _adjustHeight = 0.f;
|
2014-08-19 10:28:24 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2019-08-13 18:19:32 +08:00
|
|
|
int _scriptEditBoxHandler = 0;
|
2014-08-19 10:28:24 +08:00
|
|
|
#endif
|
2015-03-25 18:17:58 +08:00
|
|
|
};
|
2014-08-19 10:28:24 +08:00
|
|
|
}
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2014-08-19 10:28:24 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* __UIEDITTEXT_H__ */
|
|
|
|
|