Esempio n. 1
0
void Warp::selectClosestControlPoint( const WarpList &warps, const ivec2 &position )
{
	WarpRef  warp;
	unsigned i, index;
	float    d, distance = 10.0e6f;

	// find warp and distance to closest control point
	for( WarpConstReverseIter itr = warps.rbegin(); itr != warps.rend(); ++itr ) {
		i = ( *itr )->findControlPoint( position, &d );

		if( d < distance ) {
			distance = d;
			index = i;
			warp = *itr;
		}
	}

	// select the closest control point and deselect all others
	for( WarpConstIter itr = warps.begin(); itr != warps.end(); ++itr ) {
		if( *itr == warp )
			( *itr )->selectControlPoint( index );
		else
			( *itr )->deselectControlPoint();
	}
}
Esempio n. 2
0
bool Warp::handleResize( WarpList &warps, const ivec2 &size )
{
	for( WarpIter itr = warps.begin(); itr != warps.end(); ++itr )
		( *itr )->resize( size );

	return false;
}
Esempio n. 3
0
bool Warp::handleMouseDrag( WarpList &warps, MouseEvent &event )
{
	for( WarpReverseIter itr = warps.rbegin(); itr != warps.rend() && !event.isHandled(); ++itr )
		( *itr )->mouseDrag( event );

	return event.isHandled();
}
Esempio n. 4
0
bool Warp::handleMouseDown( WarpList &warps, MouseEvent &event )
{
	// find and select closest control point
	selectClosestControlPoint( warps, event.getPos() );

	for( WarpReverseIter itr = warps.rbegin(); itr != warps.rend() && !event.isHandled(); ++itr )
		( *itr )->mouseDown( event );

	return event.isHandled();
}
Esempio n. 5
0
WarpList Warp::readSettings( const DataSourceRef &source )
{
	XmlTree  doc;
	WarpList warps;

	// try to load the specified xml file
	try {
		doc = XmlTree( source );
	}
	catch( ... ) {
		return warps;
	}

	// check if this is a valid file
	bool isWarp = doc.hasChild( "warpconfig" );
	if( !isWarp ) return warps;

	//
	if( isWarp ) {
		// get first profile
		XmlTree profileXml = doc.getChild( "warpconfig/profile" );

		// iterate maps
		for( XmlTree::ConstIter child = profileXml.begin( "map" ); child != profileXml.end(); ++child ) {
			XmlTree warpXml = child->getChild( "warp" );

			// create warp of the correct type
			std::string method = warpXml.getAttributeValue<std::string>( "method", "unknown" );
			if( method == "bilinear" ) {
				WarpBilinearRef warp( new WarpBilinear() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
			else if( method == "perspective" ) {
				WarpPerspectiveRef warp( new WarpPerspective() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
			else if( method == "perspectivebilinear" ) {
				WarpPerspectiveBilinearRef warp( new WarpPerspectiveBilinear() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
		}
	}

	return warps;
}
Esempio n. 6
0
bool Warp::handleKeyDown( WarpList &warps, KeyEvent &event )
{
	for( WarpReverseIter itr = warps.rbegin(); itr != warps.rend() && !event.isHandled(); ++itr )
		( *itr )->keyDown( event );

	switch( event.getCode() ) {
	case KeyEvent::KEY_UP:
	case KeyEvent::KEY_DOWN:
	case KeyEvent::KEY_LEFT:
	case KeyEvent::KEY_RIGHT:
		// do not select another control point
		break;
	}

	return event.isHandled();
}
Esempio n. 7
0
void Warp::writeSettings( const WarpList &warps, const DataTargetRef &target )
{
	// create default <profile> (profiles are not yet supported)
	XmlTree profile;
	profile.setTag( "profile" );
	profile.setAttribute( "name", "default" );

	//
	for( unsigned i = 0; i < warps.size(); ++i ) {
		// create <map>
		XmlTree map;
		map.setTag( "map" );
		map.setAttribute( "id", i + 1 );
		map.setAttribute( "display", 1 ); // not supported yet

		// create <warp>
		map.push_back( warps[i]->toXml() );

		// add map to profile
		profile.push_back( map );
	}

	// create config document and root <warpconfig>
	XmlTree doc;
	doc.setTag( "warpconfig" );
	doc.setAttribute( "version", "1.0" );
	doc.setAttribute( "profile", "default" );

	// add profile to root
	doc.push_back( profile );

	// write file
	doc.write( target );
}
void PinballWarpingApp::setupWarps()
{
    fs::path settings = getAssetPath( "" ) / "warps.xml";
    
    if( fs::exists( settings ) ) {
        // load warp settings from file if one exists
        mWarps = Warp::readSettings( loadFile( settings ) );
    }
    else {
        // otherwise create a warp from scratch
        mWarps.push_back( WarpPerspectiveBilinear::create() );
    }
    
    try {
        Warp::setSize( mWarps, getWindowSize()); //vec2(400, 800) );
    }
    catch( const std::exception &e ) {
        console() << e.what() << std::endl;
    }
}
Esempio n. 9
0
void Warp::setSize( const WarpList &warps, int w, int h )
{
	for( WarpConstIter itr = warps.begin(); itr != warps.end(); ++itr )
		( *itr )->setSize( w, h );
}
Esempio n. 10
0
void Copy_Warps (WarpList& rNew, const WarpList& old)
{
    rNew.reserve(old.size());
    for (WarpList::const_iterator i = old.begin(); i != old.end(); i ++)
        rNew.push_back((*i)->Clone());
}
Esempio n. 11
0
void Destroy_Warps (WarpList& warps)
{
    for (WarpList::iterator iWarp = warps.begin(); iWarp != warps.end(); iWarp ++)
        delete *iWarp;
    warps.clear();
}