void BloomingNeonApp::drawStrokedRect( const Rectf &rect )
{
	// we don't want any texture on our lines
	glDisable(GL_TEXTURE_2D);

	gl::drawLine(rect.getUpperLeft(), rect.getUpperRight());
	gl::drawLine(rect.getUpperRight(), rect.getLowerRight());
	gl::drawLine(rect.getLowerRight(), rect.getLowerLeft());
	gl::drawLine(rect.getLowerLeft(), rect.getUpperLeft());
}
void SmilesApp::draw()
{
	gl::enableAlphaBlending();
	gl::clear( Color::black() );
    gl::color(1.0f, 1.0f, 1.0f);
    
    // draw webcam capture
	if( !mCapture || !mSurface )
		return;
    gl::draw( gl::Texture(mSurface) );
    
    if(mGreyChannel){
    gl::pushMatrices();{
        gl::translate(mSmileRect.getUpperLeft());
        gl::draw( gl::Texture(mGreyChannel) );
    }gl::popMatrices();
    }
    
    // draw rect that actually gets analysed:
    gl::color(ColorA(0.0f, 1.0f, 0.0f, 1.0f));
    gl::drawStrokedRect(mSmileRect);
    gl::drawStrokedCircle(mSmileRect.getUpperLeft(), 10);
    gl::drawStrokedCircle(mSmileRect.getUpperRight(), 10);
    gl::drawStrokedCircle(mSmileRect.getLowerLeft(), 10);
    gl::drawStrokedCircle(mSmileRect.getLowerRight(), 10);
    
    
    //draw mSmileThreshold
    gl::pushMatrices();{
        gl::color(ColorA(1.0f, 0.0f, 0.0f, 0.3f));
        gl::drawSolidRect(Rectf( 0, (1-mSmileThreshold)*getWindowHeight(), getWindowWidth(), getWindowHeight() ) );
        gl::drawStrokedRect( Rectf(0, 0, getWindowWidth(), getWindowHeight() ) );
    }gl::popMatrices();
    
    //draw faces
    if(!mFaces.empty()){
        gl::pushMatrices();{
            gl::translate(mSmileRect.getUpperLeft());
            gl::color(1.0f, 1.0f, 1.0f);
            for(list<VisualObject *>::iterator it = mFaces.begin(); it != mFaces.end(); ++it) {
                mFace = static_cast<FaceObject*>(*it);
                gl::drawStrokedRect(Rectf(mFace->x, mFace->y, mFace->x+mFace->xSize, mFace->y+mFace->ySize ));
            }
        }gl::popMatrices();
    }
    
    mParams.draw();
}
예제 #3
0
void Layer::beginClip( View *view, Renderer *ren )
{
	Rectf viewWorldBounds = view->getWorldBounds();
	vec2 lowerLeft = viewWorldBounds.getLowerLeft();
	if( mRootView->mRendersToFrameBuffer ) {
		// get bounds of view relative to framebuffer. // TODO: need a method like convertPointToView( view, point );
		Rectf frameBufferWorldBounds = mRootView->getWorldBounds();
 		Rectf viewBoundsInFrameBuffer = viewWorldBounds - frameBufferWorldBounds.getUpperLeft();

		// Take lower left relative to FrameBuffer, which might actually be larger than mFrameBufferBounds
		lowerLeft = viewBoundsInFrameBuffer.getLowerLeft();
		lowerLeft.y = mFrameBuffer->getHeight() - lowerLeft.y;

		// TODO: reason through if this makes sense in general
		// - needed to add it when rendering to virtual canvas but stroked rect went beyond borders
		lowerLeft.y += mFrameBufferBounds.y1;
	}
	else {
		// rendering to window, flip y relative to Graph's bottom left using its clipping size
		ivec2 clippingSize = mRootView->getGraph()->getClippingSize();
		lowerLeft.y = clippingSize.y - lowerLeft.y;
	}

	auto ctx = gl::context();
	ctx->pushBoolState( GL_SCISSOR_TEST, GL_TRUE );
	ctx->pushScissor( std::pair<ivec2, ivec2>( lowerLeft, view->getSize() ) );
}
예제 #4
0
size_t ScanlinePacker::pushRect( Rectf rect )
{	// TODO: better error handling
	assert( rect.getWidth() < mConstraints.x );
	if( rect.getUpperLeft() != vec2( 0 ) )
	{
		rect -= rect.getUpperLeft();
	}

	vec2 loc( mPadding );
	bool placed = false;
	while( !placed )
	{
		for( const Rectf &r : mRectangles )
		{
			Rectf bounds = r.inflated( mPadding );
			if( bounds.contains( loc ) )
			{	// move to the outside edge of bounds
				loc.x = bounds.getX2();
			}
		}
		if( loc.x + rect.getWidth() < mConstraints.x - mPadding.x )
		{	// probably placed, let's check our boundaries
			placed = true;
			Rectf potentialBounds = (rect + loc).inflated( vec2( -1.0f, -1.0f ) );
			for( const Rectf &r : mRectangles )
			{
				Rectf bounds = r.inflated( mPadding );
				if( potentialBounds.intersects( bounds ) )
				{
					placed = false;
				}
			}
		}
		if( !placed )
		{	// move to next row for continued evaluation
			loc.x = mPadding.x;
			loc.y += mPadding.y;	// could vary this step to optimize for grid
		}
		else
		{
			rect += loc;
			mRectangles.push_back( rect );
		}
	}
	return mRectangles.size() - 1;
}
예제 #5
0
void RenderMesh2D::setAsBox( const Rectf &bounds )
{
  if( vertices.size() != 4 ){ vertices.assign( 4, Vertex() ); }
  vertices[0].position = bounds.getUpperRight();
  vertices[1].position = bounds.getUpperLeft();
  vertices[2].position = bounds.getLowerRight();
  vertices[3].position = bounds.getLowerLeft();
}
예제 #6
0
vec2 Control::getHitPercent( const vec2 &pt )
{
    vec2 hp;
    Rectf r = mHitRect;
    r.offset( getOrigin() );
    hp = ( pt - r.getUpperLeft() ) / r.getSize();
    return hp;
}
void SmilesApp::mouseDown( MouseEvent event ){
    
    if(mSmileRect.getUpperLeft().distance(event.getPos())<10){mSmileRectDraggingCorner=0;}
    if(mSmileRect.getUpperRight().distance(event.getPos())<10){mSmileRectDraggingCorner=1;}
    if(mSmileRect.getLowerLeft().distance(event.getPos())<10){mSmileRectDraggingCorner=2;}
    if(mSmileRect.getLowerRight().distance(event.getPos())<10){mSmileRectDraggingCorner=3;}
    
}
예제 #8
0
void TouchUi::setMask( const Rectf& bounds )
{
	mMask.clear();
	mMask.moveTo( bounds.getUpperLeft() );
	mMask.lineTo( bounds.getUpperRight() );
	mMask.lineTo( bounds.getLowerRight() );
	mMask.lineTo( bounds.getLowerLeft() );
	mMask.close();
}
예제 #9
0
vec2 View::getHitPercent( const vec2 &pt )
{
    vec2 hp;
    Rectf r;
    r.set( 0, 0, getWidth(), getHeight() );
    r.offset( getOrigin() );
    hp = ( pt - r.getUpperLeft() ) / r.getSize();
    return hp;
}
예제 #10
0
void GoodNightMorningApp::drawTweets()
{
	gl::color( ColorA( 1, 1, 1, mMorningTweetAlpha ) );
	if( mMorningTweetTex )
		gl::draw( mMorningTweetTex, Vec2f( 0.1f, mMorningTweetPos ) * mDrawBounds.getSize() + mDrawBounds.getUpperLeft() );
	gl::color( ColorA( 1, 1, 1, mNightTweetAlpha ) );
	if( mNightTweetTex )
		gl::draw( mNightTweetTex, Vec2f( 0.6f, mNightTweetPos ) * mDrawBounds.getSize() + mDrawBounds.getUpperLeft() );
	gl::color( Color::white() ); // restore for future drawing
}
 void ShapeTesselator::add(const Rectf &rect)
 {
     vector<Vec2f> polygon;
     polygon.emplace_back(rect.getUpperLeft());
     polygon.emplace_back(rect.getUpperRight());
     polygon.emplace_back(rect.getLowerRight());
     polygon.emplace_back(rect.getLowerLeft());
     
     add(polygon);
 }
