Exemplo n.º 1
0
Layout* UI::createLayout(int i){
    auto lo=Layout::create();
    lo->setBackGroundImage("HelloWorld.png");
    lo->setBackGroundImageScale9Enabled(true);
    lo->setContentSize(Size(480,320)*1.5);
    for (int i=0; i<5; i++) {
        for (int j=0; j<7; j++) {
            auto ub=Button::create();
            ub->loadTextureNormal("editBG.png");
            ub->loadTexturePressed("editBG.png");
            ub->loadTextureDisabled("editBg.png");
            ub->setScale9Enabled(true);
            ub->setContentSize(Size(100,50));
            ub->setPressedActionEnabled(true);
            ub->setZoomScale(0.5f);
            ub->setTitleFontName("fonts/Marker Felt.ttf");
            ub->setTitleFontSize(30);
            ub->setTitleColor(Color3B::GREEN);
            ub->setTitleText(StringUtils::format("%d--%d",i,j));
            ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this));
            ub->setTag(i);
            ub->setPosition(Vec2(70+120*i, 35+j*60));
            lo->addChild(ub);
        }
    }
    return lo;
}
Exemplo n.º 2
0
void AMDemodGUI::onMenuDialogCalled(const QPoint &p)
{
    BasicChannelSettingsDialog dialog(&m_channelMarker, this);
    dialog.setUseReverseAPI(m_settings.m_useReverseAPI);
    dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress);
    dialog.setReverseAPIPort(m_settings.m_reverseAPIPort);
    dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex);
    dialog.setReverseAPIChannelIndex(m_settings.m_reverseAPIChannelIndex);
    dialog.move(p);
    dialog.exec();

    m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency();
    m_settings.m_rgbColor = m_channelMarker.getColor().rgb();
    m_settings.m_title = m_channelMarker.getTitle();
    m_settings.m_useReverseAPI = dialog.useReverseAPI();
    m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
    m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
    m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
    m_settings.m_reverseAPIChannelIndex = dialog.getReverseAPIChannelIndex();

    setWindowTitle(m_settings.m_title);
    setTitleColor(m_settings.m_rgbColor);

    applySettings();
}
Exemplo n.º 3
0
AMDemodGUI::AMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) :
	RollupWidget(parent),
	ui(new Ui::AMDemodGUI),
	m_pluginAPI(pluginAPI),
	m_deviceUISet(deviceUISet),
	m_channelMarker(this),
	m_doApplySettings(true),
	m_squelchOpen(false),
	m_samUSB(true),
	m_tickCount(0)
{
	ui->setupUi(this);
	setAttribute(Qt::WA_DeleteOnClose, true);
	connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
    connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));

	m_amDemod = reinterpret_cast<AMDemod*>(rxChannel); //new AMDemod(m_deviceUISet->m_deviceSourceAPI);
	m_amDemod->setMessageQueueToGUI(getInputMessageQueue());

	connect(&MainWindow::getInstance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); // 50 ms

	CRightClickEnabler *audioMuteRightClickEnabler = new CRightClickEnabler(ui->audioMute);
	connect(audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect()));

	CRightClickEnabler *samSidebandRightClickEnabler = new CRightClickEnabler(ui->ssb);
    connect(samSidebandRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(samSSBSelect()));

    ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03)));
    ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
    ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999);
	ui->channelPowerMeter->setColorTheme(LevelMeterSignalDB::ColorGreenAndBlue);

	m_channelMarker.blockSignals(true);
	m_channelMarker.setColor(Qt::yellow);
	m_channelMarker.setBandwidth(5000);
	m_channelMarker.setCenterFrequency(0);
    m_channelMarker.setTitle("AM Demodulator");
    m_channelMarker.blockSignals(false);
    m_channelMarker.setVisible(true); // activate signal on the last setting only

    setTitleColor(m_channelMarker.getColor());
    m_settings.setChannelMarker(&m_channelMarker);

    m_deviceUISet->registerRxChannelInstance(AMDemod::m_channelIdURI, this);
	m_deviceUISet->addChannelMarker(&m_channelMarker);
	m_deviceUISet->addRollupWidget(this);

	connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor()));
    connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor()));
    connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));

    m_iconDSBUSB.addPixmap(QPixmap("://dsb.png"), QIcon::Normal, QIcon::Off);
    m_iconDSBUSB.addPixmap(QPixmap("://usb.png"), QIcon::Normal, QIcon::On);
    m_iconDSBLSB.addPixmap(QPixmap("://dsb.png"), QIcon::Normal, QIcon::Off);
    m_iconDSBLSB.addPixmap(QPixmap("://lsb.png"), QIcon::Normal, QIcon::On);

	displaySettings();
	applySettings(true);
}
Exemplo n.º 4
0
void WFMDemodGUI::applySettings()
{
	setTitleColor(m_channelMarker->getColor());
	m_channelizer->configure(m_threadedSampleSink->getMessageQueue(),
		48000,
		m_channelMarker->getCenterFrequency());
	m_wfmDemod->configure(m_threadedSampleSink->getMessageQueue(),
		ui->afBW->value() * 1000.0,
		ui->volume->value() * 0.1);
}
Exemplo n.º 5
0
Button* OptionScene::createButton(std::string text, Size size, std::function<void(Ref*)> callback)
{
	auto button = Button::create("UI/ButtonNormal.png", "UI/ButtonSelected.png");
	button->setTitleText(text);
	button->setTitleFontName(MyCreator::normalFont);
	button->setTitleColor(Color3B::BLACK);
	button->setTitleFontSize(30);
	button->addClickEventListener(callback);
	button->setScale9Enabled(true);
	button->setContentSize(size);
	return button;
}
Exemplo n.º 6
0
void ChannelAnalyzerGUI::displaySettings()
{
    m_channelMarker.blockSignals(true);
    m_channelMarker.setCenterFrequency(m_settings.m_frequency);
    m_channelMarker.setBandwidth(m_settings.m_bandwidth * 2);
    m_channelMarker.setTitle(m_settings.m_title);
    m_channelMarker.setLowCutoff(m_settings.m_lowCutoff);

    if (m_settings.m_ssb)
    {
        if (m_settings.m_bandwidth < 0) {
            m_channelMarker.setSidebands(ChannelMarker::lsb);
        } else {
            m_channelMarker.setSidebands(ChannelMarker::usb);
        }
    }
    else
    {
        m_channelMarker.setSidebands(ChannelMarker::dsb);
    }

    m_channelMarker.blockSignals(false);
    m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only

    setTitleColor(m_settings.m_rgbColor);
    setWindowTitle(m_channelMarker.getTitle());

    ui->channelSampleRate->setValueRange(7, 0.501*m_channelAnalyzer->getInputSampleRate(), m_channelAnalyzer->getInputSampleRate());
    ui->channelSampleRate->setValue(m_settings.m_downSampleRate);

    blockApplySettings(true);

    ui->useRationalDownsampler->setChecked(m_settings.m_downSample);
    setNewFinalRate();
    if (m_settings.m_ssb) {
        ui->BWLabel->setText("LP");
    } else {
        ui->BWLabel->setText("BP");
    }
    ui->ssb->setChecked(m_settings.m_ssb);
    ui->BW->setValue(m_settings.m_bandwidth/100);
    ui->lowCut->setValue(m_settings.m_lowCutoff/100);
    ui->deltaFrequency->setValue(m_settings.m_frequency);
    ui->spanLog2->setCurrentIndex(m_settings.m_spanLog2);
    displayPLLSettings();
    ui->signalSelect->setCurrentIndex((int) m_settings.m_inputType);
    ui->rrcFilter->setChecked(m_settings.m_rrc);
    QString rolloffStr = QString::number(m_settings.m_rrcRolloff/100.0, 'f', 2);
    ui->rrcRolloffText->setText(rolloffStr);

    blockApplySettings(false);
}
Exemplo n.º 7
0
void NFMDemodGUI::displaySettings()
{
    m_channelMarker.blockSignals(true);
    m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset);
    m_channelMarker.setBandwidth(m_settings.m_rfBandwidth);
    m_channelMarker.setTitle(m_settings.m_title);
    m_channelMarker.blockSignals(false);
    m_channelMarker.setColor(m_settings.m_rgbColor);

    setTitleColor(m_settings.m_rgbColor);
    setWindowTitle(m_channelMarker.getTitle());

    blockApplySettings(true);

    ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());

    ui->rfBW->setCurrentIndex(NFMDemodSettings::getRFBWIndex(m_settings.m_rfBandwidth));

    ui->afBWText->setText(QString("%1 k").arg(m_settings.m_afBandwidth / 1000.0));
    ui->afBW->setValue(m_settings.m_afBandwidth / 1000.0);

    ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 0, 'f', 1));
    ui->volume->setValue(m_settings.m_volume * 10.0);

    ui->squelchGateText->setText(QString("%1").arg(m_settings.m_squelchGate * 10.0f, 0, 'f', 0));
    ui->squelchGate->setValue(m_settings.m_squelchGate);

    ui->deltaSquelch->setChecked(m_settings.m_deltaSquelch);
    ui->squelch->setValue(m_settings.m_squelch * 1.0);

    if (m_settings.m_deltaSquelch)
    {
        ui->squelchText->setText(QString("%1").arg((-m_settings.m_squelch) / 1.0, 0, 'f', 0));
        ui->squelchText->setToolTip(tr("Squelch AF balance threshold (%)"));
        ui->squelch->setToolTip(tr("Squelch AF balance threshold (%)"));
    }
    else
    {
        ui->squelchText->setText(QString("%1").arg(m_settings.m_squelch / 1.0, 0, 'f', 0));
        ui->squelchText->setToolTip(tr("Squelch power threshold (dB)"));
        ui->squelch->setToolTip(tr("Squelch power threshold (dB)"));
    }

    ui->ctcssOn->setChecked(m_settings.m_ctcssOn);
    ui->audioMute->setChecked(m_settings.m_audioMute);

    ui->ctcss->setCurrentIndex(m_settings.m_ctcssIndex);

    blockApplySettings(false);
}
Exemplo n.º 8
0
void ChannelAnalyzerGUI::onMenuDialogCalled(const QPoint& p)
{
    BasicChannelSettingsDialog dialog(&m_channelMarker, this);
    dialog.move(p);
    dialog.exec();

    m_settings.m_frequency = m_channelMarker.getCenterFrequency();
    m_settings.m_rgbColor = m_channelMarker.getColor().rgb();
    m_settings.m_title = m_channelMarker.getTitle();

    setWindowTitle(m_settings.m_title);
    setTitleColor(m_settings.m_rgbColor);

    applySettings();
}
Exemplo n.º 9
0
bool UIFocusTestVertical::init()
{
    if (UIFocusTestBase::init()) {
        
        Size winSize = Director::getInstance()->getVisibleSize();
        
        _verticalLayout = VBox::create();
        _verticalLayout->setPosition(Vec2(winSize.width/2 - 100, winSize.height - 70));
        _uiLayer->addChild(_verticalLayout);
        _verticalLayout->setTag(100);
        _verticalLayout->setScale(0.5);
        
        _verticalLayout->setFocused(true);
        _verticalLayout->setLoopFocus(true);
        _firstFocusedWidget = _verticalLayout;
        
        int count = 3;
        for (int i=0; i<count; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setTouchEnabled(true);
            w->setTag(i);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestVertical::onImageViewClicked, this));
            _verticalLayout->addChild(w);
            if (i == 2) {
                w->requestFocus();
            }
        }
        
        _loopText = Text::create("loop enabled", "Airal", 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(UIFocusTestVertical::toggleFocusLoop, this));
        this->addChild(btn);
        
        
        return true;
    }
    return false;
}
Exemplo n.º 10
0
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);

        // clone the inner sprite: https://github.com/cocos2d/cocos2d-x/issues/16924
        button->_buttonNormalRenderer->copyTo(_buttonNormalRenderer);
        _normalFileName = button->_normalFileName;
        _normalTextureSize = button->_normalTextureSize;
        _normalTexType = button->_normalTexType;
        _normalTextureLoaded = button->_normalTextureLoaded;
        setupNormalTexture(!_normalFileName.empty());

        button->_buttonClickedRenderer->copyTo(_buttonClickedRenderer);
        _clickedFileName = button->_clickedFileName;
        _pressedTextureSize = button->_pressedTextureSize;
        _pressedTexType = button->_pressedTexType;
        _pressedTextureLoaded = button->_pressedTextureLoaded;
        setupPressedTexture(!_clickedFileName.empty());

        button->_buttonDisabledRenderer->copyTo(_buttonDisabledRenderer);
        _disabledFileName = button->_disabledFileName;
        _disabledTextureSize = button->_disabledTextureSize;
        _disabledTexType = button->_disabledTexType;
        _disabledTextureLoaded = button->_disabledTextureLoaded;
        setupDisabledTexture(!_disabledFileName.empty());

        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        if(nullptr != button->getTitleRenderer())
        {
            setTitleText(button->getTitleText());
            setTitleFontName(button->getTitleFontName());
            setTitleFontSize(button->getTitleFontSize());
            setTitleColor(button->getTitleColor());
        }
        setPressedActionEnabled(button->_pressedActionEnabled);
        setZoomScale(button->_zoomScale);
    }

}
Exemplo n.º 11
0
bool UIButtonTitleEffectTest::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add a label in which the button events will be displayed
        _displayValueLabel = Text::create("Button Title Effect", "fonts/Marker Felt.ttf",32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
        _uiLayer->addChild(_displayValueLabel);
        
        
        // Create the button
        auto button = Button::create("cocosui/animationbuttonnormal.png",
                                     "cocosui/animationbuttonpressed.png");
        button->setNormalizedPosition(Vec2(0.3f, 0.5f));
        button->setTitleText("PLAY GAME");
        button->setTitleFontName("fonts/Marker Felt.ttf");
        button->setZoomScale(0.3f);
        button->setScale(2.0f);
        button->setPressedActionEnabled(true);
        Label *title = button->getTitleRenderer();
        button->setTitleColor(Color3B::RED);
        title->enableShadow(Color4B::BLACK,Size(2,-2));

        
        _uiLayer->addChild(button);
        
        // Create the button
        auto button2 = Button::create("cocosui/animationbuttonnormal.png",
                                      "cocosui/animationbuttonpressed.png");
        button2->setNormalizedPosition(Vec2(0.8f, 0.5f));
        button2->setTitleText("PLAY GAME");
        auto title2 = button2->getTitleRenderer();
        title2->enableOutline(Color4B::GREEN, 3);
        _uiLayer->addChild(button2);
        
        return true;
    }
    return false;
}
Exemplo n.º 12
0
void AMDemodGUI::applySettings()
{
	if (m_doApplySettings)
	{
		setTitleColor(m_channelMarker.getColor());

		m_channelizer->configure(m_channelizer->getInputMessageQueue(),
			48000,
			m_channelMarker.getCenterFrequency());

		ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
		ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0);

		m_amDemod->configure(m_amDemod->getInputMessageQueue(),
			ui->rfBW->value() * 100.0,
			ui->volume->value() / 10.0,
			ui->squelch->value(),
			ui->audioMute->isChecked());
	}
}
Exemplo n.º 13
0
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {   
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);
        loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType);
        loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType);
        loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType);
        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        setTitleText(button->getTitleText());
        setTitleFontName(button->getTitleFontName());
        setTitleFontSize(button->getTitleFontSize());
        setTitleColor(button->getTitleColor());
        setPressedActionEnabled(button->_pressedActionEnabled);
    }
}
Exemplo n.º 14
0
bool MainScene::init()
{
    Size sizeWin = DIRECTOR->getWinSize();
    float listWidth = sizeWin.width - sizeWin.height;
    
    // background layout
    auto layerColor = LayerColor::create(Color4B::WHITE, sizeWin.width, sizeWin.height);
    auto drawNodeV = DrawNode::create();
    drawNodeV->drawSegment(Point(listWidth, 0), Point(listWidth, sizeWin.height), 2, Color4F::GRAY);
    layerColor->addChild(drawNodeV);
    auto drawNodeH = DrawNode::create();
    drawNodeH->drawSegment(Point(listWidth, sizeWin.height / 3), Point(sizeWin.width, sizeWin.height / 3), 2, Color4F::GRAY);
    layerColor->addChild(drawNodeH);
    addChild(layerColor);
    
    // title
    auto btnTitle = Button::create();
    btnTitle->setTouchEnabled(true);
    btnTitle->ignoreContentAdaptWithSize(false);
    btnTitle->setTitleFontName("Marker Felt");
    btnTitle->setTitleText("Cocos2d Manual");
    btnTitle->setTitleColor(Color3B::GREEN);
    btnTitle->setTitleFontSize(30);
    btnTitle->setSize(Size(listWidth, 40));
    btnTitle->setPosition(Point(listWidth / 2, sizeWin.height - 30));
    BIND_LISTENER_TOUCH(btnTitle, this, MainScene::onTouchTitle);
    addChild(btnTitle);
    
    // manual layer
    auto layerDisplay = ManualDisplay::create();
    auto layerCode = ManualCode::create();
    auto layerList = ManualList::create();
    layerCode->setDisplay(layerDisplay);
    layerCode->setTag(Tag::TAG_CODELAYER);
    layerList->setCode(layerCode);
    addChild(layerDisplay);
    addChild(layerCode);
    addChild(layerList);
    
    return Layer::init();
}
Exemplo n.º 15
0
void DSDDemodGUI::applySettings()
{
	if (m_doApplySettings)
	{
		qDebug() << "DSDDemodGUI::applySettings";

		setTitleColor(m_channelMarker.getColor());

		m_channelizer->configure(m_channelizer->getInputMessageQueue(),
			48000,
			m_channelMarker.getCenterFrequency());

		ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
		ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0);
	    ui->rfBWText->setText(QString("%1k").arg(ui->rfBW->value() / 10.0, 0, 'f', 1));
	    ui->demodGainText->setText(QString("%1").arg(ui->demodGain->value() / 100.0, 0, 'f', 2));
	    ui->fmDeviationText->setText(QString("%1k").arg(ui->fmDeviation->value() / 10.0, 0, 'f', 1));
		ui->squelchGateText->setText(QString("%1").arg(ui->squelchGate->value() * 10.0, 0, 'f', 0));
	    ui->volumeText->setText(QString("%1").arg(ui->volume->value() / 10.0, 0, 'f', 1));
	    ui->enableCosineFiltering->setChecked(m_enableCosineFiltering);
	    ui->syncOrConstellation->setChecked(m_syncOrConstellation);
	    ui->slot1On->setChecked(m_slot1On);
        ui->slot2On->setChecked(m_slot2On);
        ui->tdmaStereoSplit->setChecked(m_tdmaStereo);

		m_dsdDemod->configure(m_dsdDemod->getInputMessageQueue(),
			ui->rfBW->value(),
			ui->demodGain->value(),
			ui->fmDeviation->value(),
			ui->volume->value(),
			DSDDemodBaudRates::getRate(ui->baudRate->currentIndex()),
			ui->squelchGate->value(), // in 10ths of ms
			ui->squelch->value(),
			ui->audioMute->isChecked(),
			m_enableCosineFiltering,
			m_syncOrConstellation,
			m_slot1On,
			m_slot2On,
			m_tdmaStereo);
	}
}
Exemplo n.º 16
0
//按钮
void UI:: initButton(){
    auto visibleSize=Director::getInstance()->getVisibleSize();
    auto ub=Button::create();
    ub->loadTextureNormal("0.png");
    ub->loadTexturePressed("2.png");
    ub->loadTextureDisabled("2.png");
    ub->setScale9Enabled(true);
    ub->setContentSize(cocos2d::Size(128,128));
    ub->setPressedActionEnabled(true);
    ub->setZoomScale(2);
    ub->setTitleFontName("fonts/Marker Felt.ttf");
    ub->setTitleFontSize(30);
    ub->setTitleColor(cocos2d::Color3B::YELLOW);
    ub->setTitleText("HHLLO Button");
   // ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this));
    //添加触摸事件
    ub->addTouchEventListener (this,toucheventselector(UI::buttonClick));
    ub->setPosition(visibleSize/2);
    addChild(ub);
    
}
Exemplo n.º 17
0
bool Pause::init() {
    if (!Setting::init()) {
        return false;
    }

    auto resumeButton = ui::Button::create("Pics/button/OptionNormal.png", "Pics/button/OptionSelected.png");
    resumeButton->setTitleFontName("Fonts/Amplify.ttf");
    resumeButton->setTitleFontSize(36);    
    resumeButton->setTitleText("RESUME");
    resumeButton->setTitleColor(Color3B(53, 54, 165));
    resumeButton->addTouchEventListener([](Ref* pSender, ui::Widget::TouchEventType type) {
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->popScene();
            if (UserDefault::getInstance()->getBoolForKey(SOUND_KEY)) {
                SimpleAudioEngine::getInstance()->playEffect(FILE_SOUND_1);
            }
        }
    });
    resumeButton->setPosition(Vec2(480, 200));

    this->addChild(resumeButton);
    return true;
}
Exemplo n.º 18
0
cocos2d::ui::Button* GameLayer::create_button(std::string text, cocos2d::ccMenuCallback cb)
{
    auto param = ui::LinearLayoutParameter::create();
    param->setGravity(ui::LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
    param->setMargin(ui::Margin(0, menu_fontsize/2, 0, 0));

    auto btn = ui::Button::create();
    btn->setTitleFontName(menu_font);
    btn->setTitleFontSize(menu_fontsize);
    btn->setTitleColor(Color3B::GREEN);
    btn->setLayoutParameter(param);
    btn->setTouchEnabled(true);
    btn->setPressedActionEnabled(true);

    btn->addTouchEventListener([this,cb](Ref* ref, ui::Widget::TouchEventType event)
            {
            if (event == ui::Widget::TouchEventType::ENDED){ cb(NULL); }
            });
    btn->setTitleText(text);

    return btn;

};
Exemplo n.º 19
0
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);
        auto normalSprite = button->_buttonNormalRenderer->getSprite();
        if (nullptr != normalSprite)
        {
            loadTextureNormal(normalSprite->getSpriteFrame());
        }
        auto clickedSprite = button->_buttonClickedRenderer->getSprite();
        if (nullptr != clickedSprite)
        {
            loadTexturePressed(clickedSprite->getSpriteFrame());
        }
        auto disabledSprite = button->_buttonDisableRenderer->getSprite();
        if (nullptr != disabledSprite)
        {
            loadTextureDisabled(disabledSprite->getSpriteFrame());
        }
        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        if(nullptr != button->getTitleRenderer())
        {
            setTitleText(button->getTitleText());
            setTitleFontName(button->getTitleFontName());
            setTitleFontSize(button->getTitleFontSize());
            setTitleColor(button->getTitleColor());
        }
        setPressedActionEnabled(button->_pressedActionEnabled);
        setZoomScale(button->_zoomScale);
    }

}
Exemplo n.º 20
0
LoRaDemodGUI::LoRaDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
	RollupWidget(parent),
	ui(new Ui::LoRaDemodGUI),
	m_pluginAPI(pluginAPI),
	m_basicSettingsShown(false)
{
	ui->setupUi(this);
	setAttribute(Qt::WA_DeleteOnClose, true);
	connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
	connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));

	m_spectrumVis = new SpectrumVis(ui->glSpectrum);
	m_LoRaDemod = new LoRaDemod(m_spectrumVis);
	m_channelizer = new Channelizer(m_LoRaDemod);
	m_threadedSampleSink = new ThreadedSampleSink(m_channelizer);
	m_pluginAPI->addSampleSink(m_threadedSampleSink);

	ui->glSpectrum->setCenterFrequency(16000);
	ui->glSpectrum->setSampleRate(32000);
	ui->glSpectrum->setDisplayWaterfall(true);
	ui->glSpectrum->setDisplayMaxHold(true);

	setTitleColor(Qt::magenta);

	m_channelMarker = new ChannelMarker(this);
	m_channelMarker->setColor(Qt::magenta);
	m_channelMarker->setBandwidth(7813);
	m_channelMarker->setCenterFrequency(0);
	m_channelMarker->setVisible(true);
	connect(m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged()));
	m_pluginAPI->addChannelMarker(m_channelMarker);

	ui->spectrumGUI->setBuddies(m_threadedSampleSink->getMessageQueue(), m_spectrumVis, ui->glSpectrum);

	applySettings();
}
Exemplo n.º 21
0
void Button::setColor(const Color3B &color)
{
    Widget::setColor(color);
    setTitleColor(_titleColor);
}
Exemplo n.º 22
0
void AMDemodGUI::displaySettings()
{
    m_channelMarker.blockSignals(true);
    m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset);
    m_channelMarker.setBandwidth(m_settings.m_rfBandwidth);
    m_channelMarker.setTitle(m_settings.m_title);
    m_channelMarker.blockSignals(false);
    m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only

    setTitleColor(m_settings.m_rgbColor);
    setWindowTitle(m_channelMarker.getTitle());

    blockApplySettings(true);

    ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());

    int displayValue = m_settings.m_rfBandwidth/100.0;
    ui->rfBW->setValue(displayValue);
    ui->rfBWText->setText(QString("%1 kHz").arg(displayValue / 10.0, 0, 'f', 1));

    ui->volume->setValue(m_settings.m_volume * 10.0);
    ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 0, 'f', 1));

    ui->squelch->setValue(m_settings.m_squelch);
    ui->squelchText->setText(QString("%1 dB").arg(m_settings.m_squelch));

    ui->audioMute->setChecked(m_settings.m_audioMute);
    ui->bandpassEnable->setChecked(m_settings.m_bandpassEnable);
    ui->pll->setChecked(m_settings.m_pll);

    qDebug() << "AMDemodGUI::displaySettings:"
            << " m_pll: " << m_settings.m_pll
            << " m_syncAMOperation: " << m_settings.m_syncAMOperation;

    if (m_settings.m_pll)
    {
        if (m_settings.m_syncAMOperation == AMDemodSettings::SyncAMLSB)
        {
            m_samUSB = false;
            ui->ssb->setChecked(true);
            ui->ssb->setIcon(m_iconDSBLSB);
        }
        else if (m_settings.m_syncAMOperation == AMDemodSettings::SyncAMUSB)
        {
            m_samUSB = true;
            ui->ssb->setChecked(true);
            ui->ssb->setIcon(m_iconDSBUSB);
        }
        else
        {
            ui->ssb->setChecked(false);
        }
    }
    else
    {
        ui->ssb->setChecked(false);
        ui->ssb->setIcon(m_iconDSBUSB);
    }

    blockApplySettings(false);
}
Exemplo n.º 23
0
/****************************************************************************
**
** Copyright (C) 2016 - 2017
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

// Include
#include <float.h>
#include <QMessageBox>
#include <QSettings>
#include "constants.h"
#include "hlms_node_samplerblock.h"
#include "hlms_node_porttypes.h"

//****************************************************************************/
HlmsNodeSamplerblock::HlmsNodeSamplerblock(QString title, QGraphicsItem* parent) :
    Magus::QtNode(title, parent),
    mTextureType(0),
    mTextureIndex(0),
    mSamplerblockEnabled(true),
    mTextureAddressingModeU(0),
    mTextureAddressingModeV(0),
    mTextureAddressingModeW(0),
    mMipLodBias(0.0f),
    mMaxAnisotropy(1.0f),
    mCompareFunction(8),
    mMinLod(-FLT_MAX),
    mMaxLod(FLT_MAX),
    mBorderColourRed(255.0f),
    mBorderColourGreen(255.0f),
    mBorderColourBlue(255.0f),
    mUvSet(0),
    mBlendMode(0),
    mMapWeight(1.0f),
    mEmissiveColourRed(0.0f),
    mEmissiveColourGreen(0.0f),
    mEmissiveColourBlue(0.0f),
    mAnimationEnabled(false),
    mSequenceNumber(-1)
{
    mFileNameTexture = QString("");
    mBaseNameTexture = QString("");
    mPathTexture = QString("");
    mOffset = QVector2D(0.0f, 0.0f);
    mScale = QVector2D(1.0f, 1.0f);
    mAnimationScale = QVector2D(1.0f, 1.0f);
    mAnimationTranslate = QVector2D(0.0f, 0.0f);

    // Define the connection policy
    HlmsPbsDatablockSamplerblockPortType hlmsPbsDatablockSamplerblockPortType;
    HlmsSamplerblockDatablockPortType hlmsSamplerblockDatablockPortType;
    hlmsPbsDatablockSamplerblockPortType.addPortTypeToConnectionPolicy(hlmsSamplerblockDatablockPortType);

    // Apply values from settings.cfg
    QSettings settings(FILE_SETTINGS, QSettings::IniFormat);
    mTextureMinFilter = settings.value(SETTINGS_SAMPLERBLOCK_FILTER_INDEX).toInt();
    mTextureMagFilter = settings.value(SETTINGS_SAMPLERBLOCK_FILTER_INDEX).toInt();
    mTextureMipFilter = settings.value(SETTINGS_SAMPLERBLOCK_FILTER_INDEX).toInt();

    // Custome node settings
    setTitleColor(Qt::white);
    setHeaderTitleIcon(ICON_SAMPLERBLOCK);
    setAction1Icon(ICON_MINMAX);
    setAction2Icon(ICON_CLOSE);
    alignTitle(Magus::ALIGNED_LEFT);
    setHeaderColor(QColor("#874E96"));
    mPort = createPort(PORT_ID_SAMPLERBLOCK,
                       PORT_DATABLOCK,
                       hlmsPbsDatablockSamplerblockPortType,
                       QColor("#874E96"),
                       Magus::PORT_SHAPE_CIRCLE,
                       Magus::ALIGNED_LEFT,
                       QColor("#874E96"));

    setPortNameColor(Qt::white);
    setZoom(0.9);
}
Exemplo n.º 24
0
void TCPSrcGUI::applySettings()
{
	if (m_doApplySettings)
	{
		bool ok;

		Real outputSampleRate = ui->sampleRate->text().toDouble(&ok);

		if((!ok) || (outputSampleRate < 1000))
		{
			outputSampleRate = 48000;
		}

		Real rfBandwidth = ui->rfBandwidth->text().toDouble(&ok);

		if((!ok) || (rfBandwidth > outputSampleRate))
		{
			rfBandwidth = outputSampleRate;
		}

		int tcpPort = ui->tcpPort->text().toInt(&ok);

		if((!ok) || (tcpPort < 1) || (tcpPort > 65535))
		{
			tcpPort = 9999;
		}

		int boost = ui->boost->value();

		setTitleColor(m_channelMarker.getColor());
		ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
		ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0);
		ui->sampleRate->setText(QString("%1").arg(outputSampleRate, 0));
		ui->rfBandwidth->setText(QString("%1").arg(rfBandwidth, 0));
		ui->tcpPort->setText(QString("%1").arg(tcpPort));
		ui->boost->setValue(boost);
		m_channelMarker.disconnect(this, SLOT(channelMarkerChanged()));
		m_channelMarker.setBandwidth((int)rfBandwidth);
		connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(channelMarkerChanged()));
		ui->glSpectrum->setSampleRate(outputSampleRate);

		m_channelizer->configure(m_channelizer->getInputMessageQueue(),
			outputSampleRate,
			m_channelMarker.getCenterFrequency());

		TCPSrc::SampleFormat sampleFormat;

		switch(ui->sampleFormat->currentIndex())
		{
			case 0:
				sampleFormat = TCPSrc::FormatSSB;
				break;
			case 1:
				sampleFormat = TCPSrc::FormatNFM;
				break;
			case 2:
				sampleFormat = TCPSrc::FormatS16LE;
				break;
			default:
				sampleFormat = TCPSrc::FormatSSB;
				break;
		}

		m_sampleFormat = sampleFormat;
		m_outputSampleRate = outputSampleRate;
		m_rfBandwidth = rfBandwidth;
		m_tcpPort = tcpPort;
		m_boost = boost;

		m_tcpSrc->configure(m_tcpSrc->getInputMessageQueue(),
			sampleFormat,
			outputSampleRate,
			rfBandwidth,
			tcpPort,
			boost);

		ui->applyBtn->setEnabled(false);
	}
}
bool ProvisionalScene::init()
{
    if(!Layer::init()){return false;}
    
    auto sprite = Sprite::create("ImageFile/Menubg.png");
    sprite->setPosition(winSize/2);
    this->addChild(sprite,3);
    
    Layer* optionLayer = Layer::create();
    
    //メニューリスト生成----------------------------------------------------->
    menuList->setContentSize(Size(winSize.width,winSize.height));
    menuList->Node::setPosition((winSize - menuList->getContentSize())/2);
    addChild(menuList,1);
    
    //スライダーバー生成----------------------------------------------------->
    for (int i = 0; i < 3; i++)
    {
        slider[i] = Slider::create();
        slider[i]->loadBarTexture("ImageFile/sliderTrack.png");
        slider[i]->loadSlidBallTextures("ImageFile/sliderThumb.png",
                                        "ImageFile/sliderThumb.png","");
        slider[i]->loadProgressBarTexture("ImageFile/sliderProgress.png");
        slider[i]->Node::setScale(2);
    }
    slider[0]->setPosition(Vec2(1225, -350));
    slider[1]->setPosition(Vec2(1225, -500));
    slider[2]->setPosition(Vec2(1225, -650));
    
    //Closeボタン生成--------------------------------------------------->
    auto closeButton = Button::create("ImageFile/button1.png",
                                      "ImageFile/button1selected.png");
    closeButton->setPosition(Vec2(winSize.width/2, -780));
    closeButton->setScale(1.8,1.8);
    closeButton->setTitleText("閉じる");
    closeButton->setTitleFontSize(16);
    closeButton->setTitleColor(Color3B::WHITE);
    
    //レイアウト生成------------------------------------>
    auto layout = Layout::create();
    layout->setPosition(menuList->getContentSize()/2);
    
    //レイアウトの背景画像生成------------------------------------------->
    auto imageView = ImageView::create("ImageFile/option/option_window.png");
    imageView->setPosition(Vec2(winSize.width/2,-winSize.height/2));
    imageView->setScale(1.5, 1.5);
    layout->addChild(imageView);
    
    for (int i = 0; i<3; i++) {
        layout->addChild(slider[i]);
    }
    
    layout->addChild(closeButton);
    menuList->addChild(layout);
    menuList->setEnabled(false);
    
    optionButton->setPosition(Vec2(200,100));
    optionButton->setScale(0.1);
    addChild(optionButton,4);
    
    optionButton->addTouchEventListener([&,this](Ref *pSender, Widget::TouchEventType type){
    
        this->reorderChild(menuList, 3);
        menuList->setEnabled(true);

    });
    
    return true;
}
Exemplo n.º 26
0
bool UIFocusTestListView::init()
{
    if (UIFocusTestBase::init()) {
        
        Size winSize = Director::getInstance()->getVisibleSize();
        
        _listView = ListView::create();
        _listView->setDirection(ui::ScrollView::Direction::VERTICAL);
        _listView->setBounceEnabled(true);
        _listView->setBackGroundImage("cocosui/green_edit.png");
        _listView->setBackGroundImageScale9Enabled(true);
        _listView->setContentSize(Size(240, 130));
        
        _listView->setPosition(Vec2(40, 70));
        _uiLayer->addChild(_listView);
        _listView->setScale(0.8);
        
        _listView->setFocused(true);
        _listView->setLoopFocus(true);
        _listView->setTag(-1000);
        _firstFocusedWidget = _listView;
        
        // create model
        Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
        default_button->setName("Title Button");
        
        
        // set model
        _listView->setItemModel(default_button);
        
        // add default item
        ssize_t count = 20;
        for (int i = 0; i < count / 4; ++i)
        {
            _listView->pushBackDefaultItem();
        }
        // insert default item
        for (int i = 0; i < count / 4; ++i)
        {
            _listView->insertDefaultItem(0);
        }
        
        
        
        _loopText = Text::create("loop enabled", "Airal", 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(UIFocusTestListView::toggleFocusLoop, this));
        this->addChild(btn);
        
        
        return true;
    }
    return false;
}
Exemplo n.º 27
0
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.8);
        
        _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", "Airal", 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;
}
Exemplo n.º 28
0
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.6);
        
        _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.4);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this));
            _horizontalLayout->addChild(w);
        }
        
        //add HBox into VBox
        VBox *vbox = VBox::create();
        vbox->setScale(0.8);
        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", "Airal", 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;
}
Exemplo n.º 29
0
cocos2d::ui::Button* GameLayer::create_button(std::string text, BoolFuncNoArgs cb, bool start_disabled, ButtonState* btn_state)
{
    auto param = ui::LinearLayoutParameter::create();
    param->setGravity(ui::LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);

    auto disable_button = [](ui::Button* button)
    {
        button->setTitleColor(Color3B::GRAY);
        button->setTouchEnabled(false);
        button->setPressedActionEnabled(false);
    };

    auto btn = ui::Button::create("main_UI_export_10_x4.png", "", "", ui::TextureResType::PLIST);

    btn->setTitleFontName(menu_font);
    btn->setTitleFontSize(menu_fontsize);
    btn->setTitleColor(Color3B::BLACK);
    btn->getTitleRenderer()->getTexture()->setAliasTexParameters();

    btn->setColor(Color3B(114, 160, 72));

    btn->getVirtualRenderer()->setScale(sx(1.0f));
    btn->setScaleX(sx(1.0f));
    btn->setScaleY(sy(1.0f));

    param->setMargin(ui::Margin(0, sy(15.0f)*btn->getScaleY(), 0, sy(15.0f)*btn->getScaleY()));

    btn->setLayoutParameter(param);
    btn->setTouchEnabled(true);
    btn->setPressedActionEnabled(true);

    if (start_disabled) 
    {
        disable_button(btn);
    };

    btn->setTitleText(text);
    if (btn_state)
    {
        //update the text
        btn_state->swap_state(btn, btn_state->current);
    };

    btn->addTouchEventListener(
        [btn_state, cb, btn, disable_button](Ref* ref, ui::Widget::TouchEventType event)
            {
                if (event == ui::Widget::TouchEventType::ENDED)
                {
                    if (!cb())
                    {
                        disable_button(btn);
                    };
                    if (btn_state)
                    {
                        btn_state->current = !btn_state->current;
                        btn_state->swap_state(btn, btn_state->current);
                    };
                }
            }
    );

    return btn;

};
Exemplo n.º 30
0
Alert* Alert::create()
{
    //usual cocos create, note that I'm skipping handling errors. should fix that
    Alert* alert = new (std::nothrow) Alert();
    if (alert && alert->init())
    {
        alert->autorelease();
    }

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Size node_size = visibleSize*0.80f;
    alert->setContentSize(node_size);
    alert->setLayoutType(ui::Layout::Type::RELATIVE);

    //alert->setBackGroundColor(Color3B::BLACK);
    //alert->setBackGroundColorOpacity(255/1.5);
    //alert->setBackGroundColorType(ui::LayoutBackGroundColorType::SOLID);

    alert->setBackGroundImage("main_UI_export_10_x4.png", TextureResType::PLIST);
    alert->setBackGroundImageScale9Enabled(true);
    alert->setBackGroundImageColor(Color3B(114, 160, 72));
    //alert->setBackGroundImageOpacity(200.0f);
    //layout->setClippingEnabled(true);

    auto create_txt = [&](std::string msg, ui::RelativeLayoutParameter* param) {
        auto txt = ui::Text::create(msg, DEFAULT_FONT, sx(25.0f));
        Label* lbl = (Label*)txt->getVirtualRenderer();
        lbl->getFontAtlas()->setAliasTexParameters();
        txt->setTextColor(Color4B::BLACK);
        //txt->enableOutline(Color4B::BLACK, 2);

        txt->ignoreContentAdaptWithSize(false); //word wrap or something

        alert->addChild(txt);

        txt->setLayoutParameter(param);
        return txt;
    };

    auto header_param = ui::RelativeLayoutParameter::create();
    header_param->setRelativeName("header_param");
    header_param->setAlign(ui::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);
    header_param->setMargin(ui::Margin(sx(10), sy(30), sx(10), sy(10)));

    alert->header_txt = create_txt("Title Here", header_param);

    auto sub_header_param = ui::RelativeLayoutParameter::create();
    sub_header_param->setRelativeName("sub_header_param");
    sub_header_param->setAlign(ui::RelativeAlign::LOCATION_BELOW_CENTER);
    sub_header_param->setMargin(ui::Margin(sx(10), sy(10), sx(10), sy(10)));

    alert->sub_header_txt = create_txt("Sub header", sub_header_param);
    sub_header_param->setRelativeToWidgetName("header_param");

    auto body_param = ui::RelativeLayoutParameter::create();
    body_param->setAlign(ui::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL);
    body_param->setMargin(ui::Margin(sx(30), sy(10), sx(10), sy(10)));
    alert->body_txt = create_txt("Body content", body_param);

    Size body_size = alert->body_txt->getAutoRenderSize();
    alert->body_txt->setTextAreaSize(Size(
        body_size.width,
        body_size.height
    ));


    auto close_btn = ui::Button::create();
    close_btn->addTouchEventListener([alert](Ref*, TouchEventType type)
    {
        if (type == TouchEventType::ENDED)
        {
            Size visibleSize = Director::getInstance()->getVisibleSize();
            Vec2 origin = Director::getInstance()->getVisibleOrigin();

            Vec2 pos = Vec2(
                origin.x + visibleSize.width - 20,
                origin.y + 20
                );
            alert->shrink_close(pos);
        };

    });

    close_btn->setTitleText("X");
    close_btn->setTitleColor(Color3B::RED);
    close_btn->setTitleFontSize(sx(40.0f));
    close_btn->getTitleRenderer()->enableOutline(Color4B::GRAY, 10);
    close_btn->setScaleX(sx(1.0f));
    close_btn->setScaleY(sy(1.0f));
    alert->close_btn = close_btn;

    ui::RelativeLayoutParameter* close_param = ui::RelativeLayoutParameter::create();
    close_param->setAlign(ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT);
    close_param->setMargin(ui::Margin(sx(30), sy(20), sx(30), sy(30)));
    alert->close_btn->setLayoutParameter(close_param);
    alert->addChild(alert->close_btn);

    auto done_btn = ui::Button::create();
    done_btn->addTouchEventListener([alert](Ref*, TouchEventType type)
    {
        if (type == TouchEventType::ENDED)
        {
            Size visibleSize = Director::getInstance()->getVisibleSize();
            Vec2 origin = Director::getInstance()->getVisibleOrigin();

            Vec2 pos = Vec2(
                origin.x + visibleSize.width - 20,
                origin.y + 20
                );
            alert->shrink_close(pos);
        };

    });

    done_btn->setScale9Enabled(true);
    done_btn->loadTextureNormal("main_UI_export_10_scale9_x4.png", ui::TextureResType::PLIST);
    done_btn->setTitleText("Done");
    done_btn->setTitleFontSize(40.0f);
    done_btn->setTitleFontName(DEFAULT_FONT);
    auto lbl_size = done_btn->getTitleRenderer()->getContentSize();
    done_btn->setContentSize(
            Size(
                lbl_size.width * 1.5f,
                lbl_size.height * 1.5f
                )
            );

    done_btn->ignoreContentAdaptWithSize(false); //word wrap or something

    done_btn->setTitleColor(Color3B::BLACK);
    done_btn->setScaleX(sx(1.0f));
    done_btn->setScaleY(sy(1.0f));
    alert->done_btn = done_btn;


    ui::RelativeLayoutParameter* done_param = ui::RelativeLayoutParameter::create();
    done_param->setAlign(ui::RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL);
    done_param->setMargin(ui::Margin(sx(30), sy(20), sx(30), sy(30)));
    done_param->setRelativeName("done_btn");
    alert->done_btn->setLayoutParameter(done_param);
    alert->addChild(alert->done_btn);

    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);

    listener->onTouchBegan = CC_CALLBACK_2(Alert::onTouchBegan, alert);
    listener->onTouchEnded = CC_CALLBACK_2(Alert::onTouchEnded, alert);

    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, alert);

    return alert;
};