Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop_socket

This commit is contained in:
samuele3hu 2014-03-31 17:08:19 +08:00
commit 60296e79d6
16 changed files with 159 additions and 27 deletions

View File

@ -37,6 +37,7 @@
#include "CCEventDispatcher.h" #include "CCEventDispatcher.h"
#include "CCEventType.h" #include "CCEventType.h"
#include "CCEventCustom.h" #include "CCEventCustom.h"
#include "platform/CCFileUtils.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -76,7 +77,7 @@ Label* Label::create(const std::string& text, const std::string& fontName, float
{ {
do do
{ {
if (fontName.find('.') != fontName.npos) if (FileUtils::getInstance()->isFileExist(fontName))
{ {
TTFConfig ttfConfig(fontName.c_str(),fontSize,GlyphCollection::DYNAMIC); TTFConfig ttfConfig(fontName.c_str(),fontSize,GlyphCollection::DYNAMIC);
if (ret->setTTFConfig(ttfConfig)) if (ret->setTTFConfig(ttfConfig))
@ -344,6 +345,7 @@ void Label::reset()
_shadowEnabled = false; _shadowEnabled = false;
_clipEnabled = false; _clipEnabled = false;
_blendFuncDirty = false;
} }
void Label::updateShaderProgram() void Label::updateShaderProgram()
@ -1012,7 +1014,10 @@ void Label::createSpriteWithFontDefinition()
_textSprite->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); _textSprite->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
this->setContentSize(_textSprite->getContentSize()); this->setContentSize(_textSprite->getContentSize());
texture->release(); texture->release();
_textSprite->setBlendFunc(_blendFunc); if (_blendFuncDirty)
{
_textSprite->setBlendFunc(_blendFunc);
}
Node::addChild(_textSprite,0,Node::INVALID_TAG); Node::addChild(_textSprite,0,Node::INVALID_TAG);
@ -1051,7 +1056,7 @@ void Label::updateContent()
void Label::updateFont() void Label::updateFont()
{ {
if (_fontName.find('.') != _fontName.npos) if (FileUtils::getInstance()->isFileExist(_fontName))
{ {
_fontConfig.fontFilePath = _fontName; _fontConfig.fontFilePath = _fontName;
_fontConfig.fontSize = _fontSize; _fontConfig.fontSize = _fontSize;
@ -1084,7 +1089,10 @@ void Label::drawTextSprite(Renderer *renderer, bool parentTransformUpdated)
if (_shadowEnabled && _shadowNode == nullptr) if (_shadowEnabled && _shadowNode == nullptr)
{ {
_shadowNode = Sprite::createWithTexture(_textSprite->getTexture()); _shadowNode = Sprite::createWithTexture(_textSprite->getTexture());
_shadowNode->setBlendFunc(_blendFunc); if (_shadowNode)
{
_shadowNode->setBlendFunc(_blendFunc);
}
_shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); _shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
_shadowNode->setColor(_shadowColor); _shadowNode->setColor(_shadowColor);
_shadowNode->setOpacity(_effectColorF.a * _displayedOpacity); _shadowNode->setOpacity(_effectColorF.a * _displayedOpacity);
@ -1390,4 +1398,17 @@ void Label::listenToFontAtlasPurge(EventCustom *event)
} }
} }
void Label::setBlendFunc(const BlendFunc &blendFunc)
{
_blendFunc = blendFunc;
_blendFuncDirty = true;
if (_textSprite)
{
_textSprite->setBlendFunc(blendFunc);
if (_shadowNode)
{
_shadowNode->setBlendFunc(blendFunc);
}
}
}
NS_CC_END NS_CC_END

View File

@ -255,6 +255,7 @@ public:
*/ */
void listenToFontAtlasPurge(EventCustom *event); void listenToFontAtlasPurge(EventCustom *event);
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
protected: protected:
void onDraw(const kmMat4& transform, bool transformUpdated); void onDraw(const kmMat4& transform, bool transformUpdated);
@ -378,6 +379,7 @@ protected:
Color4F _textColorF; Color4F _textColorF;
bool _clipEnabled; bool _clipEnabled;
bool _blendFuncDirty;
private: private:
CC_DISALLOW_COPY_AND_ASSIGN(Label); CC_DISALLOW_COPY_AND_ASSIGN(Label);

View File

@ -116,6 +116,11 @@ namespace cocostudio
} }
panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType")); panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType"));
int bgimgcr = DICTOOL->getIntValue_json(options, "colorR");
int bgimgcg = DICTOOL->getIntValue_json(options, "colorG");
int bgimgcb = DICTOOL->getIntValue_json(options, "colorB");
panel->setBackGroundImageColor(Color3B(bgimgcr, bgimgcg, bgimgcb));
WidgetReader::setColorPropsFromJsonDictionary(widget, options); WidgetReader::setColorPropsFromJsonDictionary(widget, options);
} }

