示例#1
0
文件: gui.cpp 项目: Glyth/xoreos
void GUI::loadWidget(const Aurora::GFF3Struct &strct, Widget *parent) {
	WidgetContext ctx(strct, parent);

	createWidget(ctx);

	addWidget(ctx.widget);

	if (ctx.parent) {
		if (ctx.strct->getString("Obj_Parent") != ctx.parent->getTag())
			throw Common::Exception("Parent's tag != Obj_Parent");

		parent->addChild(*ctx.widget);

		float pX, pY, pZ;
		parent->getPosition(pX, pY, pZ);

		float x = ctx.strct->getDouble("Obj_X") * 100.0 + pX;
		float y = ctx.strct->getDouble("Obj_Y") * 100.0 + pY;
		float z = pZ - ctx.strct->getDouble("Obj_Z") * 100.0;

		ctx.widget->setPosition(x, y, z);
	} else {
		// We'll ignore these for now, centering the GUI
	}

	initWidget(ctx);

	// Create a caption/label and move the label to its destined position
	WidgetLabel *label = createCaption(ctx);
	if (label && ctx.strct->hasField("Obj_Caption")) {
		const Aurora::GFF3Struct &caption = ctx.strct->getStruct("Obj_Caption");

		float alignH = caption.getDouble("AurString_AlignH");
		float alignV = caption.getDouble("AurString_AlignV");

		float labelX = ctx.strct->getDouble("Obj_Label_X") * 100.0;
		float labelY = ctx.strct->getDouble("Obj_Label_Y") * 100.0;
		float labelZ = ctx.strct->getDouble("Obj_Label_Z") * 100.0;

		if (ctx.type != kWidgetTypeLabel) {
			if (label->getWidth() > ctx.widget->getWidth() || label->getHeight() > ctx.widget->getHeight())
				label->setText(label->getText(), alignH, ctx.widget->getWidth(), ctx.widget->getHeight());

			labelX += ctx.widget->getWidth () * alignV;
			labelY += ctx.widget->getHeight() * alignH;

			labelX -= label->getWidth () / 2;
			labelY -= label->getHeight() / 2;
		} else {
			float labelWidth = 0.0;
			if (ctx.strct->hasField("Obj_Label_Width"))
				labelWidth = ctx.strct->getDouble("Obj_Label_Width") * 100.0;

			float labelHeight = 0.0;
			if (ctx.strct->hasField("Obj_Label_Height"))
				labelHeight = ctx.strct->getDouble("Obj_Label_Height") * 100.0;

			if (alignV == 0.5) {
				bool multilines = false;
				if (label->getWidth() > labelWidth)
					multilines = true;

				label->setText(label->getText(), alignH, labelWidth, labelHeight);
				labelX += labelWidth * alignH;

				if (multilines)
					labelY += label->getHeight() * alignV;
			}

			labelX -= label->getWidth () * alignH;

			labelY -= label->getHeight();
			labelY -= label->getHeight() * alignV;
		}

		label->movePosition(labelX, labelY, -labelZ);
	}

	// uint32 layer = strct.getUint("Obj_Layer");
	// bool locked = strct.getUint("Obj_Locked") != 0;

	// Go down to the children
	if (ctx.strct->hasField("Obj_ChildList")) {
		const Aurora::GFF3List &children = ctx.strct->getList("Obj_ChildList");

		for (Aurora::GFF3List::const_iterator c = children.begin(); c != children.end(); ++c)
			loadWidget(**c, ctx.widget);
	}
}