void ParticleSystem::update(Timer* timer ) { static float prevTime = (float) timer->getSeconds(); float curTime = (float) timer->getSeconds(); float dt = curTime - prevTime; prevTime = curTime; Rectf bounds = mBounds; float minX = -kBorder; float minY = -kBorder; float maxX = bounds.getWidth(); float maxY = bounds.getHeight(); // Avoid the borders in the remap because the velocity might be zero. // Nothing interesting happens where velocity is zero. float dx = (float)(mFluid->resX() - 4) / (float) bounds.getWidth(); float dy = (float)(mFluid->resY() - 4) / (float) bounds.getHeight(); for( int i = 0; i < numParticles(); ++i ) { Particle& part = mParticles.at( i ); if( part.pos().x < minX || part.pos().y < minY || part.pos().x >= maxX || part.pos().y >= maxY ) { part.reset( newParticleVec(), Rand::randFloat( 0.0f, 1.0f ), mColor ); } float x = part.pos().x * dx + 2.0f; float y = part.pos().y * dy + 2.0f; Vec2f vel = mFluid->velocity().bilinearSampleChecked( x, y, Vec2f( 0.0f, 0.0f ) ); part.addForce( vel ); part.update( mFluid->dt(), dt ); } }
void ParticleSoup::update() { static float prevTime = (float)app::getElapsedSeconds(); float curTime = (float)app::getElapsedSeconds(); float dt = curTime - prevTime; prevTime = curTime; Rectf bounds = ci::app::getWindowBounds(); float minX = -kBorder; float minY = -kBorder; float maxX = bounds.getWidth(); float maxY = bounds.getHeight(); // Avoid the borders in the remap because the velocity might be zero. // Nothing interesting happens where velocity is zero. float dx = (float)(mFluid->resX() - 4)/(float)bounds.getWidth(); float dy = (float)(mFluid->resY() - 4)/(float)bounds.getHeight(); for( int i = 0; i < numParticles(); ++i ) { Particle& part = mParticles.at( i ); if( part.pos().x < minX || part.pos().y < minY || part.pos().x >= maxX || part.pos().y >= maxY ) { vec2 P; P.x = Rand::randFloat( bounds.x1 + 5.0f, bounds.x2 - 5.0f ); P.y = Rand::randFloat( bounds.y1 + 5.0f, bounds.y2 - 5.0f ); float life = Rand::randFloat( 2.0f, 3.0f ); part.reset( P, life, mColor ); } float x = part.pos().x*dx + 2.0f; float y = part.pos().y*dy + 2.0f; vec2 vel = mFluid->velocity().bilinearSampleChecked( x, y, vec2( 0.0f, 0.0f ) ); part.addForce( vel ); part.update( mFluid->dt(), dt ); } }
/////////////////////////////////////////////////////////// // // TRANSFORMATIONS // // Fit src inside dst Rectf rectToFit( Rectf src, Rectf dst ) { float sw = src.getWidth(); float sh = src.getHeight(); float sa = (sw / sh); // aspect ratio float dw = dst.getWidth(); float dh = dst.getHeight(); float da = (dw / dh); // aspect ratio // different ratio if (da > sa) { float scale = (dh / sh); float gap = (dw - (sw * scale)) / 2.0f; return Rectf( gap, 0, dw-gap, dh); } else if (da < sa) { float scale = (dw / sw); float gap = (dh - (sh * scale)) / 2.0f; return Rectf( 0, gap, dw, dh-gap ); } // Same ratio else return dst; }
// Renders a given SVG group 'groupName' into a new gl::Texture gl::Texture renderSvgGroupToTexture( const svg::Doc &doc, const std::string &groupName, const Rectf &rect, bool alpha ) { cairo::SurfaceImage srfImg( rect.getWidth(), rect.getHeight(), alpha ); cairo::Context ctx( srfImg ); ctx.scale( rect.getWidth() / doc.getWidth(), rect.getHeight() / doc.getHeight() ); ctx.render( doc / groupName ); return gl::Texture( srfImg.getSurface() ); }
Cell::Cell(ci::Vec2f& p) { _position = ci::Vec2f(p); _artwork = svg::Doc::create(app::getAssetPath("Cell.svg")); Rectf rect = _artwork->getBoundingBox(); cairo::SurfaceImage sImg(rect.getWidth(), rect.getHeight(), true); cairo::Context ctx(sImg); ctx.scale(rect.getWidth() / _artwork->getWidth(), rect.getHeight() / _artwork->getHeight()); ctx.render(*_artwork); _texture = sImg.getSurface(); }
void TestbedApp::setup() { std::vector<std::string> testNames; testCount = 0; while( nullptr != g_testEntries[testCount].createFcn ) { testNames.push_back( g_testEntries[testCount].name ); ++testCount; } testIndex = b2Clamp(testIndex, 0, testCount-1); testSelection = testIndex; entry = g_testEntries + testIndex; if (entry && entry->createFcn) { test = entry->createFcn(); testSelection = testIndex; testIndex = -1; } #if ! defined( CINDER_GL_ES ) mParams = params::InterfaceGl( "Params", ivec2( 250, 400 ) ); mParams.addParam( "Tests", testNames, &testSelection ); mParams.addSeparator(); mParams.addParam( "Vel Iters", &settings.velocityIterations, "min=1 max=500 step=1" ); mParams.addParam( "Pos Iters", &settings.positionIterations, "min=0 max=100 step=1" ); mParams.addParam( "Pcl Iters", &settings.particleIterations, "min=1 max=100 step=1" ); mParams.addParam( "Hertz", &settingsHz, "min=1 max=100 step=1" ); mParams.addSeparator(); mParams.addParam( "Sleep", &settings.enableSleep ); mParams.addParam( "Warm Starting", &settings.enableWarmStarting ); mParams.addParam( "Time of Impact", &settings.enableContinuous ); mParams.addParam( "Sub-Stepping", &settings.enableSubStepping ); mParams.addParam( "Strict Particle/Body Contacts", &settings.strictContacts ); mParams.addSeparator( "Draw" ); mParams.addParam( "Shapes", &settings.drawShapes ); mParams.addParam( "Particles", &settings.drawParticles ); mParams.addParam( "Joints", &settings.drawJoints ); mParams.addParam( "AABBs", &settings.drawAABBs) ; mParams.addParam( "Contact Points", &settings.drawContactPoints ); mParams.addParam( "Contact Normals", &settings.drawContactNormals ); mParams.addParam( "Contact Impulses", &settings.drawContactImpulse ); mParams.addParam( "Friction Impulses", &settings.drawFrictionImpulse ); mParams.addParam( "Center of Masses", &settings.drawCOMs ); mParams.addParam( "Statistics", &settings.drawStats ); mParams.addParam( "Profile", &settings.drawProfile ); #else float s = 1080.0f/480.0f; Rectf r = Rectf( 0, 0, 50*s, 50*s ); mLeftButton = r + vec2( 0, getWindowHeight() - r.getHeight() ); mRightButton = r + vec2( getWindowWidth() - r.getWidth(), getWindowHeight() - r.getHeight() ); #endif }
float CoordConverter::getBaseYValue(const Window& window) { const Window* parent = window.getParent(); const Rectf parent_rect(parent ? parent->getChildContentArea(window.isNonClient()).get() : Rectf(Vector2f(0, 0), window.getRootContainerSize()) ); const float parent_height = parent_rect.getHeight(); float baseY = parent_rect.d_min.d_y; baseY += asAbsolute(window.getArea().d_min.d_y, parent_height); switch(window.getVerticalAlignment()) { case VA_CENTRE: baseY += (parent_height - window.getPixelSize().d_height) * 0.5f; break; case VA_BOTTOM: baseY += parent_height - window.getPixelSize().d_height; break; default: break; } return alignToPixels(baseY); }
float FalagardSlider::getValueFromThumb(void) const { Slider* w = (Slider*)d_window; // get area the thumb is supposed to use as it's area. const WidgetLookFeel& wlf = getLookNFeel(); const Rectf area(wlf.getNamedArea("ThumbTrackArea").getArea().getPixelRect(*w)); // get accesss to the thumb Thumb* theThumb = w->getThumb(); // slider is vertical if (d_vertical) { // pixel extent of total available area the thumb moves in float slideExtent = area.getHeight() - theThumb->getPixelSize().d_height; // calculate value represented by current thumb position float thumbValue = (CoordConverter::asAbsolute( theThumb->getYPosition(), w->getPixelSize().d_height) - area.top()) / (slideExtent / w->getMaxValue()); // return final thumb value according to slider settings return d_reversed ? thumbValue : w->getMaxValue() - thumbValue; } // slider is horizontal else { // pixel extent of total available area the thumb moves in float slideExtent = area.getWidth() - theThumb->getPixelSize().d_width; // calculate value represented by current thumb position float thumbValue = (CoordConverter::asAbsolute( theThumb->getXPosition(), w->getPixelSize().d_width) - area.left()) / (slideExtent / w->getMaxValue()); // return final thumb value according to slider settings return d_reversed ? w->getMaxValue() - thumbValue : thumbValue; } }
void drawAudioBuffer( const audio::Buffer &buffer, const Rectf &bounds, bool drawFrame, const ci::ColorA &color ) { gl::ScopedGlslProg glslScope( getStockShader( gl::ShaderDef().color() ) ); gl::color( color ); const float waveHeight = bounds.getHeight() / (float)buffer.getNumChannels(); const float xScale = bounds.getWidth() / (float)buffer.getNumFrames(); float yOffset = bounds.y1; for( size_t ch = 0; ch < buffer.getNumChannels(); ch++ ) { PolyLine2f waveform; const float *channel = buffer.getChannel( ch ); float x = bounds.x1; for( size_t i = 0; i < buffer.getNumFrames(); i++ ) { x += xScale; float y = ( 1 - ( channel[i] * 0.5f + 0.5f ) ) * waveHeight + yOffset; waveform.push_back( vec2( x, y ) ); } if( ! waveform.getPoints().empty() ) gl::draw( waveform ); yOffset += waveHeight; } if( drawFrame ) { gl::color( color.r, color.g, color.b, color.a * 0.6f ); gl::drawStrokedRect( bounds ); } }
void MultiSlider::setup() { float numSliders = (float)mData.size(); vec2 size = getSize(); size.y = mSliderHeight = std::max( size.y - mPadding.mTop - mPadding.mBottom, ( (float)FontSize::SMALL + mPadding.mBottom + mPadding.mTop ) ); mSliderSpacing = mPadding.mTop; size.y = mSliderHeight * numSliders + mPadding.mTop * 2.0f + mPadding.mBottom * 2.0f; if( mData.size() > 1 ) size.y += mSliderSpacing * ( numSliders - 1.0f ); setSize( size ); vec2 hitRectSize = mHitRect.getSize(); float width = hitRectSize.x - ( mPadding.mLeft + mPadding.mRight ); Rectf rect = mHitRect; int index = 0; for( auto &it : mData ) { rect.y1 = mHitRect.y1 + mPadding.mTop + ( mSliderSpacing + mSliderHeight ) * index; rect.y2 = rect.y1 + mSliderHeight; rect.x1 = mHitRect.x1 + mPadding.mLeft; rect.x2 = rect.x1 + width; string sliderName = it.mKey; LabelRef label = Label::create( sliderName + "_LABEL", sliderName, FontSize::SMALL ); mLabelsMap[sliderName] = label; addSubView( label ); float labelHeight = label->getHeight(); float offset = ( rect.getHeight() - labelHeight ) / 2.0f; label->setOrigin( vec2( rect.x1, rect.y1 + offset ) ); index++; } View::setup(); }
void drawGrid(const Rectf &bounds, float sx, float sy, const Vec2f &offset) { float x1 = bounds.x1 - utils::math::boundf(bounds.x1 - offset.x, sx); float y1 = bounds.y1 - utils::math::boundf(bounds.y1 - offset.y, sy); int nx = int(ci::math<float>::ceil(bounds.getWidth() / sx)) + 1; int ny = int(ci::math<float>::ceil(bounds.getHeight() / sy)) + 1; vector<Vec2f> vertices; vertices.reserve((nx + ny) * 4); for (int iy = 0; iy < ny; iy++) { float y = y1 + iy * sy; vertices.emplace_back(bounds.x1, y); vertices.emplace_back(bounds.x2, y); } for (int ix = 0; ix < nx; ix++) { float x = x1 + ix * sx; vertices.emplace_back(x, bounds.y1); vertices.emplace_back(x, bounds.y2); } glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertices.data()); glDrawArrays(GL_LINES, 0, vertices.size()); glDisableClientState(GL_VERTEX_ARRAY); }
void drawVerticalGradient(const Rectf &bounds, const ColorA &color1, const ColorA &color2, float v1, float v2) { float x1 = bounds.x1; float x2 = bounds.x2; float y0 = bounds.y1; float y1 = y0 + bounds.getHeight() * v1; float y2 = y0 + bounds.getHeight() * v2; float y3 = bounds.y2; const float vertices[] = { x1, y0, x2, y0, x1, y1, x2, y1, x1, y2, x2, y2, x1, y3, x2, y3, }; vector<ColorA> colors; for (int i = 0; i < 4; i++) colors.push_back(color1); for (int i = 0; i < 4; i++) colors.push_back(color2); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertices); glColorPointer(4, GL_FLOAT, 0, colors.data()); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4 * 2); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); }
void Cell::loopName(std::string& n) { _loopName = n; fs::path fileName = app::getAssetPath(_loopName + ".svg"); if(fileName.empty()) { _artwork = svg::Doc::create(app::getAssetPath("Cell.svg")); } else { _artwork = svg::Doc::create(fileName); } Rectf rect = _artwork->getBoundingBox(); cairo::SurfaceImage sImg(rect.getWidth(), rect.getHeight(), true); cairo::Context ctx(sImg); ctx.scale(rect.getWidth() / _artwork->getWidth(), rect.getHeight() / _artwork->getHeight()); ctx.render(*_artwork); _texture = sImg.getSurface(); }
void Fluid2DTextureApp::draw() { // clear out the window with black gl::clear( Color( 0, 0, 0 ) ); gl::setMatricesWindow( getWindowWidth(), getWindowHeight() ); // Update the positions and tex coords Rectf drawRect = getWindowBounds(); int limX = mFluid2D.resX() - 1; int limY = mFluid2D.resY() - 1; float dx = drawRect.getWidth()/(float)limX; float dy = drawRect.getHeight()/(float)limY; for( int j = 0; j < mFluid2D.resY(); ++j ) { for( int i = 0; i < mFluid2D.resX(); ++i ) { Vec2f P = Vec2f( i*dx, j*dy ); Vec2f uv = mFluid2D.texCoordAt( i, j ); int idx = j*mFluid2D.resX() + i; mTriMesh.getVertices()[idx] = P; mTriMesh.getTexCoords()[idx] = uv; } } mTex.bind(); gl::draw( mTriMesh ); mTex.unbind(); mParams.draw(); }
//----------------------------------------------------------------------------// float UnifiedDim::getValue(const Window&, const Rectf& container) const { switch (d_what) { case DT_LEFT_EDGE: case DT_RIGHT_EDGE: case DT_X_POSITION: case DT_X_OFFSET: case DT_WIDTH: return CoordConverter::asAbsolute(d_value, container.getWidth()); break; case DT_TOP_EDGE: case DT_BOTTOM_EDGE: case DT_Y_POSITION: case DT_Y_OFFSET: case DT_HEIGHT: return CoordConverter::asAbsolute(d_value, container.getHeight()); break; default: CEGUI_THROW(InvalidRequestException( "unknown or unsupported DimensionType encountered.")); break; } }
void drawBuffer(const std::deque<int8_t>& buffer, const Rectf &bounds, bool drawFrame, const ci::ColorA &color, float scaleFactor ) { gl::ScopedGlslProg glslScope( getStockShader( gl::ShaderDef().color() ) ); gl::color( color ); const float waveHeight = bounds.getHeight(); const float xScale = bounds.getWidth() / (float)buffer.size(); float yOffset = bounds.y1; PolyLine2f waveform; float x = bounds.x1; for( size_t i = 0; i < buffer.size(); i++ ) { x += xScale; float y = ( 1.0f - ( buffer[i] * scaleFactor + 0.5f) ) * waveHeight + yOffset; waveform.push_back( vec2( x, y ) ); } if( ! waveform.getPoints().empty() ) gl::draw( waveform ); if( drawFrame ) { gl::color( color.r, color.g, color.b, color.a * 0.6f ); gl::drawStrokedRect( bounds ); } }
void Fluid2DTextureApp::draw() { // clear out the window with black gl::clear( Color( 0, 0, 0 ) ); gl::setMatricesWindow( getWindowWidth(), getWindowHeight() ); // Update the positions and tex coords Rectf drawRect = getWindowBounds(); int limX = mFluid2D.resX() - 1; int limY = mFluid2D.resY() - 1; float dx = drawRect.getWidth()/(float)limX; float dy = drawRect.getHeight()/(float)limY; for( int j = 0; j < mFluid2D.resY(); ++j ) { for( int i = 0; i < mFluid2D.resX(); ++i ) { vec2 P = vec2( i*dx, j*dy ); vec2 uv = mFluid2D.texCoordAt( i, j ); int idx = j*mFluid2D.resX() + i; mTriMesh->getPositions<2>()[idx] = P; mTriMesh->getTexCoords0<2>()[idx] = uv; } } mTex->bind(); gl::bindStockShader( gl::ShaderDef().color().texture() ); gl::draw( gl::VboMesh::create(*mTriMesh) ); mTex->unbind(); mParams.draw(); }
void Context::copySurface( const SurfaceBase &surface, const Area &srcArea, const Rectf &dstRect ) { if( ( dstRect.getWidth() == 0 ) || ( dstRect.getHeight() == 0 ) ) return; save(); cairo_set_source_surface( mCairo, const_cast<SurfaceBase&>( surface ).getCairoSurface(), 0, 0 ); cairo_pattern_t *sourcePattern = cairo_get_source( mCairo ); cairo_matrix_t m; cairo_matrix_init_identity( &m ); cairo_matrix_scale( &m, srcArea.getWidth() / (float)dstRect.getWidth(), srcArea.getHeight() / (float)dstRect.getHeight() ); cairo_matrix_translate( &m, srcArea.getX1() - dstRect.getX1(), srcArea.getY1() - dstRect.getY1() ); cairo_pattern_set_matrix( sourcePattern, &m ); cairo_rectangle( mCairo, dstRect.getX1(), dstRect.getY1(), dstRect.getWidth(), dstRect.getHeight() ); cairo_fill( mCairo ); restore(); }
void PeerCircle::draw( const Rectf &rect ) { RectMapping rm( sWorldRect, rect, true ); //app::console() << mId << ": " << mRadius << std::endl; gl::color( Color::white() ); gl::drawStrokedCircle( rm.map( mPos ), lmap< float >( 0.f, sWorldRect.getHeight(), 0.f, rect.getHeight(), mRadius ) ); }
//----------------------------------------------------------------------------// void OpenGLESTexture::loadCompressedTextureBuffer(const Rectf& dest_area, const GLvoid* buffer) const { const GLsizei image_size = getCompressedTextureSize(dest_area.getSize()); glCompressedTexImage2D(GL_TEXTURE_2D, 0, d_format, static_cast<GLsizei>(dest_area.getWidth()), static_cast<GLsizei>(dest_area.getHeight()), 0, image_size, buffer); }
void Particles::UpdateParticles( float deltaTime ) { std::vector< float > fftData( MAX_BUCKETS ); const ParamInfo* fftInfo = FindParamInfo( PID_FFT_INPUT ); for( size_t index = 0; index < MAX_BUCKETS; ++index ) fftData[ index ] = fftInfo->elements[ index ].value; glResources.FlipBuffers(); ScopedShaderBinding shaderBinding( glResources.GetUpdateShader().GetGLID() ); glEnable( GL_RASTERIZER_DISCARD ); glBindBufferRange( GL_TRANSFORM_FEEDBACK_BUFFER, 0, glResources.GetBackBufferID(), 0, MAX_BUCKETS * MAX_PARTICLES_PER_BUCKET * sizeof( Vertex ) ); glBeginTransformFeedback( GL_POINTS ); std::vector< Vec4f > spawnAreas( numBuckets ); std::vector< float > spawnChances( numBuckets ); memset( spawnChances.data(), 0, spawnChances.size() * sizeof( float ) ); //TODO: Map from fft's num bins to our num buckets. Audio guys halp! for( size_t index = 0; index < numBuckets && index < fftData.size(); ++index ) { float widthPerBucket = 1.6f / numBuckets; Rectf spawnArea; spawnArea.l = -0.8f + index * widthPerBucket + 0.1f * widthPerBucket; spawnArea.r = spawnArea.l + widthPerBucket - 0.1f * widthPerBucket; spawnArea.t = -1.0f; spawnArea.b = -1.1f; //left, width, bottom, height spawnAreas[ index ] = Vec4f( spawnArea.l, spawnArea.getWidth(), spawnArea.t, spawnArea.getHeight() ); spawnChances[ index ] = fftData[ index ] * fftData[ index ] * 3.0f; } glUniform1f( glResources.GetUpdateShader().FindUniform( "MAX_AGE" ), 60.0f / bpm * maxAge ); glUniform4fv( glResources.GetUpdateShader().FindUniform( "SPAWN_AREAS" ), (GLsizei)spawnAreas.size(), (float*)spawnAreas.data() ); glUniform1fv( glResources.GetUpdateShader().FindUniform( "SPAWN_CHANCES" ), (GLsizei)spawnChances.size(), spawnChances.data() ); glUniform1f( glResources.GetUpdateShader().FindUniform( "ENERGY_MAX_AGE_FACTOR" ), energyMaxAgeFactor ); glUniform1f( glResources.GetUpdateShader().FindUniform( "TURBULENCE_DETAIL" ), turbulenceDetail ); glUniform1f( glResources.GetUpdateShader().FindUniform( "TURBULENCE_SPEED" ), turbulenceSpeed ); glUniform1f( glResources.GetUpdateShader().FindUniform( "BURST_DURATION" ), burstDuration ); glUniform1f( glResources.GetUpdateShader().FindUniform( "BURST_INTENSITY" ), burstIntensity ); glUniform1f( glResources.GetUpdateShader().FindUniform( "Time" ), getTicks() / 1000.0f ); glUniform1f( glResources.GetUpdateShader().FindUniform( "DeltaTime" ), deltaTime ); glUniform2i( glResources.GetUpdateShader().FindUniform( "RenderSize" ), currentViewport.width, currentViewport.height ); ScopedVAOBinding vaoBinding( glResources.GetFrontVAOID() ); glDrawArrays( GL_POINTS, 0, static_cast< GLsizei >( numBuckets * numParticlesPerBucket ) ); vaoBinding.EndScope(); glEndTransformFeedback(); glBindBufferRange( GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0, 0, 0 ); glDisable( GL_RASTERIZER_DISCARD ); }
RectMapping::RectMapping( const Rectf &aSrcRect, const Rectf &aDstRect, bool preserveSrcAspect ) : mSrcRect( aSrcRect ), mDstRect( aDstRect ) { if( preserveSrcAspect ) { float srcAspect = aSrcRect.getWidth() / (float)aSrcRect.getHeight(); float dstAspect = aDstRect.getWidth() / (float)aDstRect.getHeight(); if( srcAspect < dstAspect ) { // src is narrower aspect float heightRatio = mDstRect.getHeight() / mSrcRect.getHeight(); float effectiveWidth = mSrcRect.getWidth() * heightRatio; float offsetX = ( mDstRect.getWidth() - effectiveWidth ) / 2.0f; float dstWidth = mDstRect.getHeight() * srcAspect; mDstRect.set( mDstRect.x1 + offsetX, mDstRect.getY1(), mDstRect.x1 + offsetX + dstWidth, mDstRect.getY2() ); } else { // src is wider aspect float effectiveHeight = mSrcRect.getHeight() * ( mDstRect.getWidth() / mSrcRect.getWidth() ); float offsetY = ( mDstRect.getHeight() - effectiveHeight ) / 2.0f; float dstHeight = mDstRect.getWidth() / srcAspect; mDstRect.set( mDstRect.x1, mDstRect.getY1() + offsetY, mDstRect.x2, mDstRect.getY1() + offsetY + dstHeight ); } } }
void FlickrImageViewerApp::draw() { // clear out the window with black gl::clear( Color( 0, 0, 0 ) ); // calculate elapsed time in seconds (since last swap) double elapsed = ( getElapsedSeconds() - mTimeSwapped ); // calculate crossfade alpha value double fade = ci::math<double>::clamp(elapsed / mTimeFade, 0.0, 1.0); // calculate zoom factor float zoom = getWindowWidth() / 600.0f * 0.025f; // draw back image if(mBack) { Rectf image = mBack.getBounds(); Rectf window = getWindowBounds(); float sx = window.getWidth() / image.getWidth(); // scale width to fit window float sy = window.getHeight() / image.getHeight(); // scale height to fit window float s = ci::math<float>::max(sx, sy) + zoom * (float) (elapsed + mTimeDuration); // fit window and zoom over time float w = image.getWidth() * s; // resulting width float h = image.getHeight() * s; // resulting height float ox = -0.5f * (w - window.getWidth()); // horizontal position to keep image centered float oy = -0.5f * (h - window.getHeight()); // vertical position to keep image centered image.set(ox, oy, ox+w, oy+h); gl::color( Color(1, 1, 1) ); gl::draw( mBack, image ); } // draw front image if(mFront) { Rectf image = mFront.getBounds(); Rectf window = getWindowBounds(); float sx = window.getWidth() / image.getWidth(); float sy = window.getHeight() / image.getHeight(); float s = ci::math<float>::max(sx, sy) + zoom * (float) elapsed; float w = image.getWidth() * s; float h = image.getHeight() * s; float ox = -0.5f * (w - window.getWidth()); float oy = -0.5f * (h - window.getHeight()); image.set(ox, oy, ox+w, oy+h); gl::color( ColorA(1, 1, 1, (float) fade) ); gl::enableAlphaBlending(); gl::draw( mFront, image ); gl::disableAlphaBlending(); } }
void UserManager::setBounds( const Rectf &rect ) { mOutputRect = rect; Rectf kRect( 0, 0, 640, 480 ); // kinect image rect Rectf dRect = kRect.getCenteredFit( mOutputRect, true ); if( mOutputRect.getAspectRatio() > dRect.getAspectRatio() ) dRect.scaleCentered( mOutputRect.getWidth() / dRect.getWidth() ); else dRect.scaleCentered( mOutputRect.getHeight() / dRect.getHeight() ); mOutputMapping = RectMapping( kRect, dRect, true ); }
/************************************************************************* Draw the tree item in its current state. *************************************************************************/ void TreeItem::draw(GeometryBuffer& buffer, const Rectf& targetRect, float alpha, const Rectf* clipper) const { Rectf finalRect(targetRect); if (d_iconImage != 0) { Rectf finalPos(finalRect); finalPos.setWidth(targetRect.getHeight()); finalPos.setHeight(targetRect.getHeight()); d_iconImage->render(buffer, finalPos, clipper, ColourRect(Colour(1,1,1,alpha))); finalRect.d_min.d_x += targetRect.getHeight(); } if (d_selected && d_selectBrush != 0) d_selectBrush->render(buffer, finalRect, clipper, getModulateAlphaColourRect(d_selectCols, alpha)); const Font* font = getFont(); if (!font) return; Vector2f draw_pos(finalRect.getPosition()); draw_pos.d_y -= (font->getLineSpacing() - font->getBaseline()) * 0.5f; if (!d_renderedStringValid) parseTextString(); const ColourRect final_colours( getModulateAlphaColourRect(ColourRect(0xFFFFFFFF), alpha)); for (size_t i = 0; i < d_renderedString.getLineCount(); ++i) { d_renderedString.draw(d_owner, i, buffer, draw_pos, &final_colours, clipper, 0.0f); draw_pos.d_y += d_renderedString.getPixelSize(d_owner, i).d_height; } }
Sizef FalagardTooltip::getTextSize() const { Tooltip* w = (Tooltip*)d_window; Sizef sz(w->getTextSize_impl()); // get WidgetLookFeel for the assigned look. const WidgetLookFeel& wlf = getLookNFeel(); const Rectf textArea(wlf.getNamedArea("TextArea").getArea().getPixelRect(*w)); const Rectf wndArea(CoordConverter::asAbsolute(w->getArea(), w->getParentPixelSize())); sz.d_width = CoordConverter::alignToPixels(sz.d_width + wndArea.getWidth() - textArea.getWidth()); sz.d_height = CoordConverter::alignToPixels(sz.d_height + wndArea.getHeight() - textArea.getHeight()); return sz; }
void View::addRect( vector<RenderData> &data, const ColorA &color, const Rectf &rect, float z ) { int offset = data.size(); data.push_back( RenderData() ); data.push_back( RenderData() ); data.push_back( RenderData() ); data.push_back( RenderData() ); data.push_back( RenderData() ); data.push_back( RenderData() ); float x = mBounds.x1 + rect.x1; float y = mBounds.y1 + rect.y1; if( !mSuperView.expired() ) { vec2 origin = mSuperView.lock()->getOrigin(); x += origin.x; y += origin.y; } float w = rect.getWidth(); float h = rect.getHeight(); data[offset+0].pos = vec3( x, y, z ); data[offset+1].pos = vec3( x+w, y, z ); data[offset+2].pos = vec3( x+w, y+h, z ); data[offset+3].pos = vec3( x+w, y+h, z ); data[offset+4].pos = vec3( x, y+h, z ); data[offset+5].pos = vec3( x, y, z ); data[offset+0].color = vec4( color.r, color.g, color.b, color.a ); data[offset+1].color = vec4( color.r, color.g, color.b, color.a ); data[offset+2].color = vec4( color.r, color.g, color.b, color.a ); data[offset+3].color = vec4( color.r, color.g, color.b, color.a ); data[offset+4].color = vec4( color.r, color.g, color.b, color.a ); data[offset+5].color = vec4( color.r, color.g, color.b, color.a ); data[offset+0].uv = vec2( 0, 0 ); data[offset+1].uv = vec2( 1, 0 ); data[offset+2].uv = vec2( 1, 1 ); data[offset+3].uv = vec2( 1, 1 ); data[offset+4].uv = vec2( 0, 1 ); data[offset+5].uv = vec2( 0, 0 ); }
//----------------------------------------------------------------------------// void OpenGLESTexture::loadUncompressedTextureBuffer(const Rectf& dest_area, const GLvoid* buffer) const { GLint old_pack; glGetIntegerv(GL_UNPACK_ALIGNMENT, &old_pack); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(dest_area.left()), static_cast<GLint>(dest_area.top()), static_cast<GLsizei>(dest_area.getWidth()), static_cast<GLsizei>(dest_area.getHeight()), d_format, d_subpixelFormat, buffer); glPixelStorei(GL_UNPACK_ALIGNMENT, old_pack); }
//----------------------------------------------------------------------------// void OpenGL3Texture::blitFromMemory(void* sourceData, const Rectf& area) { // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); // set texture to required size glBindTexture(GL_TEXTURE_2D, d_ogltexture); glTexSubImage2D(GL_TEXTURE_2D, 0, GLint(area.left()), GLint(area.top()), GLsizei(area.getWidth()), GLsizei(area.getHeight()), GL_RGBA8, GL_UNSIGNED_BYTE, sourceData ); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); }
Rectf getCoveringRect(gl::Texture texture, Area containerArea) { float scale; Rectf bounds = texture.getBounds(); bounds = bounds.getCenteredFit(containerArea, true); int container_h = containerArea.getHeight(), container_w = containerArea.getWidth(), texture_h = bounds.getHeight(), texture_w = bounds.getWidth(); if (abs(container_h - texture_h) > abs(container_w - texture_w)) scale = (float) container_h/texture_h; else scale = (float) container_w/texture_w; bounds.scaleCentered(scale + .05); return bounds; }