Advertisement
Guest User

Untitled

a guest
Jul 8th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. bool Button::init()
  2. {
  3. if (!Widget::init())
  4. {
  5. return false;
  6. }
  7.  
  8. this->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
  9. this->setContentSize(Size(width + 4, height + 4));
  10. this->setCascadeOpacityEnabled(true);
  11. this->setTouchEnabled(true);
  12.  
  13. clip = ClippingNode::create();
  14. clip->setCascadeOpacityEnabled(true);
  15.  
  16. shape = Shape::create(width, height, color, 2, Color4B(color.r / 2, color.g / 2, color.b / 2, color.a), cornerRadius);
  17. clip->addChild(shape);
  18.  
  19. clip->setStencil(shape);
  20. this->addChild(clip);
  21.  
  22. noise = Sprite::create("noise.png");
  23. noise->setScale(Director::getInstance()->getContentScaleFactor());
  24. clip->addChild(noise, 1);
  25.  
  26. noise2 = Sprite::create("noise.png");
  27. noise2->setScale(Director::getInstance()->getContentScaleFactor());
  28. noise2->setPositionY(-noise2->getContentSize().height * noise2->getScale());
  29. clip->addChild(noise2, 1);
  30.  
  31. return true;
  32. }
  33.  
  34. void Button::setLabel(string text, float fontSize, Color4B color, string ttfFont, bool shadow)
  35. {
  36. if (label != NULL)
  37. {
  38. label->removeFromParent();
  39. }
  40.  
  41. do {
  42. label = Label::createWithTTF(text, ttfFont + ".ttf", fontSize--);
  43. } while (label->getContentSize().width + 5 > shape->getContentSize().width);
  44.  
  45. label->setHorizontalAlignment(TextHAlignment::CENTER);
  46. label->setTextColor(color);
  47. if (shadow)
  48. {
  49. label->enableShadow(Color4B(0, 0, 0, 127), Size(fontSize / 10, -fontSize / 10));
  50. }
  51. this->addChild(label);
  52. }
  53.  
  54. void Button::setIcon(std::string img, float size, bool card)
  55. {
  56. if (spriite != NULL)
  57. {
  58. spriite->removeFromParent();
  59. }
  60.  
  61. spriite = Spriite::create(img, size, card);
  62. spriite->setCascadeOpacityEnabled(true);
  63. this->addChild(spriite);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement