diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 614fec4b36..9f9a35be6e 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -37,6 +37,7 @@ #include "CCEventDispatcher.h" #include "CCEventType.h" #include "CCEventCustom.h" +#include "platform/CCFileUtils.h" NS_CC_BEGIN @@ -76,7 +77,7 @@ Label* Label::create(const std::string& text, const std::string& fontName, float { do { - if (fontName.find('.') != fontName.npos) + if (FileUtils::getInstance()->isFileExist(fontName)) { TTFConfig ttfConfig(fontName.c_str(),fontSize,GlyphCollection::DYNAMIC); if (ret->setTTFConfig(ttfConfig)) @@ -344,6 +345,7 @@ void Label::reset() _shadowEnabled = false; _clipEnabled = false; + _blendFuncDirty = false; } void Label::updateShaderProgram() @@ -1012,7 +1014,10 @@ void Label::createSpriteWithFontDefinition() _textSprite->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); this->setContentSize(_textSprite->getContentSize()); texture->release(); - _textSprite->setBlendFunc(_blendFunc); + if (_blendFuncDirty) + { + _textSprite->setBlendFunc(_blendFunc); + } Node::addChild(_textSprite,0,Node::INVALID_TAG); @@ -1051,7 +1056,7 @@ void Label::updateContent() void Label::updateFont() { - if (_fontName.find('.') != _fontName.npos) + if (FileUtils::getInstance()->isFileExist(_fontName)) { _fontConfig.fontFilePath = _fontName; _fontConfig.fontSize = _fontSize; @@ -1084,7 +1089,10 @@ void Label::drawTextSprite(Renderer *renderer, bool parentTransformUpdated) if (_shadowEnabled && _shadowNode == nullptr) { _shadowNode = Sprite::createWithTexture(_textSprite->getTexture()); - _shadowNode->setBlendFunc(_blendFunc); + if (_shadowNode) + { + _shadowNode->setBlendFunc(_blendFunc); + } _shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); _shadowNode->setColor(_shadowColor); _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 diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 6f7d2ce6d8..12750f8a39 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -255,6 +255,7 @@ public: */ void listenToFontAtlasPurge(EventCustom *event); + virtual void setBlendFunc(const BlendFunc &blendFunc) override; protected: void onDraw(const kmMat4& transform, bool transformUpdated); @@ -378,6 +379,7 @@ protected: Color4F _textColorF; bool _clipEnabled; + bool _blendFuncDirty; private: CC_DISALLOW_COPY_AND_ASSIGN(Label); diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 3bb361d7e0..4bd5573fee 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -116,6 +116,11 @@ namespace cocostudio } 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); } diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index 8dac6ccf49..89627b5ea6 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -392,8 +392,15 @@ void Button::onPressStateChangedToNormal() } else { - _buttonNormalRenderer->stopAllActions(); - _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); + if (_scale9Enabled) + { + updateTextureRGBA(); + } + else + { + _buttonNormalRenderer->stopAllActions(); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); + } } } @@ -418,8 +425,15 @@ void Button::onPressStateChangedToPressed() _buttonNormalRenderer->setVisible(true); _buttonClickedRenderer->setVisible(true); _buttonDisableRenderer->setVisible(false); - _buttonNormalRenderer->stopAllActions(); - _buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); + if (_scale9Enabled) + { + _buttonNormalRenderer->setColor(Color3B::GRAY); + } + else + { + _buttonNormalRenderer->stopAllActions(); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); + } } } diff --git a/cocos/ui/UIListView.cpp b/cocos/ui/UIListView.cpp index d5964eca33..e553de07c1 100644 --- a/cocos/ui/UIListView.cpp +++ b/cocos/ui/UIListView.cpp @@ -49,6 +49,7 @@ ListView::~ListView() _listViewEventListener = nullptr; _listViewEventSelector = nullptr; _items.clear(); + CC_SAFE_RELEASE(_model); } ListView* ListView::create() diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index 706d7b624e..178ca2870e 100644 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -29,6 +29,23 @@ NS_CC_BEGIN 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) { _tag = tag; @@ -262,7 +279,7 @@ void RichText::handleTextRenderer(const char *text, const char *fontName, float { float overstepPercent = (-_leftSpaceWidth) / textRendererWidth; std::string curText = text; - size_t stringLength = curText.length(); + size_t stringLength = _calcCharCount(text); int leftLength = stringLength * (1.0f - overstepPercent); std::string leftWords = curText.substr(0, leftLength); std::string cutWords = curText.substr(leftLength, curText.length()-1); diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 36b95ff6e1..15b36fd40c 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -167,14 +167,15 @@ void UICCTextField::insertText(const char * text, size_t len) } #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) int input_count = _calcCharCount(text); - if (input_count > _maxLength) + int total = text_count + input_count; + if (total > _maxLength) { int ascii = 0; int unicode = 0; int end = 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]; @@ -291,12 +292,24 @@ void UICCTextField::setPasswordStyleText(const char* styleText) void UICCTextField::setPasswordText(const char *text) { - std::string tempStr; - for (size_t i = 0; i < strlen(text); ++i) + std::string tempStr = ""; + 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); } - Label::setString(tempStr.c_str()); + + Label::setString(tempStr); } void UICCTextField::setAttachWithIME(bool attach) @@ -433,21 +446,59 @@ Size TextField::getTouchSize() void TextField::setText(const std::string& text) { std::string strText(text); + 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(); if (isPasswordEnabled()) { _textFieldRenderer->setPasswordText(content); _textFieldRenderer->setString(""); - _textFieldRenderer->insertText(content, static_cast(strlen(content))); + _textFieldRenderer->insertText(content, strlen(content)); } else { _textFieldRenderer->setString(content); } + textfieldRendererScaleChangedWithSize(); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp index f4f9a1c878..86924143ad 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp @@ -188,6 +188,12 @@ bool Box2DView::initWithEntryID(int entryId) _eventDispatcher->addEventListenerWithFixedPriority(listener, -10); _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; } @@ -222,6 +228,7 @@ Box2DView::~Box2DView() { // Removes Touch Event Listener _eventDispatcher->removeEventListener(_touchListener); + _eventDispatcher->removeEventListener(_keyboardListener); delete m_test; } // @@ -239,7 +246,7 @@ bool Box2DView::onTouchBegan(Touch* touch, Event* event) auto nodePosition = convertToNodeSpace( touchLocation ); 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) @@ -262,6 +269,18 @@ void Box2DView::onTouchEnded(Touch* touch, Event* event) 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(code)); +} + +void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event) +{ + log("onKeyReleased, keycode: %d", code); + m_test->KeyboardUp(static_cast(code)); +} + // void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration) // { // //// Only run for valid values diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h index b7c71823ef..4c73a975c2 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h @@ -32,6 +32,7 @@ class Test; class Box2DView : public Layer { EventListenerTouchOneByOne* _touchListener; + EventListenerKeyboard* _keyboardListener; TestEntry* m_entry; Test* m_test; int m_entryID; @@ -47,6 +48,9 @@ public: bool onTouchBegan(Touch* touch, Event* event); void onTouchMoved(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); static Box2DView* viewWithEntryID(int entryId); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp b/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp index b904ee6e87..e39dafb36e 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp @@ -242,9 +242,9 @@ void GLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color) }; 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(); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp b/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp index 2d6f22f65c..57d437a92b 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp @@ -76,7 +76,7 @@ TestEntry g_testEntries[] = {"Convex Hull", ConvexHull::Create}, {"Apply Force", ApplyForce::Create}, {"Continuous Test", ContinuousTest::Create}, - {"Time of Impact", TimeOfImpact::Create}, + // {"Time of Impact", TimeOfImpact::Create}, {"Motor Joint", MotorJoint::Create}, {"One-Sided Platform", OneSidedPlatform::Create}, {"Mobile", Mobile::Create}, diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h b/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h index 9244a66d6b..d16e659379 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h @@ -35,7 +35,7 @@ public: // Create ground body. { b2BodyDef bodyDef; - bodyDef.position.Set(0.0f, 20.0f); + bodyDef.position.Set(0.0f, 5.0f); ground = m_world->CreateBody(&bodyDef); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h b/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h index 50e852e331..ea4784190b 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h @@ -35,7 +35,7 @@ public: // Create ground body. { b2BodyDef bodyDef; - bodyDef.position.Set(0.0f, 20.0f); + bodyDef.position.Set(0.0f, 5.0f); ground = m_world->CreateBody(&bodyDef); } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp index 8e6d6af61a..de1c800a8f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp @@ -50,7 +50,8 @@ bool UITextTest_LineWrap::init() // Create the line wrap Text* text = Text::create(); - text->setTextAreaSize(Size(280, 150)); + text->ignoreContentAdaptWithSize(false); + text->setSize(Size(280, 150)); text->setTextHorizontalAlignment(TextHAlignment::CENTER); text->setText("Text can line wrap"); text->setFontName("AmericanTypewriter"); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp index 43cea9cf34..ed24585037 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp @@ -39,11 +39,7 @@ EditBoxTest::EditBoxTest() // top _editName = EditBox::create(editBoxSize, Scale9Sprite::create("extensions/green_edit.png")); _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"); -#else - _editName->setFontName("fonts/Paint Boy.ttf"); -#endif _editName->setFontSize(25); _editName->setFontColor(Color3B::RED); _editName->setPlaceHolder("Name:"); diff --git a/tests/cpp-tests/Resources/background.wav.REMOVED.git-id b/tests/cpp-tests/Resources/background.wav.REMOVED.git-id new file mode 100644 index 0000000000..8a31e772f9 --- /dev/null +++ b/tests/cpp-tests/Resources/background.wav.REMOVED.git-id @@ -0,0 +1 @@ +dfe4693f9fee1aae7907f204f3dcb37cd629b422 \ No newline at end of file