// Temporary fix until OF 0.8.0 static void rectangle(ofPath & path, const ofRectangle & r){ path.moveTo(r.getTopLeft()); path.lineTo(r.getTopRight()); path.lineTo(r.getBottomRight()); path.lineTo(r.getBottomLeft()); path.close(); }
void hlct::LivesDisplay::draw(const ofRectangle& stageRect, const int& livesLeft, const float& scale){ float iconW = full.getWidth() * scale; float iconH = full.getHeight() * scale; float rectW = stageRect.getWidth(); float rectH = stageRect.getHeight(); float rectX = rectW - iconW * totalLives; float rectY = 0; ofPushMatrix(); ofPushStyle(); ofTranslate(stageRect.getTopRight()); ofTranslate(-iconW * this->totalLives, -iconH / 2); for (int i = 0; i < this->totalLives; i++){ ofPushMatrix(); ofTranslate(iconW * i, iconH/2); if (i < livesLeft) { ofSetColor(ofColor::white, 200); full.draw(0, 0, iconW, iconH); } else { ofSetColor(ofColor::white, 200); dead.draw(0, 0, iconW, iconH); } ofPopMatrix(); } ofPopStyle(); ofPopMatrix(); }
//---------------------------------------------------------- void ofPath::rectangle(const ofRectangle & r){ moveTo(r.getTopLeft()); lineTo(r.getTopRight()); lineTo(r.getBottomRight()); lineTo(r.getBottomLeft()); close(); }
/* ofxOscilloscope::ofxOscilloscope() { _variableNames = NULL; //ofTrueTypeFont::setGlobalDpi(72); _legendFont.loadFont("verdana.ttf", 12, true, true); //_legendFont.setLineHeight(18.0f); //_legendFont.setLetterSpacing(1.037); _min=ofPoint(0,0); _max=ofGetWindowSize(); _legendWidth=100; } */ ofxOscilloscope::ofxOscilloscope(ofRectangle scopeArea, ofTrueTypeFont legendFont, int legendWidth, ofColor outlineColor, ofColor zeroLineColor, ofColor backgroundColor, float plotLineWidth, float outlineWidth) { _min = scopeArea.getTopLeft(); _max = scopeArea.getBottomRight(); _legendWidth = legendWidth; // Create scopePlot ofPoint min = _min; ofPoint max = _max; min.x = min.x + _legendWidth; _scopePlot = ofxScopePlot(min, max, zeroLineColor, plotLineWidth); setBackgroundColor(backgroundColor); setOutlineColor(outlineColor); setOutlineWidth(outlineWidth); if(legendFont.isLoaded()) { setLegendFont(legendFont); } else { _legendFont.loadFont("verdana.ttf", 12, true, true); //_legendFont.setLineHeight(18.0f); //_legendFont.setLetterSpacing(1.037); //ofTrueTypeFont::setGlobalDpi(72); } // Default values _legendPadding = 10; _textSpacer = 20; }
void RectangleUtils::distributeHorz(RectanglePointers& rects, const ofRectangle& boundingRect, ofAlignHorz horzAnchor) { if(rects.size() >= 3 && horzAnchor != OF_ALIGN_HORZ_IGNORE) { sortByHorzAnchor(rects,horzAnchor); float nPos = rects.size() - 1; // adjust to bounding bounding rect. if bounding rect is based on the group, nothing will change rects[0]->translateX(boundingRect.getLeft() - rects[0]->getLeft()); rects[nPos]->translateX(boundingRect.getRight() - rects[nPos]->getRight()); float leftX = rects[0]->getHorzAnchor(horzAnchor); float rightX = rects[nPos]->getHorzAnchor(horzAnchor); float span = ( rightX - leftX ) / ( nPos ); for(size_t i = 1; i < nPos; i++) { rects[i]->translateX((leftX - rects[i]->getHorzAnchor(horzAnchor)) + i * span); } } else { if(horzAnchor == OF_ALIGN_HORZ_IGNORE) { ofLogVerbose("ofDistributeHorizontal") << "OF_ALIGN_HORZ_IGNORE distribute requested, ignoring."; } else { ofLogWarning("ofDistributeHorizontal") << "Not enough rectangles to distribute."; } } }
void yeseulCooperMessages::tensionEffect(ofRectangle rec1, ofRectangle rec2) { if (abs((dimensions.width/2+margin-redMove*1.1 - (0-dimensions.width/2-rec1.getWidth()-margin+redMove*1.6))) < rec1.getWidth()) { redMove+=redTextSpeed/7; } else { redMove+=redTextSpeed; } if (abs((dimensions.width/2+margin-greenMove) - (0-dimensions.width/2-rec1.getWidth()-margin+greenMove)) < rec1.getWidth()) { greenMove+=greenTextSpeed/6; } else { greenMove+=greenTextSpeed; } if (abs((0-dimensions.width/2-margin-rec1.getWidth()+purpleMove*1.7) - (dimensions.width/2+margin-150-purpleMove*1.4)) < rec1.getWidth()) { purpleMove+=purpleTextSpeed/6; } else { purpleMove+=purpleTextSpeed; } resetPosition(); }
void DrawGame::drawScaledStringByFont( string Txt, ofTrueTypeFont* pFont, ofRectangle Rect ) { // debug float sh = pFont->stringHeight(Txt); float sw = pFont->stringWidth(Txt); ofRectangle R0(0,0,sw,-sh); ofVec2f Trans = Rect.getCenter()-R0.getCenter(); float sx,sy; sx = Rect.getWidth()/R0.getWidth(); sy = -Rect.getHeight()/R0.getHeight(); ofMatrix4x4 Mat; Mat.translate(-R0.getCenter()); Mat.scale(sx,sy,1.0f); // Mat.translate(Rect.getCenter()/ofVec2f(sx,sy)); Mat.translate(Rect.getCenter()); ofMultMatrix(Mat); pFont->drawString(Txt,0,0); ofMatrix4x4 MatI; MatI = Mat.getInverse(); ofMultMatrix(MatI); }
void RectangleUtils::distributeVert(RectanglePointers& rects, const ofRectangle& boundingRect, ofAlignVert vertAnchor) { if(rects.size() >= 3 && vertAnchor != OF_ALIGN_VERT_IGNORE) { sortByVertAnchor(rects,vertAnchor); float nPos = rects.size() - 1; // adjust to bounding bounding rect. if bounding rect is based on the group, nothing will change rects[0]->translateY(boundingRect.getTop() - rects[0]->getTop()); rects[nPos]->translateY(boundingRect.getBottom() - rects[nPos]->getBottom()); float topY = rects[0]->getVertAnchor(vertAnchor); float bottomY = rects[nPos]->getVertAnchor(vertAnchor); float span = ( bottomY - topY ) / ( nPos ); for(size_t i = 1; i < nPos; i++) { rects[i]->translateY((topY - rects[i]->getVertAnchor(vertAnchor)) + i * span); } } else { if(vertAnchor == OF_ALIGN_VERT_IGNORE) { ofLogVerbose("ofDistributeVertical") << "OF_ALIGN_VERT_IGNORE distribute requested, ignoring."; } else { ofLogWarning("ofDistributeVertical") << "Not enough rectangles to distribute."; } } }
void Dimentions::drawBrakets(ofRectangle _rect, float size, float margin){ ofPushStyle(); ofSetLineWidth(2); ofPushMatrix(); ofTranslate(_rect.getTopLeft() + ofPoint(-margin,-margin)); ofLine(0, 0, size, 0); ofLine(0, 0, 0, size); ofPopMatrix(); ofPushMatrix(); ofTranslate(_rect.getTopRight() + ofPoint(margin,-margin)); ofLine(0, 0, -size, 0); ofLine(0, 0, 0, size); ofPopMatrix(); ofPushMatrix(); ofTranslate(_rect.getBottomLeft() + ofPoint(-margin,margin)); ofLine(0, 0, size, 0); ofLine(0, 0, 0, -size); ofPopMatrix(); ofPushMatrix(); ofTranslate(_rect.getBottomRight() + ofPoint(margin,margin)); ofLine(0, 0, -size, 0); ofLine(0, 0, 0, -size); ofPopMatrix(); ofPopStyle(); }
//-------------------------------------------------------------- void Surface::drawDevicePointSurface(ofRectangle& rect) { ofPushStyle(); ofSetColor(255,255,255,255); ofEnableAlphaBlending(); vector<Device*>::iterator itDevices = m_listDevices.begin(); ofVec2f posSurface; Device* pDevice=0; for (;itDevices!=m_listDevices.end();++itDevices) { pDevice = *itDevices; posSurface.set(rect.getX()+pDevice->m_pointSurface.x*rect.getWidth(), rect.getY()+pDevice->m_pointSurface.y*rect.getHeight()); if (GLOBALS->mp_deviceManager->getDeviceCurrent() == pDevice) { ofSetColor(255,255,255,255); } else ofSetColor(255,255,254,100); ofLine(posSurface.x,posSurface.y-40, posSurface.x, posSurface.y+40); ofLine(posSurface.x-40,posSurface.y, posSurface.x+40,posSurface.y); ofDrawBitmapString(pDevice->m_id, posSurface.x+4, posSurface.y-4); } ofPopStyle(); }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setSensorCrop(ofRectangle& rectangle) { sensorCropConfig.xLeft = ((uint32_t)rectangle.getLeft() << 16)/100; sensorCropConfig.xTop = ((uint32_t)rectangle.getTop() << 16)/100; sensorCropConfig.xWidth = ((uint32_t)rectangle.getWidth() << 16)/100; sensorCropConfig.xHeight = ((uint32_t)rectangle.getHeight() << 16)/100; OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigInputCropPercentages, &sensorCropConfig); OMX_TRACE(error); if(error != OMX_ErrorNone) { ofLogError(__func__) << omxErrorToString(error); if(error == OMX_ErrorBadParameter) { ofLogWarning(__func__) << "resetting cropRectangle to known good params (0, 0, 100, 100)"; cropRectangle.set(0, 0, 100, 100); return updateSensorCrop(); } } return error; }
//---------- ofRectangle operator*(const ofRectangle & rectangle, const ofMatrix4x4 & transform) { auto topLeft = rectangle.getTopLeft(); auto scale = ofVec4f(rectangle.getWidth(), rectangle.getHeight(), 0.0f, 0.0f); // w = 0 so no translate topLeft = topLeft * transform; scale = scale * transform; return ofRectangle(topLeft.x, topLeft.y, scale.x, scale.y); }
//-------------------------------------------------------------- void testApp::drawVertAlignMark(const ofRectangle& rect, const ofColor& color, ofAlignVert vAlign) { if(vAlign != OF_ALIGN_VERT_IGNORE) { float vAnchor = rect.getVertAnchor(vAlign); ofSetColor(color,120); ofLine(rect.getLeft() - 13, vAnchor, rect.getLeft() - 3, vAnchor); ofLine(rect.getRight() + 13, vAnchor, rect.getRight() + 3, vAnchor); } }
//-------------------------------------------------------------- void testApp::drawHorzAlignMark(const ofRectangle& rect, const ofColor& color, ofAlignHorz hAlign) { if(hAlign != OF_ALIGN_HORZ_IGNORE) { float hAnchor = rect.getHorzAnchor(hAlign); ofSetColor(color,120); ofLine(hAnchor, rect.getTop() - 13, hAnchor, rect.getTop() - 3); ofLine(hAnchor, rect.getBottom() + 13, hAnchor, rect.getBottom() + 3); } }
void hlct::Game::drawLoadingBar(const ofRectangle& rect, const float& width){ ofNoFill(); ofDrawRectangle(rect); ofFill(); ofDrawRectangle(rect.getTopLeft(), rect.getWidth()*width, rect.getHeight()); }
//---------------------------------------------------------- void ofRectangle::growToInclude(const ofRectangle& rect){ float x0 = MIN(getMinX(),rect.getMinX()); float x1 = MAX(getMaxX(),rect.getMaxX()); float y0 = MIN(getMinY(),rect.getMinY()); float y1 = MAX(getMaxY(),rect.getMaxY()); float w = x1 - x0; float h = y1 - y0; set(x0,y0,w,h); }
void KinectGrabber::setKinectROI(ofRectangle ROI){ minX = static_cast<int>(ROI.getMinX()); maxX = static_cast<int>(ROI.getMaxX()); minY = static_cast<int>(ROI.getMinY()); maxY = static_cast<int>(ROI.getMaxY()); ROIwidth = maxX-minX; ROIheight = maxY-minY; resetBuffers(); }
//-------------------------------------------------------------- void center(const ofRectangle& rect, int angle) { if (angle % 2 == 0) { ofTranslate(ofGetWidth() * 0.5f - rect.getWidth() * 0.5f, ofGetHeight() * 0.5f - rect.getHeight() * 0.5f); } else { ofTranslate(ofGetWidth() * 0.5f - rect.getHeight() * 0.5f, ofGetHeight() * 0.5f - rect.getWidth() * 0.5f); } }
ClipperLib::IntRect Clipper::toClipper(const ofRectangle& rectangle, ClipperLib::cInt scale) { ClipperLib::IntRect rect; rect.left = rectangle.getLeft() * scale; rect.right = rectangle.getRight() * scale; rect.top = rectangle.getTop() * scale; rect.bottom = rectangle.getBottom() * scale; return rect; }
void yeseulCooperMessages::animateText(ofRectangle rec1, ofRectangle rec2) { ofRotate(315+rotation); ofSetColor(ofColor::fromHsb(7, 255, 100)); ofFill(); for (int n = 0; n < 3; n++) { font.drawStringAsShapes(text1, dimensions.width/2+margin-redMove*1.2, -rec1.getHeight()); font.drawStringAsShapes(text2, dimensions.width/2+margin-redMove*1.1, 0); font.drawStringAsShapes(text1, 0-dimensions.width/2-rec1.getWidth()-margin+redMove*1.6, rec1.getHeight()); font.drawStringAsShapes(text2, 0-dimensions.width/2-rec2.getWidth()-margin-50+redMove*1.4, rec2.getHeight()*2); } ofRotate(90); ofSetColor(ofColor::fromHsb(90, 255, 20)); ofFill(); for (int n = 0; n < 3; n++) { font.drawStringAsShapes(text1, dimensions.width/2+margin-greenMove, -rec1.getHeight()); font.drawStringAsShapes(text2, dimensions.width/2+margin-greenMove, 0); font.drawStringAsShapes(text1, 0-dimensions.width/2-rec1.getWidth()-margin+greenMove, rec1.getHeight()); font.drawStringAsShapes(text2, 0-dimensions.width/2-rec2.getWidth()-margin+greenMove, rec2.getHeight()*2); } ofRotate(90); ofSetColor(ofColor::fromHsb(200, 255, 20)); ofFill(); for (int n = 0; n < 3; n++) { font.drawStringAsShapes(text1, 0-dimensions.width/2-margin-rec1.getWidth()-150+purpleMove*1.7, rec1.getHeight()); font.drawStringAsShapes(text2, 0-dimensions.width/2-margin-rec2.getWidth()-150+purpleMove*1.5, rec2.getHeight()*2); font.drawStringAsShapes(text1, dimensions.width/2+margin-purpleMove-70, -rec1.getHeight()); font.drawStringAsShapes(text2, dimensions.width/2+margin-purpleMove*1.4, 0); // } }
/* ** ofxMultiScope */ ofxMultiScope::ofxMultiScope(int numScopes, ofRectangle scopeArea, ofTrueTypeFont legendFont, int legendWidth, ofColor outlineColor, ofColor zeroLineColor, ofColor backgroundColor) { _min = scopeArea.getTopLeft(); _max = scopeArea.getBottomRight(); _numScopes = numScopes; scopes.resize(_numScopes); for (int i=0; i<_numScopes; i++) { ofPoint sMin(_min.x, _min.y + i*(_max.y - _min.y)/_numScopes); ofPoint sMax(_max.x, _min.y + (i+1)*(_max.y - _min.y)/_numScopes); scopes.at(i) = ofxOscilloscope(sMin, sMax, legendFont, legendWidth, outlineColor, zeroLineColor); } }
//-------------------------------------------------------------- void pbPushRect( const ofPoint &p1, const ofPoint &p2, const ofPoint &p3, const ofPoint &p4, const ofRectangle &texRect, vector<ofPoint> &points, vector<ofVec2f> &texs ) { points.push_back( p1 ); points.push_back( p2 ); points.push_back( p3 ); points.push_back( p4 ); texs.push_back( texRect.getTopLeft() ); texs.push_back( texRect.getTopRight() ); texs.push_back( texRect.getBottomRight() ); texs.push_back( texRect.getBottomLeft() ); }
ofRectangle ofRectangleTransform(const ofRectangle & rect, const ofMatrix4x4 & mat) { ofVec3f tl = rect.getTopLeft(); ofVec3f br = rect.getBottomRight(); tl = mat.preMult(tl); br = mat.preMult(br); ofRectangle r; r.setPosition(tl); r.growToInclude(br); return r; }
//-------------------------------------------------------------- //текстурированные прямоугольники void pbPushRect( const ofPoint &p, const ofPoint &w, const ofPoint &h, const ofRectangle &texRect, vector<ofPoint> &points, vector<ofVec2f> &texs ) { points.push_back( p ); points.push_back( p + w ); points.push_back( p + w + h ); points.push_back( p + h ); texs.push_back( texRect.getTopLeft() ); texs.push_back( texRect.getTopRight() ); texs.push_back( texRect.getBottomRight() ); texs.push_back( texRect.getBottomLeft() ); }
void LaserGroup::normalize(const ofRectangle& boundingBox) { for(auto laser: m_lasers) { ofPoint pos = laser->getPosition(); pos.x = (pos.x - boundingBox.getX()) / boundingBox.getWidth(); pos.y = (pos.y - boundingBox.getY()) / boundingBox.getHeight(); pos.y = 1 - pos.y; laser->setPosition(pos); //ofLogNotice() <<"LaserGroup::normalize -> id " << getId()<< ", channel = " << getChannel() << ", x = " << laser->getPosition().x << ", y = " << laser->getPosition().y << ", z = " << laser->getPosition().z ; } }
void Communitas::init(ofRectangle _space){ ofPoint center = ofPoint(_space.getCenter().x * width,_space.getCenter().y * height); space.setFromCenter(center, MIN(width, height), MIN(width, height)); // Allocate the fbo and clean it // fbo.allocate(width, height); fbo.begin(); ofClear(0,0); fbo.end(); fade = 1.0f; blur.allocate(width, height); blur.setFade(fade); blur.setPasses(5); universe.set(space); nucle.set(space); universe.mass = 0.75f; universe.vortex = space.height*0.1f; universe.maxDistance = space.height*0.4f; //universe.density = 0.4f; universe.ph = 6.5f; universe.joinParticles = true; universe.correctOrbits = true; universe.proportional = true; universe.clockwise = true; //universe.impulse = 0.4f; universe.angle = 0.0f; nucle.mass = 10.0f; nucle.vortex = space.height*0.1; nucle.maxDistance = space.height*0.1; nucle.density = 1.0f; //= 0.05; nucle.ph = 7.0f; //= 6.9; nucle.joinParticles = true; nucle.correctOrbits = false;// = true; nucle.proportional = false; nucle.clockwise = false; nucle.impulse = 0.19f; nucle.angle = 0.0f; //= -25; reset(); }
void ofxParticleSystem::applyVectorField(float * field, int fieldWidth, int fieldHeight, int numComponents, ofRectangle areaOfInfluence, float force) { for(list<ofxParticle*>::iterator it = particles.begin(); it != particles.end(); it++){ ofxParticle & p = (**it); ofVec2f pos(p.position.x,p.position.y); if(areaOfInfluence.inside(pos)){ int x = (int)ofMap(pos.x, areaOfInfluence.getMinX(), areaOfInfluence.getMaxX(), 0, fieldWidth-1); int y = (int)ofMap(pos.y, areaOfInfluence.getMinY(), areaOfInfluence.getMaxY(), 0, fieldHeight-1); int index = (x+y*fieldWidth)*numComponents; ofVec2f dir(field[index],field[index+1]); dir.scale(force); // cout << "(" << dir.x << "," << dir.y << ")\n"; p.applyForce(dir); } } }
//-------------------------------------------------------------- void pbPushRect( float x, float y, float z, float w, float h, const ofRectangle &texRect, vector<ofPoint> &points, vector<ofVec2f> &texs ) { points.push_back( ofPoint( x, y, z ) ); points.push_back( ofPoint( x + w, y, z ) ); points.push_back( ofPoint( x + w, y + h, z ) ); points.push_back( ofPoint( x, y + h, z ) ); texs.push_back( texRect.getTopLeft() ); texs.push_back( texRect.getTopRight() ); texs.push_back( texRect.getBottomRight() ); texs.push_back( texRect.getBottomLeft() ); }
DrawGame::GUIDataSlot::GUIDataSlot( ofParameter<float>& p, ofParameter<float>& pmax, string tag, string title, ofRectangle R, float TitleWdRatio, ofTrueTypeFont* font, float MaxValue, float BarEdgeWidth, ofColor CrTxt, ofColor CrBarEmpty, ofColor CrBarFill, ofColor CrBarEdge): dataSrc(&p), dataMaxSrc(&pmax), GUIBase(tag), pFont(font), Title(title), maxVal(MaxValue), titleWdRatio(TitleWdRatio), edgeWd(BarEdgeWidth), CrText(CrTxt), CrBG(CrBarEmpty), CrFill(CrBarFill), CrEdge(CrBarEdge) { if(Crs.size()==0) { ofColor defCrs[10] = { ofColor::yellow, ofColor::green, ofColor::darkGreen, ofColor::skyBlue, ofColor::cyan, ofColor::blue, ofColor::blueViolet, ofColor::violet, ofColor::chocolate, ofColor::black}; for(int i=0;i<10;i++) { Crs.push_back(defCrs[i]); } } Rect.setFromCenter(ofVec2f(0,0),R.getWidth(),R.getHeight()); ofNode::setPosition(R.getCenter()); }
void mousePressed(int x, int y, int button) { x /= globalScale; y /= globalScale; canvas.mousePressed(x, y, button); side.mousePressed(x, y, button); // cout << btnHelpPos.distance(ofPoint(x,y)) << endl; if (btnHelpPos.distance(ofPoint(x,y))<btnHelp.width/2) showHelp(); if (btnNew.hitTest(x,y)) { files.cur=-1; canvas.clear(); files.unloadFile(); } if (btnSave.hitTest(x,y)) files.save(); if (btnLoadPrevious.hitTest(x,y)) files.loadPrevious(); if (btnLoadNext.hitTest(x,y)) files.loadNext(); if (btnPrint.hitTest(x,y)) print(); if (btnStop.hitTest(x,y)) stop(); if (btnOops.hitTest(x,y)) { btnOops.selected=true; } if (btnZoomIn.hitTest(x,y)) btnZoomIn.selected=true; if (btnZoomOut.hitTest(x,y)) btnZoomOut.selected=true; if (btnHigher.hitTest(x,y)) btnHigher.selected=true; if (btnLower.hitTest(x,y)) btnLower.selected=true; if (btnTwistLeft.hitTest(x,y)) btnTwistLeft.selected=true; if (btnTwistRight.hitTest(x,y)) btnTwistRight.selected=true; if (shapeButtons.inside(x,y)) { int index = ofNormalize(x,shapeButtons.x,shapeButtons.x+shapeButtons.width) * shapeString.size(); side.setShape(shapeString.at(index)); } }