void ViewerController::createGridLayout(const ci::Rectf area, const int numItems, std::vector<ci::Vec2f>& positions){ if(numItems < 1) return; float xStart = area.getX1(); float yStart = area.getY1(); float numContents = (float)(numItems); int contentsPerRow = (int)ceilf(sqrt(numContents)); if(numContents > 5) contentsPerRow += 1; /// make the aspect more wide if(numContents > 15) contentsPerRow += 1; /// make the aspect more wide if(numContents > 25) contentsPerRow += 1; /// make the aspect more wide if(numContents > 35) contentsPerRow += 2; /// make the aspect more more wide int numRows = (int)ceilf(numContents / (float)(contentsPerRow)); float xSpacing = area.getWidth() / (float)(contentsPerRow); float ySpacing = area.getHeight() / (float)(numRows); int rowCounter = 0; xStart += xSpacing / 2.0f; float xp = xStart; float yp = yStart; for(int i = 0; i < numItems; i++){ ci::Vec2f origin = ci::Vec2f(xp, yp); if(contentsPerRow == 1){ origin.x = area.getX1() + area.getWidth() / 2.0f; } if(numRows == 1){ origin.y = yStart + area.getHeight() / 4.0f; } positions.push_back(origin); xp += xSpacing; rowCounter++; if(rowCounter == contentsPerRow){ rowCounter = 0; xp = xStart; if(numRows == 2){ // 2 rows, the second row was too low yp += ySpacing / 2.0f; } else { yp += ySpacing; } } } }
void GestureApp::drawUi() { // Dial gl::color( ColorAf( Colorf::white(), 0.2f + mDialBrightness ) ); gl::drawSolidCircle( mDialPosition, mDialRadius, mCircleResolution * 2 ); gl::color( mBackgroundColor ); float angle = mDialValue * (float)M_PI * 2.0f; vec2 pos( math<float>::cos( angle ), math<float>::sin( angle ) ); pos *= mDialRadius - mDotSpacing; gl::drawSolidCircle( mDialPosition + pos, mDotRadius, mCircleResolution ); // Swipe float x = mSwipeRect.x1 + mSwipePos * mSwipeRect.getWidth(); Rectf a( mSwipeRect.x1, mSwipeRect.y1, x, mSwipeRect.y2 ); Rectf b( x, mSwipeRect.y1, mSwipeRect.x2, mSwipeRect.y2 ); gl::color( ColorAf( Colorf::gray( 0.5f ), 0.2f + mSwipeBrightness ) ); gl::drawSolidRect( a ); gl::color( ColorAf( Colorf::white(), 0.2f + mSwipeBrightness ) ); gl::drawSolidRect( b ); // Keys for ( vector<Key>::iterator iter = mKeys.begin(); iter != mKeys.end(); ++iter ) { gl::color( ColorAf( Colorf::white(), 0.2f + iter->mBrightness ) ); gl::drawSolidRect( iter->mBounds ); } }
void QLiveGUI::init( ci::Rectf rect ) // rect doesn't make any f*****g sense! TODO: remove this shit! { std::vector<QLiveTrackRef> tracks = mLive->getTracks(); if ( tracks.empty() ) return; int margin = 15; int n = 0; for( auto k=0; k < tracks.size(); k++ ) if ( !boost::starts_with( tracks[k]->getName(), "_") ) // IGNORE all the params in the tracks that starts with "_" n++; Vec2f size; size.x = ( rect.getWidth() - ( n + 1 ) * margin ) / n; size.y = 150; for( auto k=0; k < tracks.size(); k++ ) { if ( boost::starts_with( tracks[k]->getName(), "_") ) // IGNORE all the params in the tracks that starts with "_" continue; mControls.push_back( QLiveGuiTrackControl::create( mLive, tracks[k], size, mCanvas ) ); } }
/* ging methods */ void CinderOpenNISkeleton::debugDrawLabels( Font font, ci::Rectf depthArea ) { // Apply scale based on window size, vs dimensions of depth image ( will be 320 or 640 ) ci::Vec2i inputSize = CinderOpenNISkeleton::getDimensions(); ci::Vec3f depthMapScale = ci::Vec3f( depthArea.getWidth() / inputSize.x, depthArea.getHeight() / inputSize.y, 0.5f ); for (int i = 0; i < maxUsers; ++i) { // Do the labels first XnPoint3D userCenterOfMass; mUserGenerator.GetCoM(currentUsers[i], userCenterOfMass); mDepthGenerator.ConvertRealWorldToProjective(1, &userCenterOfMass, &userCenterOfMass); // Scale and place based on center of 'depthArea' rectangle ci::Vec2i labelPosition = ci::Vec2i(depthArea.getX1() + depthMapScale.x*userCenterOfMass.X, depthArea.getY1() + depthMapScale.y*userCenterOfMass.Y); glColor4f(1.0f-Colors[i%nColors][0], 1.0f-Colors[i%nColors][1], 1.0f-Colors[i%nColors][2], 1); if ( mUserGenerator.GetSkeletonCap().IsTracking(currentUsers[i]) ) { // Is being tracked gl::drawString("Tracking", labelPosition, Color::white(), font ); } else if ( mUserGenerator.GetSkeletonCap().IsCalibrating(currentUsers[i]) ) { // Is calibrating gl::drawString("Calibrating", labelPosition, Color::white(), font ); } else { // Still waiting for intial pose gl::drawString("Waiting for Pose", labelPosition, Color::white(), font ); } } }
// ------------------------------------------------------- void BasePretzel::updateBounds(const ci::Vec2f &offset, const ci::Rectf &parentBounds){ mOffset.set(offset); mParentBounds = parentBounds; mBounds.x2 = parentBounds.getWidth(); mGlobalOffset.set( mGlobal->getGlobalPos() ); }
void View::addCenterLines( std::vector<RenderData> &data, const ci::ColorA &color, const ci::Rectf rect, float lineWidth ) { vec2 offset = rect.getUpperLeft(); float w = rect.getWidth(); float h = rect.getHeight(); float hw = w*0.5; float hh = h*0.5; addLine( data, color, offset + vec2(0, hh), offset + vec2(w, hh), lineWidth ); addLine( data, color, offset + vec2(hw, 0), offset + vec2(hw, h), lineWidth ); }
void View::addPointGrid( std::vector<RenderData> &data, const ci::ColorA &color, const ci::Rectf rect, float gridInterval, float pointSize ) { vec2 offset = rect.getUpperLeft(); float w = rect.getWidth(); float h = rect.getHeight(); float hw = w*0.5; float hh = h*0.5; for( int x = 0; x <= hw; x+=gridInterval ) { for( int y = 0; y <= hh; y+=gridInterval ) { addPoint( data, color, offset + vec2(hw+x, hh+y), pointSize ); addPoint( data, color, offset + vec2(hw-x, hh+y), pointSize ); addPoint( data, color, offset + vec2(hw-x, hh-y), pointSize ); addPoint( data, color, offset + vec2(hw+x, hh-y), pointSize ); } } }
void World::setBounds(const ci::Rectf& f, const float restitution) { if (f.x2 <= f.x1 || f.y2 <= f.y1) { DS_LOG_WARNING_M("World constructed on invalid bounds (" << f << ")", PHYSICS_LOG); return; } b2BodyDef def; def.type = b2_staticBody; def.fixedRotation = true; mBounds = mWorld->CreateBody(&def); if (!mBounds) throw std::runtime_error("ds::physics::World() can't create mBounds"); b2PolygonShape shape; b2FixtureDef fixtureDef; fixtureDef.shape = &shape; fixtureDef.density = 0.0f; fixtureDef.friction = mFriction; fixtureDef.restitution = restitution; // Make the world walls large enough to prevent anything from flying outside. const float world_w = f.getWidth(), world_h = f.getHeight(); // left set_polygon_shape(*this, f.x1-world_w, f.y1-world_h, f.x1, f.y2+world_h, shape); fixtureDef.userData = BOUNDS_LEFT_PTR; mBounds->CreateFixture(&fixtureDef); // top set_polygon_shape(*this, f.x1-world_w, f.y1-world_h, f.x2+world_w, f.y1, shape); fixtureDef.userData = BOUNDS_TOP_PTR; mBounds->CreateFixture(&fixtureDef); // right set_polygon_shape(*this, f.x2, f.y1-world_h, f.x2+world_w, f.y2+world_h, shape); fixtureDef.userData = BOUNDS_RIGHT_PTR; mBounds->CreateFixture(&fixtureDef); // bottom set_polygon_shape(*this, f.x1-world_w, f.y2, f.x2+world_w, f.y2+world_h, shape); fixtureDef.userData = BOUNDS_BOTTOM_PTR; mBounds->CreateFixture(&fixtureDef); }
ci::gl::TextureRef PretzelGlobal::getTextureFromSkin( ci::Rectf rect ){ Surface srf( rect.getWidth(), rect.getHeight(), true); srf.copyFrom( mSkinSurf, Area(rect.x1, rect.y1, rect.x2, rect.y2), vec2(-rect.x1, -rect.y1) ); return ci::gl::Texture::create( srf ); }