Esempio n. 1
0
File: base.cpp Progetto: 0of/fido
int main() {
  // init container
  auto container = std::make_unique<LTest::SequentialTestRunnableContainer>();

  // alloc spec
  auto spec = std::make_shared<LTest::SequentialTestSpec>();

  // init spec
  initSpec(*spec);

  // assign the spec as first runnable to run
  container->scheduleToRun(spec);

  // run the container
  container->start();

  return 0;
}
Esempio n. 2
0
void MainLayer::initSpec()
{
	if (!_isUseSpec)
		return;

	auto delay = DelayTime::create(0.5f);
	auto callback = CallFunc::create([=](){
		if (_specIndex == PAGE_COUNT) {
			_pageView->setPositionX(0);
			_specIndex = 0;
		}
		else {
			this->createSpec(_specIndex);
			_specIndex++;
			initSpec();
		}});
	this->runAction(Sequence::createWithTwoActions(delay, callback));
}
Esempio n. 3
0
bool MainLayer::initUI()
{
	_rootNode = CSLoader::createNode("MainScene.csb");
	_hideNode = _rootNode->getChildByName<Node*>("Node_Main");
	this->addChild(_rootNode);

	for (auto& child : LsTools::seekNodeByName(_rootNode, "Node_btn")->getChildren()) {
		auto btn = dynamic_cast<Button*>(child);
		btn->addTouchEventListener(CC_CALLBACK_2(MainLayer::clickMainBtn, this));
	}

	_pageView = static_cast<PageView*>(LsTools::seekNodeByName(_rootNode, "PageView"));
	CCASSERT(_pageView, "page view");
	_pageView->setCustomScrollThreshold(MY_SCREEN.width / 8);
	_pageView->setUsingCustomScrollThreshold(true);
	_pageView->addEventListener(CC_CALLBACK_2(MainLayer::pageViewEvent, this));
	_pageView->setClippingType(Layout::ClippingType::SCISSOR);
	_mapFocusZOrder.clear();
	for (ssize_t i = 0; i < PAGE_COUNT; i++) {
		auto page = _pageView->getPage(i);

		if (i == MAIN_PAGE) {
			for (auto& child : page->getChildren()) {
				//排除倒影
				std::string::size_type idx = child->getName().find("dy_");
				if (idx != std::string::npos)
					continue;
				_mapFocusZOrder.insert(std::pair<int, int>(child->getTag(), child->getLocalZOrder()));
				auto view = dynamic_cast<ImageView*>(child);
				view->addTouchEventListener(CC_CALLBACK_2(MainLayer::clickMainPageItem, this));
				if (view->getTag() == 22){
					_recommend = view;
					CC_SAFE_RETAIN(_recommend);
				}
			}
		}
		else if (i == MAIN_PAGE_PLUS){
			for (auto& child : page->getChildren()) {
				//排除倒影
				std::string::size_type idx = child->getName().find("dy_");
				if (idx != std::string::npos)
					continue;
				_mapFocusZOrder.insert(std::pair<int, int>(child->getTag(), child->getLocalZOrder()));
				auto view = dynamic_cast<ImageView*>(child);
				view->addTouchEventListener(CC_CALLBACK_2(MainLayer::clickMainPlusPageItem, this));
			}
		}
		else if (i == CATEGORY_PAGE) {
			for (auto& child : page->getChildren()) {
				std::string::size_type idx = child->getName().find("dy_");
				if (idx != std::string::npos)
					continue;
				_mapFocusZOrder.insert(std::pair<int, int>(child->getTag(), child->getLocalZOrder()));
				auto view = dynamic_cast<ImageView*>(child);
				view->addTouchEventListener(CC_CALLBACK_2(MainLayer::clickCategoryPageItem, this));
			}
		}
		else if (i == MANAGE_PAGE) {
			for (auto& child : page->getChildren()) {
				std::string::size_type idx = child->getName().find("dy_");
				if (idx != std::string::npos)
					continue;
				_mapFocusZOrder.insert(std::pair<int, int>(child->getTag(), child->getLocalZOrder()));
				auto view = dynamic_cast<ImageView*>(child);
				if (view->getName() == "3")	//Remote QR
				{
					CQR_Encode code;
					float size = 5.5f;
					std::string ip = PH::getPlatformIP();
					std::string str = ZM->getServerAddress() + "?" + formatStr("commend=%d&xLinkIP=%s", CommendEnum::DOWNLOAD_REMOTE, ip.c_str());
					LS_LOG("CQR_Encode:%s", str.c_str());
					auto drawNode = LsTools::createQRAndDraw(code, size, LsTools::str2charp(str));
					drawNode->setPosition(cocos2d::Vec2((view->getContentSize().width - size * code.m_nSymbleSize) / 2 - 6,
						view->getContentSize().height - (view->getContentSize().height - size * code.m_nSymbleSize) / 2 + 45));
					view->addChild(drawNode);
				}
				else
					view->addTouchEventListener(CC_CALLBACK_2(MainLayer::clickManagerPageItem, this));
			}
		}
	}
	_tabNode = _pageView->getPage(_pageView->getCurPageIndex());
	_navi_Scelect = dynamic_cast<Sprite*>(LsTools::seekNodeByName(_rootNode, "Navi_Scelect"));
	_bg = _rootNode->getChildByName<Sprite*>("background");

	//倒影
	if (_isUseSpec)
	{
		initSpec();

		for (int i = 0; i < PAGE_COUNT; i++)
		{
			auto sprite = dynamic_cast<Sprite*>(LsTools::seekNodeByName(_rootNode, formatStr("dy_%d", i)));
			sprite->setVisible(true);
			GLchar * fragSource = (GLchar*)String::createWithContentsOfFile(
				FileUtils::getInstance()->fullPathForFilename("blend.fsh").c_str())->getCString();
			auto glprogram = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, fragSource);
			auto program = GLProgramState::getOrCreateWithGLProgram(glprogram);
			V3F_C4B_T2F_Quad quad = sprite->getQuad();
			float minTex = (quad.tl.texCoords.v > quad.bl.texCoords.v ? quad.bl.texCoords.v : quad.tl.texCoords.v);
			float maxTex = (quad.tl.texCoords.v < quad.bl.texCoords.v ? quad.bl.texCoords.v : quad.tl.texCoords.v);
			program->setUniformFloat("minTex", minTex);
			program->setUniformFloat("maxTex", maxTex);
			sprite->setGLProgramState(program);
		}
	}

	return true;
}