コード例 #1
0
ファイル: UIFocusTest.cpp プロジェクト: anilgulgor/myGame
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;
}
コード例 #2
0
ファイル: color_popup.cpp プロジェクト: webbie1887/aseprite
ColorPopup::ColorPopup(const ColorButtonOptions& options)
  : PopupWindowPin(" ", // Non-empty to create title-bar and close button
                   ClickBehavior::CloseOnClickInOtherWindow,
                   options.canPinSelector)
  , m_vbox(VERTICAL)
  , m_topBox(HORIZONTAL)
  , m_color(app::Color::fromMask())
  , m_closeButton(nullptr)
  , m_colorPaletteContainer(options.showIndexTab ?
                            new ui::View: nullptr)
  , m_colorPalette(options.showIndexTab ?
                   new PaletteView(false, PaletteView::SelectOneColor, this, 7*guiscale()):
                   nullptr)
  , m_simpleColors(nullptr)
  , m_oldAndNew(Shade(2), ColorShades::ClickEntries)
  , m_maskLabel("Transparent Color Selected")
  , m_canPin(options.canPinSelector)
  , m_insideChange(false)
  , m_disableHexUpdate(false)
{
  if (options.showSimpleColors) {
    if (!g_simplePal) {
      ResourceFinder rf;
      rf.includeDataDir("palettes/tags.gpl");
      if (rf.findFirst())
        g_simplePal.reset(load_palette(rf.filename().c_str()));
    }

    if (g_simplePal)
      m_simpleColors = new SimpleColors(this, &m_tooltips);
  }

  ButtonSet::Item* item = m_colorType.addItem("Index");
  item->setFocusStop(false);
  if (!options.showIndexTab)
    item->setVisible(false);

  m_colorType.addItem("RGB")->setFocusStop(false);
  m_colorType.addItem("HSV")->setFocusStop(false);
  m_colorType.addItem("HSL")->setFocusStop(false);
  m_colorType.addItem("Gray")->setFocusStop(false);
  m_colorType.addItem("Mask")->setFocusStop(false);

  m_topBox.setBorder(gfx::Border(0));
  m_topBox.setChildSpacing(0);

  if (m_colorPalette) {
    m_colorPaletteContainer->attachToView(m_colorPalette);
    m_colorPaletteContainer->setExpansive(true);
  }
  m_sliders.setExpansive(true);

  m_topBox.addChild(&m_colorType);
  m_topBox.addChild(new Separator("", VERTICAL));
  m_topBox.addChild(&m_hexColorEntry);
  m_topBox.addChild(&m_oldAndNew);

  // TODO fix this hack for close button in popup window
  // Move close button (decorative widget) inside the m_topBox
  {
    WidgetsList decorators;
    for (auto child : children()) {
      if (child->type() == kWindowCloseButtonWidget) {
        m_closeButton = child;
        removeChild(child);
        break;
      }
    }
    if (m_closeButton) {
      m_topBox.addChild(new BoxFiller);
      VBox* vbox = new VBox;
      vbox->addChild(m_closeButton);
      m_topBox.addChild(vbox);
    }
  }
  setText("");                  // To remove title

  m_vbox.addChild(&m_tooltips);
  if (m_simpleColors)
    m_vbox.addChild(m_simpleColors);
  m_vbox.addChild(&m_topBox);
  if (m_colorPaletteContainer)
    m_vbox.addChild(m_colorPaletteContainer);
  m_vbox.addChild(&m_sliders);
  m_vbox.addChild(&m_maskLabel);
  addChild(&m_vbox);

  m_colorType.ItemChange.connect(base::Bind<void>(&ColorPopup::onColorTypeClick, this));

  m_sliders.ColorChange.connect(&ColorPopup::onColorSlidersChange, this);
  m_hexColorEntry.ColorChange.connect(&ColorPopup::onColorHexEntryChange, this);
  m_oldAndNew.Click.connect(&ColorPopup::onSelectOldColor, this);

  // Set RGB just for the sizeHint(), and then deselect the color type
  // (the first setColor() call will setup it correctly.)
  selectColorType(app::Color::RgbType);
  m_colorType.deselectItems();

  m_onPaletteChangeConn =
    App::instance()->PaletteChange.connect(&ColorPopup::onPaletteChange, this);

  InitTheme.connect(
    [this]{
      setSizeHint(gfx::Size(300*guiscale(), sizeHint().h));
    });
  initTheme();
}
コード例 #3
0
ファイル: UIFocusTest.cpp プロジェクト: anilgulgor/myGame
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;
}