Esempio n. 1
0
std::string cLed::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	Iterator<Node> node;
	std::string name, id;
	int width = 0, height = 0;
	bool foundTop = false, foundLeft = false; // requireds
	rectangle frame;
	if(parent->getBg() == cDialog::BG_DARK)
		setColour(sf::Color::White);
	for(attr = attr.begin(&who); attr != attr.end(); attr++){
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "state"){
			std::string val;
			attr->GetValue(&val);
			if(val == "red") setState(led_red);
			else if(val == "green") setState(led_green);
			else if(val == "off") setState(led_off);
			else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
//		}else if(name == "fromlist"){
//			attr->GetValue(&fromList);
		}else if(name == "font"){
			std::string val;
			attr->GetValue(&val);
			if(val == "dungeon")
				setFormat(TXT_FONT, FONT_DUNGEON);
			else if(val == "plain")
				setFormat(TXT_FONT, FONT_PLAIN);
			else if(val == "bold")
				setFormat(TXT_FONT, FONT_BOLD);
			else if(val == "maidenword")
				setFormat(TXT_FONT, FONT_MAIDWORD);
			else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
		}else if(name == "size"){
			std::string val;
			attr->GetValue(&val);
			if(val == "large")
				setFormat(TXT_SIZE, 12);
			else if(val == "small")
				setFormat(TXT_SIZE, 10);
			else if(val == "title")
				setFormat(TXT_SIZE, 18);
			else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
		}else if(name == "color" || name == "colour"){
			std::string val;
			attr->GetValue(&val);
			sf::Color clr;
			try{
				clr = parseColor(val);
			}catch(int){
				throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
			}
			setColour(clr);
		} else if(name == "wrap") {
			std::string val;
			attr->GetValue(&val);
			if(val == "true")
				setFormat(TXT_WRAP, true);
			else setFormat(TXT_WRAP, false);
		}else if(name == "top"){
			attr->GetValue(&frame.top), foundTop = true;
		}else if(name == "left"){
			attr->GetValue(&frame.left), foundLeft = true;
		}else if(name == "width"){
			attr->GetValue(&width);
		}else if(name == "height"){
			attr->GetValue(&height);
		}else throw xBadAttr("led",name,attr->Row(),attr->Column(),fname);
	}
	if(!foundTop) throw xMissingAttr("led","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("led","left",who.Row(),who.Column(),fname);
	if(width > 0) {
		frame.right = frame.left + width;
	}else{
		frame.right = frame.left + 14;
	}
	if(height > 0) {
		frame.bottom = frame.top + height;
	}else{
		frame.bottom = frame.top + 10;
	}
	setBounds(frame);
	std::string content;
	for(node = node.begin(&who); node != node.end(); node++){
		std::string val;
		int type = node->Type();
		node->GetValue(&val);
		if(type == TiXmlNode::TEXT)
			content += dlogStringFilter(val);
		else if(type != TiXmlNode::COMMENT) {
			val = '<' + val + '>';
			throw xBadVal("led",xBadVal::CONTENT,content + val,node->Row(),node->Column(),fname);
		}
	}
	setText(content);
	return id;
}
Esempio n. 2
0
std::string cScrollPane::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	Iterator<Element> node;
	std::string name, id;
	rectangle frame;
	int width = 0, height = 0;
	bool foundTop = false, foundLeft = false;
	scroll.setStyle(SCROLL_LED);
	for(attr = attr.begin(&who); attr != attr.end(); attr++) {
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "top")
			attr->GetValue(&frame.top), foundTop = true;
		else if(name == "left")
			attr->GetValue(&frame.left), foundLeft = true;
		else if(name == "width")
			attr->GetValue(&width);
		else if(name == "height")
			attr->GetValue(&height);
		else if(name == "framed") {
			std::string val;
			attr->GetValue(&val);
			if(val == "true") setFormat(TXT_FRAME, true);
			else setFormat(TXT_FRAME, false);
		}else if(name == "outline") {
			std::string val;
			attr->GetValue(&val);
			if(val == "solid") setFormat(TXT_FRAMESTYLE, FRM_SOLID);
			else if(val == "inset") setFormat(TXT_FRAMESTYLE, FRM_INSET);
			else if(val == "outset") setFormat(TXT_FRAMESTYLE, FRM_OUTSET);
			else if(val == "double") setFormat(TXT_FRAMESTYLE, FRM_DOUBLE);
		}else if(name == "style"){
			std::string val;
			attr->GetValue(&val);
			if(val == "white") setStyle(SCROLL_WHITE);
			else if(val == "led") setStyle(SCROLL_LED);
			else throw xBadVal("slider", name, val, attr->Row(), attr->Column(), fname);
		} else throw xBadAttr("pane",name,attr->Row(),attr->Column(),fname);
	}
	if(!foundTop) throw xMissingAttr("pane","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("pane","left",who.Row(),who.Column(),fname);
	if(width > 0) {
		frame.width() = width;
	}else{
		throw xMissingAttr("pane","width",who.Row(),who.Column(),fname);
	}
	if(height > 0) {
		frame.height() = height;
	}else{
		frame.height() = 10;
	}
	setBounds(frame);
	for(node = node.begin(&who); node != node.end(); node++) {
		std::string val;
		int type = node->Type();
		node->GetValue(&val);
		if(type == TiXmlNode::ELEMENT) {
			if(val == "field") {
				auto field = parent->parse<cTextField>(*node);
				contents.insert(field);
				// TODO: Add field to tab order
				//tabOrder.push_back(field);
			} else if(val == "text") {
				auto text = parent->parse<cTextMsg>(*node);
				contents.insert(text);
			} else if(val == "pict") {
				auto pict = parent->parse<cPict>(*node);
				contents.insert(pict);
			} else if(val == "slider") {
				auto slide = parent->parse<cScrollbar>(*node);
				contents.insert(slide);
			} else if(val == "button") {
				auto button = parent->parse<cButton>(*node);
				contents.insert(button);
			} else if(val == "led") {
				auto led = parent->parse<cLed>(*node);
				contents.insert(led);
			} else if(val == "group") {
				auto group = parent->parse<cLedGroup>(*node);
				contents.insert(group);
			} else throw xBadNode(val,node->Row(),node->Column(),fname);
		} else if(type != TiXmlNode::COMMENT)
			throw xBadVal("pane",xBadVal::CONTENT,val,node->Row(),node->Column(),fname);
	}
	recalcRect();
	return id;
}
Esempio n. 3
0
std::string cButton::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	Iterator<Node> node;
	std::string name, id;
	int width = 0, height = 0;
	bool foundType = false, foundTop = false, foundLeft = false; // required attributes
	rectangle frame;
	for(attr = attr.begin(&who); attr != attr.end(); attr++){
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "wrap"){
			std::string val;
			attr->GetValue(&val);
			if(val == "true") setFormat(TXT_WRAP, true);
		}else if(name == "type"){
			std::string val;
			foundType = true;
			attr->GetValue(&val);
			if(val == "small")
				setBtnType(BTN_SM);
			else if(val == "regular")
				setBtnType(BTN_REG);
			else if(val == "large")
				setBtnType(BTN_LG);
			else if(val == "help")
				setBtnType(BTN_HELP);
			else if(val == "left")
				setBtnType(BTN_LEFT);
			else if(val == "right")
				setBtnType(BTN_RIGHT);
			else if(val == "up")
				setBtnType(BTN_UP);
			else if(val == "down")
				setBtnType(BTN_DOWN);
			else if(val == "tiny")
				setBtnType(BTN_TINY);
			else if(val == "done")
				setBtnType(BTN_DONE);
			else if(val == "tall")
				setBtnType(BTN_TALL);
			else if(val == "trait")
				setBtnType(BTN_TRAIT);
			else if(val == "push")
				setBtnType(BTN_PUSH);
		}else if(name == "color" || name == "colour"){
			std::string val;
			attr->GetValue(&val);
			sf::Color clr;
			try{
				clr = parseColor(val);
			}catch(int){
				throw xBadVal("button",name,val,attr->Row(),attr->Column(),fname);
			}
			setColour(clr);
		}else if(name == "def-key"){
			std::string val;
			attr->GetValue(&val);
			try{
				attachKey(parseKey(val));
			}catch(int){
				throw xBadVal("button",name,val,attr->Row(),attr->Column(),fname);
			}
//		}else if(name == "fromlist"){
//			attr->GetValue(&fromList);
		}else if(name == "top"){
			attr->GetValue(&frame.top), foundTop = true;
		}else if(name == "left"){
			attr->GetValue(&frame.left), foundLeft = true;
		}else if(name == "width"){
			attr->GetValue(&width);
		}else if(name == "height"){
			attr->GetValue(&height);
		}else throw xBadAttr("button",name,attr->Row(),attr->Column(),fname);
	}
	if(parent->getBg() == cDialog::BG_DARK && (getBtnType() == BTN_TINY || getBtnType() == BTN_PUSH))
		setColour(sf::Color::White);
	if(!foundType) throw xMissingAttr("button","type",who.Row(),who.Column(),fname);
	if(!foundTop) throw xMissingAttr("button","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("button","left",who.Row(),who.Column(),fname);
	switch(getBtnType()){
		case BTN_SM:
			frame.right = frame.left + 23;
			frame.bottom = frame.top + 23;
			break;
		case BTN_LG:
			frame.right = frame.left + 102;
			frame.bottom = frame.top + 23;
			break;
		case BTN_HELP:
			frame.right = frame.left + 16;
			frame.bottom = frame.top + 13;
			break;
		case BTN_TINY:
		case BTN_LED: // this should never happen
			frame.right = frame.left + 14;
			frame.bottom = frame.top + 10;
			break;
		case BTN_TALL:
		case BTN_TRAIT:
			frame.right = frame.left + 63;
			frame.bottom = frame.top + 40;
			break;
		case BTN_PUSH:
			frame.right = frame.left + 30;
			frame.bottom = frame.top + 30;
			break;
		default:
			frame.right = frame.left + 63;
			frame.bottom = frame.top + 23;
	}
	if(width > 0)
		frame.right = frame.left + width;
	if(height > 0)
		frame.bottom = frame.top + height;
	setBounds(frame);
	std::string content;
	for(node = node.begin(&who); node != node.end(); node++){
		std::string val;
		int type = node->Type();
		node->GetValue(&val);
		if(type == TiXmlNode::ELEMENT && val == "key"){
			// TODO: There's surely a better way to do this
			if(content.length() > 0) throw xBadVal("button",xBadVal::CONTENT,content + val,node->Row(),node->Column(),fname);
//			labelWithKey = true;
		}else if(type == TiXmlNode::TEXT)
			content += dlogStringFilter(val);
		else if(type != TiXmlNode::COMMENT) {
			val = '<' + val + '>';
			throw xBadVal("button",xBadVal::CONTENT,val,node->Row(),node->Column(),fname);
		}
	}
	setText(content);
	return id;
}
Esempio n. 4
0
std::string cScrollbar::parse(ticpp::Element& who, std::string fname) {
	using namespace ticpp;
	Iterator<Attribute> attr;
	std::string name, id;
	bool foundTop = false, foundLeft = false, foundMax = false; // required attributes
	bool foundVertical = false;
	rectangle frame;
	int width = 0, height = 0;
	style = SCROLL_LED; // Dialog scrollbars have a different default.
	for(attr = attr.begin(&who); attr != attr.end(); attr++){
		attr->GetName(&name);
		if(name == "name")
			attr->GetValue(&id);
		else if(name == "vertical"){
			std::string val;
			attr->GetValue(&val);
			if(val == "true") vert = true;
			else vert = false;
			foundVertical = true;
		}else if(name == "style"){
			std::string val;
			attr->GetValue(&val);
			if(val == "white") style = SCROLL_WHITE;
			else if(val == "led") style = SCROLL_LED;
			else throw xBadVal("slider", name, val, attr->Row(), attr->Column(), fname);
		}else if(name == "link"){
			attr->GetValue(&link);
		}else if(name == "initial"){
			attr->GetValue(&pos);
		}else if(name == "max"){
			attr->GetValue(&max);
			foundMax = true;
		}else if(name == "page-size"){
			attr->GetValue(&pgsz);
		}else if(name == "top"){
			attr->GetValue(&frame.top), foundTop = true;
		}else if(name == "left"){
			attr->GetValue(&frame.left), foundLeft = true;
		}else if(name == "width"){
			attr->GetValue(&width);
		}else if(name == "height"){
			attr->GetValue(&height);
		}else throw xBadAttr("slider",name,attr->Row(),attr->Column(),fname);
	}
	if(!foundMax) throw xMissingAttr("slider","num",who.Row(),who.Column(),fname);
	if(!foundTop) throw xMissingAttr("slider","top",who.Row(),who.Column(),fname);
	if(!foundLeft) throw xMissingAttr("slider","left",who.Row(),who.Column(),fname);
	if(pos > max) throw xBadAttr("slider","initial",who.Row(),who.Column(),fname);
	int thickness = vert ? up_rect[style][VERT].width() : up_rect[style][HORZ].height();
	if(width > 0) {
		frame.right = frame.left + width;
		if(height == 0 && !foundVertical)
			vert = false;
	}else{
		if(vert) frame.width() = thickness;
		else frame.width() = 25;
	}
	if(height > 0) {
		frame.bottom = frame.top + height;
		if(width == 0 && !foundVertical)
			vert = true;
	}else{
		frame.bottom = frame.top + 10;
		if(vert) frame.height() = 25;
		else frame.height() = thickness;
	}
	setBounds(frame);
	if(parent->hasControl(link))
		parent->getControl(link).setTextToNum(pos);
	return id;
}