mirror of https://github.com/axmolengine/axmol.git
Merge: 42fc96bdac
3d1690cc25
Merge pull request #681 from adxeproject/refactor-layer-new Use sprite to implement layer color for auto batch draw
This commit is contained in:
parent
d0ac92acbf
commit
5ef42d4e39
|
@ -4,9 +4,9 @@ Copyright (c) 2010-2012 cocos2d-x.org
|
|||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2021 Bytedance Inc.
|
||||
Copyright (c) 2021-2022 Bytedance Inc.
|
||||
|
||||
https://adxeproject.github.io/
|
||||
https://adxeproject.github.io/adxe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -52,96 +52,16 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Layer
|
||||
Layer::Layer()
|
||||
{
|
||||
_ignoreAnchorPointForPosition = true;
|
||||
setAnchorPoint(Vec2(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
Layer::~Layer() {}
|
||||
|
||||
bool Layer::init()
|
||||
{
|
||||
setContentSize(_director->getWinSize());
|
||||
return true;
|
||||
}
|
||||
|
||||
Layer* Layer::create()
|
||||
{
|
||||
Layer* ret = new Layer();
|
||||
if (ret->init())
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Layer::getDescription() const
|
||||
{
|
||||
return StringUtils::format("<Layer | Tag = %d>", _tag);
|
||||
auto ret = new Layer();
|
||||
ret->initLayer();
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// LayerColor
|
||||
|
||||
LayerColor::LayerColor()
|
||||
{
|
||||
// default blend function
|
||||
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
||||
|
||||
auto& pipelinePS = _customCommand.getPipelineDescriptor().programState;
|
||||
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_COLOR);
|
||||
|
||||
//!!! LayerColor private programState don't want affect by Node::_programState, so store at _customCommand
|
||||
pipelinePS = new backend::ProgramState(program);
|
||||
|
||||
auto vertexLayout = pipelinePS->getVertexLayout();
|
||||
const auto& attributeInfo = pipelinePS->getProgram()->getActiveAttributes();
|
||||
auto iter = attributeInfo.find("a_position");
|
||||
if (iter != attributeInfo.end())
|
||||
{
|
||||
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
|
||||
}
|
||||
iter = attributeInfo.find("a_color");
|
||||
if (iter != attributeInfo.end())
|
||||
{
|
||||
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::FLOAT4,
|
||||
sizeof(_vertexData[0].vertices), false);
|
||||
}
|
||||
vertexLayout->setLayout(sizeof(_vertexData[0]));
|
||||
|
||||
_mvpMatrixLocation = pipelinePS->getUniformLocation("u_MVPMatrix");
|
||||
|
||||
_customCommand.createIndexBuffer(CustomCommand::IndexFormat::U_SHORT, 6, CustomCommand::BufferUsage::STATIC);
|
||||
unsigned short indices[] = {0, 1, 2, 2, 1, 3};
|
||||
_customCommand.updateIndexBuffer(indices, sizeof(indices));
|
||||
|
||||
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), 4, CustomCommand::BufferUsage::DYNAMIC);
|
||||
|
||||
_customCommand.setDrawType(CustomCommand::DrawType::ELEMENT);
|
||||
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE);
|
||||
}
|
||||
|
||||
LayerColor::~LayerColor()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_customCommand.getPipelineDescriptor().programState);
|
||||
}
|
||||
|
||||
/// blendFunc getter
|
||||
const BlendFunc& LayerColor::getBlendFunc() const
|
||||
{
|
||||
return _blendFunc;
|
||||
}
|
||||
/// blendFunc setter
|
||||
void LayerColor::setBlendFunc(const BlendFunc& var)
|
||||
{
|
||||
_blendFunc = var;
|
||||
}
|
||||
LayerColor::LayerColor() {}
|
||||
|
||||
LayerColor* LayerColor::create()
|
||||
{
|
||||
|
@ -159,55 +79,47 @@ LayerColor* LayerColor::create()
|
|||
|
||||
LayerColor* LayerColor::create(const Color4B& color, float width, float height)
|
||||
{
|
||||
LayerColor* ret = new LayerColor();
|
||||
if (ret->initWithColor(color, width, height))
|
||||
LayerColor* layer = new LayerColor();
|
||||
if (layer->initWithColor(color, width, height))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
layer->autorelease();
|
||||
return layer;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
CC_SAFE_DELETE(layer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LayerColor* LayerColor::create(const Color4B& color)
|
||||
{
|
||||
LayerColor* ret = new LayerColor();
|
||||
if (ret->initWithColor(color))
|
||||
LayerColor* layer = new LayerColor();
|
||||
if (layer->initWithColor(color))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
layer->autorelease();
|
||||
return layer;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
CC_SAFE_DELETE(layer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool LayerColor::init()
|
||||
{
|
||||
Vec2 s = _director->getWinSize();
|
||||
Size s = _director->getWinSize();
|
||||
return initWithColor(Color4B(0, 0, 0, 0), s.width, s.height);
|
||||
}
|
||||
|
||||
bool LayerColor::initWithColor(const Color4B& color, float w, float h)
|
||||
{
|
||||
if (Layer::init())
|
||||
if (Sprite::init())
|
||||
{
|
||||
// Anchor behavior same with Layer
|
||||
_ignoreAnchorPointForPosition = true;
|
||||
setAnchorPoint(Vec2(0.5f, 0.5f));
|
||||
|
||||
// default blend function
|
||||
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||
|
||||
_displayedColor.r = _realColor.r = color.r;
|
||||
_displayedColor.g = _realColor.g = color.g;
|
||||
_displayedColor.b = _realColor.b = color.b;
|
||||
_displayedOpacity = _realOpacity = color.a;
|
||||
|
||||
for (size_t i = 0; i < sizeof(_squareVertices) / sizeof(_squareVertices[0]); i++)
|
||||
{
|
||||
_squareVertices[i].x = 0.0f;
|
||||
_squareVertices[i].y = 0.0f;
|
||||
}
|
||||
|
||||
updateColor();
|
||||
setContentSize(Vec2(w, h));
|
||||
const Rect defaultRect{0.f, 0.f, 2.f, 2.f};
|
||||
setTextureRect(defaultRect, false, defaultRect.size);
|
||||
setContentSize(Size(w, h));
|
||||
setColor(Color3B{color});
|
||||
setOpacity(color.a);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -216,72 +128,23 @@ bool LayerColor::initWithColor(const Color4B& color, float w, float h)
|
|||
|
||||
bool LayerColor::initWithColor(const Color4B& color)
|
||||
{
|
||||
Vec2 s = _director->getWinSize();
|
||||
Size s = _director->getWinSize();
|
||||
return initWithColor(color, s.width, s.height);
|
||||
}
|
||||
|
||||
/// override contentSize
|
||||
void LayerColor::setContentSize(const Vec2& size)
|
||||
{
|
||||
_squareVertices[1].x = size.width;
|
||||
_squareVertices[2].y = size.height;
|
||||
_squareVertices[3].x = size.width;
|
||||
_squareVertices[3].y = size.height;
|
||||
|
||||
Layer::setContentSize(size);
|
||||
}
|
||||
|
||||
void LayerColor::changeWidthAndHeight(float w, float h)
|
||||
{
|
||||
this->setContentSize(Vec2(w, h));
|
||||
this->setContentSize(Size(w, h));
|
||||
}
|
||||
|
||||
void LayerColor::changeWidth(float w)
|
||||
{
|
||||
this->setContentSize(Vec2(w, _contentSize.height));
|
||||
this->setContentSize(Size(w, _contentSize.height));
|
||||
}
|
||||
|
||||
void LayerColor::changeHeight(float h)
|
||||
{
|
||||
this->setContentSize(Vec2(_contentSize.width, h));
|
||||
}
|
||||
|
||||
void LayerColor::updateColor()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
_vertexData[i].colors.r = _displayedColor.r / 255.0f;
|
||||
_vertexData[i].colors.g = _displayedColor.g / 255.0f;
|
||||
_vertexData[i].colors.b = _displayedColor.b / 255.0f;
|
||||
_vertexData[i].colors.a = _displayedOpacity / 255.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void LayerColor::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
||||
{
|
||||
_customCommand.init(_globalZOrder, _blendFunc);
|
||||
renderer->addCommand(&_customCommand);
|
||||
|
||||
cocos2d::Mat4 projectionMat = _director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
||||
auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
|
||||
pipelineDescriptor.programState->setUniform(_mvpMatrixLocation, projectionMat.m, sizeof(projectionMat.m));
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
Vec4 pos;
|
||||
pos.x = _squareVertices[i].x;
|
||||
pos.y = _squareVertices[i].y;
|
||||
pos.z = _positionZ;
|
||||
pos.w = 1;
|
||||
_modelViewTransform.transformVector(&pos);
|
||||
_vertexData[i].vertices = Vec3(pos.x, pos.y, pos.z) / pos.w;
|
||||
}
|
||||
updateVertexBuffer();
|
||||
}
|
||||
|
||||
void LayerColor::updateVertexBuffer()
|
||||
{
|
||||
_customCommand.updateVertexBuffer(_vertexData, sizeof(_vertexData));
|
||||
this->setContentSize(Size(_contentSize.width, h));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -293,25 +156,25 @@ LayerGradient::~LayerGradient() {}
|
|||
|
||||
LayerGradient* LayerGradient::create(const Color4B& start, const Color4B& end)
|
||||
{
|
||||
LayerGradient* ret = new LayerGradient();
|
||||
if (ret->initWithColor(start, end))
|
||||
LayerGradient* layer = new LayerGradient();
|
||||
if (layer->initWithColor(start, end))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
layer->autorelease();
|
||||
return layer;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
CC_SAFE_DELETE(layer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LayerGradient* LayerGradient::create(const Color4B& start, const Color4B& end, const Vec2& v)
|
||||
{
|
||||
LayerGradient* ret = new LayerGradient();
|
||||
if (ret->initWithColor(start, end, v))
|
||||
LayerGradient* layer = new LayerGradient();
|
||||
if (layer->initWithColor(start, end, v))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
layer->autorelease();
|
||||
return layer;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
CC_SAFE_DELETE(layer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -356,8 +219,6 @@ bool LayerGradient::initWithColor(const Color4B& start, const Color4B& end, cons
|
|||
|
||||
void LayerGradient::updateColor()
|
||||
{
|
||||
LayerColor::updateColor();
|
||||
|
||||
float h = _alongVector.getLength();
|
||||
if (h == 0)
|
||||
return;
|
||||
|
@ -380,25 +241,36 @@ void LayerGradient::updateColor()
|
|||
Color4F E(_endColor.r / 255.0f, _endColor.g / 255.0f, _endColor.b / 255.0f, _endOpacity * opacityf / 255.0f);
|
||||
|
||||
// (-1, -1)
|
||||
_vertexData[0].colors.r = E.r + (S.r - E.r) * ((c + u.x + u.y) / (2.0f * c));
|
||||
_vertexData[0].colors.g = E.g + (S.g - E.g) * ((c + u.x + u.y) / (2.0f * c));
|
||||
_vertexData[0].colors.b = E.b + (S.b - E.b) * ((c + u.x + u.y) / (2.0f * c));
|
||||
_vertexData[0].colors.a = E.a + (S.a - E.a) * ((c + u.x + u.y) / (2.0f * c));
|
||||
_quad.bl.colors.r = (E.r + (S.r - E.r) * ((c + u.x + u.y) / (2.0f * c))) * 255;
|
||||
_quad.bl.colors.g = (E.g + (S.g - E.g) * ((c + u.x + u.y) / (2.0f * c))) * 255;
|
||||
_quad.bl.colors.b = (E.b + (S.b - E.b) * ((c + u.x + u.y) / (2.0f * c))) * 255;
|
||||
_quad.bl.colors.a = (E.a + (S.a - E.a) * ((c + u.x + u.y) / (2.0f * c))) * 255;
|
||||
// (1, -1)
|
||||
_vertexData[1].colors.r = E.r + (S.r - E.r) * ((c - u.x + u.y) / (2.0f * c));
|
||||
_vertexData[1].colors.g = E.g + (S.g - E.g) * ((c - u.x + u.y) / (2.0f * c));
|
||||
_vertexData[1].colors.b = E.b + (S.b - E.b) * ((c - u.x + u.y) / (2.0f * c));
|
||||
_vertexData[1].colors.a = E.a + (S.a - E.a) * ((c - u.x + u.y) / (2.0f * c));
|
||||
_quad.br.colors.r = (E.r + (S.r - E.r) * ((c - u.x + u.y) / (2.0f * c))) * 255;
|
||||
_quad.br.colors.g = (E.g + (S.g - E.g) * ((c - u.x + u.y) / (2.0f * c))) * 255;
|
||||
_quad.br.colors.b = (E.b + (S.b - E.b) * ((c - u.x + u.y) / (2.0f * c))) * 255;
|
||||
_quad.br.colors.a = (E.a + (S.a - E.a) * ((c - u.x + u.y) / (2.0f * c))) * 255;
|
||||
// (-1, 1)
|
||||
_vertexData[2].colors.r = E.r + (S.r - E.r) * ((c + u.x - u.y) / (2.0f * c));
|
||||
_vertexData[2].colors.g = E.g + (S.g - E.g) * ((c + u.x - u.y) / (2.0f * c));
|
||||
_vertexData[2].colors.b = E.b + (S.b - E.b) * ((c + u.x - u.y) / (2.0f * c));
|
||||
_vertexData[2].colors.a = E.a + (S.a - E.a) * ((c + u.x - u.y) / (2.0f * c));
|
||||
_quad.tl.colors.r = (E.r + (S.r - E.r) * ((c + u.x - u.y) / (2.0f * c))) * 255;
|
||||
_quad.tl.colors.g = (E.g + (S.g - E.g) * ((c + u.x - u.y) / (2.0f * c))) * 255;
|
||||
_quad.tl.colors.b = (E.b + (S.b - E.b) * ((c + u.x - u.y) / (2.0f * c))) * 255;
|
||||
_quad.tl.colors.a = (E.a + (S.a - E.a) * ((c + u.x - u.y) / (2.0f * c))) * 255;
|
||||
// (1, 1)
|
||||
_vertexData[3].colors.r = E.r + (S.r - E.r) * ((c - u.x - u.y) / (2.0f * c));
|
||||
_vertexData[3].colors.g = E.g + (S.g - E.g) * ((c - u.x - u.y) / (2.0f * c));
|
||||
_vertexData[3].colors.b = E.b + (S.b - E.b) * ((c - u.x - u.y) / (2.0f * c));
|
||||
_vertexData[3].colors.a = E.a + (S.a - E.a) * ((c - u.x - u.y) / (2.0f * c));
|
||||
_quad.tr.colors.r = (E.r + (S.r - E.r) * ((c - u.x - u.y) / (2.0f * c))) * 255;
|
||||
_quad.tr.colors.g = (E.g + (S.g - E.g) * ((c - u.x - u.y) / (2.0f * c))) * 255;
|
||||
_quad.tr.colors.b = (E.b + (S.b - E.b) * ((c - u.x - u.y) / (2.0f * c))) * 255;
|
||||
_quad.tr.colors.a = (E.a + (S.a - E.a) * ((c - u.x - u.y) / (2.0f * c))) * 255;
|
||||
|
||||
// renders using batch node
|
||||
if (_renderMode == RenderMode::QUAD_BATCHNODE)
|
||||
{
|
||||
if (_atlasIndex != INDEX_NOT_INITIALIZED)
|
||||
_textureAtlas->updateQuad(&_quad, _atlasIndex);
|
||||
else
|
||||
// no need to set it recursively
|
||||
// update dirty_, don't update recursiveDirty_
|
||||
setDirty(true);
|
||||
}
|
||||
}
|
||||
|
||||
const Color3B& LayerGradient::getStartColor() const
|
||||
|
@ -547,7 +419,7 @@ bool LayerRadialGradient::initWithColor(const cocos2d::Color4B& startColor,
|
|||
for (int i = 0; i < 4; ++i)
|
||||
_vertices[i] = {0.0f, 0.0f};
|
||||
|
||||
if (Layer::init())
|
||||
if (Node::initLayer())
|
||||
{
|
||||
convertColor4B24F(_startColorRend, startColor);
|
||||
_startColor = startColor;
|
||||
|
@ -589,7 +461,7 @@ void LayerRadialGradient::setContentSize(const Vec2& size)
|
|||
_vertices[2].y = size.height;
|
||||
_vertices[3].x = size.width;
|
||||
_vertices[3].y = size.height;
|
||||
Layer::setContentSize(size);
|
||||
Node::setContentSize(size);
|
||||
|
||||
_customCommand.updateVertexBuffer(_vertices, sizeof(_vertices));
|
||||
}
|
||||
|
@ -693,7 +565,7 @@ void LayerRadialGradient::setBlendFunc(const BlendFunc& blendFunc)
|
|||
_blendFunc = blendFunc;
|
||||
}
|
||||
|
||||
BlendFunc LayerRadialGradient::getBlendFunc() const
|
||||
const BlendFunc& LayerRadialGradient::getBlendFunc() const
|
||||
{
|
||||
return _blendFunc;
|
||||
}
|
||||
|
@ -782,7 +654,7 @@ void LayerMultiplex::addLayer(Node* layer)
|
|||
|
||||
bool LayerMultiplex::init()
|
||||
{
|
||||
if (Layer::init())
|
||||
if (Node::initLayer())
|
||||
{
|
||||
_enabledLayer = 0;
|
||||
return true;
|
||||
|
@ -792,7 +664,7 @@ bool LayerMultiplex::init()
|
|||
|
||||
bool LayerMultiplex::initWithLayers(Node* layer, va_list params)
|
||||
{
|
||||
if (Layer::init())
|
||||
if (Node::initLayer())
|
||||
{
|
||||
_layers.reserve(5);
|
||||
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
||||
|
@ -804,7 +676,7 @@ bool LayerMultiplex::initWithLayers(Node* layer, va_list params)
|
|||
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
||||
_layers.pushBack(layer);
|
||||
|
||||
Layer* l = va_arg(params, Layer*);
|
||||
Node* l = va_arg(params, Node*);
|
||||
while (l)
|
||||
{
|
||||
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
||||
|
@ -814,7 +686,7 @@ bool LayerMultiplex::initWithLayers(Node* layer, va_list params)
|
|||
}
|
||||
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
||||
_layers.pushBack(l);
|
||||
l = va_arg(params, Layer*);
|
||||
l = va_arg(params, Node*);
|
||||
}
|
||||
|
||||
_enabledLayer = 0;
|
||||
|
@ -827,7 +699,7 @@ bool LayerMultiplex::initWithLayers(Node* layer, va_list params)
|
|||
|
||||
bool LayerMultiplex::initWithArray(const Vector<Node*>& arrayOfLayers)
|
||||
{
|
||||
if (Layer::init())
|
||||
if (Node::initLayer())
|
||||
{
|
||||
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
|
||||
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
||||
|
|
|
@ -4,9 +4,9 @@ Copyright (c) 2010-2012 cocos2d-x.org
|
|||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2021 Bytedance Inc.
|
||||
Copyright (c) 2021-2022 Bytedance Inc.
|
||||
|
||||
https://adxeproject.github.io/
|
||||
https://adxeproject.github.io/adxe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -14,10 +14,8 @@ in the Software without restriction, including without limitation the rights
|
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -29,6 +27,7 @@ THE SOFTWARE.
|
|||
#pragma once
|
||||
|
||||
#include "2d/CCNode.h"
|
||||
#include "2d/CCSprite.h"
|
||||
#include "base/CCProtocols.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
|
@ -41,35 +40,11 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
//
|
||||
// Layer
|
||||
//
|
||||
/** @class Layer
|
||||
* @brief Layer is a subclass of Node that implements the TouchEventsDelegate protocol.
|
||||
|
||||
All features from Node are valid, plus the following new features:
|
||||
- It can receive iPhone Touches
|
||||
- It can receive Accelerometer input
|
||||
*/
|
||||
/* !!!HACK, the memory model of 'Layer' is identical to 'Node' */
|
||||
class CC_DLL Layer : public Node
|
||||
{
|
||||
public:
|
||||
/** Creates a fullscreen black layer.
|
||||
*
|
||||
* @return An autoreleased Layer object.
|
||||
*/
|
||||
static Layer* create();
|
||||
|
||||
// Overrides
|
||||
virtual std::string getDescription() const override;
|
||||
|
||||
Layer();
|
||||
virtual ~Layer();
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(Layer);
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -77,14 +52,14 @@ private:
|
|||
//
|
||||
/** @class LayerColor
|
||||
* @brief LayerColor is a subclass of Layer that implements the RGBAProtocol protocol.
|
||||
|
||||
All features from Layer are valid, plus the following new features:
|
||||
- opacity
|
||||
- RGB colors
|
||||
*/
|
||||
class CC_DLL LayerColor : public Layer, public BlendProtocol
|
||||
class CC_DLL LayerColor : public Sprite
|
||||
{
|
||||
public:
|
||||
|
||||
/** Creates a fullscreen black layer.
|
||||
*
|
||||
* @return An autoreleased LayerColor object.
|
||||
|
@ -97,13 +72,13 @@ public:
|
|||
* @param height The height of layer.
|
||||
* @return An autoreleased LayerColor object.
|
||||
*/
|
||||
static LayerColor* create(const Color4B& color, float width, float height);
|
||||
static LayerColor * create(const Color4B& color, float width, float height);
|
||||
/** Creates a Layer with color. Width and height are the window size.
|
||||
*
|
||||
* @param color The color of layer.
|
||||
* @return An autoreleased LayerColor object.
|
||||
*/
|
||||
static LayerColor* create(const Color4B& color);
|
||||
static LayerColor * create(const Color4B& color);
|
||||
|
||||
/** Change width in Points.
|
||||
*
|
||||
|
@ -122,48 +97,14 @@ public:
|
|||
@since v0.8
|
||||
*/
|
||||
void changeWidthAndHeight(float w, float h);
|
||||
|
||||
//
|
||||
// Overrides
|
||||
//
|
||||
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
|
||||
|
||||
virtual void setContentSize(const Vec2& var) override;
|
||||
/** BlendFunction. Conforms to BlendProtocol protocol */
|
||||
/**
|
||||
* @lua NA
|
||||
*/
|
||||
virtual const BlendFunc& getBlendFunc() const override;
|
||||
/**
|
||||
*@code
|
||||
*When this function bound into js or lua,the parameter will be changed
|
||||
*In js: var setBlendFunc(var src, var dst)
|
||||
*In lua: local setBlendFunc(local src, local dst)
|
||||
*@endcode
|
||||
*/
|
||||
virtual void setBlendFunc(const BlendFunc& blendFunc) override;
|
||||
|
||||
LayerColor();
|
||||
virtual ~LayerColor();
|
||||
|
||||
bool init() override;
|
||||
bool initWithColor(const Color4B& color, float width, float height);
|
||||
bool initWithColor(const Color4B& color);
|
||||
|
||||
protected:
|
||||
virtual void updateColor() override;
|
||||
void updateVertexBuffer();
|
||||
|
||||
BlendFunc _blendFunc;
|
||||
Vec2 _squareVertices[4];
|
||||
CustomCommand _customCommand;
|
||||
|
||||
V3F_C4F _vertexData[4];
|
||||
|
||||
backend::UniformLocation _mvpMatrixLocation;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(LayerColor);
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -316,7 +257,7 @@ protected:
|
|||
* @brief LayerRadialGradient is a subclass of Layer that draws radial gradients across the background.
|
||||
@since v3.16
|
||||
*/
|
||||
class CC_DLL LayerRadialGradient : public Layer
|
||||
class CC_DLL LayerRadialGradient : public Node, BlendProtocol
|
||||
{
|
||||
public:
|
||||
/** Create a LayerRadialGradient
|
||||
|
@ -366,7 +307,7 @@ public:
|
|||
Color3B getEndColor3B() const;
|
||||
|
||||
void setBlendFunc(const BlendFunc& blendFunc);
|
||||
BlendFunc getBlendFunc() const;
|
||||
const BlendFunc& getBlendFunc() const;
|
||||
|
||||
LayerRadialGradient();
|
||||
virtual ~LayerRadialGradient();
|
||||
|
@ -408,7 +349,7 @@ Features:
|
|||
- It supports one or more children
|
||||
- Only one children will be active a time
|
||||
*/
|
||||
class CC_DLL LayerMultiplex : public Layer
|
||||
class CC_DLL LayerMultiplex : public Node
|
||||
{
|
||||
public:
|
||||
/** Creates and initializes a LayerMultiplex object.
|
||||
|
|
|
@ -114,7 +114,7 @@ bool Menu::init()
|
|||
|
||||
bool Menu::initWithArray(const Vector<MenuItem*>& arrayOfItems)
|
||||
{
|
||||
if (Layer::init())
|
||||
if (Node::initLayer())
|
||||
{
|
||||
_enabled = true;
|
||||
// menu in the center of the screen
|
||||
|
@ -161,29 +161,29 @@ bool Menu::initWithArray(const Vector<MenuItem*>& arrayOfItems)
|
|||
*/
|
||||
void Menu::addChild(Node* child)
|
||||
{
|
||||
Layer::addChild(child);
|
||||
Node::addChild(child);
|
||||
}
|
||||
|
||||
void Menu::addChild(Node* child, int zOrder)
|
||||
{
|
||||
Layer::addChild(child, zOrder);
|
||||
Node::addChild(child, zOrder);
|
||||
}
|
||||
|
||||
void Menu::addChild(Node* child, int zOrder, int tag)
|
||||
{
|
||||
CCASSERT(dynamic_cast<MenuItem*>(child) != nullptr, "Menu only supports MenuItem objects as children");
|
||||
Layer::addChild(child, zOrder, tag);
|
||||
Node::addChild(child, zOrder, tag);
|
||||
}
|
||||
|
||||
void Menu::addChild(Node* child, int zOrder, std::string_view name)
|
||||
{
|
||||
CCASSERT(dynamic_cast<MenuItem*>(child) != nullptr, "Menu only supports MenuItem objects as children");
|
||||
Layer::addChild(child, zOrder, name);
|
||||
Node::addChild(child, zOrder, name);
|
||||
}
|
||||
|
||||
void Menu::onEnter()
|
||||
{
|
||||
Layer::onEnter();
|
||||
Node::onEnter();
|
||||
}
|
||||
|
||||
void Menu::onExit()
|
||||
|
@ -199,7 +199,7 @@ void Menu::onExit()
|
|||
_state = Menu::State::WAITING;
|
||||
}
|
||||
|
||||
Layer::onExit();
|
||||
Node::onExit();
|
||||
}
|
||||
|
||||
void Menu::removeChild(Node* child, bool cleanup)
|
||||
|
|
|
@ -45,7 +45,7 @@ class Touch;
|
|||
* - You can add MenuItem objects in runtime using addChild.
|
||||
* - But the only accepted children are MenuItem objects.
|
||||
*/
|
||||
class CC_DLL Menu : public Layer
|
||||
class CC_DLL Menu : public Node
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -205,6 +205,13 @@ bool Node::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Node::initLayer() {
|
||||
_ignoreAnchorPointForPosition = true;
|
||||
setAnchorPoint(Vec2(0.5f, 0.5f));
|
||||
setContentSize(_director->getWinSize());
|
||||
return true;
|
||||
}
|
||||
|
||||
void Node::cleanup()
|
||||
{
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
|
|
|
@ -1838,6 +1838,9 @@ public:
|
|||
|
||||
virtual bool init();
|
||||
|
||||
// Compatible old Layer::create
|
||||
bool initLayer();
|
||||
|
||||
protected:
|
||||
/// lazy allocs
|
||||
void childrenAlloc();
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
bool initWithScene(Scene* scene)
|
||||
{
|
||||
#ifdef CC_PLATFORM_PC
|
||||
_trackLayer = utils::newInstance<Layer>();
|
||||
_trackLayer = utils::newInstance<Node>(&Node::initLayer);
|
||||
|
||||
// note: when at the first click to focus the window, this will not take effect
|
||||
auto listener = EventListenerTouchOneByOne::create();
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Layer* _trackLayer = nullptr;
|
||||
Node* _trackLayer = nullptr;
|
||||
};
|
||||
|
||||
class ImGuiGlobalEventTracker : public ImGuiEventTracker
|
||||
|
|
Loading…
Reference in New Issue