Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Button::init()
- {
- if (!Widget::init())
- {
- return false;
- }
- this->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
- this->setContentSize(Size(width + 4, height + 4));
- this->setCascadeOpacityEnabled(true);
- this->setTouchEnabled(true);
- clip = ClippingNode::create();
- clip->setCascadeOpacityEnabled(true);
- shape = Shape::create(width, height, color, 2, Color4B(color.r / 2, color.g / 2, color.b / 2, color.a), cornerRadius);
- clip->addChild(shape);
- clip->setStencil(shape);
- this->addChild(clip);
- noise = Sprite::create("noise.png");
- noise->setScale(Director::getInstance()->getContentScaleFactor());
- clip->addChild(noise, 1);
- noise2 = Sprite::create("noise.png");
- noise2->setScale(Director::getInstance()->getContentScaleFactor());
- noise2->setPositionY(-noise2->getContentSize().height * noise2->getScale());
- clip->addChild(noise2, 1);
- return true;
- }
- void Button::setLabel(string text, float fontSize, Color4B color, string ttfFont, bool shadow)
- {
- if (label != NULL)
- {
- label->removeFromParent();
- }
- do {
- label = Label::createWithTTF(text, ttfFont + ".ttf", fontSize--);
- } while (label->getContentSize().width + 5 > shape->getContentSize().width);
- label->setHorizontalAlignment(TextHAlignment::CENTER);
- label->setTextColor(color);
- if (shadow)
- {
- label->enableShadow(Color4B(0, 0, 0, 127), Size(fontSize / 10, -fontSize / 10));
- }
- this->addChild(label);
- }
- void Button::setIcon(std::string img, float size, bool card)
- {
- if (spriite != NULL)
- {
- spriite->removeFromParent();
- }
- spriite = Spriite::create(img, size, card);
- spriite->setCascadeOpacityEnabled(true);
- this->addChild(spriite);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement