Exemplo n.º 1
0
DragNDropResponse::DragNDropResponse(JsonClient *client, const QtJson::JsonObject &command) :
    DelayedResponse(client, command)
{
    WidgetLocatorContext<QWidget> ctx(static_cast<Player *>(jsonClient()), command, "srcoid");
    WidgetLocatorContext<QWidget> ctx2(static_cast<Player *>(jsonClient()), command, "destoid");

    if (ctx.hasError()) { writeResponse(ctx.lastError); return; }
    if (ctx2.hasError()) { writeResponse(ctx2.lastError); return; }

    QPoint srcPos;
    if (command.contains("srcpos") && ! command["srcpos"].isNull()) {
        srcPos = pointFromString(command["srcpos"].toString());
    } else {
        srcPos = ctx.widget->rect().center();
    }

    QPoint destPos;
    if (command.contains("destpos") && ! command["destpos"].isNull()) {
        destPos = pointFromString(command["destpos"].toString());
    } else {
        destPos = ctx2.widget->rect().center();
    }

    m_src = ctx.widget;
    m_dest = ctx2.widget;
    m_srcPos = srcPos;
    m_destPos = destPos;
}
Exemplo n.º 2
0
bool anim::fromXMLElement(XMLElement* elem)
{
	const char* cName = elem->Name();
	if(cName == NULL) return false;
	string sName = cName;
	if(sName == "rot")
	{
		type |= ANIM_ROT;
		
		min.x = 0;
		max.x = 0;
		speed.SetZero();
		dirx = true;
		pingpong = false;
		
		elem->QueryBoolAttribute("pingpong", &pingpong);
		elem->QueryFloatAttribute("min", &min.x);
		elem->QueryFloatAttribute("max", &max.x);
		elem->QueryFloatAttribute("speed", &speed.x);
		
		if(speed.x < 0)
		{
			speed.x = -speed.x;
			dirx = false;
		}
	}
	else if(sName == "frameseq")
	{
		type |= ANIM_FRAMESEQ;
	
		float32 fps = 0;
		
		elem->QueryFloatAttribute("fps", &fps);
		elem->QueryFloatAttribute("repeat", &repeat);
		elem->QueryFloatAttribute("repeatvar", &repeatvar);
		
		if(fps <= 0) fps = 60;
		framedelay = 1.0/fps;
		
		for(XMLElement* fr = elem->FirstChildElement("frame"); fr != NULL; fr = fr->NextSiblingElement("frame"))
		{
			const char* cImg = fr->Attribute("img");
			if(cImg == NULL) return false;
			Image* img = getImage(cImg);
			frames.push_back(img);
		}
		
		nextAnim = curTime + repeat + randFloat(-repeatvar, repeatvar);
		nextFrame = 0;
		curFrame = frames.end();
	}
	else if(sName == "velfac")	//Item dependant on velocity
	{
		type |= ANIM_VELFAC;
		
		elem->QueryFloatAttribute("min", &minrot);
		elem->QueryFloatAttribute("max", &maxrot);
		elem->QueryFloatAttribute("mul", &rotmul);
		elem->QueryBoolAttribute("add", &rotadd);
		const char* cAxis = elem->Attribute("axis");
		if(cAxis != NULL)
			axis = cAxis;
	}
	else if(sName == "size" || sName == "pos" || sName == "center" || sName == "shear")
	{
		if(sName == "size")
			type |= ANIM_SIZE;
		else if(sName == "pos")
			type |= ANIM_POS;
		else if(sName == "center")
			type |= ANIM_CENTER;
		else if(sName == "shear")
			type |= ANIM_SHEAR;
		
		min.SetZero();
		max.SetZero();
		speed.SetZero();
		dirx = diry = true;
		pingpong = false;
		
		elem->QueryBoolAttribute("pingpong", &pingpong);
		const char* cMin = elem->Attribute("min");
		if(cMin != NULL)
			min = pointFromString(cMin);
		const char* cMax = elem->Attribute("max");
		if(cMax != NULL)
			max = pointFromString(cMax);
		const char* cSpeed = elem->Attribute("speed");
		if(cSpeed != NULL)
			speed = pointFromString(cSpeed);
		
		if(speed.x < 0)
		{
			speed.x = -speed.x;
			dirx = false;
		}
		if(speed.y < 0)
		{
			speed.y = -speed.y;
			diry = false;
		}
	}
	else if(sName == "file")	//Defines an animation in a file elsewhere
	{
		const char* cPath = elem->Attribute("path");
		if(cPath == NULL) return false;
		return fromXML(cPath);	//Create animation from XML. We can get crazy recursive here if we want to design everything that stupid.
	}
	//else if(sName == "")	//TODO: Support more animation types
	else return false;
	
	return true;
}