[New Feature] CCEditBox support in cocos2d-x


#1

Hey all, CCEditBox has been supported in the latest cocos2d-x codes on github(https://github.com/cocos2d/cocos2d-x).
CCEditBox is a wrapper of system edit control. It’s the subclass of CCControlButton. The usage of CCEditBox is very easy since you only need a few lines of code as bellow.

    m_pEditName = CCEditBox::create(editBoxSize, CCScale9Sprite::create("extensions/green_edit.png"));
    m_pEditName->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4));
    m_pEditName->setFontColor(ccRED);
    m_pEditName->setPlaceHolder("Name:");
    m_pEditName->setMaxLength(8);
    m_pEditName->setReturnType(kKeyboardReturnTypeDone);
    m_pEditName->setDelegate(this);
    addChild(m_pEditName);


For more details, you should refer to ExtensionsTest/EditBoxTest.
It only supports IOS and Android now, but we will make it support other platforms as soon as possible.

Any suggestions will be appreciated. :slight_smile:


QQ20120817-2.png (272.0 KB)


QQ20120817-1.png (230.8 KB)


#2

Can’t wait to see this working in android, good work.


#3

looks great. Is there any way to easily import it to rc01 projects? I tried to add it but the compiler complains about ExtensionMacros.h is missing…

thanks.

JB


#4

Great work! Looking forward to use this in a near future.


#5

Thank you!


#6

The amazing thing, thank you!
Looking forward it in Android.


#7

oh,Great work! thank you!
I want to see its lua export in next version.


#8

ExtensionMacros.h is placed at cocos2d-x/extensions/ExtensionMacros.h.

Jesus Bosch wrote:

looks great. Is there any way to easily import it to rc01 projects? I tried to add it but the compiler complains about ExtensionMacros.h is missing…
>
>
thanks.
>
JB


#9

Hey all guys,
I am glad to make you know that CCEditBox has been implemented on android. It refers to my PR (https://github.com/cocos2d/cocos2d-x/pull/1224).
Hope you like it. :slight_smile:


#10

very useful stuff, but i can’t make it work on the latest version(2.0.1), i think it’s properly that “CCEGLView” and “EAGLView” classes have been changed, i tried to change codes on ur works to avoid some errors,
but unfortunately, crash when i clicked on the edit box, errors from these lines of code:
// CCEGLViewProtocol* eglView = CCEGLView::sharedOpenGLView();
the latest version returns a reference not a point.
plz have a look on it, thank you.


#11

If you want to make it works on 2.0.1, you should modify many codes. So just wait for the v2.0.2 version. It will be released today or tomorrow.

yangzhong pan wrote:

very useful stuff, but i can’t make it work on the latest version(2.0.1), i think it’s properly that “CCEGLView” and “EAGLView” classes have been changed, i tried to change codes on ur works to avoid some errors,
but unfortunately, crash when i clicked on the edit box, errors from these lines of code:
// CCEGLViewProtocol* eglView = CCEGLView::sharedOpenGLView();
the latest version returns a reference not a point.
plz have a look on it, thank you.


#12

James Chen wrote:

If you want to make it works on 2.0.1, you should modify many codes. So just wait for the v2.0.2 version. It will be released today or tomorrow.
>
I found a bug in class CCHTTPClient which is added by v2.0.2 version ,when i dump CCHttpResponse->getResponseData() to string by using method string data(CCHttpResponse->getResponseData()>begin, CCHttpResponse>getResponseData()->end ), it will lost some data.
This situation is when use CCHTTPClient::getInstant()->send() some times later , the boring bug will show.


#13

Guys, great work!

It looks pretty good in iOS. But this strange box on the top of the screen in Android is not a production-ready stuff (I hope I did not hurt anybody).

I looked at Cocos2dxEditBoxDialog.java. At first glance it does not seem very hard to change the position of the component and to make its background transparent.

Please share your opinion and any hesitations about those changes if you have any.

Do you have plans to improve the component?

Thank you in advance for your answers.


#14

Yes, on android we doesn’t use transparent system control covering on CCControlButton. we did try that. But because of lots of different android devices with different resolutions, using this way will lead to different behavior on different device. What’s more, we can’t get the keyboard’s height to make view push up when editbox is placed at where below keyboard.
If you have any good scheme,just let me know. Thanks! :slight_smile:

Fedor Shubin wrote:

Guys, great work!
>
It looks pretty good in iOS. But this strange box on the top of the screen in Android is not a production-ready stuff (I hope I did not hurt anybody).
>
I looked at Cocos2dxEditBoxDialog.java. At first glance it does not seem very hard to change the position of the component and to make its background transparent.
>
Please share your opinion and any hesitations about those changes if you have any.
>
Do you have plans to improve the component?
>
Thank you in advance for your answers.


#15

why editBox->getText() returns NULL in IOS if you don’t click editbox maybe we can return “” always ?


#16

On IOS, it will invoke

const char*  CCEditBoxImplIOS::getText(void)
{
    return [GET_IMPL.textField.text UTF8String];
}

Do you mean that CCEditBoxImplIOS::getText will return NULL?
Z C wrote:

why editBox->getText() returns NULL in IOS if you don’t click editbox maybe we can return “” always ?


#17

James Chen wrote:

On IOS, it will invoke
[…]
Do you mean that CCEditBoxImplIOS::getText will return NULL?
Z C wrote:
> why editBox->getText() returns NULL in IOS if you don’t click editbox maybe we can return “” always ?

Yes, in IOS,it will invoke that method,but the truth when you use editbox and never click it,then you use getText(),it will return null,not a char or string, maybe you can try this situation .


#18

there are some bugs in editbox:
1.if you add a editbox into a layer , then add a new layer with a not transparent background, you will find the edit will be seen in the screen , but expect is the editbox should be cover by new layer.
2.if you add a editbox into a layer which is not full screen , then the setPosition() will not correct.
3.maybe we can set font size , ttf ,and change background or anchorPoint ,etc


#19

CCEditbox cannot support line breaks and wrapping? which means that CCEditbox only can be used as a line edit, not a text edit.

wonder if CCEditbox cannot support line breaks and wrapping, thx


#20

Yes, it doesn’t support multi-line, but you can input as many words as you want, if the length of string is out of bounds, ellipsis(…) will appear.

wenbin wang wrote:

CCEditbox cannot support line breaks and wrapping? which means that CCEditbox only can be used as a line edit, not a text edit.
>
wonder if CCEditbox cannot support line breaks and wrapping, thx