Esempio n. 1
0
void DramaChatLayer::SetFigure(std::string filename, bool bReverse, int nCol, int nRow)
{
	NDNode* node = GetChild(m_nTagFigure);

	if (node && node->IsKindOfClass(RUNTIME_CLASS(NDUIImage)))
	{
		NDPicture* pic = NDPicturePool::DefaultPool()->AddPicture(
				filename);
		pic->SetReverse(bReverse);

		int nCutX= nCol * 256;
		int nCutY= nRow * 256;
		pic->Cut(CCRectMake(nCutX+1, nCutY+1, 255, 255));

		((NDUIImage*) node)->SetPicture(pic);
	}
}
Esempio n. 2
0
bool DrawAni::doDraw(const int frameIndex, const AniModify* mod_lev2,
					 const AniModify* mod_lev3)
{
	if (!m_pkAni || !m_pkInstance || !m_pkInstance->getOwnerNode())
		return false;

	// get picture to draw
	NDPicture* pkPicture = getPicture(m_pkAni, frameIndex);
	if (!pkPicture)
		return false;

	// get node screen rect
	CCRect kNodeRect;
	NDNode* pkOwnerNode = m_pkInstance->getOwnerNode();

	if (pkOwnerNode->IsA(RTCLS(NDTileObj)))
	{
		NDTileObj* pkTileObj = (NDTileObj*) pkOwnerNode;
		if (pkTileObj->isPlayer() || pkTileObj->isPath())
			kNodeRect = pkOwnerNode->GetScreenRect();
		else
			kNodeRect = pkOwnerNode->GetPushScreenRect();
	}
	else
	{
		kNodeRect = pkOwnerNode->GetScreenRect();
	}

	// node center pos (caution: world map tile obj!)
	CCPoint centerPos = CCPointMake(
		kNodeRect.origin.x + kNodeRect.size.width * 0.5f,
		kNodeRect.origin.y + kNodeRect.size.height * 0.5f);

	// get node scale (recursive)
	float nodeScaleX = pkOwnerNode->GetScaleX_R();
	float nodeScaleY = pkOwnerNode->GetScaleY_R();

	// add offset
	int sign = pkOwnerNode->isReverse() ? -1 : 1;
	centerPos.x += m_pkAni->m_kAniModifyEx.getOffsetX() * COORD_SCALE_X_960 * nodeScaleX
		* sign;
	centerPos.y += m_pkAni->m_kAniModifyEx.getOffsetY() * COORD_SCALE_Y_960 * nodeScaleY;

	// apply mod: offset
	if (mod_lev2)
	{
		centerPos.x += mod_lev2->getOffsetX() * COORD_SCALE_X_960 * nodeScaleX
			* sign;
		centerPos.y += mod_lev2->getOffsetY() * COORD_SCALE_Y_960 * nodeScaleY;
	}
	if (mod_lev3)
	{
		centerPos.x += mod_lev3->getOffsetX() * COORD_SCALE_X_960 * nodeScaleX
			* sign;
		centerPos.y += mod_lev3->getOffsetY() * COORD_SCALE_Y_960 * nodeScaleY;
	}

	// calculate pic size
	CCSize picSize = pkPicture->GetSize();
	if (m_pkAni->m_kAniModifyEx.getStretch())
	{
		picSize.width *= COORD_SCALE_X_960;
		picSize.height *= COORD_SCALE_Y_960;
	}
	else
	{
		picSize.width *= RESOURCE_SCALE_960;
		picSize.height *= RESOURCE_SCALE_960;
	}

	if (m_pkAni->m_kAniModifyEx.getFullScreen())
	{
		// apply fullscreen 
		picSize = CCDirector::sharedDirector()->getWinSizeInPixels();
	}
	else
	{
		// size override
		if (m_pkAni->m_kAniModifyEx.sizeOverride())
		{
			picSize = CCSizeMake(m_pkAni->m_kAniModifyEx.getWidth(), m_pkAni->m_kAniModifyEx.getHeight());
		}

		// apply node scale
		picSize.width *= nodeScaleX;
		picSize.height *= nodeScaleY;

		// apply scale
		picSize.width *= m_pkAni->m_kAniModifyEx.getScale();
		picSize.height *= m_pkAni->m_kAniModifyEx.getScale();

		// apply mod: scale
		if (mod_lev2)
		{
			picSize.width *= mod_lev2->getScale();
			picSize.height *= mod_lev2->getScale();
		}
		if (mod_lev3)
		{
			picSize.width *= mod_lev3->getScale();
			picSize.height *= mod_lev3->getScale();
		}
	}

	// apply alpha
	applyAlpha(pkPicture, mod_lev2);

	// apply HSL
	applyHSL(pkPicture, mod_lev2);

	// target rect to draw in
	CCRect picRect = CCRectMake(centerPos.x - picSize.width * 0.5f,
		centerPos.y - picSize.height * 0.5f, picSize.width, picSize.height);

	// check to disable scissor
	if (!isAllowScissor())
	{
		NDDirector::DefaultDirector()->DisableScissor();
	}

	// draw
	if (m_pkInstance && m_pkInstance->getOwnerNode())
	{
		// apply from action: opacity/rotation/gaussianBlur
		NDNode* pkOwnerNode = m_pkInstance->getOwnerNode();
		pkPicture->SetOpacity(pkOwnerNode->getRGBA()->getOpacity());
		pkPicture->SetRotation(pkOwnerNode->getCCNode()->getRotation());
		pkPicture->SetRotationX(pkOwnerNode->getCCNode()->getRotationX());
		pkPicture->SetRotationY(pkOwnerNode->getCCNode()->getRotationY());
		pkPicture->setGaussianBlur(pkOwnerNode->getCCNode()->getGaussianBlur());

		// toggle reverse
		bool bReverse = m_pkAni->m_kAniModifyEx.getReverse();
		if (pkOwnerNode->isReverse())
			bReverse = !bReverse;
		pkPicture->SetReverse(bReverse);
	}
	pkPicture->DrawInRect(picRect);
}