View File

@ -392,8 +392,15 @@ void Button::onPressStateChangedToNormal()
} }
else else
{ {
_buttonNormalRenderer->stopAllActions(); if (_scale9Enabled)
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); {
updateTextureRGBA();
}
else
{
_buttonNormalRenderer->stopAllActions();
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
}
} }
} }
@ -418,8 +425,15 @@ void Button::onPressStateChangedToPressed()
_buttonNormalRenderer->setVisible(true); _buttonNormalRenderer->setVisible(true);
_buttonClickedRenderer->setVisible(true); _buttonClickedRenderer->setVisible(true);
_buttonDisableRenderer->setVisible(false); _buttonDisableRenderer->setVisible(false);
_buttonNormalRenderer->stopAllActions(); if (_scale9Enabled)
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); {
_buttonNormalRenderer->setColor(Color3B::GRAY);
}
else
{
_buttonNormalRenderer->stopAllActions();
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f);
}
} }
} }

View File

@ -49,6 +49,7 @@ ListView::~ListView()
_listViewEventListener = nullptr; _listViewEventListener = nullptr;
_listViewEventSelector = nullptr; _listViewEventSelector = nullptr;
_items.clear(); _items.clear();
CC_SAFE_RELEASE(_model);
} }
ListView* ListView::create() ListView* ListView::create()

View File

