Ejemplo n.º 1
0
///  gui tweak page, material properties
//------------------------------------------------------------------------------------------------------------
void CGui::CreateGUITweakMtr()
{
	ScrollView* view = app->mGui->findWidget<ScrollView>("TweakView",false);
	if (!view)  return;
	
	//  clear last view
	MyGUI::EnumeratorWidgetPtr widgets = view->getEnumerator ();
	app->mGui->destroyWidgets(widgets);

	if (pSet->tweak_mtr == "")  return;
	sh::MaterialInstance* mat = app->mFactory->getMaterialInstance(pSet->tweak_mtr);
	//if (!mat)  return;
	
	int y = 0;
	const sh::PropertyMap& props = mat->listProperties();
	for (sh::PropertyMap::const_iterator it = props.begin(); it != props.end(); ++it)
	{
		sh::PropertyValuePtr pv = (*it).second;
		std::string name = (*it).first;
		
		//  get type
		std::string sVal = pv->_getStringValue();
		//? if (boost::is_alnum(sVal))  continue;
		bool isStr = false;
		for (int c=0; c < sVal.length(); ++c)  if (sVal[c] >= 'a' && sVal[c] <= 'z')
			isStr = true;

		if (!isStr)
		{
			//  get size
			std::vector<std::string> tokens;
			boost::split(tokens, sVal, boost::is_any_of(" "));
			int size = tokens.size();

			//LogO("PROP: " + name + "  val: " + sVal + "  type:" + toStr(type));
			const static char ch[6] = "rgbau";
			const static Colour clrsType[5] = {Colour(0.9,0.9,0.7),Colour(0.8,1.0,0.8),
						Colour(0.7,0.85,1.0),Colour(0.7,1.0,1.0),Colour(1.0,1.0,1.0)};

			//  for each component (xy,rgb..)
			for (int i=0; i < size; ++i)
			{
				String nameSi = name + ":" + toStr(size) + "." + toStr(i);  // size and id in name
				float val = boost::lexical_cast<float> (tokens[i]);
				int t = std::min(4,i);  const Colour& clr = clrsType[std::max(0,std::min(4,size-1))];

				//  name text
				int x = 0, xs = 150;
				TextBox* txt = view->createWidget<TextBox>("TextBox", x,y, xs,20, Align::Default, nameSi + ".txt");
				gcom->setOrigPos(txt, "OptionsWnd");  txt->setTextColour(clr);
				txt->setCaption(size == 1 ? name : name + "." + ch[t]);

				//  val edit
				x += xs;  xs = 60;
				EditBox* edit = view->createWidget<EditBox>("EditBox", x,y, xs,20, Align::Default, nameSi + "E");
				gcom->setOrigPos(edit, "OptionsWnd");  edit->setTextColour(clr);  edit->setColour(clr);
				edit->setCaption(fToStr(val,3,6));
				if (edit->eventEditTextChange.empty())  edit->eventEditTextChange += newDelegate(this, &CGui::edTweak);
				
				//  slider
				x += xs + 10;  xs = 400;
				Slider* sl = view->createWidget<Slider>("Slider", x,y-1, xs,19, Align::Default, nameSi);
				gcom->setOrigPos(sl, "OptionsWnd");  sl->setColour(clr);
				sl->setValue(val);  //powf(val * 1.f/2.f, 1.f/2.f));  //v
				if (sl->eventValueChanged.empty())  sl->eventValueChanged += newDelegate(this, &CGui::slTweak);

				y += 22;
			}
			y += 8;
		}
	}
	view->setCanvasSize(1100, y+500);  //?..
	view->setCanvasAlign(Align::Default);

	gcom->doSizeGUI(view->getEnumerator());
}