fix opacity issue when replace Widget textures

This commit is contained in:
andyque 2014-07-08 11:30:27 +08:00
parent 3344ebbcdd
commit 2a2184331e
7 changed files with 63 additions and 37 deletions

View File

@ -263,9 +263,6 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType)
updateFlippedX();
updateFlippedY();
_buttonNormalRenderer->setColor(this->getColor());
_buttonNormalRenderer->setOpacity(this->getOpacity());
updateContentSizeWithTextureSize(_normalTextureSize);
_normalTextureLoaded = true;
_normalTextureAdaptDirty = true;
@ -314,9 +311,6 @@ void Button::loadTexturePressed(const std::string& selected,TextureResType texTy
updateFlippedX();
updateFlippedY();
_buttonDisableRenderer->setColor(this->getColor());
_buttonDisableRenderer->setOpacity(this->getOpacity());
_pressedTextureLoaded = true;
_pressedTextureAdaptDirty = true;
}
@ -363,8 +357,6 @@ void Button::loadTextureDisabled(const std::string& disabled,TextureResType texT
_disabledTextureSize = _buttonDisableRenderer->getContentSize();
updateFlippedX();
updateFlippedY();
_buttonDisableRenderer->setColor(this->getColor());
_buttonDisableRenderer->setOpacity(this->getOpacity());
_disabledTextureLoaded = true;
_disabledTextureAdaptDirty = true;

View File

@ -184,8 +184,6 @@ void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResTyp
}
updateFlippedX();
updateFlippedY();
_backGroundBoxRenderer->setColor(this->getColor());
_backGroundBoxRenderer->setOpacity(this->getOpacity());
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
_backGroundBoxRendererAdaptDirty = true;
@ -212,8 +210,7 @@ void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelect
}
updateFlippedX();
updateFlippedY();
_backGroundSelectedBoxRenderer->setColor(this->getColor());
_backGroundSelectedBoxRenderer->setOpacity(this->getOpacity());
_backGroundSelectedBoxRendererAdaptDirty = true;
}
@ -238,8 +235,7 @@ void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType tex
}
updateFlippedX();
updateFlippedY();
_frontCrossRenderer->setColor(this->getColor());
_frontCrossRenderer->setOpacity(this->getOpacity());
_frontCrossRendererAdaptDirty = true;
}
@ -264,8 +260,6 @@ void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabl
}
updateFlippedX();
updateFlippedY();
_backGroundBoxDisabledRenderer->setColor(this->getColor());
_backGroundBoxDisabledRenderer->setOpacity(this->getOpacity());
_backGroundBoxDisabledRendererAdaptDirty = true;
}
@ -291,8 +285,6 @@ void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabl
}
updateFlippedX();
updateFlippedY();
_frontCrossDisabledRenderer->setColor(this->getColor());
_frontCrossDisabledRenderer->setOpacity(this->getOpacity());
_frontCrossDisabledRendererAdaptDirty = true;
}

View File

@ -154,8 +154,6 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType)
_imageTextureSize = _imageRenderer->getContentSize();
updateFlippedX();
updateFlippedY();
_imageRenderer->setColor(this->getColor());
_imageRenderer->setOpacity(this->getOpacity());
updateContentSizeWithTextureSize(_imageTextureSize);
_imageRendererAdaptDirty = true;

View File

@ -160,8 +160,6 @@ void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
default:
break;
}
_barRenderer->setColor(this->getColor());
_barRenderer->setOpacity(this->getOpacity());
_barRendererTextureSize = _barRenderer->getContentSize();

View File

@ -148,8 +148,6 @@ void Slider::loadBarTexture(const std::string& fileName, TextureResType texType)
default:
break;
}
_barRenderer->setColor(this->getColor());
_barRenderer->setOpacity(this->getOpacity());
_barRendererAdaptDirty = true;
_progressBarRendererDirty = true;
@ -190,9 +188,6 @@ void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType
break;
}
_progressBarRenderer->setColor(this->getColor());
_progressBarRenderer->setOpacity(this->getOpacity());
_progressBarRenderer->setAnchorPoint(Vec2(0.0f, 0.5f));
_progressBarTextureSize = _progressBarRenderer->getContentSize();
_progressBarRendererDirty = true;
@ -314,8 +309,6 @@ void Slider::loadSlidBallTextureNormal(const std::string& normal,TextureResType
default:
break;
}
_slidBallNormalRenderer->setColor(this->getColor());
_slidBallNormalRenderer->setOpacity(this->getOpacity());
}
void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType)
@ -337,8 +330,6 @@ void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResTyp
default:
break;
}
_slidBallPressedRenderer->setColor(this->getColor());
_slidBallPressedRenderer->setOpacity(this->getOpacity());
}
void Slider::loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType)
@ -360,8 +351,6 @@ void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResTyp
default:
break;
}
_slidBallDisabledRenderer->setColor(this->getColor());
_slidBallDisabledRenderer->setOpacity(this->getOpacity());
}
void Slider::setPercent(int percent)

