2015-08-31 18:36:27 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2012 James Chen
|
2015-09-14 11:07:51 +08:00
|
|
|
Copyright (c) 2013-2015 zilongshanren
|
|
|
|
|
2015-08-31 18:36:27 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIEditBoxIMPLICOMMON_H__
|
|
|
|
#define __UIEditBoxIMPLICOMMON_H__
|
|
|
|
|
|
|
|
#include "platform/CCPlatformConfig.h"
|
2016-04-25 11:17:09 +08:00
|
|
|
#include "ui/UIEditBox/UIEditBoxImpl-common.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "ui/UIEditBox/UIEditBoxImpl.h"
|
2015-08-31 18:36:27 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
class EditBox;
|
|
|
|
|
2016-04-27 03:08:09 +08:00
|
|
|
class CC_GUI_DLL EditBoxImplCommon : public EditBoxImpl
|
2015-08-31 18:36:27 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
EditBoxImplCommon(EditBox* pEditText);
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~EditBoxImplCommon();
|
|
|
|
|
2015-10-02 16:59:12 +08:00
|
|
|
virtual bool initWithSize(const Size& size) override;
|
2015-08-31 18:36:27 +08:00
|
|
|
|
2015-10-02 16:59:12 +08:00
|
|
|
virtual void setFont(const char* pFontName, int fontSize) override;
|
|
|
|
virtual void setFontColor(const Color4B& color) override;
|
|
|
|
virtual void setPlaceholderFont(const char* pFontName, int fontSize) override;
|
|
|
|
virtual void setPlaceholderFontColor(const Color4B& color) override;
|
|
|
|
virtual void setInputMode(EditBox::InputMode inputMode) override;
|
|
|
|
virtual void setInputFlag(EditBox::InputFlag inputFlag) override;
|
|
|
|
virtual void setReturnType(EditBox::KeyboardReturnType returnType) override;
|
|
|
|
virtual void setText(const char* pText) override;
|
|
|
|
virtual void setPlaceHolder(const char* pText) override;
|
|
|
|
virtual void setVisible(bool visible) override;
|
2015-08-31 18:36:27 +08:00
|
|
|
|
2015-10-02 16:59:12 +08:00
|
|
|
virtual void setMaxLength(int maxLength) override;
|
2017-02-17 15:45:19 +08:00
|
|
|
virtual void setTextHorizontalAlignment(TextHAlignment alignment) override;
|
|
|
|
|
|
|
|
virtual int getMaxLength() override { return _maxLength; }
|
|
|
|
virtual const char* getText(void) override { return _text.c_str(); }
|
|
|
|
virtual const char* getPlaceHolder(void) override { return _placeHolder.c_str(); }
|
|
|
|
|
|
|
|
virtual const char* getFontName() override { return _fontName.c_str(); }
|
|
|
|
virtual int getFontSize() override { return _fontSize; }
|
|
|
|
virtual const Color4B& getFontColor() override { return _colText; }
|
|
|
|
|
|
|
|
virtual const char* getPlaceholderFontName() override { return _placeholderFontName.c_str(); }
|
|
|
|
virtual int getPlaceholderFontSize() override { return _placeholderFontSize; }
|
|
|
|
virtual const Color4B& getPlaceholderFontColor() override { return _colPlaceHolder; }
|
|
|
|
|
|
|
|
virtual EditBox::InputMode getInputMode() override { return _editBoxInputMode; }
|
|
|
|
virtual EditBox::InputFlag getInputFlag() override { return _editBoxInputFlag; }
|
|
|
|
virtual EditBox::KeyboardReturnType getReturnType() override { return _keyboardReturnType; }
|
|
|
|
virtual TextHAlignment getTextHorizontalAlignment() override { return _alignment; }
|
2016-11-09 10:38:00 +08:00
|
|
|
|
2015-08-31 18:36:27 +08:00
|
|
|
virtual void refreshInactiveText();
|
|
|
|
|
2015-10-02 16:59:12 +08:00
|
|
|
virtual void setContentSize(const Size& size) override;
|
2015-08-31 18:36:27 +08:00
|
|
|
|
2015-10-02 16:59:12 +08:00
|
|
|
virtual void setAnchorPoint(const Vec2& anchorPoint) override {}
|
|
|
|
virtual void setPosition(const Vec2& pos) override {}
|
2015-08-31 18:36:27 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2015-10-02 16:59:12 +08:00
|
|
|
virtual void onEnter(void) override;
|
|
|
|
virtual void openKeyboard() override;
|
|
|
|
virtual void closeKeyboard() override;
|
2015-08-31 18:36:27 +08:00
|
|
|
|
|
|
|
virtual void onEndEditing(const std::string& text);
|
|
|
|
|
|
|
|
void editBoxEditingDidBegin();
|
|
|
|
void editBoxEditingChanged(const std::string& text);
|
2016-11-03 14:02:53 +08:00
|
|
|
void editBoxEditingDidEnd(const std::string& text, EditBoxDelegate::EditBoxEndAction action = EditBoxDelegate::EditBoxEndAction::UNKNOWN);
|
|
|
|
|
2015-10-02 16:59:12 +08:00
|
|
|
virtual bool isEditing() override = 0;
|
2015-08-31 18:36:27 +08:00
|
|
|
virtual void createNativeControl(const Rect& frame) = 0;
|
|
|
|
virtual void setNativeFont(const char* pFontName, int fontSize) = 0;
|
|
|
|
virtual void setNativeFontColor(const Color4B& color) = 0;
|
|
|
|
virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) = 0;
|
|
|
|
virtual void setNativePlaceholderFontColor(const Color4B& color) = 0;
|
|
|
|
virtual void setNativeInputMode(EditBox::InputMode inputMode) = 0;
|
|
|
|
virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) = 0;
|
|
|
|
virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType) = 0;
|
2016-11-09 10:38:00 +08:00
|
|
|
virtual void setNativeTextHorizontalAlignment(cocos2d::TextHAlignment alignment) = 0;
|
2015-08-31 18:36:27 +08:00
|
|
|
virtual void setNativeText(const char* pText) = 0;
|
|
|
|
virtual void setNativePlaceHolder(const char* pText) = 0;
|
|
|
|
virtual void setNativeVisible(bool visible) = 0;
|
|
|
|
virtual void updateNativeFrame(const Rect& rect) = 0;
|
|
|
|
virtual const char* getNativeDefaultFontName() = 0;
|
|
|
|
virtual void nativeOpenKeyboard() = 0;
|
|
|
|
virtual void nativeCloseKeyboard() = 0;
|
|
|
|
virtual void setNativeMaxLength(int maxLength) {};
|
|
|
|
|
|
|
|
|
2017-05-17 16:20:21 +08:00
|
|
|
protected:
|
2016-11-09 10:38:00 +08:00
|
|
|
void initInactiveLabels(const Size& size);
|
|
|
|
void setInactiveText(const char* pText);
|
|
|
|
void refreshLabelAlignment();
|
2016-12-07 09:21:17 +08:00
|
|
|
void placeInactiveLabels(const Size& size);
|
2016-02-04 14:21:07 +08:00
|
|
|
virtual void doAnimationWhenKeyboardMove(float duration, float distance)override {};
|
2016-11-09 10:38:00 +08:00
|
|
|
|
2015-08-31 18:36:27 +08:00
|
|
|
Label* _label;
|
|
|
|
Label* _labelPlaceHolder;
|
|
|
|
EditBox::InputMode _editBoxInputMode;
|
|
|
|
EditBox::InputFlag _editBoxInputFlag;
|
|
|
|
EditBox::KeyboardReturnType _keyboardReturnType;
|
2016-11-09 10:38:00 +08:00
|
|
|
cocos2d::TextHAlignment _alignment;
|
|
|
|
|
2015-08-31 18:36:27 +08:00
|
|
|
std::string _text;
|
|
|
|
std::string _placeHolder;
|
2017-02-17 15:45:19 +08:00
|
|
|
|
|
|
|
std::string _fontName;
|
|
|
|
std::string _placeholderFontName;
|
|
|
|
|
|
|
|
int _fontSize;
|
|
|
|
int _placeholderFontSize;
|
|
|
|
|
2015-08-31 18:36:27 +08:00
|
|
|
Color4B _colText;
|
|
|
|
Color4B _colPlaceHolder;
|
|
|
|
|
|
|
|
int _maxLength;
|
|
|
|
Size _contentSize;
|
2017-05-04 15:04:47 +08:00
|
|
|
bool _editingMode;
|
2015-08-31 18:36:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __UIEditBoxIMPLICOMMON_H__ */
|
|
|
|
|