void WarpPerspective::draw( bool controls ) { // only draw grid while editing if( isEditModeEnabled() ) { gl::pushModelMatrix(); gl::multModelMatrix( getTransform() ); glLineWidth( 1.0f ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); gl::ScopedColor color( Color::white() ); for( int i = 0; i <= 1; i++ ) { float s = i / 1.0f; gl::drawLine( vec2( s * (float) mWidth, 0.0f ), vec2( s * (float) mWidth, (float) mHeight ) ); gl::drawLine( vec2( 0.0f, s * (float) mHeight ), vec2( (float) mWidth, s * (float) mHeight ) ); } gl::drawLine( vec2( 0.0f, 0.0f ), vec2( (float) mWidth, (float) mHeight ) ); gl::drawLine( vec2( (float) mWidth, 0.0f ), vec2( 0.0f, (float) mHeight ) ); gl::popModelMatrix(); if( controls ) { // draw control points for( int i = 0; i < 4; i++ ) drawControlPoint( toVec2f( mDestination[i] ), i == mSelected ); } } }
void WarpPerspective::draw( bool controls ) { // only draw grid while editing if( isEditModeEnabled() ) { gl::pushModelMatrix(); gl::multModelMatrix( getTransform() ); gl::ScopedGlslProg shader( gl::getStockShader( gl::ShaderDef().color() ) ); gl::ScopedLineWidth linewidth( 1.0f ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); gl::ScopedColor color( Color::white() ); for( int i = 0; i <= 1; i++ ) { float s = i / 1.0f; gl::drawLine( vec2( s * (float)mWidth, 0.0f ), vec2( s * (float)mWidth, (float)mHeight ) ); gl::drawLine( vec2( 0.0f, s * (float)mHeight ), vec2( (float)mWidth, s * (float)mHeight ) ); } gl::drawLine( vec2( 0.0f, 0.0f ), vec2( (float)mWidth, (float)mHeight ) ); gl::drawLine( vec2( (float)mWidth, 0.0f ), vec2( 0.0f, (float)mHeight ) ); gl::popModelMatrix(); if( controls && mSelected < mPoints.size() ) { // draw control points for( int i = 0; i < 4; i++ ) queueControlPoint( mDestination[i], i == mSelected ); drawControlPoints(); } } }
bool WarpPerspectiveBilinear::keyDown(KeyEvent event) { if( ! isEditModeEnabled() ) return false; if(mSelected >= mPoints.size()) return false; switch( event.getCode() ) { case KeyEvent::KEY_UP: case KeyEvent::KEY_DOWN: case KeyEvent::KEY_LEFT: case KeyEvent::KEY_RIGHT: { // make sure cursor keys are handled by 1 warp only if(!isCorner( mSelected ) || !mWarp->keyDown(event)) return WarpBilinear::keyDown( event ); return true; } break; case KeyEvent::KEY_F9: case KeyEvent::KEY_F10: // let only the Perspective warp handle rotating return mWarp->keyDown(event); case KeyEvent::KEY_F11: case KeyEvent::KEY_F12: // let only the Bilinear warp handle flipping return WarpBilinear::keyDown( event ); default: { // let both warps handle the other keyDown events bool handled = mWarp->keyDown(event); return (WarpBilinear::keyDown( event ) || handled); } break; } }
void WarpPerspectiveBilinear::keyDown( KeyEvent &event ) { if( !isEditModeEnabled() ) return; if( mSelected >= mPoints.size() ) return; switch( event.getCode() ) { case KeyEvent::KEY_UP: case KeyEvent::KEY_DOWN: case KeyEvent::KEY_LEFT: case KeyEvent::KEY_RIGHT: // make sure cursor keys are handled by 1 warp only if( !isCorner( mSelected ) ) mWarp->keyDown( event ); if( !event.isHandled() ) WarpBilinear::keyDown( event ); break; case KeyEvent::KEY_F9: case KeyEvent::KEY_F10: // let only the Perspective warp handle rotating mWarp->keyDown( event ); break; case KeyEvent::KEY_F11: case KeyEvent::KEY_F12: // let only the Bilinear warp handle flipping WarpBilinear::keyDown( event ); break; default: // let both warps handle the other keyDown events mWarp->keyDown( event ); WarpBilinear::keyDown( event ); break; } }
void WarpPerspective::keyDown( KeyEvent &event ) { // let base class handle keys first Warp::keyDown( event ); if( event.isHandled() ) return; // disable keyboard input when not in edit mode if( !isEditModeEnabled() ) return; // do not listen to key input if not selected if( mSelected >= mPoints.size() ) return; switch( event.getCode() ) { case KeyEvent::KEY_F9: // rotate content ccw std::swap( mPoints[1], mPoints[2] ); std::swap( mPoints[0], mPoints[1] ); std::swap( mPoints[3], mPoints[0] ); mSelected = ( mSelected + 1 ) % 4; mIsDirty = true; break; case KeyEvent::KEY_F10: // rotate content cw std::swap( mPoints[3], mPoints[0] ); std::swap( mPoints[0], mPoints[1] ); std::swap( mPoints[1], mPoints[2] ); mSelected = ( mSelected + 3 ) % 4; mIsDirty = true; break; case KeyEvent::KEY_F11: // flip content horizontally std::swap( mPoints[0], mPoints[1] ); std::swap( mPoints[2], mPoints[3] ); if( mSelected % 2 ) mSelected--; else mSelected++; mIsDirty = true; break; case KeyEvent::KEY_F12: // flip content vertically std::swap( mPoints[0], mPoints[3] ); std::swap( mPoints[1], mPoints[2] ); mSelected = ( (unsigned)mPoints.size() - 1 ) - mSelected; mIsDirty = true; break; default: return; } event.setHandled( true ); }
bool WarpPerspectiveBilinear::mouseDrag( MouseEvent event ) { if( !isEditModeEnabled() ) return false; if(mSelected >= mPoints.size()) return false; // depending on selected control point, let perspective or bilinear warp handle it if( isCorner( mSelected ) ) { return mWarp->mouseDrag( event ); } else { return Warp::mouseDrag( event ); } }
void WarpPerspectiveBilinear::mouseDown( MouseEvent &event ) { if( !isEditModeEnabled() ) return; if( mSelected >= mPoints.size() ) return; // depending on selected control point, let perspective or bilinear warp handle it if( isCorner( mSelected ) ) { mWarp->mouseDown( event ); } else { Warp::mouseDown( event ); } }
void WarpPerspectiveBilinear::draw(bool controls) { // apply perspective transform gl::pushModelView(); gl::multModelView( mWarp->getTransform() ); // draw bilinear warp WarpBilinear::draw(false); // restore transform gl::popModelView(); // draw edit interface if( isEditModeEnabled() ) { if(controls) { // draw control points for(unsigned i=0;i<mPoints.size();++i) drawControlPoint( getControlPoint(i) * mWindowSize, mSelected==i ); } } }