@ -29,6 +29,23 @@ NS_CC_BEGIN
namespace ui { namespace ui {
static int _calcCharCount(const char * pszText)
{
int n = 0;
char ch = 0;
while ((ch = *pszText))
{
CC_BREAK_IF(! ch);
if (0x80 != (0xC0 & ch))
{
++n;
}
++pszText;
}
return n;
}
bool RichElement::init(int tag, const Color3B &color, GLubyte opacity) bool RichElement::init(int tag, const Color3B &color, GLubyte opacity)
{ {
_tag = tag; _tag = tag;
@ -262,7 +279,7 @@ void RichText::handleTextRenderer(const char *text, const char *fontName, float
{ {
float overstepPercent = (-_leftSpaceWidth) / textRendererWidth; float overstepPercent = (-_leftSpaceWidth) / textRendererWidth;
std::string curText = text; std::string curText = text;
size_t stringLength = curText.length(); size_t stringLength = _calcCharCount(text);
int leftLength = stringLength * (1.0f - overstepPercent); int leftLength = stringLength * (1.0f - overstepPercent);
std::string leftWords = curText.substr(0, leftLength); std::string leftWords = curText.substr(0, leftLength);
std::string cutWords = curText.substr(leftLength, curText.length()-1); std::string cutWords = curText.substr(leftLength, curText.length()-1);

View File

@ -167,14 +167,15 @@ void UICCTextField::insertText(const char * text, size_t len)
} }
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
int input_count = _calcCharCount(text); int input_count = _calcCharCount(text);
if (input_count > _maxLength) int total = text_count + input_count;
if (total > _maxLength)
{ {
int ascii = 0; int ascii = 0;
int unicode = 0; int unicode = 0;
int end = 0; int end = 0;
int count = 0; int count = 0;
for (int i = 0; i < input_count * 3; ++i) for (int i = 0; i < total * 3; ++i)
{ {
char value = text[i]; char value = text[i];
@ -291,12 +292,24 @@ void UICCTextField::setPasswordStyleText(const char* styleText)
void UICCTextField::setPasswordText(const char *text) void UICCTextField::setPasswordText(const char *text)
{ {
std::string tempStr; std::string tempStr = "";
for (size_t i = 0; i < strlen(text); ++i) int text_count = _calcCharCount(text);
int max = text_count;
if (_maxLengthEnabled)
{
if (text_count > _maxLength)
{
max = _maxLength;
}
}
for (int i = 0; i < max; ++i)
{ {
tempStr.append(_passwordStyleText); tempStr.append(_passwordStyleText);
} }
Label::setString(tempStr.c_str());
Label::setString(tempStr);
} }
void UICCTextField::setAttachWithIME(bool attach) void UICCTextField::setAttachWithIME(bool attach)
@ -433,21 +446,59 @@ Size TextField::getTouchSize()
void TextField::setText(const std::string& text) void TextField::setText(const std::string& text)
{ {
std::string strText(text); std::string strText(text);
if (isMaxLengthEnabled()) if (isMaxLengthEnabled())
{ {
strText = strText.substr(0, getMaxLength()); int max = _textFieldRenderer->getMaxLength();
int text_count = _calcCharCount(text.c_str());
int total = text_count + _calcCharCount(getStringValue().c_str());
if (total > max)
{
int ascii = 0;
int unicode = 0;
int end = 0;
int count = 0;
for (int i = 0; i < total * 3; ++i)
{
char value = text[i];
if (value >= 0 && value <= 127) // ascii
{
ascii++;
count++;
}
else
{
unicode++;
if (unicode % 3 == 0)
{
count++;
}
}
if (count == max)
{
break;
}
}
end = ascii + unicode;
strText = strText.substr(0, end);
}
} }
const char* content = strText.c_str(); const char* content = strText.c_str();
if (isPasswordEnabled()) if (isPasswordEnabled())
{ {
_textFieldRenderer->setPasswordText(content); _textFieldRenderer->setPasswordText(content);
_textFieldRenderer->setString(""); _textFieldRenderer->setString("");
_textFieldRenderer->insertText(content, static_cast<int>(strlen(content))); _textFieldRenderer->insertText(content, strlen(content));
} }
else else
{ {
_textFieldRenderer->setString(content); _textFieldRenderer->setString(content);
} }
textfieldRendererScaleChangedWithSize(); textfieldRendererScaleChangedWithSize();
} }

View File

@ -188,6 +188,12 @@ bool Box2DView::initWithEntryID(int entryId)
_eventDispatcher->addEventListenerWithFixedPriority(listener, -10); _eventDispatcher->addEventListenerWithFixedPriority(listener, -10);
_touchListener = listener; _touchListener = listener;
auto keyboardListener = EventListenerKeyboard::create();
keyboardListener->onKeyPressed = CC_CALLBACK_2(Box2DView::onKeyPressed, this);
keyboardListener->onKeyReleased = CC_CALLBACK_2(Box2DView::onKeyReleased, this);
_eventDispatcher->addEventListenerWithFixedPriority(keyboardListener, -11);
_keyboardListener = keyboardListener;
return true; return true;
} }
@ -222,6 +228,7 @@ Box2DView::~Box2DView()
{ {
// Removes Touch Event Listener // Removes Touch Event Listener
_eventDispatcher->removeEventListener(_touchListener); _eventDispatcher->removeEventListener(_touchListener);
_eventDispatcher->removeEventListener(_keyboardListener);
delete m_test; delete m_test;
} }
// //
@ -239,7 +246,7 @@ bool Box2DView::onTouchBegan(Touch* touch, Event* event)
auto nodePosition = convertToNodeSpace( touchLocation ); auto nodePosition = convertToNodeSpace( touchLocation );
log("Box2DView::onTouchBegan, pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y); log("Box2DView::onTouchBegan, pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y);
return m_test->MouseDown(b2Vec2(nodePosition.x,nodePosition.y)); return m_test->MouseDown(b2Vec2(nodePosition.x,nodePosition.y));
} }
void Box2DView::onTouchMoved(Touch* touch, Event* event) void Box2DView::onTouchMoved(Touch* touch, Event* event)
@ -262,6 +269,18 @@ void Box2DView::onTouchEnded(Touch* touch, Event* event)
m_test->MouseUp(b2Vec2(nodePosition.x,nodePosition.y)); m_test->MouseUp(b2Vec2(nodePosition.x,nodePosition.y));
} }
void Box2DView::onKeyPressed(EventKeyboard::KeyCode code, Event* event)
{
log("Box2dView:onKeyPressed, keycode: %d", code);
m_test->Keyboard(static_cast<unsigned char>(code));
}
void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event)
{
log("onKeyReleased, keycode: %d", code);
m_test->KeyboardUp(static_cast<unsigned char>(code));
}
// void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration) // void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration)
// { // {
// //// Only run for valid values // //// Only run for valid values

View File

@ -32,6 +32,7 @@ class Test;
class Box2DView : public Layer class Box2DView : public Layer
{ {
EventListenerTouchOneByOne* _touchListener; EventListenerTouchOneByOne* _touchListener;
EventListenerKeyboard* _keyboardListener;
TestEntry* m_entry; TestEntry* m_entry;
Test* m_test; Test* m_test;
int m_entryID; int m_entryID;
@ -47,6 +48,9 @@ public:
bool onTouchBegan(Touch* touch, Event* event); bool onTouchBegan(Touch* touch, Event* event);
void onTouchMoved(Touch* touch, Event* event); void onTouchMoved(Touch* touch, Event* event);
void onTouchEnded(Touch* touch, Event* event); void onTouchEnded(Touch* touch, Event* event);
void onKeyPressed(EventKeyboard::KeyCode code, Event* event);
void onKeyReleased(EventKeyboard::KeyCode code, Event* event);
//virtual void accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration); //virtual void accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration);
static Box2DView* viewWithEntryID(int entryId); static Box2DView* viewWithEntryID(int entryId);

View File

@ -242,9 +242,9 @@ void GLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color)
}; };
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices);
glDrawArrays(GL_LINE_LOOP, 0, 8); glDrawArrays(GL_LINE_LOOP, 0, 4);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,8); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,4);
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }

