UIEditBoxImpl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2012 James Chen
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #ifndef __UIEditBoxIMPL_H__
  23. #define __UIEditBoxIMPL_H__
  24. #include "ui/UIEditBox/UIEditBox.h"
  25. namespace cocos2d {
  26. namespace ui{
  27. class CC_GUI_DLL EditBoxImpl
  28. {
  29. public:
  30. /**
  31. * @js NA
  32. */
  33. EditBoxImpl(EditBox* pEditBox) : _delegate(nullptr),_editBox(pEditBox) {}
  34. /**
  35. * @js NA
  36. * @lua NA
  37. */
  38. virtual ~EditBoxImpl() {}
  39. virtual bool initWithSize(const Size& size) = 0;
  40. virtual void setFont(const char* pFontName, int fontSize) = 0;
  41. virtual void setFontColor(const Color4B& color) = 0;
  42. virtual void setPlaceholderFont(const char* pFontName, int fontSize) = 0;
  43. virtual void setPlaceholderFontColor(const Color4B& color) = 0;
  44. virtual void setInputMode(EditBox::InputMode inputMode) = 0;
  45. virtual void setInputFlag(EditBox::InputFlag inputFlag) = 0;
  46. virtual void setMaxLength(int maxLength) = 0;
  47. virtual int getMaxLength() = 0;
  48. virtual void setTextHorizontalAlignment(TextHAlignment alignment) = 0;
  49. virtual void setReturnType(EditBox::KeyboardReturnType returnType) = 0;
  50. virtual bool isEditing() = 0;
  51. virtual void setText(const char* pText) = 0;
  52. virtual const char* getText(void) = 0;
  53. virtual void setPlaceHolder(const char* pText) = 0;
  54. virtual const char* getPlaceHolder(void) = 0;
  55. virtual const char* getFontName() = 0;
  56. virtual int getFontSize() = 0;
  57. virtual const Color4B& getFontColor() = 0;
  58. virtual const char* getPlaceholderFontName() = 0;
  59. virtual int getPlaceholderFontSize() = 0;
  60. virtual const Color4B& getPlaceholderFontColor() = 0;
  61. virtual EditBox::InputMode getInputMode() = 0;
  62. virtual EditBox::InputFlag getInputFlag() = 0;
  63. virtual EditBox::KeyboardReturnType getReturnType() = 0;
  64. virtual TextHAlignment getTextHorizontalAlignment() = 0;
  65. virtual void doAnimationWhenKeyboardMove(float duration, float distance) = 0;
  66. virtual void openKeyboard() = 0;
  67. virtual void closeKeyboard() = 0;
  68. virtual void setPosition(const Vec2& pos) = 0;
  69. virtual void setVisible(bool visible) = 0;
  70. virtual void setContentSize(const Size& size) = 0;
  71. virtual void setAnchorPoint(const Vec2& anchorPoint) = 0;
  72. /**
  73. * check the editbox's position, update it when needed
  74. */
  75. virtual void updatePosition(float dt){};
  76. /**
  77. * @js NA
  78. * @lua NA
  79. */
  80. virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) = 0;
  81. /**
  82. * @js NA
  83. * @lua NA
  84. */
  85. virtual void onEnter(void) = 0;
  86. void setDelegate(EditBoxDelegate* pDelegate) { _delegate = pDelegate; };
  87. EditBoxDelegate* getDelegate() { return _delegate; };
  88. EditBox* getEditBox() { return _editBox; };
  89. protected:
  90. EditBoxDelegate* _delegate;
  91. EditBox* _editBox;
  92. };
  93. // This method must be implemented at each subclass of EditBoxImpl.
  94. extern EditBoxImpl* __createSystemEditBox(EditBox* pEditBox);
  95. }
  96. }
  97. #endif /* __UIEditBoxIMPL_H__ */