예제 #12
0
void TextLabels::renderString( const std::u16string &str, vec2 *cursor, float stretch )
{
	std::u16string::const_iterator itr;
	for( itr = str.begin(); itr != str.end(); ++itr ) {
		// retrieve character code
		uint16_t id = (uint16_t)*itr;

		if( mFont->contains( id ) ) {
			// get metrics for this character to speed up measurements
			Font::Metrics m = mFont->getMetrics( id );

			// skip whitespace characters
			if( !isWhitespaceUtf16( id ) ) {
				size_t index = mVertices.size();

				Rectf bounds = mFont->getBounds( m, mFontSize );
				mVertices.push_back( vec3( *cursor + bounds.getUpperLeft(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getUpperRight(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getLowerRight(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getLowerLeft(), 0 ) );

				bounds = mFont->getTexCoords( m );
				mTexcoords.push_back( bounds.getUpperLeft() );
				mTexcoords.push_back( bounds.getUpperRight() );
				mTexcoords.push_back( bounds.getLowerRight() );
				mTexcoords.push_back( bounds.getLowerLeft() );

				mIndices.push_back( index + 0 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 1 );
				mIndices.push_back( index + 1 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 2 );

				mOffsets.insert( mOffsets.end(), 4, mOffset );
			}

			if( id == 32 )
				cursor->x += stretch * mFont->getAdvance( m, mFontSize );
			else
				cursor->x += mFont->getAdvance( m, mFontSize );
		}
	}

	//
	mBoundsInvalid = true;
}
예제 #13
0
파일: Dialer.cpp 프로젝트: eriser/Cinder-UI
vec2 DialerT<T>::getHitPercent( const vec2 &pt )
{
    vec2 hp;
    Rectf r = mHitRect;
    r.offset( getOrigin() );
    r.x1 += mPadding.mLeft;
    r.x2 -= mPadding.mRight;
    r.y1 += mPadding.mTop;
    r.y2 -= mPadding.mBottom;
    hp = ( pt - r.getUpperLeft() ) / r.getSize();
    return hp;
}
  ShapeProxy(nvg::Context& vg, shared_ptr<Shape> shape) : mShape{ shape } {
    mBounds = mShape->getBounds();

    // Grow the bounds a little to preserve nice anti-aliasing at the edges.
    mBounds.inflate(vec2(2));

    auto fboSize = mBounds.getSize() * getWindow()->getContentScale();
    auto fbo = gl::Fbo::create(fboSize.x, fboSize.y, gl::Fbo::Format().stencilBuffer());
    gl::ScopedFramebuffer fboScp(fbo);

    gl::viewport(fboSize);
    gl::clear(ColorAf::zero());
    gl::clear(GL_STENCIL_BUFFER_BIT);

    vg.beginFrame(mBounds.getSize(), getWindow()->getContentScale());
    vg.translate(-mBounds.getUpperLeft());
    mShape->draw(vg);
    vg.endFrame();

    mTexture = fbo->getColorTexture();
  }
예제 #15
0
void iosKeyboardApp::drawTextView( const TextView &textView )
{
	gl::color( Color( "PowderBlue" ) );
	gl::drawSolidRect( textView.mBounds );

	Color borderColor = textView.mIsSelected ? Color( "DodgerBlue" ) : Color( "DarkGray" );
	gl::color( borderColor );
	gl::drawStrokedRect( textView.mBounds );

	Rectf fitRect = textView.getTextBounds();
	vec2 offset( 0.0f, mFont.getAscent() );

	TextBox tbox = TextBox().font( mFont ).size( fitRect.getWidth(), fitRect.getHeight() ).premultiplied();

	if( textView.mText.empty() && ! textView.mIsSelected ) {
		tbox.color( Color::gray( 0.6f ) ).text( textView.mPlacerholderText );
	}
	else {
		tbox.color( Color( "FireBrick" ) ).text( textView.mText );
	}
	gl::color( Color::white() );
	gl::draw( tbox.render(), fitRect.getUpperLeft() );
}
예제 #16
0
VboRef Vbo::createPlane(const Rectf &rect)
{
    return createPlane(rect.getUpperLeft(), rect.getLowerRight());
}