Пример #1
0
//! ---|> Component
void Connector::doLayout(){

	Geometry::Vec2 parentsAbsPos=hasParent()?getParent()->getAbsPosition():Geometry::Vec2();

	Geometry::Rect r;
	r.invalidate();
//	std::cout << r.getX();

	if( getFirstComponent() )
		r.include( getFirstComponent()->getAbsRect().getCenter()-parentsAbsPos );
//	std::cout << (getFirstComponent()->getAbsRect().getCenter()-parentsAbsPos).getX();

	if( getSecondComponent() )
		r.include( getSecondComponent()->getAbsRect().getCenter()-parentsAbsPos );

	if(getContentsCount()>2){
		// TODO!!!!!
	}
	setPosition(Geometry::Vec2(r.getX(),r.getY()));
	setSize(r.getWidth(),r.getHeight());
	Geometry::Vec2 myAbsPos=getAbsPosition();

	if(getFirstChild() && getFirstComponent()){
		getFirstChild()->setPosition( getFirstComponent()->getAbsRect().getCenter()-myAbsPos );
	}
	if(getLastChild() && getSecondComponent()){
		getLastChild()->setPosition( getSecondComponent()->getAbsRect().getCenter()-myAbsPos );
//		getLastChild()->setPosition(Vec2(r.getWidth(),r.getHeight()));
	}

	if(getContentsCount()>2){
		// TODO!!!!!
	}
}
Пример #2
0
void drawRect(RenderingContext & rc, const Geometry::Rect & rect) {
	static Util::Reference<Mesh> mesh;
	if (mesh.isNull()) {
		VertexDescription vertexDescription;
		vertexDescription.appendPosition2D();
		mesh = new Mesh(vertexDescription, 4, 6);
		mesh->setDrawMode(Mesh::DRAW_TRIANGLES);

		MeshVertexData & vd = mesh->openVertexData();
		float * vertices = reinterpret_cast<float *> (vd.data());
		*vertices++ = 0.0f; // Bottom left
		*vertices++ = 0.0f;
		*vertices++ = 1.0f; // Bottom right
		*vertices++ = 0.0f;
		*vertices++ = 1.0f; // Top right
		*vertices++ = 1.0f;
		*vertices++ = 0.0f; // Top left
		*vertices++ = 1.0f;
		vd.updateBoundingBox();
		vd.markAsChanged();

		MeshIndexData & id = mesh->openIndexData();
		uint32_t * indices = id.data();
		indices[0] = 0;
		indices[1] = 2;
		indices[2] = 1;
		indices[3] = 0;
		indices[4] = 3;
		indices[5] = 2;
		id.updateIndexRange();
		id.markAsChanged();
	}

	Geometry::Matrix4x4 matrix;
	matrix.translate(rect.getX(), rect.getY(), 0.0f);
	matrix.scale(rect.getWidth(), rect.getHeight(), 1.0f);
	rc.pushMatrix_modelToCamera();
	rc.multMatrix_modelToCamera(matrix);
	rc.displayMesh(mesh.get());
	rc.popMatrix_modelToCamera();
}