Conflicts:
	scripting/javascript/bindings/generated
This commit is contained in:
James Chen 2013-02-25 22:18:57 +08:00
commit 5fafaa8b67
9 changed files with 132 additions and 12 deletions

1
.gitignore vendored
View File

@ -62,6 +62,7 @@ xcschememanagement.plist
build/
.DS_Store
xcuserdata/
DerivedData/
# Ignore files built by bada
.Simulator-Debug/

View File

@ -124,6 +124,17 @@ const char* CCEditBox::getText(void)
return NULL;
}
void CCEditBox::setFont(const char* pFontName, int fontSize)
{
if (pFontName != NULL)
{
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setFont(pFontName, fontSize);
}
}
}
void CCEditBox::setFontColor(const ccColor3B& color)
{
m_colText = color;
@ -133,6 +144,17 @@ void CCEditBox::setFontColor(const ccColor3B& color)
}
}
void CCEditBox::setPlaceholderFont(const char* pFontName, int fontSize)
{
if (pFontName != NULL)
{
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setPlaceholderFont(pFontName, fontSize);
}
}
}
void CCEditBox::setPlaceholderFontColor(const ccColor3B& color)
{
m_colText = color;
@ -219,6 +241,15 @@ void CCEditBox::setContentSize(const CCSize& size)
}
}
void CCEditBox::setAnchorPoint(const CCPoint& anchorPoint)
{
CCControlButton::setAnchorPoint(anchorPoint);
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setAnchorPoint(anchorPoint);
}
}
void CCEditBox::visit(void)
{
CCControlButton::visit();
@ -240,18 +271,15 @@ void CCEditBox::onExit(void)
static CCRect getRect(CCNode * pNode)
{
CCRect rc;
rc.origin = pNode->getPosition();
rc.size = pNode->getContentSize();
rc.origin.x -= rc.size.width / 2;
rc.origin.y -= rc.size.height / 2;
return rc;
return pNode->boundingBox();
}
void CCEditBox::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
// CCLOG("CCEditBox::keyboardWillShow");
CCRect rectTracked = getRect(this);
// some adjustment for margin between the keyboard and the edit box.
rectTracked.origin.y -= 4;
// if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done.
if (!rectTracked.intersectsRect(info.end))

View File

@ -212,11 +212,25 @@ public:
*/
const char* getText(void);
/**
* Set the font.
* @param pFontName The font name.
* @param fontSize The font size.
*/
void setFont(const char* pFontName, int fontSize);
/**
* Set the font color of the widget's text.
*/
void setFontColor(const ccColor3B& color);
/**
* Set the placeholder's font.
* @param pFontName The font name.
* @param fontSize The font size.
*/
void setPlaceholderFont(const char* pFontName, int fontSize);
/**
* Set the font color of the placeholder text when the edit box is empty.
* Not supported on IOS.
@ -273,6 +287,7 @@ public:
/* override functions */
virtual void setPosition(const CCPoint& pos);
virtual void setContentSize(const CCSize& size);
virtual void setAnchorPoint(const CCPoint& anchorPoint);
virtual void visit(void);
virtual void onExit(void);
virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info);

View File

@ -40,7 +40,9 @@ public:
virtual ~CCEditBoxImpl() {}
virtual bool initWithSize(const CCSize& size) = 0;
virtual void setFont(const char* pFontName, int fontSize) = 0;
virtual void setFontColor(const ccColor3B& color) = 0;
virtual void setPlaceholderFont(const char* pFontName, int fontSize) = 0;
virtual void setPlaceholderFontColor(const ccColor3B& color) = 0;
virtual void setInputMode(EditBoxInputMode inputMode) = 0;
virtual void setInputFlag(EditBoxInputFlag inputFlag) = 0;
@ -59,6 +61,7 @@ public:
virtual void setPosition(const CCPoint& pos) = 0;
virtual void setContentSize(const CCSize& size) = 0;
virtual void setAnchorPoint(const CCPoint& anchorPoint) = 0;
virtual void visit(void) = 0;

View File

