//--------------------------------------------------------------
void ofxMtlMapping2D::init(int width, int height, string mappingXmlFilePath, string uiXmlFilePath)
{
    // The first we call ofxMtlMapping2DControls::mapping2DControls() we pass the xml file to use as param.
    ofxMtlMapping2DControls::mapping2DControls(uiXmlFilePath)->disable();
    
    // ----
    _fbo.allocate(width, height, GL_RGBA);

    // ----
    ofxMtlMapping2DSettings::infoFont.loadFont("mapping/controls/ReplicaBold.ttf", 10);
    
    // ----
    _mappingXmlFilePath = mappingXmlFilePath;
    loadShapesList();
    
}
Exemple #2
0
//--------------------------------------------------------------
void ofxMtlMapping2D::update()
{
    ofxMtlMapping2DControls::mapping2DControls()->update();
    
    // ---- save mapping to xml
    if(ofxMtlMapping2DControls::mapping2DControls()->saveMapping()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetSaveMapping();
        saveShapesList();
    }
    
    
    // ---- load mapping from xml
    if(ofxMtlMapping2DControls::mapping2DControls()->loadMapping()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetLoadMapping();
        loadShapesList();
    }
    
    
    
    // ----
    // Editing or not !?
    if(!ofxMtlMapping2DControls::mapping2DControls()->editShapes())
        return;
    
    
    // ----
    // Create a new shape
    if(ofxMtlMapping2DControls::mapping2DControls()->createNewQuad()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape();
        createQuad(1020/2, 720/2);
        return;
    }
    
    if(ofxMtlMapping2DControls::mapping2DControls()->createNewGrid()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape();
        createGrid(1020/2, 720/2);
        return;
    }
    
    if(ofxMtlMapping2DControls::mapping2DControls()->createNewTriangle()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape();
        createTriangle(1020/2, 720/2);
        return;
    }
    
    if(ofxMtlMapping2DControls::mapping2DControls()->createNewMask()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape();
        createMask(1020/2, 720/2);
        return;
    }
    
    // ----
    // Selected shape with UI
    if(ofxMtlMapping2DControls::mapping2DControls()->selectedShapeChanged()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetSelectedShapeChangedFlag();

        list<ofxMtlMapping2DShape*>::iterator it = iteratorForShapeWithId(ofxMtlMapping2DControls::mapping2DControls()->selectedShapeId());
        if(it != ofxMtlMapping2DShapes::pmShapes.end()) {
            ofxMtlMapping2DShape* shape = *it;
            shape->setAsActiveShape(true);
            
            // Put active shape at the top of the list
            ofxMtlMapping2DShapes::pmShapes.push_front(shape);
            ofxMtlMapping2DShapes::pmShapes.erase(it);
        }
    }

    
    // ----
    // We changed of mode - Output / Input
    if(ofxMtlMapping2DControls::mapping2DControls()->mappingModeChanged()) {
        ofxMtlMapping2DControls::mapping2DControls()->resetMappingChangedFlag();        
        
        // ---- OUTPUT MODE
        if(ofxMtlMapping2DControls::mapping2DControls()->mappingMode() == MAPPING_MODE_OUTPUT) {
            list<ofxMtlMapping2DShape*>::iterator it;
            for (it=ofxMtlMapping2DShapes::pmShapes.begin(); it!=ofxMtlMapping2DShapes::pmShapes.end(); it++) {
                ofxMtlMapping2DShape* shape = *it;
                shape->enable();
                
                if(shape->inputPolygon) {
                    // If this Shape is textured and has an 'inputPolygon'
                    shape->inputPolygon->setAsIdle();
                }
            }
        // ---- INPUT MODE
        } else if (ofxMtlMapping2DControls::mapping2DControls()->mappingMode() == MAPPING_MODE_INPUT) {
            list<ofxMtlMapping2DShape*>::iterator it;
            for (it=ofxMtlMapping2DShapes::pmShapes.begin(); it!=ofxMtlMapping2DShapes::pmShapes.end(); it++) {
                ofxMtlMapping2DShape* shape = *it;
                shape->setAsIdle();
                shape->inputPolygon->enable();
            }
        }
    
    }
    
    // ----
    // Update the Shapes
    list<ofxMtlMapping2DShape*>::iterator it;
    for (it=ofxMtlMapping2DShapes::pmShapes.begin(); it!=ofxMtlMapping2DShapes::pmShapes.end(); it++) {
        ofxMtlMapping2DShape* shape = *it;
        shape->update();
    }
}
Exemple #3
0
//--------------------------------------------------------------
void ofxMtlMapping2D::keyPressed(int key)
{
    // ----
    switch (key) {
        case 9:  // TAB
            //ofToggleFullscreen();
            break;
            
        case 'l':
            loadShapesList();
            break;
            
        case 'm':
            //ofxMtlMapping2DControls::mapping2DControls()->toggle();
            break;
            
        case 's':
            ofxMtlMapping2DControls::mapping2DControls()->save();
            saveShapesList();
            break;
            
        case 356:
            //left
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->left();
                }
            }
            break;
                
        case 357: //up
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->up();
                }
            }
            break;
        
        case 358: //right
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->right();
                }
            }
            break;
                
        case 359: //down
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->down();
                }
            }
            break;
            
        case 127:
            deleteShape();
            break;
            
        case 8:
            //deleteShape();
            break;
            
//        case 'b':
//            if ((ofxMtlMapping2DShape::activeShapeId + 1) >= ofxMtlMapping2DShapes::pmShapes.size()) {
//                ofxMtlMapping2DShapes::pmShapes[0]->setAsActiveShape();
//            } else {
//                ofxMtlMapping2DShapes::pmShapes[(ofxMtlMapping2DShape::activeShapeId + 1)]->setAsActiveShape();
//            }
//        break;

            
        case 'n':
            /*if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape) {
                    ofxMtlMapping2DShape::activeVertexId++;
                    ofxMtlMapping2DShape::activeVertexId %= ofxMtlMapping2DShape::activeShape->vertices.size();
                    
                    //-----
                    if (ofxMtlMapping2DShape::activeShape->vertices.size() > ofxMtlMapping2DShape::activeVertexId)
                    {
                        list<ofxMtlMapping2DVertex*>::iterator it = ofxMtlMapping2DShape::activeShape->vertices.begin();
                        advance(it, ofxMtlMapping2DShape::activeVertexId);
                        ofxMtlMapping2DVertex* vertex = *it;
                        vertex->setAsActive();
                    }
                }
            }*/
            break;
    }
}