View File

@ -76,7 +76,7 @@ TestEntry g_testEntries[] =
{"Convex Hull", ConvexHull::Create}, {"Convex Hull", ConvexHull::Create},
{"Apply Force", ApplyForce::Create}, {"Apply Force", ApplyForce::Create},
{"Continuous Test", ContinuousTest::Create}, {"Continuous Test", ContinuousTest::Create},
{"Time of Impact", TimeOfImpact::Create}, // {"Time of Impact", TimeOfImpact::Create},
{"Motor Joint", MotorJoint::Create}, {"Motor Joint", MotorJoint::Create},
{"One-Sided Platform", OneSidedPlatform::Create}, {"One-Sided Platform", OneSidedPlatform::Create},
{"Mobile", Mobile::Create}, {"Mobile", Mobile::Create},

View File

@ -35,7 +35,7 @@ public:
// Create ground body. // Create ground body.
{ {
b2BodyDef bodyDef; b2BodyDef bodyDef;
bodyDef.position.Set(0.0f, 20.0f); bodyDef.position.Set(0.0f, 5.0f);
ground = m_world->CreateBody(&bodyDef); ground = m_world->CreateBody(&bodyDef);
} }

View File

@ -35,7 +35,7 @@ public:
// Create ground body. // Create ground body.
{ {
b2BodyDef bodyDef; b2BodyDef bodyDef;
bodyDef.position.Set(0.0f, 20.0f); bodyDef.position.Set(0.0f, 5.0f);
ground = m_world->CreateBody(&bodyDef); ground = m_world->CreateBody(&bodyDef);
} }

View File

@ -50,7 +50,8 @@ bool UITextTest_LineWrap::init()
// Create the line wrap // Create the line wrap
Text* text = Text::create(); Text* text = Text::create();
text->setTextAreaSize(Size(280, 150)); text->ignoreContentAdaptWithSize(false);
text->setSize(Size(280, 150));
text->setTextHorizontalAlignment(TextHAlignment::CENTER); text->setTextHorizontalAlignment(TextHAlignment::CENTER);
text->setText("Text can line wrap"); text->setText("Text can line wrap");
text->setFontName("AmericanTypewriter"); text->setFontName("AmericanTypewriter");

View File

@ -39,11 +39,7 @@ EditBoxTest::EditBoxTest()
// top // top
_editName = EditBox::create(editBoxSize, Scale9Sprite::create("extensions/green_edit.png")); _editName = EditBox::create(editBoxSize, Scale9Sprite::create("extensions/green_edit.png"));
_editName->setPosition(Point(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4)); _editName->setPosition(Point(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4));
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
_editName->setFontName("Paint Boy"); _editName->setFontName("Paint Boy");
#else
_editName->setFontName("fonts/Paint Boy.ttf");
#endif
_editName->setFontSize(25); _editName->setFontSize(25);
_editName->setFontColor(Color3B::RED); _editName->setFontColor(Color3B::RED);
_editName->setPlaceHolder("Name:"); _editName->setPlaceHolder("Name:");

View File

@ -0,0 +1 @@
dfe4693f9fee1aae7907f204f3dcb37cd629b422