@ -72,14 +72,16 @@ bool CCEditBoxImplAndroid::initWithSize(const CCSize& size)
{
int fontSize = getFontSizeAccordingHeightJni(size.height-12);
m_pLabel = CCLabelTTF::create("", "", size.height-12);
m_pLabel->setAnchorPoint(ccp(0, 0));
m_pLabel->setPosition(ccp(5, 2));
// align the text vertically center
m_pLabel->setAnchorPoint(ccp(0, 0.5f));
m_pLabel->setPosition(ccp(5, size.height / 2.0f));
m_pLabel->setColor(m_colText);
m_pEditBox->addChild(m_pLabel);
m_pLabelPlaceHolder = CCLabelTTF::create("", "", size.height-12);
m_pLabelPlaceHolder->setAnchorPoint(ccp(0, 0));
m_pLabelPlaceHolder->setPosition(ccp(5, 2));
// align the text vertically center
m_pLabelPlaceHolder->setAnchorPoint(ccp(0, 0.5f));
m_pLabelPlaceHolder->setPosition(ccp(5, size.height / 2.0f));
m_pLabelPlaceHolder->setVisible(false);
m_pLabelPlaceHolder->setColor(m_colPlaceHolder);
m_pEditBox->addChild(m_pLabelPlaceHolder);
@ -88,12 +90,33 @@ bool CCEditBoxImplAndroid::initWithSize(const CCSize& size)
return true;
}
void CCEditBoxImplAndroid::setFont(const char* pFontName, int fontSize)
{
if(m_pLabel != NULL) {
m_pLabel->setFontName(pFontName);
m_pLabel->setFontSize(fontSize);
}
if(m_pLabelPlaceHolder != NULL) {
m_pLabelPlaceHolder->setFontName(pFontName);
m_pLabelPlaceHolder->setFontSize(fontSize);
}
}
void CCEditBoxImplAndroid::setFontColor(const ccColor3B& color)
{
m_colText = color;
m_pLabel->setColor(color);
}
void CCEditBoxImplAndroid::setPlaceholderFont(const char* pFontName, int fontSize)
{
if(m_pLabelPlaceHolder != NULL) {
m_pLabelPlaceHolder->setFontName(pFontName);
m_pLabelPlaceHolder->setFontSize(fontSize);
}
}
void CCEditBoxImplAndroid::setPlaceholderFontColor(const ccColor3B& color)
{
m_colPlaceHolder = color;
@ -196,6 +219,11 @@ void CCEditBoxImplAndroid::setContentSize(const CCSize& size)
}
void CCEditBoxImplAndroid::setAnchorPoint(const CCPoint& anchorPoint)
{ // don't need to be implemented on android platform.
}
void CCEditBoxImplAndroid::visit(void)
{ // don't need to be implemented on android platform.

View File

@ -44,7 +44,9 @@ public:
virtual ~CCEditBoxImplAndroid();
virtual bool initWithSize(const CCSize& size);
virtual void setFont(const char* pFontName, int fontSize);
virtual void setFontColor(const ccColor3B& color);
virtual void setPlaceholderFont(const char* pFontName, int fontSize);
virtual void setPlaceholderFontColor(const ccColor3B& color);
virtual void setInputMode(EditBoxInputMode inputMode);
virtual void setInputFlag(EditBoxInputFlag inputFlag);
@ -58,6 +60,7 @@ public:
virtual void setPlaceHolder(const char* pText);
virtual void setPosition(const CCPoint& pos);
virtual void setContentSize(const CCSize& size);
virtual void setAnchorPoint(const CCPoint& anchorPoint);
virtual void visit(void);
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
virtual void openKeyboard();

View File

@ -74,7 +74,9 @@ public:
virtual ~CCEditBoxImplIOS();
virtual bool initWithSize(const CCSize& size);
virtual void setFont(const char* pFontName, int fontSize);
virtual void setFontColor(const ccColor3B& color);
virtual void setPlaceholderFont(const char* pFontName, int fontSize);
virtual void setPlaceholderFontColor(const ccColor3B& color);
virtual void setInputMode(EditBoxInputMode inputMode);
virtual void setInputFlag(EditBoxInputFlag inputFlag);
@ -88,6 +90,7 @@ public:
virtual void setPlaceHolder(const char* pText);
virtual void setPosition(const CCPoint& pos);
virtual void setContentSize(const CCSize& size);
virtual void setAnchorPoint(const CCPoint& anchorPoint);
virtual void visit(void);
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
virtual void openKeyboard();
@ -95,6 +98,8 @@ public:
private:
CCSize m_tContentSize;
CCPoint m_obPosition;
CCPoint m_obAnchorPoint;
EditBoxImplIOS* m_systemControl;
int m_nMaxTextLength;
bool m_bInRetinaMode;

View File

@ -69,6 +69,7 @@
if (!textField_) break;
[textField_ setTextColor:[UIColor whiteColor]];
textField_.font = [UIFont systemFontOfSize:frameRect.size.height*2/3]; //TODO need to delete hard code here.
textField_.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField_.backgroundColor = [UIColor clearColor];
textField_.borderStyle = UITextBorderStyleNone;
textField_.delegate = self;
@ -212,6 +213,7 @@ CCEditBoxImpl* __createSystemEditBox(CCEditBox* pEditBox)
CCEditBoxImplIOS::CCEditBoxImplIOS(CCEditBox* pEditText)
: CCEditBoxImpl(pEditText)
, m_systemControl(NULL)
, m_obAnchorPoint(ccp(0.5f, 0.5f))
, m_nMaxTextLength(-1)
{
m_bInRetinaMode = [[EAGLView sharedEGLView] contentScaleFactor] == 2.0f ? true : false;
@ -253,11 +255,26 @@ bool CCEditBoxImplIOS::initWithSize(const CCSize& size)
return false;
}
void CCEditBoxImplIOS::setFont(const char* pFontName, int fontSize)
{
if(pFontName == NULL)
return;
NSString * fntName = [NSString stringWithUTF8String:pFontName];
UIFont *textFont = [UIFont fontWithName:fntName size:fontSize];
if(textFont != nil)
[m_systemControl.textField setFont:textFont];
}
void CCEditBoxImplIOS::setFontColor(const ccColor3B& color)
{
m_systemControl.textField.textColor = [UIColor colorWithRed:color.r / 255.0f green:color.g / 255.0f blue:color.b / 255.0f alpha:1.0f];
}
void CCEditBoxImplIOS::setPlaceholderFont(const char* pFontName, int fontSize)
{
// TODO need to be implemented.
}
void CCEditBoxImplIOS::setPlaceholderFontColor(const ccColor3B& color)
{
// TODO need to be implemented.
@ -387,8 +404,9 @@ static CGPoint convertDesignCoordToScreenCoord(const CCPoint& designCoord, bool
void CCEditBoxImplIOS::setPosition(const CCPoint& pos)
{
//TODO should consider anchor point, the default value is (0.5, 0,5)
[m_systemControl setPosition:convertDesignCoordToScreenCoord(ccp(pos.x-m_tContentSize.width/2, pos.y+m_tContentSize.height/2), m_bInRetinaMode)];
m_obPosition = pos;
CCPoint designCoord = ccp(pos.x - m_tContentSize.width * m_obAnchorPoint.x, pos.y + m_tContentSize.height * (1 - m_obAnchorPoint.y));
[m_systemControl setPosition:convertDesignCoordToScreenCoord(designCoord, m_bInRetinaMode)];
}
void CCEditBoxImplIOS::setContentSize(const CCSize& size)
@ -397,6 +415,13 @@ void CCEditBoxImplIOS::setContentSize(const CCSize& size)
CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height);
}
void CCEditBoxImplIOS::setAnchorPoint(const CCPoint& anchorPoint)
{
CCLOG("[Edit text] anchor point = (%f, %f)", anchorPoint.x, anchorPoint.y);
m_obAnchorPoint = anchorPoint;
setPosition(m_obPosition);
}
void CCEditBoxImplIOS::visit(void)
{

View File

@ -38,8 +38,14 @@ EditBoxTest::EditBoxTest()
// top
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));
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
m_pEditName->setFont("Paint Boy", 25);
#else
m_pEditName->setFont("fonts/Paint Boy.ttf", 25);
#endif
m_pEditName->setFontColor(ccRED);
m_pEditName->setPlaceHolder("Name:");
m_pEditName->setPlaceholderFontColor(ccWHITE);
m_pEditName->setMaxLength(8);
m_pEditName->setReturnType(kKeyboardReturnTypeDone);
m_pEditName->setDelegate(this);
@ -48,6 +54,11 @@ EditBoxTest::EditBoxTest()
// middle
m_pEditPassword = CCEditBox::create(editBoxSize, CCScale9Sprite::create("extensions/orange_edit.png"));
m_pEditPassword->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
m_pEditPassword->setFont("A Damn Mess", 30);
#else
m_pEditPassword->setFont("fonts/A Damn Mess.ttf", 30);
#endif
m_pEditPassword->setFontColor(ccGREEN);
m_pEditPassword->setPlaceHolder("Password:");
m_pEditPassword->setMaxLength(6);
@ -59,6 +70,7 @@ EditBoxTest::EditBoxTest()
// bottom
m_pEditEmail = CCEditBox::create(CCSizeMake(editBoxSize.width, editBoxSize.height), CCScale9Sprite::create("extensions/yellow_edit.png"));
m_pEditEmail->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4));
m_pEditEmail->setAnchorPoint(ccp(0.5, 1.0f));
m_pEditEmail->setPlaceHolder("Email:");
m_pEditEmail->setInputMode(kEditBoxInputModeEmailAddr);
m_pEditEmail->setDelegate(this);