BrushPopup::BrushPopup() : PopupWindow("", ClickBehavior::CloseOnClickInOtherWindow) , m_tooltipManager(nullptr) , m_standardBrushes(3) , m_customBrushes(nullptr) { auto& brushes = App::instance()->brushes(); setAutoRemap(false); setBorder(gfx::Border(2)*guiscale()); setChildSpacing(0); m_box.noBorderNoChildSpacing(); m_standardBrushes.setTriggerOnMouseUp(true); addChild(&m_box); HBox* top = new HBox; top->addChild(&m_standardBrushes); top->addChild(new BoxFiller); m_box.addChild(top); m_box.addChild(new Separator("", HORIZONTAL)); for (const auto& brush : brushes.getStandardBrushes()) m_standardBrushes.addItem( new SelectBrushItem( BrushSlot(BrushSlot::Flags::BrushType, brush))); m_standardBrushes.setTransparent(true); m_standardBrushes.setBgColor(gfx::ColorNone); brushes.ItemsChange.connect(&BrushPopup::onBrushChanges, this); }
void ColorSliders::addSlider(Channel channel, const char* labelText, int min, int max) { Label* label = new Label(labelText); Slider* absSlider = new Slider(min, max, 0); Slider* relSlider = new Slider(min-max, max-min, 0); Entry* entry = new Entry(4, "0"); m_label.push_back(label); m_absSlider.push_back(absSlider); m_relSlider.push_back(relSlider); m_entry.push_back(entry); m_channel.push_back(channel); absSlider->setProperty(SkinSliderPropertyPtr(new SkinSliderProperty(new ColorSliderBgPainter(channel)))); absSlider->setDoubleBuffered(true); get_skin_property(entry)->setLook(MiniLook); absSlider->Change.connect(Bind<void>(&ColorSliders::onSliderChange, this, m_absSlider.size()-1)); relSlider->Change.connect(Bind<void>(&ColorSliders::onSliderChange, this, m_relSlider.size()-1)); entry->Change.connect(Bind<void>(&ColorSliders::onEntryChange, this, m_entry.size()-1)); HBox* box = new HBox(); box->addChild(absSlider); box->addChild(relSlider); absSlider->setExpansive(true); relSlider->setExpansive(true); relSlider->setVisible(false); gfx::Size sz(INT_MAX, SkinTheme::instance()->dimensions.colorSliderHeight()); label->setMaxSize(sz); box->setMaxSize(sz); entry->setMaxSize(sz); m_grid.addChildInCell(label, 1, 1, LEFT | MIDDLE); m_grid.addChildInCell(box, 1, 1, HORIZONTAL | VERTICAL | EXPANSIVE); m_grid.addChildInCell(entry, 1, 1, LEFT | MIDDLE); }
bool UIFocusTestNestedLayout3::init() { if (UIFocusTestBase::init()) { Size winSize = Director::getInstance()->getVisibleSize(); _verticalLayout = VBox::create(); _verticalLayout->setPosition(Vec2(40, winSize.height - 70)); _uiLayer->addChild(_verticalLayout); _verticalLayout->setScale(0.8f); _verticalLayout->setFocused(true); _verticalLayout->setLoopFocus(true); _verticalLayout->setTag(-1000); _firstFocusedWidget = _verticalLayout; HBox *upperHBox = HBox::create(); upperHBox->setTag(-200); _verticalLayout->addChild(upperHBox); LinearLayoutParameter *params = LinearLayoutParameter::create(); params->setMargin(Margin(0,0,50,0)); LinearLayoutParameter *vparams = LinearLayoutParameter::create(); vparams->setMargin(Margin(10, 0, 0, 140)); upperHBox->setLayoutParameter(vparams); int count = 3; for (int i=0; i<count; ++i) { VBox *firstVbox = VBox::create(); firstVbox->setScale(0.5); firstVbox->setLayoutParameter(params); firstVbox->setTag((i+1) * 100); int count1 = 3; for (int j=0; j<count1; ++j) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setTouchEnabled(true); w->setTag(j+firstVbox->getTag()+1); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this)); firstVbox->addChild(w); } upperHBox->addChild(firstVbox); } HBox *bottomHBox = HBox::create(); bottomHBox->setScale(0.5); bottomHBox->setTag(600); bottomHBox->setLayoutParameter(vparams); count = 3; LinearLayoutParameter *bottomParams = LinearLayoutParameter::create(); bottomParams->setMargin(Margin(0, 0, 8, 0)); for (int i=0; i < count; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setLayoutParameter(bottomParams); w->setTouchEnabled(true); w->setTag(i+601); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this)); bottomHBox->addChild(w); } _verticalLayout->addChild(bottomHBox); _loopText = Text::create("loop enabled", "Arial", 20); _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50)); _loopText->setColor(Color3B::GREEN); this->addChild(_loopText); auto btn = Button::create("cocosui/switch-mask.png"); btn->setTitleText("Toggle Loop"); btn->setPosition(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this)); this->addChild(btn); return true; } return false; }
bool UIFocusTestNestedLayout2::init() { if (UIFocusTestBase::init()) { Size winSize = Director::getInstance()->getVisibleSize(); _horizontalLayout = HBox::create(); _horizontalLayout->setPosition(Vec2(winSize.width/2 - 200, winSize.height - 70)); _uiLayer->addChild(_horizontalLayout); _horizontalLayout->setScale(0.6f); _horizontalLayout->setFocused(true); _horizontalLayout->setLoopFocus(true); _horizontalLayout->setTag(100); _firstFocusedWidget = _horizontalLayout; int count1 = 2; for (int i=0; i<count1; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setAnchorPoint(Vec2(0,1)); w->setTouchEnabled(true); w->setTag(i+count1); w->setScaleY(2.4f); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); _horizontalLayout->addChild(w); } //add HBox into VBox VBox *vbox = VBox::create(); vbox->setScale(0.8f); vbox->setTag(101); _horizontalLayout->addChild(vbox); int count2 = 2; for (int i=0; i < count2; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setAnchorPoint(Vec2(0,1)); w->setScaleX(2.0); w->setTouchEnabled(true); w->setTag(i+count1+count2); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); vbox->addChild(w); } HBox *innerHBox = HBox::create(); vbox->addChild(innerHBox); innerHBox->setTag(102); // innerVBox->setPassFocusToChild(false); // innerVBox->setFocusEnabled(false); int count3 = 2; for (int i=0; i<count3; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setTouchEnabled(true); w->setTag(i+count1+count2+count3); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); innerHBox->addChild(w); } _loopText = Text::create("loop enabled", "Arial", 20); _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50)); _loopText->setColor(Color3B::GREEN); this->addChild(_loopText); auto btn = Button::create("cocosui/switch-mask.png"); btn->setTitleText("Toggle Loop"); btn->setPosition(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::toggleFocusLoop, this)); this->addChild(btn); return true; } return false; }