void Skin::setSkinData(const BaseData &var) { _skinData = var; setScaleX(_skinData.scaleX); setScaleY(_skinData.scaleY); setRotationSkewX(CC_RADIANS_TO_DEGREES(_skinData.skewX)); setRotationSkewY(CC_RADIANS_TO_DEGREES(-_skinData.skewY)); setPosition(_skinData.x, _skinData.y); _skinTransform = getNodeToParentTransform(); updateArmatureTransform(); }
void Widget::copyProperties(Widget *widget) { setEnabled(widget->isEnabled()); setVisible(widget->isVisible()); setBright(widget->isBright()); setTouchEnabled(widget->isTouchEnabled()); setLocalZOrder(widget->getLocalZOrder()); setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); _ignoreSize = widget->_ignoreSize; this->setContentSize(widget->_contentSize); _customSize = widget->_customSize; _sizeType = widget->getSizeType(); _sizePercent = widget->_sizePercent; _positionType = widget->_positionType; _positionPercent = widget->_positionPercent; setPosition(widget->getPosition()); setAnchorPoint(widget->getAnchorPoint()); setScaleX(widget->getScaleX()); setScaleY(widget->getScaleY()); setRotation(widget->getRotation()); setRotationSkewX(widget->getRotationSkewX()); setRotationSkewY(widget->getRotationSkewY()); setFlippedX(widget->isFlippedX()); setFlippedY(widget->isFlippedY()); setColor(widget->getColor()); setOpacity(widget->getOpacity()); _touchEventCallback = widget->_touchEventCallback; _touchEventListener = widget->_touchEventListener; _touchEventSelector = widget->_touchEventSelector; _clickEventListener = widget->_clickEventListener; _focused = widget->_focused; _focusEnabled = widget->_focusEnabled; _propagateTouchEvents = widget->_propagateTouchEvents; copySpecialProperties(widget); Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary; for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter) { setLayoutParameter(iter->second->clone()); } }
void Widget::copyProperties(Widget *widget) { setEnabled(widget->isEnabled()); setVisible(widget->isVisible()); setBright(widget->isBright()); setTouchEnabled(widget->isTouchEnabled()); setLocalZOrder(widget->getLocalZOrder()); setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); _ignoreSize = widget->_ignoreSize; _size = widget->_size; _customSize = widget->_customSize; _sizeType = widget->getSizeType(); _sizePercent = widget->_sizePercent; _positionType = widget->_positionType; _positionPercent = widget->_positionPercent; setPosition(widget->getPosition()); setAnchorPoint(widget->getAnchorPoint()); setScaleX(widget->getScaleX()); setScaleY(widget->getScaleY()); setRotation(widget->getRotation()); setRotationSkewX(widget->getRotationSkewX()); setRotationSkewY(widget->getRotationSkewY()); setFlippedX(widget->isFlippedX()); setFlippedY(widget->isFlippedY()); setColor(widget->getColor()); setOpacity(widget->getOpacity()); _touchEventCallback = widget->_touchEventCallback; _touchEventListener = widget->_touchEventListener; _touchEventSelector = widget->_touchEventSelector; _focused = widget->_focused; _focusEnabled = widget->_focusEnabled; copySpecialProperties(widget); //FIXME:copy focus properties, also make sure all the subclass the copy behavior is correct Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary; for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter) { setLayoutParameter(iter->second->clone()); } onSizeChanged(); }
void Widget::copyProperties(Widget *widget) { setEnabled(widget->isEnabled()); setVisible(widget->isVisible()); setBright(widget->isBright()); setTouchEnabled(widget->isTouchEnabled()); _touchPassedEnabled = false; setLocalZOrder(widget->getLocalZOrder()); setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); _ignoreSize = widget->_ignoreSize; _size = widget->_size; _customSize = widget->_customSize; copySpecialProperties(widget); _sizeType = widget->getSizeType(); _sizePercent = widget->_sizePercent; _positionType = widget->_positionType; _positionPercent = widget->_positionPercent; setPosition(widget->getPosition()); setAnchorPoint(widget->getAnchorPoint()); setScaleX(widget->getScaleX()); setScaleY(widget->getScaleY()); setRotation(widget->getRotation()); setRotationSkewX(widget->getRotationSkewX()); setRotationSkewY(widget->getRotationSkewY()); setFlippedX(widget->isFlippedX()); setFlippedY(widget->isFlippedY()); setColor(widget->getColor()); setOpacity(widget->getOpacity()); Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary; for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter) { setLayoutParameter(iter->second->clone()); } onSizeChanged(); }
void CCSlot::_updateFrame() { const auto frameDisplay = (DBCCSprite*)(this->_rawDisplay); if (this->_display && this->_displayIndex >= 0) { const unsigned displayIndex = this->_displayIndex; const auto rawDisplayData = displayIndex < this->_displayDataSet->displays.size() ? this->_displayDataSet->displays[displayIndex] : nullptr; const auto replacedDisplayData = displayIndex < this->_replacedDisplayDataSet.size() ? this->_replacedDisplayDataSet[displayIndex] : nullptr; const auto currentDisplayData = replacedDisplayData ? replacedDisplayData : rawDisplayData; const auto currentTextureData = static_cast<CCTextureData*>(currentDisplayData->textureData); if (currentTextureData) { if (!currentTextureData->texture) { const auto textureAtlasTexture = static_cast<CCTextureAtlasData*>(currentTextureData->parent)->texture; if (textureAtlasTexture) { cocos2d::Rect rect(currentTextureData->region.x, currentTextureData->region.y, currentTextureData->region.width, currentTextureData->region.height); cocos2d::Vec2 offset(0.f, 0.f); cocos2d::Size originSize(currentTextureData->region.width, currentTextureData->region.height); /*if (currentTextureData->frame) { offset.setPoint(-currentTextureData->frame->x, -currentTextureData->frame->y); originSize.setSize(currentTextureData->frame->width, currentTextureData->frame->height); }*/ currentTextureData->texture = cocos2d::SpriteFrame::createWithTexture(textureAtlasTexture, rect, currentTextureData->rotated, offset, originSize); // TODO multiply textureAtlas currentTextureData->texture->retain(); } } const auto currentTexture = this->_armature->_replacedTexture ? static_cast<cocos2d::Texture2D*>(this->_armature->_replacedTexture) : (currentTextureData->texture ? currentTextureData->texture->getTexture() : nullptr); if (currentTexture) { if (this->_meshData && this->_display == this->_meshDisplay) { const auto& region = currentTextureData->region; const auto& textureAtlasSize = currentTextureData->texture->getTexture()->getContentSizeInPixels(); auto displayVertices = new cocos2d::V3F_C4B_T2F[(unsigned)(this->_meshData->uvs.size() / 2)]; // does cocos2dx release it? auto vertexIndices = new unsigned short[this->_meshData->vertexIndices.size()]; // does cocos2dx release it? cocos2d::Rect boundsRect(999999.f, 999999.f, -999999.f, -999999.f); for (std::size_t i = 0, l = this->_meshData->uvs.size(); i < l; i += 2) { const auto iH = (unsigned)(i / 2); const auto x = this->_meshData->vertices[i]; const auto y = this->_meshData->vertices[i + 1]; cocos2d::V3F_C4B_T2F vertexData; vertexData.vertices.set(x, -y, 0.f); vertexData.texCoords.u = (region.x + this->_meshData->uvs[i] * region.width) / textureAtlasSize.width; vertexData.texCoords.v = (region.y + this->_meshData->uvs[i + 1] * region.height) / textureAtlasSize.height; vertexData.colors = cocos2d::Color4B::WHITE; displayVertices[iH] = vertexData; if (boundsRect.origin.x > x) { boundsRect.origin.x = x; } if (boundsRect.size.width < x) { boundsRect.size.width = x; } if (boundsRect.origin.y > -y) { boundsRect.origin.y = -y; } if (boundsRect.size.height < -y) { boundsRect.size.height = -y; } } boundsRect.size.width -= boundsRect.origin.x; boundsRect.size.height -= boundsRect.origin.y; for (std::size_t i = 0, l = this->_meshData->vertexIndices.size(); i < l; ++i) { vertexIndices[i] = this->_meshData->vertexIndices[i]; } // In cocos2dx render meshDisplay and frameDisplay are the same display frameDisplay->setSpriteFrame(currentTextureData->texture); // polygonInfo will be override if (currentTexture != currentTextureData->texture->getTexture()) { frameDisplay->setTexture(currentTexture); // Relpace texture // polygonInfo will be override } // cocos2d::PolygonInfo polygonInfo; auto& triangles = polygonInfo.triangles; triangles.verts = displayVertices; triangles.indices = vertexIndices; triangles.vertCount = (unsigned)(this->_meshData->uvs.size() / 2); triangles.indexCount = (unsigned)(this->_meshData->vertexIndices.size()); polygonInfo.rect = boundsRect; // Copy frameDisplay->setPolygonInfo(polygonInfo); frameDisplay->setContentSize(boundsRect.size); if (this->_meshData->skinned) { frameDisplay->setScale(1.f, 1.f); frameDisplay->setRotationSkewX(0.f); frameDisplay->setRotationSkewY(0.f); frameDisplay->setPosition(0.f, 0.f); } frameDisplay->setAnchorPoint(cocos2d::Vec2::ZERO); } else { cocos2d::Vec2 pivot(currentDisplayData->pivot.x, currentDisplayData->pivot.y); const auto& rectData = currentTextureData->frame ? *currentTextureData->frame : currentTextureData->region; auto width = rectData.width; auto height = rectData.height; if (!currentTextureData->frame && currentTextureData->rotated) { width = rectData.height; height = rectData.width; } if (currentDisplayData->isRelativePivot) { pivot.x *= width; pivot.y *= height; } if (currentTextureData->frame) { pivot.x += currentTextureData->frame->x; pivot.y += currentTextureData->frame->y; } if (rawDisplayData && rawDisplayData != currentDisplayData) { pivot.x += rawDisplayData->transform.x - currentDisplayData->transform.x; pivot.y += rawDisplayData->transform.y - currentDisplayData->transform.y; } pivot.x = pivot.x / currentTextureData->region.width; pivot.y = 1.f - pivot.y / currentTextureData->region.height; frameDisplay->setSpriteFrame(currentTextureData->texture); // polygonInfo will be override if (currentTexture != currentTextureData->texture->getTexture()) { frameDisplay->setTexture(currentTexture); // Relpace texture // polygonInfo will be override } frameDisplay->setAnchorPoint(pivot); } this->_updateVisible(); return; } } } frameDisplay->setTexture(nullptr); frameDisplay->setTextureRect(cocos2d::Rect::ZERO); frameDisplay->setAnchorPoint(cocos2d::Vec2::ZERO); frameDisplay->setVisible(false); }