View File

@ -88,8 +88,6 @@ void TextBMFont::setFntFile(const std::string& fileName)
_fntFileName = fileName;
_labelBMFontRenderer->setBMFontFilePath(fileName);
_labelBMFontRenderer->setColor(this->getColor());
_labelBMFontRenderer->setOpacity(this->getOpacity());
_fntFileHasInit = true;
setString(_stringValue);
}

View File

@ -42,6 +42,17 @@ bool UIButtonTest::init()
// button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest::touchEvent, this));
_uiLayer->addChild(button);
// Create the imageview
ImageView* imageView = ImageView::create();
imageView->setPosition(Vec2(widgetSize.width / 2.0f + 50+ button->getContentSize().width/2,
widgetSize.height / 2.0f));
imageView->setTag(12);
_uiLayer->addChild(imageView);
return true;
}
@ -61,7 +72,15 @@ void UIButtonTest::touchEvent(Ref *pSender, Widget::TouchEventType type)
break;
case Widget::TouchEventType::ENDED:
{
_displayValueLabel->setString(String::createWithFormat("Touch Up")->getCString());
ImageView* imageView = (ImageView*)_uiLayer->getChildByTag(12);
imageView->setVisible(false);
imageView->loadTexture("cocosui/ccicon.png");
imageView->setOpacity(0);
imageView->setVisible(true);
imageView->runAction(Sequence::create(FadeIn::create(0.5),DelayTime::create(1.0),FadeOut::create(0.5), NULL));
}
break;
case Widget::TouchEventType::CANCELED:
@ -111,10 +130,18 @@ bool UIButtonTest_Scale9::init()
button->setScale9Enabled(true);
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->setContentSize(Size(150, 70));
// button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9::touchEvent, this));
_uiLayer->addChild(button);
// Create the imageview
Button* button2 = Button::create();
button2->setPosition(Vec2(widgetSize.width / 2.0f + button->getContentSize().width + 20, widgetSize.height / 2.0f));
button2->setName("normal");
_uiLayer->addChild(button2);
Sprite *sprite = Sprite::create("cocosui/animationbuttonnormal.png");
button2->addChild(sprite);
return true;
}
return false;
@ -133,7 +160,13 @@ void UIButtonTest_Scale9::touchEvent(Ref *pSender, Widget::TouchEventType type)
break;
case Widget::TouchEventType::ENDED:
{
_displayValueLabel->setString(String::createWithFormat("Touch Up")->getCString());
Button *btn = (Button*)_uiLayer->getChildByName("normal");
btn->loadTextureNormal("cocosui/animationbuttonnormal.png");
btn->loadTexturePressed("cocosui/animationbuttonpressed.png");
btn->runAction(Sequence::create(FadeIn::create(0.5),DelayTime::create(1.0),FadeOut::create(0.5), NULL));
}
break;
case Widget::TouchEventType::CANCELED:
@ -180,8 +213,10 @@ bool UIButtonTest_PressedAction::init()
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPressedActionEnabled(true);
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
// button->addTouchEventListener(this, toucheventselector(UIButtonTest_PressedAction::touchEvent));
button->setColor(Color3B::GREEN);
button->setOpacity(30);
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_PressedAction::touchEvent, this));
button->setName("button");
_uiLayer->addChild(button);
return true;
@ -202,7 +237,11 @@ void UIButtonTest_PressedAction::touchEvent(Ref *pSender, Widget::TouchEventType
break;
case Widget::TouchEventType::ENDED:
{
_displayValueLabel->setString(String::createWithFormat("Touch Up")->getCString());
Button* btn = (Button*)_uiLayer->getChildByName("button");
btn->loadTextureNormal("cocosui/animationbuttonnormal.png");
}
break;
case Widget::TouchEventType::CANCELED:
@ -255,6 +294,16 @@ bool UIButtonTest_Title::init()
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Title::touchEvent, this));
_uiLayer->addChild(button);
TextBMFont *text = TextBMFont::create("BMFont", "cocosui/bitmapFontTest2.fnt");
text->setPosition(button->getPosition() + Vec2(button->getContentSize().width/2 + 50,0));
text->setColor(Color3B::YELLOW);
text->setOpacity(50);
text->setName("text");
_uiLayer->addChild(text);
return true;
}
return false;
@ -274,7 +323,17 @@ void UIButtonTest_Title::touchEvent(Ref *pSender, Widget::TouchEventType type)
break;
case Widget::TouchEventType::ENDED:
{
_displayValueLabel->setString(String::createWithFormat("Touch Up")->getCString());
TextBMFont *text = (TextBMFont*)_uiLayer->getChildByName("text");
text->setFntFile("cocosui/bitmapFontTest2.fnt");
if (text->getString() == "BMFont") {
text->setString("Hello");
}
else{
text->setString("BMFont");
}
}
break;
case Widget::TouchEventType::CANCELED: