Example #1
0
bool ccPolyline::initWith(ccPointCloud*& vertices, const ccPolyline& poly)
{
	bool success = true;
	if (!vertices)
	{
		ccPointCloud* cloud = dynamic_cast<ccPointCloud*>(poly.m_theAssociatedCloud);
		ccPointCloud* clone = cloud ? cloud->partialClone(&poly) : ccPointCloud::From(&poly);
		if (clone)
		{
			if (cloud)
				clone->setName(cloud->getName()); //as 'partialClone' adds the '.extract' suffix by default
			else
				clone->setGLTransformationHistory(poly.getGLTransformationHistory());
		}
		else
		{
			//not enough memory?
			ccLog::Warning("[ccPolyline::initWith] Not enough memory to duplicate vertices!");
			success = false;
		}

		vertices = clone;
	}

	if (vertices)
	{
		setAssociatedCloud(vertices);
		addChild(vertices);
		//vertices->setEnabled(false);
		assert(m_theAssociatedCloud);
		if (m_theAssociatedCloud)
			addPointIndex(0,m_theAssociatedCloud->size());
	}

	setClosed(poly.m_isClosed);
	set2DMode(poly.m_mode2D);
	setForeground(poly.m_foreground);
	setVisible(poly.isVisible());
	lockVisibility(poly.isVisiblityLocked());
	setColor(poly.m_rgbColor);
	setWidth(poly.m_width);
	showColors(poly.colorsShown());
	showVertices(poly.verticesShown());
	setVertexMarkerWidth(poly.getVertexMarkerWidth());
	setVisible(poly.isVisible());
	showArrow(m_showArrow,m_arrowIndex,m_arrowLength);
	setGlobalScale(poly.getGlobalScale());
	setGlobalShift(poly.getGlobalShift());
	setGLTransformationHistory(poly.getGLTransformationHistory());
	setMetaData(poly.metaData());
	
	return success;
}
Example #2
0
void ccPolyline::importParametersFrom(const ccPolyline& poly)
{
	setClosed(poly.m_isClosed);
	set2DMode(poly.m_mode2D);
	setForeground(poly.m_foreground);
	setVisible(poly.isVisible());
	lockVisibility(poly.isVisiblityLocked());
	setColor(poly.m_rgbColor);
	setWidth(poly.m_width);
	showColors(poly.colorsShown());
	showVertices(poly.verticesShown());
	setVertexMarkerWidth(poly.getVertexMarkerWidth());
	setVisible(poly.isVisible());
	showArrow(m_showArrow,m_arrowIndex,m_arrowLength);
	setGlobalScale(poly.getGlobalScale());
	setGlobalShift(poly.getGlobalShift());
	setGLTransformationHistory(poly.getGLTransformationHistory());
	setMetaData(poly.metaData());
}
Example #3
0
ccPolyline::ccPolyline(GenericIndexedCloudPersist* associatedCloud)
	: Polyline(associatedCloud)
	, ccShiftedObject("Polyline")
{
	set2DMode(false);
	setForeground(true);
	setVisible(true);
	lockVisibility(false);
	setColor(ccColor::white);
	showVertices(false);
	setVertexMarkerWidth(3);
	setWidth(0);
	showArrow(false,0,0);

	ccGenericPointCloud* cloud = dynamic_cast<ccGenericPointCloud*>(associatedCloud);
	if (cloud)
	{
		setGlobalScale(cloud->getGlobalScale());
		setGlobalShift(cloud->getGlobalShift());
	}
}
Example #4
0
/**
*函数说明:移动触摸,将触摸到的新汉字元素放进已选汉字盒子
*如果是倒退,那么将最后一个汉字元素从已选汉字盒子中删除
*每一次增加/删除汉字元素,都会判断当前已选的汉字是否能消除
*/
void ChrsGrid::onTouchMoved(Touch* pTouch, Event*)
{
	//移动时也可选择
	//将触摸点的坐标转化为模型坐标
	auto pos = this->convertToNodeSpace(pTouch->getLocation());

	//得到阵列坐标
	int x = pos.x / GRID_WIDTH;
	int y = pos.y / GRID_WIDTH;

	//得到汉字原点模型坐标
	auto chr_pos = Vec2(x * GRID_WIDTH, y * GRID_WIDTH);

	//是否按在汉字上
	if (y < m_row && x < m_col && Rect(chr_pos.x + 5, chr_pos.y + 5, CHR_WITDH, CHR_WITDH).containsPoint(pos))
	{
		//得到当前触摸点的汉字元素,以及最后一次选择的汉字
		auto chr = m_ChrsBox[x][y];
		auto last_chr = m_SelectedChrs.back();

		//判断当前触摸点的汉字是否与最后一次选择的相邻
		int dx = abs(chr->getX() - last_chr->getX());
		int dy = abs(chr->getY() - last_chr->getY());
		int d = dx + dy;
		if (dx < 2 && dy < 2 && d <= 2 && d > 0)
		{
			//如果符合情况,那么将其加入临时选择汉字盒子,并设置选中颜色
			//只有当临时选择汉字集合中没有该汉字元素时,才添加
			if (!m_SelectedChrs.contains(chr))
			{
				//判断哪个箭头显示
				last_chr->showArrow(chr);

				m_SelectedChrs.pushBack(chr);
				chr->getBg()->setTexture("char_bg_selected.png");

				//执行按住后动作
				chr->chrAciton();

				//得到能否消除的状态
				m_canCrush = canCrush();
				if (m_canCrush)
				{
					for (auto &chr : m_SelectedChrs)
					{
						chr->chrAciton();
					}
				}
			}
		}

		//如果当前触摸点是已选汉字盒子中倒数第二个汉字,说明是后退操作
		//将倒数第一个元素删除出已选汉字盒子
		if (m_SelectedChrs.size() >= 2)
		{
			//得到倒数第二个元素,判断是否和触摸点的元素一致
			auto secondlast_chr = m_SelectedChrs.at(m_SelectedChrs.size()-2);
			if (secondlast_chr == chr)
			{
				//对最后一个元素执行释放后动作
				m_SelectedChrs.back()->chrAciton();

				//将最后一个元素删除出去
				m_SelectedChrs.back()->getBg()->setTexture(m_SelectedChrs.back()->getNormalBG());
				m_SelectedChrs.popBack();

				//然后将现有最后一个的汉字的箭头隐藏
				auto chr = m_SelectedChrs.back();
				auto arrow = chr->getArrow();
				for (int i = 0; i < 8; i++) { if (arrow[i]->isVisible()) arrow[i]->setVisible(false); }

				m_canCrush = canCrush();
				/*
				if (m_canCrush)
				{
				for (auto &chr : m_SelectedChrs)
				{
				chr->chrAciton();
				}
				}
				*/
			}

			//更改主界面的letter label的显示
			getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), m_canCrush);
		}
	}
}