mirror of https://github.com/axmolengine/axmol.git
issue #3162: Add layer cascade color and cascade opacity test, fix bugs
This commit is contained in:
parent
a71394b122
commit
463ae20ce6
|
@ -1441,6 +1441,7 @@ void Node::setOpacity(GLubyte opacity)
|
|||
void Node::updateDisplayedOpacity(GLubyte parentOpacity)
|
||||
{
|
||||
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
||||
updateColor();
|
||||
|
||||
if (_cascadeOpacityEnabled)
|
||||
{
|
||||
|
@ -1457,7 +1458,7 @@ bool Node::isCascadeOpacityEnabled(void) const
|
|||
|
||||
void Node::setCascadeOpacityEnabled(bool cascadeOpacityEnabled)
|
||||
{
|
||||
if (_cascadeColorEnabled == cascadeOpacityEnabled)
|
||||
if (_cascadeOpacityEnabled == cascadeOpacityEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1491,7 +1492,7 @@ void Node::disableCascadeOpacity()
|
|||
_displayedOpacity = _realOpacity;
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
child->disableCascadeOpacity();
|
||||
child->updateDisplayedOpacity(255);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1517,6 +1518,7 @@ void Node::updateDisplayedColor(const Color3B& parentColor)
|
|||
_displayedColor.r = _realColor.r * parentColor.r/255.0;
|
||||
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
||||
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
||||
updateColor();
|
||||
|
||||
if (_cascadeColorEnabled)
|
||||
{
|
||||
|
@ -1564,7 +1566,7 @@ void Node::updateCascadeColor()
|
|||
void Node::disableCascadeColor()
|
||||
{
|
||||
_children.forEach([this](Node* child){
|
||||
child->disableCascadeColor();
|
||||
child->updateDisplayedColor(Color3B::WHITE);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1428,6 +1428,7 @@ protected:
|
|||
virtual void disableCascadeOpacity();
|
||||
virtual void updateCascadeColor();
|
||||
virtual void disableCascadeColor();
|
||||
virtual void updateColor() {}
|
||||
|
||||
|
||||
float _rotationX; ///< rotation angle on x-axis
|
||||
|
@ -1501,11 +1502,11 @@ protected:
|
|||
#endif
|
||||
|
||||
// opacity controls
|
||||
GLubyte _displayedOpacity;
|
||||
GLubyte _displayedOpacity;
|
||||
GLubyte _realOpacity;
|
||||
Color3B _displayedColor;
|
||||
Color3B _displayedColor;
|
||||
Color3B _realColor;
|
||||
bool _cascadeColorEnabled;
|
||||
bool _cascadeColorEnabled;
|
||||
bool _cascadeOpacityEnabled;
|
||||
|
||||
private:
|
||||
|
|
|
@ -22,7 +22,9 @@ static std::function<Layer*()> createFunctions[] = {
|
|||
CL(LayerIgnoreAnchorPointPos),
|
||||
CL(LayerIgnoreAnchorPointRot),
|
||||
CL(LayerIgnoreAnchorPointScale),
|
||||
CL(LayerExtendedBlendOpacityTest)
|
||||
CL(LayerExtendedBlendOpacityTest),
|
||||
CL(LayerBug3162A),
|
||||
CL(LayerBug3162B),
|
||||
};
|
||||
|
||||
static int sceneIdx=-1;
|
||||
|
@ -863,3 +865,91 @@ string LayerExtendedBlendOpacityTest::subtitle()
|
|||
return "You should see 3 layers";
|
||||
}
|
||||
|
||||
// LayerBug3162A
|
||||
void LayerBug3162A::onEnter()
|
||||
{
|
||||
LayerTest::onEnter();
|
||||
|
||||
Size size = VisibleRect::getVisibleRect().size;
|
||||
size.width = size.width / 2;
|
||||
size.height = size.height / 3;
|
||||
Color4B color[3] = {Color4B(255, 0, 0, 255), Color4B(0, 255, 0, 255), Color4B(0, 0, 255, 255)};
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
_layer[i] = LayerColor::create(color[i]);
|
||||
_layer[i]->setContentSize(size);
|
||||
_layer[i]->setPosition(Point(size.width/2, size.height/2) - Point(20, 20));
|
||||
_layer[i]->setOpacity(150);
|
||||
_layer[i]->setCascadeOpacityEnabled(true);
|
||||
if (i > 0)
|
||||
{
|
||||
_layer[i-1]->addChild(_layer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this->addChild(_layer[0]);
|
||||
|
||||
schedule(schedule_selector(LayerBug3162A::step), 0.5, kRepeatForever, 0);
|
||||
}
|
||||
|
||||
void LayerBug3162A::step(float dt)
|
||||
{
|
||||
_layer[0]->setCascadeOpacityEnabled(!_layer[0]->isCascadeOpacityEnabled());
|
||||
}
|
||||
|
||||
std::string LayerBug3162A::title()
|
||||
{
|
||||
return "Bug 3162 red layer cascade opacity eable/disable";
|
||||
}
|
||||
|
||||
std::string LayerBug3162A::subtitle()
|
||||
{
|
||||
return "g and b layer opacity is effected/diseffected with r layer";
|
||||
}
|
||||
|
||||
// LayerBug3162B
|
||||
void LayerBug3162B::onEnter()
|
||||
{
|
||||
LayerTest::onEnter();
|
||||
|
||||
Size size = VisibleRect::getVisibleRect().size;
|
||||
size.width = size.width / 2;
|
||||
size.height = size.height / 3;
|
||||
Color4B color[3] = {Color4B(200, 0, 0, 255), Color4B(150, 0, 0, 255), Color4B(100, 0, 0, 255)};
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
_layer[i] = LayerColor::create(color[i]);
|
||||
_layer[i]->setContentSize(size);
|
||||
_layer[i]->setPosition(Point(size.width/2, size.height/2) - Point(20, 20));
|
||||
//_layer[i]->setOpacity(150);
|
||||
if (i > 0)
|
||||
{
|
||||
_layer[i-1]->addChild(_layer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this->addChild(_layer[0]);
|
||||
|
||||
_layer[0]->setCascadeColorEnabled(true);
|
||||
_layer[1]->setCascadeColorEnabled(true);
|
||||
_layer[2]->setCascadeColorEnabled(true);
|
||||
|
||||
schedule(schedule_selector(LayerBug3162B::step), 0.5, kRepeatForever, 0);
|
||||
}
|
||||
|
||||
void LayerBug3162B::step(float dt)
|
||||
{
|
||||
_layer[0]->setCascadeColorEnabled(!_layer[0]->isCascadeColorEnabled());
|
||||
}
|
||||
|
||||
std::string LayerBug3162B::title()
|
||||
{
|
||||
return "Bug 3162 bottom layer cascade opacity eable/disable";
|
||||
}
|
||||
|
||||
std::string LayerBug3162B::subtitle()
|
||||
{
|
||||
return "u and m layer opacity is effected/diseffected with b layer";
|
||||
}
|
||||
|
|
|
@ -174,6 +174,34 @@ public:
|
|||
virtual std::string subtitle();
|
||||
};
|
||||
|
||||
class LayerBug3162A : public LayerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LayerBug3162A);
|
||||
virtual void onEnter();
|
||||
virtual std::string title();
|
||||
virtual std::string subtitle();
|
||||
|
||||
void step(float dt);
|
||||
|
||||
private:
|
||||
LayerColor* _layer[3];
|
||||
};
|
||||
|
||||
class LayerBug3162B : public LayerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LayerBug3162B);
|
||||
virtual void onEnter();
|
||||
virtual std::string title();
|
||||
virtual std::string subtitle();
|
||||
|
||||
void step(float dt);
|
||||
|
||||
private:
|
||||
LayerColor* _layer[3];
|
||||
};
|
||||
|
||||
class LayerTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue