Example #1
0
/* Creating of the options from the script. */
bool DIALOGUE::CreateOptions(){

	// atributes
	std::wstring text;
	Gdiplus::GraphicsPath path;
	// caused changes which will be paired with the options
	std::string state_name;
	std::vector<state_changes> changes; 

	if(!script.FindElem(L"OPTIONS")){
		TermLog("Options tag not found in the Dialogue scene, script.xml file is probably damaged.");
		return false;
	}
	script.IntoElem();

	// Going through the options
	if(!script.FindElem(L"OPTION")){
		script.OutOfElem();
		TermLog("No option to choose found in the dialogue scene.");
		return false;
	}
	else do {
		text = script.GetAttrib(L"text");
		
		line_top -= line_height; // Put the line above the previous
		stat = path.AddString(text.c_str(), -1, fontFamily, Gdiplus::FontStyleBold, text_size, Gdiplus::PointF(0, Gdiplus::REAL(line_top)), &strformat);
			if (stat != 0) StatusLog("GraphicPath.AddString()", stat, false);

		script.IntoElem();

		if(!CheckTests()){
			script.OutOfElem();
			continue;
		}


		// creates the map of state changes
		while(script.FindElem(L"STATECHANGE")){
			state_changes current_changes;
			current_changes.name = wstring2string(script.GetData());
			current_changes.value = atoi((wstring2string(script.GetAttrib(L"value"))).c_str());
			current_changes.replace = atoi((wstring2string(script.GetAttrib(L"replace"))).c_str())  != 0 ? true : false;
			changes.push_back(current_changes);
		}
		
		script.OutOfElem(); // Jumps out of the object

		options.push_back(OPTION(text, &path, changes));
		changes.clear();
		StatusLog("GraphicPath.Reset()", path.Reset(), false);

	} while(script.FindElem(L"OPTION"));

	script.OutOfElem();
	return true;
}
Example #2
0
void CSkinUnitODL::DrawImage(Gdiplus::Graphics& gcDrawer, Gdiplus::GraphicsPath& gcPath, Gdiplus::PointF& ptOffset, Gdiplus::REAL fScale)
{
	if (m_imgSkin)
	{
		if (m_nWrapMode>=4)
		{
			//居中模式
			Gdiplus::RectF rtArea;
			gcPath.GetBounds(&rtArea);
			Gdiplus::GraphicsPath gcDrawPath;
			//图片中间X:(width-imagewidth )/2 + left;
			//Y: (height - imageheight)/2 +top;

			Gdiplus::REAL fX0 = (rtArea.Width - m_fSkinWidth-m_nGroutX) /2.0f + rtArea.X;
			Gdiplus::REAL fY0 = (rtArea.Height - m_fSkinHeight-m_nGroutY) /2.0f + rtArea.Y;
			Gdiplus::REAL fX1 = m_fSkinWidth + m_nGroutX+ fX0;
			Gdiplus::REAL fY1 = m_fSkinHeight +m_nGroutY+ fY0;
			std::vector<Gdiplus::PointF> arrPt;
			arrPt.emplace_back(fX0, fY0);
			arrPt.emplace_back(fX1, fY0);
			arrPt.emplace_back(fX1, fY1);
			arrPt.emplace_back(fX0, fY1);
			Gdiplus::Matrix mx;
			Gdiplus::PointF ptCenter=Gdiplus::PointF((fX1+fX0)/2.0f, (fY1+fY0)/2.0f);
			mx.RotateAt(m_fRotate, ptCenter);
			mx.TransformPoints(arrPt.data(), arrPt.size());
			gcDrawPath.AddPolygon(arrPt.data(),arrPt.size());
			//如果图片的path大于当前区域Path,则居中操作在区域内
			{
				BRepBuilderAPI_MakePolygon ply1;
				for (auto& ptPos:arrPt)
				{
					ply1.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y));
				}
				ply1.Close();
				TopoDS_Face face1 = BRepBuilderAPI_MakeFace(ply1.Wire()).Face();
				std::vector<Gdiplus::PointF> arrPic;
				arrPic.resize(gcDrawPath.GetPointCount());
				gcPath.GetPathPoints(arrPic.data(), arrPic.size());

				BRepBuilderAPI_MakePolygon ply2;
				for (auto& ptPos:arrPic)
				{
					ply2.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y));
				}
				ply2.Close();
				TopoDS_Face face2 = BRepBuilderAPI_MakeFace(ply2.Wire()).Face();

				BRepAlgoAPI_Common bc(face1, face2);
				auto face = bc.Shape();
				TopExp_Explorer expWire(face, TopAbs_WIRE);
				std::vector<Gdiplus::PointF> arrDraw;
				for ( BRepTools_WireExplorer expVertex(TopoDS::Wire(expWire.Current())); expVertex.More(); expVertex.Next() )
				{
					auto pnt = BRep_Tool::Pnt(expVertex.CurrentVertex());
					arrDraw.emplace_back(static_cast<Gdiplus::REAL>(pnt.X()), static_cast<Gdiplus::REAL>(pnt.Z()));
				}
				gcDrawPath.Reset();
				gcDrawPath.AddPolygon(arrDraw.data(), arrDraw.size());
			}

			Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode;
			if (std::fabs(m_fRotate)<0.001f)
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				mx.Translate(fX0, fY0);
				brush.SetTransform(&mx);
				gcDrawer.FillPath(&brush, &gcDrawPath);
			}
			else
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				mx.Translate(fX0, fY0);
				brush.SetTransform(&mx);
				gcDrawer.FillPath(&brush, &gcDrawPath);
			}
		}
		else
		{
			//铺满模式
			Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode;
			if (std::fabs(m_fRotate)<0.001f)
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				brush.TranslateTransform(ptOffset.X, ptOffset.Y);
				gcDrawer.FillPath(&brush, &gcPath);
			}
			else
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				brush.TranslateTransform(ptOffset.X, ptOffset.Y);
				brush.RotateTransform(m_fRotate);
				gcDrawer.FillPath(&brush, &gcPath);
			}
		}
		
	}
}
Example #3
0
/* Function creates objects from script - first it take names and than it creates path for a region and afterwards the map of state changes. */
bool INTERACTIVE::CreateObjects() {
	// attributes
	std::wstring name;
	std::wstring caption;
	std::string sound_path;
	std::string caption_sound_path;
	bool finish_scene;

	// object's space
	Gdiplus::GraphicsPath boundaries;
	int verticle_count;
	Gdiplus::Point * verticles;
	int x, y;

	// caused changes
	std::string state_name;
	std::vector<state_changes> changes; 

	// control
	bool verticles_OK = true;

	// Tag is not necessary for the editor
	if(!script.FindElem(L"OBJECTS"))
		return true;
	script.IntoElem();

	// Tag is not necessary for the editor
	if(!script.FindElem(L"OBJECT")){
		script.OutOfElem();
		return true;
	}
	else do {
		// atributes reading
		name = script.GetAttrib(L"name");
		caption = script.GetAttrib(L"caption");
		sound_path = wstring2string(script.GetAttrib(L"sound_source"));
		caption_sound_path = wstring2string(script.GetAttrib(L"caption_sound")); 
		verticle_count = atoi((wstring2string(script.GetAttrib(L"v_count"))).c_str());
		if(verticle_count < 3){
			Log("Verticle count in one of the objects is too low");
			verticles_OK = false;
		} 
		finish_scene = (atoi((wstring2string(script.GetAttrib(L"finish_scene"))).c_str())) != 0 ? true : false;
		
		script.IntoElem(); // Jumps into the object

		if(!CheckTests()){
			script.OutOfElem();
			continue;
		}

		// creates verticles for the object polygon
		verticles = new Gdiplus::Point [verticle_count];
		for(int i = 0; i < verticle_count; i++){
			if(!script.FindElem(L"VERTEX")){
				Log("There is not responding count of vertices in one object in script.");
				verticles_OK = false;
			}
			x = atoi((wstring2string(script.GetAttrib(L"x"))).c_str()); 
			y = atoi((wstring2string(script.GetAttrib(L"y"))).c_str()); 
			verticles[i] = Gdiplus::Point(x, y);
			
		}
		if(!verticles_OK){
			delete [] verticles;
			script.OutOfElem();
			continue;
		}
		else{
			boundaries.AddPolygon(verticles, verticle_count);
			delete [] verticles;
		}

		// creates the vector of state changes
		while(script.FindElem(L"STATECHANGE")){
			state_changes current_changes;
			current_changes.name = wstring2string(script.GetData());
			current_changes.value = atoi((wstring2string(script.GetAttrib(L"value"))).c_str());
			current_changes.replace = atoi((wstring2string(script.GetAttrib(L"replace"))).c_str())  != 0 ? true : false;
			changes.push_back(current_changes);
		}
		
		script.OutOfElem(); // Jumps out of the object

		objects.push_back(SCENE_OBJECT(&boundaries, name, caption, sound_path, caption_sound_path, changes, finish_scene));
		boundaries.Reset();
		changes.clear();

	} while(script.FindElem(L"OBJECT"));

	script.OutOfElem();
	return true;
}