void FiniteTimeActionComponent::queueAction(cocos2d::FiniteTimeAction* action, std::function<void()> && callback /*= nullptr*/)
{
	assert(action && "FiniteTimeActionComponent::queueAction() trying to queue an empty action.");

	//Create a callback that recalls runNextAction(). Important for automatically running queued actions.
	auto weakPimpl = std::weak_ptr<FiniteTimeActionComponentImpl>(pimpl);
	auto recallSelf = cocos2d::CallFunc::create([weakPimpl]() {
		if (!weakPimpl.expired()) {
			auto strongPimpl = weakPimpl.lock();
			strongPimpl->eraseCurrentAction();
			strongPimpl->runNextAction(true);
		}
	});

	//Queue an action sequence that wraps the parameters and recallSelf.
	if (callback)
		pimpl->pushBackAction(cocos2d::Sequence::create(action, cocos2d::CallFunc::create(callback), recallSelf, nullptr));
	else
		pimpl->pushBackAction(cocos2d::Sequence::create(action, recallSelf, nullptr));

	if (pimpl->m_IsRunAutomatically)
		runNextAction();
}
Example #2
0
/*
 *  Constructs a QG_CadToolBarSelect as a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 */
QG_CadToolBarSelect::QG_CadToolBarSelect(QG_CadToolBar* parent, Qt::WindowFlags fl)
    :LC_CadToolBarInterface(parent, fl)
    ,nextAction(-1)
    ,selectAction(nullptr)
{
    initToolBars();
    if(layout()) {
        QToolButton* button=new QToolButton;
        button->setDefaultAction(m_pButtonForward);
        button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
        layout()->addWidget(button);
        static_cast<QVBoxLayout*>(layout())->addStretch(1);
    }
    connect(m_pButtonForward, SIGNAL(triggered()), this, SLOT(runNextAction()));
}
Example #3
0
/**
 * Called from the application.
 */
void QG_CadToolBar::forceNext() {
    if(activeToolbars.size()==0) return;
	auto p=activeToolbars.back();
	if (p && p->rtti() == RS2::ToolBarSelect)
		p->runNextAction();
}
void FiniteTimeActionComponent::setRunAutomatically(bool automatically)
{
	pimpl->m_IsRunAutomatically = automatically;

	runNextAction();
}