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 mouseDown( MouseEvent event ) { if (event.isLeftDown()) { mSelectionMode = 1; // 選択開始 mSelectRegion.set(event.getX()-5, event.getY()-5, event.getX()+5, event.getY()+5); } mMPPrev = event.getPos(); }
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; }
Rectf SettingsPanel::getBounds(const vector<Gwen::Controls::Base*>& vec){ Rectf rect; int h = 0; int dist = 15; for(int i=0;i<vec.size();i++){ h += vec[i]->GetSize().y + dist; } rect.set(10, h + 35, 200 + 10, 30); return rect; }
void mouseDrag( MouseEvent event ) { if (mEditMode == EditMode_RECORD) return; // 制御点の選択を行う if (event.isLeftDown()) { if (mSelectionMode == 0) return; float x1 = mSelectRegion.getX1(); float y1 = mSelectRegion.getY1(); mSelectRegion.set(x1, y1, event.getX()+5, event.getY()+5); for (int k = 0; k < mCtrlPointsNum; ++k) { if (mSelectRegion.contains(mCtrlPoints[k].pos)) { mCtrlPoints[k].isSelected = true; } else { mCtrlPoints[k].isSelected = false; } } } Vec2f d = event.getPos() - mMPPrev; if (event.isRightDown()) { for (int k = 0; k < mCtrlPointsNum; ++k) { if (mCtrlPoints[k].isSelected) { mCtrlPoints[k].mag += d; } } } if (event.isMiddleDown()) { int ci = -1; int cj = -1; float nearest = 1.e+10; for (int j = 0; j < 2; ++j) { for (int i = 0; i < 2; ++i) { Vec2f cp(distpoints[j][i][0], distpoints[j][i][1]); float dist = event.getPos().distance(cp); if (dist < nearest) { ci = i; cj = j; nearest = dist; } } } if (ci > -1 && cj > -1) { distpoints[cj][ci][0] += d.x; distpoints[cj][ci][1] += d.y; } } mMPPrev = event.getPos(); }
bool View::isHit( const vec2 &pt ) { if( mVisible ) { Rectf r; r.set( 0, 0, getWidth(), getHeight() ); r.offset( getOrigin() ); return r.contains( pt ); } return false; }
void PaintingBeingsApp::setup() { setStop(); // Setup des paramètres de OpenGL glShadeModel(GL_SMOOTH); gl::enable(GL_POLYGON_SMOOTH); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); gl::enableAlphaBlending(); gl::enableDepthRead(); gl::enableDepthWrite(); // Setup Capture webcam _capture = Capture(640, 480); _capture.start(); // Setup camera float fieldOfView = 75.0f; float nearCamera = 0.1f; float farCamera = 1000000.0f; _camera = CameraPersp(getWindowWidth(), getWindowHeight(), fieldOfView, nearCamera, farCamera); _camera.lookAt(Vec3f(0.0f, 0.0f, 50.0f), Vec3f::zero()); // Setup arcball (camera rotation) float radiusArcBall = static_cast<float>(getWindowHeight() * 0.5f); _arcball = Arcball(getWindowSize()); _arcball.setRadius(radiusArcBall); // Génération de la population d'ImageBeing _imageBeing = ImageBeing(); _rectangleAlgoGen.set(-75.0f, 25.0f, -25.0f, -25.0f); _rectangleTextutre.set(25.0f, 25.0f, 75.0f, -25.0f); // Setup de l'interface _params = params::InterfaceGl("Options", Vec2i(200, 400)); updateInterface(false); }
void ImageRetargetingApp::initTextures(fs::path path) { originalTexture = gl::Texture(loadImage( path )); originalImage = Surface(originalTexture); gradientImage = seamCarver->getGradientImage(originalImage.clone()); gradientTexture = gl::Texture(gradientImage);; seamCarvedImage = originalImage.clone(); seamCarvedTexture = gl::Texture(seamCarvedImage); segmentedImage = originalImage.clone(); segmentedTexture = gl::Texture(segmentedImage); saliencyImage = saliencySegmentor->getSaliencyMap(originalImage.clone(), SaliencySegmentor::SaliencyMethod::Sobel); saliencyImage = saliencySegmentor->getSegmentedSalientImage(saliencyImage); saliencyTexture = gl::Texture(saliencyImage); originalWidth = originalImage.getWidth(); originalHeight = originalImage.getHeight(); meshWarpRetargetter->initMesh(originalWidth, originalHeight, saliencySegmentor); linearScaleRec->set(0, 0, originalWidth, originalHeight); }
void NodeView::draw(cairo::Context &theG) { _size = _calculateSize(); cairo::GradientLinear myGradient(0, 0, 0, _size.y); if(_node->state() == WARNING) { myGradient.addColorStop(0.15, Colorf(0.518, 0.298, 0.298*0.5)); myGradient.addColorStop(0.85, Colorf(0.898, 0.467, 0.0)); } else if(_node->state() == ERROR) { myGradient.addColorStop(0.15, Colorf(0.5, 0, 0)); myGradient.addColorStop(0.85, Colorf(0.8, 0, 0)); } else { myGradient.addColorStop(0.15, Colorf(0.14, 0.12, 0.129)); myGradient.addColorStop(0.85, Colorf(0.227, 0.188, 0.2)); } Rectf myRect; myRect.set(0, 0, _size.x, _size.y); Vec2f myCorrection(0.5, 0.5); theG.translate(myCorrection); theG.translate(_position); theG.setSourceRgb(0.7, 0.7, 0.7); theG.roundedRectangle(myRect, 2); theG.setLineWidth(1); theG.stroke(); theG.translate(Vec2f(-0.5, -0.5)); theG.setSource(myGradient); theG.roundedRectangle(myRect, 2); theG.fill(); // for(int i = 0; i < _node->inputs().size(); i++) { // NodeInputBase *myInput = _node->inputs()[i]; // int myX = _size.x - (i * PIN_WIDTH + (i-1) * PIN_SPACING + PIN_SPACING + PIN_WIDTH); // // theG.setSourceRgb(0.8, 0.8, 0.8); // theG.rectangle(myX - PIN_WIDTH, 0, PIN_WIDTH, PIN_HEIGHT); // theG.fill(); // // // // } // // // // for(int i = 0; i < _node->outputs().size(); i++) { // NodeOutputBase *myOutput = _node->outputs()[i]; // // int myX = _size.x - (i * PIN_WIDTH + (i-1) * PIN_SPACING + PIN_SPACING + PIN_WIDTH); // // theG.setSourceRgb(0.8, 0.8, 0.8); // theG.rectangle(myX - PIN_WIDTH, _size.y - PIN_HEIGHT, PIN_WIDTH, PIN_HEIGHT); // theG.fill(); // } theG.translate(Vec2f(5, _size.y - 5)); theG.setSourceRgb(0.8, 0.8, 0.8); theG.setFont( _font ); theG.setFontSize( 10 ); theG.showText( _node->name() ); theG.fill(); theG.setSourceRgb(1.0, 0, 0); theG.flush(); }
void Example0101App::setup() { setWindowSize( 250, 250 ); rect.set( 50, 50, 200, 200 ); }
void ImageRetargetingApp::linearResizeWindowResize() { linearScaleWidth = linearScaleWindow->getWidth(); linearScaleHeight = linearScaleWindow->getHeight(); linearScaleRec->set(0,0,linearScaleWidth,linearScaleHeight); }
void ImageRetargetingApp::linearResizeButtonClick() { linearScaleRec->set(0,0,linearScaleWidth,linearScaleHeight); linearScaleWindow->setSize(linearScaleWidth,linearScaleHeight); }
void ImageRetargetingApp::linearResizeResetButtonClick() { linearScaleRec->set(0,0,originalImage.getWidth(),originalImage.getHeight()); linearScaleWindow->setSize(originalImage.getWidth(),originalImage.getHeight()); }